author  kleing 
Wed, 25 May 2005 10:43:15 +0200  
changeset 16074  9e569163ba8c 
parent 16071  e0136cdef722 
child 16077  c04f972bfabe 
permissions  rwrr 
16033
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

1 
(* Title: Pure/Isar/find_theorems.ML 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

2 
ID: $Id$ 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

3 
Author: Rafal Kolanski, NICTA and Tobias Nipkow, TU Muenchen 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

4 

f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

5 
Retrieve theorems from proof context. 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

6 
*) 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

7 

f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

8 
val thms_containing_limit = ref 40; 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

9 

f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

10 
signature FIND_THEOREMS = 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

11 
sig 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

12 
val find_thms: Proof.context > FactIndex.spec > (thmref * thm) list 
16036  13 
datatype 'term criterion = 
16074  14 
Name of string  Intro  Elim  Dest  Simp of 'term  Pattern of 'term 
16033
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

15 
val print_theorems: Proof.context > term option > int option > 
16036  16 
(bool * string criterion) list > unit 
16033
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

17 
end; 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

18 

f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

19 
structure FindTheorems: FIND_THEOREMS = 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

20 
struct 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

21 

f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

22 

f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

23 
(* find_thms *) 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

24 

f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

25 
fun find_thms ctxt spec = 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

26 
(PureThy.thms_containing (ProofContext.theory_of ctxt) spec @ 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

27 
ProofContext.lthms_containing ctxt spec) 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

28 
> map PureThy.selections > List.concat; 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

29 

f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

30 

f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

31 
(* matching theorems *) 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

32 

f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

33 
local 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

34 

f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

35 
(*returns all those facts whose subterm extracted by extract can be 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

36 
instantiated to obj; the list is sorted according to the number of premises 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

37 
and the size of the required substitution*) 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

38 
fun select_match (extract_thms, extract_term) ctxt obj facts = 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

39 
let 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

40 
val match = #2 o Pattern.match (Sign.tsig_of (ProofContext.sign_of ctxt)); 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

41 

f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

42 
fun match_size pat = 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

43 
let val subst = match (pat, obj) (*exception Pattern.MATCH*) 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

44 
in SOME (Vartab.foldl (op + o apsnd (Term.size_of_term o #2 o #2)) (0, subst)) end 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

45 
handle Pattern.MATCH => NONE; 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

46 

f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

47 
fun select (fact as (_, thm)) = 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

48 
let 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

49 
fun first_match (th :: ths) res = 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

50 
(case match_size (extract_term (Thm.prop_of th)) of 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

51 
SOME s => ((Thm.nprems_of th, s), fact) :: res 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

52 
 NONE => first_match ths res) 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

53 
 first_match [] res = res; 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

54 
in first_match (extract_thms thm) end; 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

55 

f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

56 
fun thm_ord (((p0, s0), _), ((p1, s1), _)) = 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

57 
prod_ord (int_ord o pairself (fn 0 => 0  x => 1)) int_ord ((p0, s0), (p1, s1)); 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

58 
in 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

59 
fold select facts [] 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

60 
> Library.sort thm_ord > map #2 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

61 
end; 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

62 

f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

63 
(*speed up retrieval by checking head symbol*) 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

64 
fun index_head ctxt prop = 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

65 
(case Term.head_of (ObjectLogic.drop_judgment (ProofContext.sign_of ctxt) prop) of 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

66 
Const (c, _) => ([c], []) 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

67 
 Free (x, _) => if ProofContext.is_known ctxt x then ([], [x]) else ([], []) 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

68 
 _ => ([], [])); 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

69 

f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

70 
in 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

71 

f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

72 
fun find_matching_thms extract ctxt prop = 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

73 
find_thms ctxt (index_head ctxt prop) 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

74 
> select_match extract ctxt prop; 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

75 

f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

76 
fun is_matching_thm extract ctxt prop fact = 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

77 
not (null (select_match extract ctxt prop [fact])); 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

78 

f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

79 
end; 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

80 

f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

81 

f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

82 

f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

83 
(** search criteria **) 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

84 

16036  85 
datatype 'term criterion = 
16074  86 
Name of string  Intro  Elim  Dest  Simp of 'term  Pattern of 'term; 
16036  87 

88 
fun read_criterion _ (Name name) = Name name 

89 
 read_criterion _ Intro = Intro 

90 
 read_criterion _ Elim = Elim 

91 
 read_criterion _ Dest = Dest 

16074  92 
 read_criterion ctxt (Simp str) = Simp (ProofContext.read_term ctxt str) 
16036  93 
 read_criterion ctxt (Pattern str) = 
94 
Pattern (hd (ProofContext.read_term_pats TypeInfer.logicT ctxt [str])); 

16033
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

95 

16036  96 
fun pretty_criterion ctxt (b, c) = 
97 
let 

98 
fun prfx s = if b then s else "" ^ s; 

99 
in 

100 
(case c of 

101 
Name name => Pretty.str (prfx "name: " ^ quote name) 

102 
 Intro => Pretty.str (prfx "intro") 

103 
 Elim => Pretty.str (prfx "elim") 

104 
 Dest => Pretty.str (prfx "dest") 

16074  105 
 Simp t => Pretty.block [Pretty.str (prfx "simp:"), Pretty.brk 1, 
16036  106 
Pretty.quote (ProofContext.pretty_term ctxt t)] 
107 
 Pattern pat => Pretty.enclose (prfx " \"") "\"" 

108 
[ProofContext.pretty_term ctxt (Term.show_dummy_patterns pat)]) 

109 
end; 

16033
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

110 

f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

111 

f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

112 

f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

113 
(** search criterion filters **) 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

114 

f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

115 
(* filter_name *) 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

116 

f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

117 
fun is_substring pat str = 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

118 
if String.size pat = 0 then true 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

119 
else if String.size pat > String.size str then false 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

120 
else if String.substring (str, 0, String.size pat) = pat then true 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

121 
else is_substring pat (String.extract (str, 1, NONE)); 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

122 

f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

123 
(*filter that just looks for a string in the name, 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

124 
substring match only (no regexps are performed)*) 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

125 
fun filter_name str_pat ((name, _), _) = is_substring str_pat name; 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

126 

f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

127 

16036  128 
(* filter intro/elim/dest rules *) 
16033
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

129 

16036  130 
local 
131 

132 
(*elimination rule: conclusion is a Var which does not appear in the major premise*) 

133 
fun is_elim ctxt thm = 

16033
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

134 
let 
16036  135 
val sg = ProofContext.sign_of ctxt; 
136 
val prop = Thm.prop_of thm; 

137 
val concl = ObjectLogic.drop_judgment sg (Logic.strip_imp_concl prop); 

138 
val major_prem = Library.take (1, Logic.strip_imp_prems prop); 

139 
val prem_vars = Drule.vars_of_terms major_prem; 

140 
in 

141 
not (null major_prem) andalso 

142 
Term.is_Var concl andalso 

143 
not (Term.dest_Var concl mem prem_vars) 

144 
end; 

16033
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

145 

f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

146 
fun filter_elim_dest check_thm ctxt goal = 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

147 
let 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

148 
val extract_elim = 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

149 
(fn thm => if Thm.no_prems thm then [] else [thm], 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

150 
hd o Logic.strip_imp_prems); 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

151 
val prems = Logic.prems_of_goal goal 1; 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

152 
in 
16036  153 
fn fact => prems > List.exists (fn prem => 
154 
is_matching_thm extract_elim ctxt prem fact 

155 
andalso (check_thm ctxt) (#2 fact)) 

16033
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

156 
end; 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

157 

16036  158 
in 
159 

160 
fun filter_intro ctxt goal = 

16033
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

161 
let 
16036  162 
val extract_intro = (single, Logic.strip_imp_concl); 
163 
val concl = Logic.concl_of_goal goal 1; 

16033
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

164 
in 
16036  165 
fn fact => is_matching_thm extract_intro ctxt concl fact 
166 
andalso not (is_elim ctxt (#2 fact)) 

16033
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

167 
end; 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

168 

16036  169 
fun filter_elim ctxt = filter_elim_dest is_elim ctxt; 
170 
fun filter_dest ctxt = filter_elim_dest (not oo is_elim) ctxt; 

171 

172 
end; 

173 

16033
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

174 

16074  175 
(* filter_simp *) 
16033
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

176 

16074  177 
fun filter_simp ctxt t = 
16033
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

178 
let 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

179 
val (_, {mk_rews = {mk, ...}, ...}) = 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

180 
MetaSimplifier.rep_ss (Simplifier.local_simpset_of ctxt); 
16074  181 
val extract_simp = (mk, #1 o Logic.dest_equals o Logic.strip_imp_concl); 
182 
in is_matching_thm extract_simp ctxt t end; 

16033
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

183 

f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

184 

f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

185 
(* filter_pattern *) 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

186 

16036  187 
fun filter_pattern ctxt pat = 
188 
let val tsig = Sign.tsig_of (ProofContext.sign_of ctxt) 

16033
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

189 
in fn (_, thm) => Pattern.matches_subterm tsig (pat, Thm.prop_of thm) end; 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

190 

f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

191 

f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

192 
(* interpret criteria as filters *) 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

193 

16036  194 
local 
195 

196 
fun err_no_goal c = 

197 
error ("Current goal required for " ^ c ^ " search criterion"); 

198 

16033
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

199 
fun filter_crit _ _ (Name name) = filter_name name 
16036  200 
 filter_crit _ NONE Intro = err_no_goal "intro" 
201 
 filter_crit _ NONE Elim = err_no_goal "elim" 

202 
 filter_crit _ NONE Dest = err_no_goal "dest" 

203 
 filter_crit ctxt (SOME goal) Intro = filter_intro ctxt goal 

204 
 filter_crit ctxt (SOME goal) Elim = filter_elim ctxt goal 

205 
 filter_crit ctxt (SOME goal) Dest = filter_dest ctxt goal 

16074  206 
 filter_crit ctxt _ (Simp str) = filter_simp ctxt str 
16036  207 
 filter_crit ctxt _ (Pattern str) = filter_pattern ctxt str; 
208 

209 
in 

16033
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

210 

f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

211 
fun filter_criterion ctxt opt_goal (b, c) = 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

212 
(if b then I else not) o filter_crit ctxt opt_goal c; 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

213 

f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

214 
fun all_filters filters = List.filter (fn x => List.all (fn f => f x) filters); 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

215 

16036  216 
end; 
217 

16033
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

218 

f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

219 
(* print_theorems *) 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

220 

16036  221 
fun print_theorems ctxt opt_goal opt_limit raw_criteria = 
16033
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

222 
let 
16036  223 
val criteria = map (apsnd (read_criterion ctxt)) raw_criteria; 
224 
val filters = map (filter_criterion ctxt opt_goal) criteria; 

16033
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

225 

16036  226 
val matches = all_filters filters (find_thms ctxt ([], [])); 
16033
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

227 
val len = length matches; 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

228 
val limit = if_none opt_limit (! thms_containing_limit); 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

229 

16036  230 
fun prt_fact (thmref, thm) = 
231 
ProofContext.pretty_fact ctxt (PureThy.string_of_thmref thmref, [thm]); 

16033
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

232 
in 
16036  233 
Pretty.big_list "searched for:" (map (pretty_criterion ctxt) criteria) :: Pretty.str "" :: 
16033
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

234 
(if null matches then [Pretty.str "nothing found"] 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

235 
else 
16036  236 
[Pretty.str ("found " ^ string_of_int len ^ " theorems" ^ 
237 
(if len <= limit then "" else " (" ^ string_of_int limit ^ " displayed)") ^ ":"), 

238 
Pretty.str ""] @ 

239 
map prt_fact (Library.drop (len  limit, matches))) 

16033
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

240 
> Pretty.chunks > Pretty.writeln 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

241 
end; 
f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

242 

f93ca3d4ffa7
Retrieve theorems from proof context  improved version of
wenzelm
parents:
diff
changeset

243 
end; 