author | wenzelm |
Fri, 26 Jul 2002 21:09:39 +0200 | |
changeset 13425 | 119ae829ad9b |
parent 13415 | 63462ccc6fac |
child 13596 | ee5f79b210c1 |
permissions | -rw-r--r-- |
5820 | 1 |
(* Title: Pure/Isar/proof.ML |
2 |
ID: $Id$ |
|
3 |
Author: Markus Wenzel, TU Muenchen |
|
8807 | 4 |
License: GPL (GNU GENERAL PUBLIC LICENSE) |
5820 | 5 |
|
6 |
Proof states and methods. |
|
7 |
*) |
|
8 |
||
8152 | 9 |
signature BASIC_PROOF = |
10 |
sig |
|
8374 | 11 |
val FINDGOAL: (int -> thm -> 'a Seq.seq) -> thm -> 'a Seq.seq |
12 |
val HEADGOAL: (int -> thm -> 'a Seq.seq) -> thm -> 'a Seq.seq |
|
8152 | 13 |
end; |
14 |
||
5820 | 15 |
signature PROOF = |
16 |
sig |
|
8152 | 17 |
include BASIC_PROOF |
5820 | 18 |
type context |
19 |
type state |
|
20 |
exception STATE of string * state |
|
6871 | 21 |
val check_result: string -> state -> 'a Seq.seq -> 'a Seq.seq |
12045 | 22 |
val init_state: theory -> state |
5820 | 23 |
val context_of: state -> context |
24 |
val theory_of: state -> theory |
|
25 |
val sign_of: state -> Sign.sg |
|
13377 | 26 |
val map_context: (context -> context) -> state -> state |
7924 | 27 |
val warn_extra_tfrees: state -> state -> state |
7605 | 28 |
val reset_thms: string -> state -> state |
6091 | 29 |
val the_facts: state -> thm list |
9469 | 30 |
val the_fact: state -> thm |
11079
a378479996f7
val get_goal: state -> context * (thm list * thm);
wenzelm
parents:
10938
diff
changeset
|
31 |
val get_goal: state -> context * (thm list * thm) |
6091 | 32 |
val goal_facts: (state -> thm list) -> state -> state |
5820 | 33 |
val use_facts: state -> state |
34 |
val reset_facts: state -> state |
|
9469 | 35 |
val is_chain: state -> bool |
6891 | 36 |
val assert_forward: state -> state |
9469 | 37 |
val assert_forward_or_chain: state -> state |
5820 | 38 |
val assert_backward: state -> state |
8206 | 39 |
val assert_no_chain: state -> state |
5820 | 40 |
val enter_forward: state -> state |
6529 | 41 |
val verbose: bool ref |
12423 | 42 |
val pretty_state: int -> state -> Pretty.T list |
10360 | 43 |
val pretty_goals: bool -> state -> Pretty.T list |
6776 | 44 |
val level: state -> int |
5820 | 45 |
type method |
6848 | 46 |
val method: (thm list -> tactic) -> method |
8374 | 47 |
val method_cases: (thm list -> thm -> (thm * (string * RuleCases.T) list) Seq.seq) -> method |
5820 | 48 |
val refine: (context -> method) -> state -> state Seq.seq |
8234 | 49 |
val refine_end: (context -> method) -> state -> state Seq.seq |
5936 | 50 |
val match_bind: (string list * string) list -> state -> state |
51 |
val match_bind_i: (term list * term) list -> state -> state |
|
8617
33e2bd53aec3
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8582
diff
changeset
|
52 |
val let_bind: (string list * string) list -> state -> state |
33e2bd53aec3
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8582
diff
changeset
|
53 |
val let_bind_i: (term list * term) list -> state -> state |
6876 | 54 |
val simple_have_thms: string -> thm list -> state -> state |
12714 | 55 |
val have_thmss: ((bstring * context attribute list) * |
56 |
(xstring * context attribute list) list) list -> state -> state |
|
57 |
val have_thmss_i: ((bstring * context attribute list) * |
|
9196 | 58 |
(thm list * context attribute list) list) list -> state -> state |
12714 | 59 |
val with_thmss: ((bstring * context attribute list) * |
60 |
(xstring * context attribute list) list) list -> state -> state |
|
61 |
val with_thmss_i: ((bstring * context attribute list) * |
|
9196 | 62 |
(thm list * context attribute list) list) list -> state -> state |
12930 | 63 |
val using_thmss: ((xstring * context attribute list) list) list -> state -> state |
64 |
val using_thmss_i: ((thm list * context attribute list) list) list -> state -> state |
|
7412 | 65 |
val fix: (string list * string option) list -> state -> state |
7665 | 66 |
val fix_i: (string list * typ option) list -> state -> state |
9469 | 67 |
val assm: ProofContext.exporter |
10464 | 68 |
-> ((string * context attribute list) * (string * (string list * string list)) list) list |
7271 | 69 |
-> state -> state |
9469 | 70 |
val assm_i: ProofContext.exporter |
10464 | 71 |
-> ((string * context attribute list) * (term * (term list * term list)) list) list |
6932 | 72 |
-> state -> state |
10464 | 73 |
val assume: |
74 |
((string * context attribute list) * (string * (string list * string list)) list) list |
|
7271 | 75 |
-> state -> state |
10464 | 76 |
val assume_i: ((string * context attribute list) * (term * (term list * term list)) list) list |
6932 | 77 |
-> state -> state |
10464 | 78 |
val presume: |
79 |
((string * context attribute list) * (string * (string list * string list)) list) list |
|
6932 | 80 |
-> state -> state |
10464 | 81 |
val presume_i: ((string * context attribute list) * (term * (term list * term list)) list) list |
6932 | 82 |
-> state -> state |
11891 | 83 |
val def: string -> context attribute list -> string * (string * string list) -> state -> state |
84 |
val def_i: string -> context attribute list -> string * (term * term list) -> state -> state |
|
11793
5f0ab6f5c280
support impromptu terminology of cases parameters;
wenzelm
parents:
11742
diff
changeset
|
85 |
val invoke_case: string * string option list * context attribute list -> state -> state |
12959 | 86 |
val multi_theorem: string |
87 |
-> (xstring * (context attribute list * context attribute list list)) option |
|
88 |
-> bstring * theory attribute list -> context attribute Locale.element list |
|
12146 | 89 |
-> ((bstring * theory attribute list) * (string * (string list * string list)) list) list |
90 |
-> theory -> state |
|
12959 | 91 |
val multi_theorem_i: string |
92 |
-> (string * (context attribute list * context attribute list list)) option |
|
93 |
-> bstring * theory attribute list |
|
94 |
-> context attribute Locale.element_i list |
|
12146 | 95 |
-> ((bstring * theory attribute list) * (term * (term list * term list)) list) list |
96 |
-> theory -> state |
|
5820 | 97 |
val chain: state -> state |
6091 | 98 |
val from_facts: thm list -> state -> state |
12971 | 99 |
val show: (bool -> state -> state) -> (state -> state Seq.seq) -> bool |
12146 | 100 |
-> ((string * context attribute list) * (string * (string list * string list)) list) list |
101 |
-> bool -> state -> state |
|
12971 | 102 |
val show_i: (bool -> state -> state) -> (state -> state Seq.seq) -> bool |
12146 | 103 |
-> ((string * context attribute list) * (term * (term list * term list)) list) list |
104 |
-> bool -> state -> state |
|
12971 | 105 |
val have: (state -> state Seq.seq) -> bool |
12146 | 106 |
-> ((string * context attribute list) * (string * (string list * string list)) list) list |
107 |
-> state -> state |
|
12971 | 108 |
val have_i: (state -> state Seq.seq) -> bool |
12146 | 109 |
-> ((string * context attribute list) * (term * (term list * term list)) list) list |
110 |
-> state -> state |
|
6404 | 111 |
val at_bottom: state -> bool |
6982 | 112 |
val local_qed: (state -> state Seq.seq) |
12146 | 113 |
-> (context -> string * (string * thm list) list -> unit) * (context -> thm -> unit) |
114 |
-> state -> state Seq.seq |
|
6950 | 115 |
val global_qed: (state -> state Seq.seq) -> state |
12244 | 116 |
-> (theory * ((string * string) * (string * thm list) list)) Seq.seq |
6896 | 117 |
val begin_block: state -> state |
6932 | 118 |
val end_block: state -> state Seq.seq |
6896 | 119 |
val next_block: state -> state |
5820 | 120 |
end; |
121 |
||
13377 | 122 |
structure Proof: PROOF = |
5820 | 123 |
struct |
124 |
||
125 |
||
126 |
(** proof state **) |
|
127 |
||
128 |
type context = ProofContext.context; |
|
129 |
||
130 |
||
131 |
(* type goal *) |
|
132 |
||
133 |
datatype kind = |
|
12959 | 134 |
Theorem of {kind: string, |
135 |
theory_spec: (bstring * theory attribute list) * theory attribute list list, |
|
13415 | 136 |
locale_spec: (string * (context attribute list * context attribute list list)) option, |
137 |
view: cterm list} | |
|
12959 | 138 |
Show of context attribute list list | |
139 |
Have of context attribute list list; |
|
5820 | 140 |
|
13415 | 141 |
fun kind_name _ (Theorem {kind = s, theory_spec = ((a, _), _), |
142 |
locale_spec = None, view = _}) = s ^ (if a = "" then "" else " " ^ a) |
|
13399
c136276dc847
support locale ``views'' (for cumulative predicates);
wenzelm
parents:
13377
diff
changeset
|
143 |
| kind_name sg (Theorem {kind = s, theory_spec = ((a, _), _), |
13415 | 144 |
locale_spec = Some (name, _), view = _}) = |
145 |
s ^ " (in " ^ Locale.cond_extern sg name ^ ")" ^ (if a = "" then "" else " " ^ a) |
|
12015 | 146 |
| kind_name _ (Show _) = "show" |
147 |
| kind_name _ (Have _) = "have"; |
|
5820 | 148 |
|
149 |
type goal = |
|
12146 | 150 |
(kind * (*result kind*) |
151 |
string list * (*result names*) |
|
152 |
term list list) * (*result statements*) |
|
153 |
(thm list * (*use facts*) |
|
154 |
thm); (*goal: subgoals ==> statement*) |
|
5820 | 155 |
|
156 |
||
157 |
(* type mode *) |
|
158 |
||
159 |
datatype mode = Forward | ForwardChain | Backward; |
|
7201 | 160 |
val mode_name = (fn Forward => "state" | ForwardChain => "chain" | Backward => "prove"); |
5820 | 161 |
|
162 |
||
163 |
(* datatype state *) |
|
164 |
||
7176 | 165 |
datatype node = |
166 |
Node of |
|
167 |
{context: context, |
|
168 |
facts: thm list option, |
|
169 |
mode: mode, |
|
12971 | 170 |
goal: (goal * ((state -> state Seq.seq) * bool)) option} |
7176 | 171 |
and state = |
5820 | 172 |
State of |
173 |
node * (*current*) |
|
174 |
node list; (*parents wrt. block structure*) |
|
175 |
||
7176 | 176 |
fun make_node (context, facts, mode, goal) = |
177 |
Node {context = context, facts = facts, mode = mode, goal = goal}; |
|
178 |
||
179 |
||
5820 | 180 |
exception STATE of string * state; |
181 |
||
182 |
fun err_malformed name state = |
|
183 |
raise STATE (name ^ ": internal error -- malformed proof state", state); |
|
184 |
||
6871 | 185 |
fun check_result msg state sq = |
186 |
(case Seq.pull sq of |
|
187 |
None => raise STATE (msg, state) |
|
188 |
| Some s_sq => Seq.cons s_sq); |
|
189 |
||
5820 | 190 |
|
7176 | 191 |
fun map_current f (State (Node {context, facts, mode, goal}, nodes)) = |
5820 | 192 |
State (make_node (f (context, facts, mode, goal)), nodes); |
193 |
||
12045 | 194 |
fun init_state thy = |
195 |
State (make_node (ProofContext.init thy, None, Forward, None), []); |
|
196 |
||
5820 | 197 |
|
198 |
||
199 |
(** basic proof state operations **) |
|
200 |
||
201 |
(* context *) |
|
202 |
||
7176 | 203 |
fun context_of (State (Node {context, ...}, _)) = context; |
5820 | 204 |
val theory_of = ProofContext.theory_of o context_of; |
205 |
val sign_of = ProofContext.sign_of o context_of; |
|
206 |
||
207 |
fun map_context f = map_current (fn (ctxt, facts, mode, goal) => (f ctxt, facts, mode, goal)); |
|
208 |
||
7176 | 209 |
fun map_context_result f (state as State (Node {context, facts, mode, goal}, nodes)) = |
5820 | 210 |
let val (context', result) = f context |
211 |
in (State (make_node (context', facts, mode, goal), nodes), result) end; |
|
212 |
||
213 |
||
7924 | 214 |
val warn_extra_tfrees = map_context o ProofContext.warn_extra_tfrees o context_of; |
10809 | 215 |
val add_binds_i = map_context o ProofContext.add_binds_i; |
6790 | 216 |
val auto_bind_goal = map_context o ProofContext.auto_bind_goal; |
12146 | 217 |
val auto_bind_facts = map_context o ProofContext.auto_bind_facts; |
6091 | 218 |
val put_thms = map_context o ProofContext.put_thms; |
219 |
val put_thmss = map_context o ProofContext.put_thmss; |
|
7605 | 220 |
val reset_thms = map_context o ProofContext.reset_thms; |
8374 | 221 |
val get_case = ProofContext.get_case o context_of; |
5820 | 222 |
|
223 |
||
224 |
(* facts *) |
|
225 |
||
7176 | 226 |
fun the_facts (State (Node {facts = Some facts, ...}, _)) = facts |
5820 | 227 |
| the_facts state = raise STATE ("No current facts available", state); |
228 |
||
9469 | 229 |
fun the_fact state = |
230 |
(case the_facts state of |
|
231 |
[thm] => thm |
|
232 |
| _ => raise STATE ("Single fact expected", state)); |
|
233 |
||
6848 | 234 |
fun assert_facts state = (the_facts state; state); |
7176 | 235 |
fun get_facts (State (Node {facts, ...}, _)) = facts; |
6848 | 236 |
|
7605 | 237 |
|
238 |
val thisN = "this"; |
|
239 |
||
5820 | 240 |
fun put_facts facts state = |
241 |
state |
|
242 |
|> map_current (fn (ctxt, _, mode, goal) => (ctxt, facts, mode, goal)) |
|
7605 | 243 |
|> (case facts of None => reset_thms thisN | Some ths => put_thms (thisN, ths)); |
5820 | 244 |
|
245 |
val reset_facts = put_facts None; |
|
246 |
||
9196 | 247 |
fun these_factss (state, named_factss) = |
13297 | 248 |
state |> put_facts (Some (flat (map snd named_factss))); |
5820 | 249 |
|
250 |
||
251 |
(* goal *) |
|
252 |
||
10553 | 253 |
local |
254 |
fun find i (state as State (Node {goal = Some goal, ...}, _)) = (context_of state, (i, goal)) |
|
255 |
| find i (State (Node {goal = None, ...}, node :: nodes)) = find (i + 1) (State (node, nodes)) |
|
256 |
| find _ (state as State (_, [])) = err_malformed "find_goal" state; |
|
257 |
in val find_goal = find 0 end; |
|
7176 | 258 |
|
11079
a378479996f7
val get_goal: state -> context * (thm list * thm);
wenzelm
parents:
10938
diff
changeset
|
259 |
fun get_goal state = |
a378479996f7
val get_goal: state -> context * (thm list * thm);
wenzelm
parents:
10938
diff
changeset
|
260 |
let val (ctxt, (_, ((_, x), _))) = find_goal state |
a378479996f7
val get_goal: state -> context * (thm list * thm);
wenzelm
parents:
10938
diff
changeset
|
261 |
in (ctxt, x) end; |
a378479996f7
val get_goal: state -> context * (thm list * thm);
wenzelm
parents:
10938
diff
changeset
|
262 |
|
5820 | 263 |
fun put_goal goal = map_current (fn (ctxt, facts, mode, _) => (ctxt, facts, mode, goal)); |
264 |
||
8374 | 265 |
fun map_goal f g (State (Node {context, facts, mode, goal = Some goal}, nodes)) = |
266 |
State (make_node (f context, facts, mode, Some (g goal)), nodes) |
|
267 |
| map_goal f g (State (nd, node :: nodes)) = |
|
268 |
let val State (node', nodes') = map_goal f g (State (node, nodes)) |
|
269 |
in map_context f (State (nd, node' :: nodes')) end |
|
270 |
| map_goal _ _ state = state; |
|
5820 | 271 |
|
272 |
fun goal_facts get state = |
|
273 |
state |
|
8374 | 274 |
|> map_goal I (fn ((result, (_, thm)), f) => ((result, (get state, thm)), f)); |
5820 | 275 |
|
276 |
fun use_facts state = |
|
277 |
state |
|
278 |
|> goal_facts the_facts |
|
279 |
|> reset_facts; |
|
280 |
||
281 |
||
282 |
(* mode *) |
|
283 |
||
7176 | 284 |
fun get_mode (State (Node {mode, ...}, _)) = mode; |
5820 | 285 |
fun put_mode mode = map_current (fn (ctxt, facts, _, goal) => (ctxt, facts, mode, goal)); |
286 |
||
287 |
val enter_forward = put_mode Forward; |
|
288 |
val enter_forward_chain = put_mode ForwardChain; |
|
289 |
val enter_backward = put_mode Backward; |
|
290 |
||
291 |
fun assert_mode pred state = |
|
292 |
let val mode = get_mode state in |
|
293 |
if pred mode then state |
|
12010 | 294 |
else raise STATE ("Illegal application of proof command in " |
295 |
^ quote (mode_name mode) ^ " mode", state) |
|
5820 | 296 |
end; |
297 |
||
298 |
fun is_chain state = get_mode state = ForwardChain; |
|
299 |
val assert_forward = assert_mode (equal Forward); |
|
300 |
val assert_forward_or_chain = assert_mode (equal Forward orf equal ForwardChain); |
|
301 |
val assert_backward = assert_mode (equal Backward); |
|
8206 | 302 |
val assert_no_chain = assert_mode (not_equal ForwardChain); |
5820 | 303 |
|
304 |
||
305 |
(* blocks *) |
|
306 |
||
6776 | 307 |
fun level (State (_, nodes)) = length nodes; |
308 |
||
5820 | 309 |
fun open_block (State (node, nodes)) = State (node, node :: nodes); |
310 |
||
311 |
fun new_block state = |
|
312 |
state |
|
313 |
|> open_block |
|
314 |
|> put_goal None; |
|
315 |
||
7487
c0f9b956a3e7
close_block: removed ProofContext.transfer_used_names;
wenzelm
parents:
7478
diff
changeset
|
316 |
fun close_block (state as State (_, node :: nodes)) = State (node, nodes) |
5820 | 317 |
| close_block state = raise STATE ("Unbalanced block parentheses", state); |
318 |
||
319 |
||
320 |
||
12423 | 321 |
(** pretty_state **) |
5820 | 322 |
|
6529 | 323 |
val verbose = ProofContext.verbose; |
324 |
||
12085 | 325 |
fun pretty_goals_local ctxt = Display.pretty_goals_aux |
326 |
(ProofContext.pretty_sort ctxt, ProofContext.pretty_typ ctxt, ProofContext.pretty_term ctxt); |
|
327 |
||
12055 | 328 |
fun pretty_facts _ _ None = [] |
329 |
| pretty_facts s ctxt (Some ths) = |
|
330 |
[Pretty.big_list (s ^ "this:") (map (ProofContext.pretty_thm ctxt) ths), Pretty.str ""]; |
|
6756 | 331 |
|
12423 | 332 |
fun pretty_state nr (state as State (Node {context = ctxt, facts, mode, goal = _}, nodes)) = |
5820 | 333 |
let |
11891 | 334 |
val ref (_, _, begin_goal) = Display.current_goals_markers; |
5820 | 335 |
|
336 |
fun levels_up 0 = "" |
|
7575 | 337 |
| levels_up 1 = ", 1 level up" |
338 |
| levels_up i = ", " ^ string_of_int i ^ " levels up"; |
|
5820 | 339 |
|
11556 | 340 |
fun subgoals 0 = "" |
341 |
| subgoals 1 = ", 1 subgoal" |
|
342 |
| subgoals n = ", " ^ string_of_int n ^ " subgoals"; |
|
12146 | 343 |
|
344 |
fun prt_names names = |
|
12242
282a92bc5655
multi_theorem: common statement header (covers *all* results);
wenzelm
parents:
12223
diff
changeset
|
345 |
(case filter_out (equal "") names of [] => "" |
12308 | 346 |
| nms => " " ^ enclose "(" ")" (space_implode " and " (take (7, nms) @ |
347 |
(if length nms > 7 then ["..."] else [])))); |
|
12146 | 348 |
|
349 |
fun prt_goal (_, (i, (((kind, names, _), (goal_facts, thm)), _))) = |
|
12085 | 350 |
pretty_facts "using " ctxt |
8462 | 351 |
(if mode <> Backward orelse null goal_facts then None else Some goal_facts) @ |
12146 | 352 |
[Pretty.str ("goal (" ^ kind_name (sign_of state) kind ^ prt_names names ^ |
353 |
levels_up (i div 2) ^ subgoals (Thm.nprems_of thm) ^ "):")] @ |
|
12085 | 354 |
pretty_goals_local ctxt begin_goal (true, true) (! Display.goals_limit) thm; |
6848 | 355 |
|
8462 | 356 |
val ctxt_prts = |
12085 | 357 |
if ! verbose orelse mode = Forward then ProofContext.pretty_context ctxt |
358 |
else if mode = Backward then ProofContext.pretty_asms ctxt |
|
7575 | 359 |
else []; |
8462 | 360 |
|
361 |
val prts = |
|
8582 | 362 |
[Pretty.str ("proof (" ^ mode_name mode ^ "): step " ^ string_of_int nr ^ |
12010 | 363 |
(if ! verbose then ", depth " ^ string_of_int (length nodes div 2 - 1) |
8561 | 364 |
else "")), Pretty.str ""] @ |
8462 | 365 |
(if null ctxt_prts then [] else ctxt_prts @ [Pretty.str ""]) @ |
366 |
(if ! verbose orelse mode = Forward then |
|
12146 | 367 |
(pretty_facts "" ctxt facts @ prt_goal (find_goal state)) |
12085 | 368 |
else if mode = ForwardChain then pretty_facts "picking " ctxt facts |
12146 | 369 |
else prt_goal (find_goal state)) |
12423 | 370 |
in prts end; |
5820 | 371 |
|
12085 | 372 |
fun pretty_goals main state = |
373 |
let val (ctxt, (_, ((_, (_, thm)), _))) = find_goal state |
|
374 |
in pretty_goals_local ctxt "" (false, main) (! Display.goals_limit) thm end; |
|
10320 | 375 |
|
5820 | 376 |
|
377 |
||
378 |
(** proof steps **) |
|
379 |
||
380 |
(* datatype method *) |
|
381 |
||
8374 | 382 |
datatype method = |
383 |
Method of thm list -> thm -> (thm * (string * RuleCases.T) list) Seq.seq; |
|
384 |
||
385 |
fun method tac = Method (fn facts => fn st => Seq.map (rpair []) (tac facts st)); |
|
386 |
val method_cases = Method; |
|
5820 | 387 |
|
388 |
||
389 |
(* refine goal *) |
|
390 |
||
8234 | 391 |
local |
392 |
||
5820 | 393 |
fun check_sign sg state = |
394 |
if Sign.subsig (sg, sign_of state) then state |
|
395 |
else raise STATE ("Bad signature of result: " ^ Sign.str_of_sg sg, state); |
|
396 |
||
8234 | 397 |
fun gen_refine current_context meth_fun state = |
6848 | 398 |
let |
12971 | 399 |
val (goal_ctxt, (_, ((result, (facts, thm)), x))) = find_goal state; |
8234 | 400 |
val Method meth = meth_fun (if current_context then context_of state else goal_ctxt); |
5820 | 401 |
|
8374 | 402 |
fun refn (thm', cases) = |
6848 | 403 |
state |
404 |
|> check_sign (Thm.sign_of_thm thm') |
|
12971 | 405 |
|> map_goal (ProofContext.add_cases cases) (K ((result, (facts, thm')), x)); |
6848 | 406 |
in Seq.map refn (meth facts thm) end; |
5820 | 407 |
|
8234 | 408 |
in |
409 |
||
410 |
val refine = gen_refine true; |
|
411 |
val refine_end = gen_refine false; |
|
412 |
||
413 |
end; |
|
414 |
||
5820 | 415 |
|
11917 | 416 |
(* goal addressing *) |
6932 | 417 |
|
8152 | 418 |
fun FINDGOAL tac st = |
8374 | 419 |
let fun find (i, n) = if i > n then Seq.fail else Seq.APPEND (tac i, find (i + 1, n)) |
420 |
in find (1, Thm.nprems_of st) st end; |
|
8152 | 421 |
|
8166 | 422 |
fun HEADGOAL tac = tac 1; |
423 |
||
9469 | 424 |
|
425 |
(* export results *) |
|
426 |
||
11816 | 427 |
fun refine_tac rule = |
12703
af5fec8a418f
refine_tac: Tactic.norm_hhf_tac before trying rule;
wenzelm
parents:
12698
diff
changeset
|
428 |
Tactic.norm_hhf_tac THEN' Tactic.rtac rule THEN_ALL_NEW (SUBGOAL (fn (goal, i) => |
11816 | 429 |
if can Logic.dest_goal (Logic.strip_assums_concl goal) then |
430 |
Tactic.etac Drule.triv_goal i |
|
431 |
else all_tac)); |
|
432 |
||
12146 | 433 |
fun export_goal inner print_rule raw_rule state = |
6932 | 434 |
let |
12971 | 435 |
val (outer, (_, ((result, (facts, thm)), x))) = find_goal state; |
12010 | 436 |
val exp_tac = ProofContext.export true inner outer; |
9469 | 437 |
fun exp_rule rule = |
438 |
let |
|
12055 | 439 |
val _ = print_rule outer rule; |
11816 | 440 |
val thmq = FINDGOAL (refine_tac rule) thm; |
12971 | 441 |
in Seq.map (fn th => map_goal I (K ((result, (facts, th)), x)) state) thmq end; |
9469 | 442 |
in raw_rule |> exp_tac |> (Seq.flat o Seq.map exp_rule) end; |
6932 | 443 |
|
12146 | 444 |
fun export_goals inner print_rule raw_rules = |
445 |
Seq.EVERY (map (export_goal inner print_rule) raw_rules); |
|
446 |
||
6932 | 447 |
fun transfer_facts inner_state state = |
448 |
(case get_facts inner_state of |
|
449 |
None => Seq.single (reset_facts state) |
|
8617
33e2bd53aec3
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8582
diff
changeset
|
450 |
| Some thms => |
33e2bd53aec3
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8582
diff
changeset
|
451 |
let |
12010 | 452 |
val exp_tac = ProofContext.export false (context_of inner_state) (context_of state); |
11816 | 453 |
val thmqs = map exp_tac thms; |
8617
33e2bd53aec3
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8582
diff
changeset
|
454 |
in Seq.map (fn ths => put_facts (Some ths) state) (Seq.commute thmqs) end); |
6932 | 455 |
|
456 |
||
457 |
(* prepare result *) |
|
458 |
||
12146 | 459 |
fun prep_result state ts raw_th = |
5820 | 460 |
let |
461 |
val ctxt = context_of state; |
|
462 |
fun err msg = raise STATE (msg, state); |
|
463 |
||
12146 | 464 |
val ngoals = Thm.nprems_of raw_th; |
5820 | 465 |
val _ = |
466 |
if ngoals = 0 then () |
|
12085 | 467 |
else (err (Pretty.string_of (Pretty.chunks (pretty_goals_local ctxt "" (true, true) |
12146 | 468 |
(! Display.goals_limit) raw_th @ |
12085 | 469 |
[Pretty.str (string_of_int ngoals ^ " unsolved goal(s)!")])))); |
5820 | 470 |
|
12146 | 471 |
val {hyps, sign, ...} = Thm.rep_thm raw_th; |
5820 | 472 |
val tsig = Sign.tsig_of sign; |
12055 | 473 |
val casms = flat (map #1 (ProofContext.assumptions_of (context_of state))); |
11816 | 474 |
val bad_hyps = Library.gen_rems Term.aconv (hyps, map Thm.term_of casms); |
12146 | 475 |
|
476 |
val th = raw_th RS Drule.rev_triv_goal; |
|
477 |
val ths = Drule.conj_elim_precise (length ts) th |
|
478 |
handle THM _ => err "Main goal structure corrupted"; |
|
5820 | 479 |
in |
12146 | 480 |
conditional (not (null bad_hyps)) (fn () => err ("Additional hypotheses:\n" ^ |
481 |
cat_lines (map (ProofContext.string_of_term ctxt) bad_hyps))); |
|
12808
a529b4b91888
RuleCases.make interface based on term instead of thm;
wenzelm
parents:
12760
diff
changeset
|
482 |
conditional (exists (not o Pattern.matches tsig) (ts ~~ map Thm.prop_of ths)) (fn () => |
12146 | 483 |
err ("Proved a different theorem: " ^ Pretty.string_of (ProofContext.pretty_thm ctxt th))); |
484 |
ths |
|
5820 | 485 |
end; |
486 |
||
487 |
||
488 |
||
489 |
(*** structured proof commands ***) |
|
490 |
||
491 |
(** context **) |
|
492 |
||
493 |
(* bind *) |
|
494 |
||
495 |
fun gen_bind f x state = |
|
496 |
state |
|
497 |
|> assert_forward |
|
498 |
|> map_context (f x) |
|
499 |
|> reset_facts; |
|
500 |
||
8617
33e2bd53aec3
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8582
diff
changeset
|
501 |
val match_bind = gen_bind (ProofContext.match_bind false); |
33e2bd53aec3
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8582
diff
changeset
|
502 |
val match_bind_i = gen_bind (ProofContext.match_bind_i false); |
33e2bd53aec3
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8582
diff
changeset
|
503 |
val let_bind = gen_bind (ProofContext.match_bind true); |
33e2bd53aec3
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8582
diff
changeset
|
504 |
val let_bind_i = gen_bind (ProofContext.match_bind_i true); |
5820 | 505 |
|
506 |
||
12714 | 507 |
(* have_thmss *) |
5820 | 508 |
|
12714 | 509 |
local |
510 |
||
511 |
fun gen_have_thmss f args state = |
|
5820 | 512 |
state |
513 |
|> assert_forward |
|
12714 | 514 |
|> map_context_result (f args) |
9196 | 515 |
|> these_factss; |
5820 | 516 |
|
12714 | 517 |
in |
518 |
||
519 |
val have_thmss = gen_have_thmss ProofContext.have_thmss; |
|
520 |
val have_thmss_i = gen_have_thmss ProofContext.have_thmss_i; |
|
521 |
||
522 |
fun simple_have_thms name thms = have_thmss_i [((name, []), [(thms, [])])]; |
|
523 |
||
524 |
end; |
|
525 |
||
526 |
||
527 |
(* with_thmss *) |
|
9196 | 528 |
|
12714 | 529 |
local |
530 |
||
531 |
fun gen_with_thmss f args state = |
|
532 |
let val state' = state |> f args |
|
9196 | 533 |
in state' |> simple_have_thms "" (the_facts state' @ the_facts state) end; |
6876 | 534 |
|
12714 | 535 |
in |
536 |
||
537 |
val with_thmss = gen_with_thmss have_thmss; |
|
538 |
val with_thmss_i = gen_with_thmss have_thmss_i; |
|
539 |
||
540 |
end; |
|
541 |
||
5820 | 542 |
|
12930 | 543 |
(* using_thmss *) |
544 |
||
545 |
local |
|
546 |
||
547 |
fun gen_using_thmss f args state = |
|
548 |
state |
|
549 |
|> assert_backward |
|
550 |
|> map_context_result (f (map (pair ("", [])) args)) |
|
551 |
|> (fn (st, named_facts) => |
|
12971 | 552 |
let val (_, (_, ((result, (facts, thm)), x))) = find_goal st; |
553 |
in st |> map_goal I (K ((result, (facts @ flat (map snd named_facts), thm)), x)) end); |
|
12930 | 554 |
|
555 |
in |
|
556 |
||
557 |
val using_thmss = gen_using_thmss ProofContext.have_thmss; |
|
558 |
val using_thmss_i = gen_using_thmss ProofContext.have_thmss_i; |
|
559 |
||
560 |
end; |
|
561 |
||
562 |
||
5820 | 563 |
(* fix *) |
564 |
||
565 |
fun gen_fix f xs state = |
|
566 |
state |
|
567 |
|> assert_forward |
|
568 |
|> map_context (f xs) |
|
569 |
|> reset_facts; |
|
570 |
||
571 |
val fix = gen_fix ProofContext.fix; |
|
572 |
val fix_i = gen_fix ProofContext.fix_i; |
|
573 |
||
574 |
||
11891 | 575 |
(* assume and presume *) |
5820 | 576 |
|
9469 | 577 |
fun gen_assume f exp args state = |
5820 | 578 |
state |
579 |
|> assert_forward |
|
9469 | 580 |
|> map_context_result (f exp args) |
11924 | 581 |
|> these_factss; |
6932 | 582 |
|
7271 | 583 |
val assm = gen_assume ProofContext.assume; |
584 |
val assm_i = gen_assume ProofContext.assume_i; |
|
11917 | 585 |
val assume = assm ProofContext.export_assume; |
586 |
val assume_i = assm_i ProofContext.export_assume; |
|
587 |
val presume = assm ProofContext.export_presume; |
|
588 |
val presume_i = assm_i ProofContext.export_presume; |
|
5820 | 589 |
|
7271 | 590 |
|
5820 | 591 |
|
11891 | 592 |
(** local definitions **) |
593 |
||
594 |
fun gen_def fix prep_term prep_pats raw_name atts (x, (raw_rhs, raw_pats)) state = |
|
595 |
let |
|
596 |
val _ = assert_forward state; |
|
597 |
val ctxt = context_of state; |
|
598 |
||
599 |
(*rhs*) |
|
600 |
val name = if raw_name = "" then Thm.def_name x else raw_name; |
|
601 |
val rhs = prep_term ctxt raw_rhs; |
|
602 |
val T = Term.fastype_of rhs; |
|
603 |
val pats = prep_pats T (ProofContext.declare_term rhs ctxt) raw_pats; |
|
604 |
||
605 |
(*lhs*) |
|
606 |
val lhs = ProofContext.bind_skolem ctxt [x] (Free (x, T)); |
|
607 |
in |
|
608 |
state |
|
609 |
|> fix [([x], None)] |
|
610 |
|> match_bind_i [(pats, rhs)] |
|
11917 | 611 |
|> assm_i ProofContext.export_def [((name, atts), [(Logic.mk_equals (lhs, rhs), ([], []))])] |
11891 | 612 |
end; |
613 |
||
614 |
val def = gen_def fix ProofContext.read_term ProofContext.read_term_pats; |
|
615 |
val def_i = gen_def fix_i ProofContext.cert_term ProofContext.cert_term_pats; |
|
616 |
||
617 |
||
8374 | 618 |
(* invoke_case *) |
619 |
||
11793
5f0ab6f5c280
support impromptu terminology of cases parameters;
wenzelm
parents:
11742
diff
changeset
|
620 |
fun invoke_case (name, xs, atts) state = |
9292 | 621 |
let |
10830 | 622 |
val (state', (lets, asms)) = |
11793
5f0ab6f5c280
support impromptu terminology of cases parameters;
wenzelm
parents:
11742
diff
changeset
|
623 |
map_context_result (ProofContext.apply_case (get_case state name xs)) state; |
13425
119ae829ad9b
support for split assumptions in cases (hyps vs. prems);
wenzelm
parents:
13415
diff
changeset
|
624 |
val assumptions = asms |> map (fn (a, ts) => |
119ae829ad9b
support for split assumptions in cases (hyps vs. prems);
wenzelm
parents:
13415
diff
changeset
|
625 |
((if a = "" then "" else NameSpace.append name a, atts), map (rpair ([], [])) ts)); |
119ae829ad9b
support for split assumptions in cases (hyps vs. prems);
wenzelm
parents:
13415
diff
changeset
|
626 |
val qnames = filter_out (equal "") (map (#1 o #1) assumptions); |
9292 | 627 |
in |
10830 | 628 |
state' |
10809 | 629 |
|> add_binds_i lets |
13425
119ae829ad9b
support for split assumptions in cases (hyps vs. prems);
wenzelm
parents:
13415
diff
changeset
|
630 |
|> map_context (ProofContext.qualified true) |
119ae829ad9b
support for split assumptions in cases (hyps vs. prems);
wenzelm
parents:
13415
diff
changeset
|
631 |
|> assume_i assumptions |
119ae829ad9b
support for split assumptions in cases (hyps vs. prems);
wenzelm
parents:
13415
diff
changeset
|
632 |
|> map_context (ProofContext.hide_thms false qnames) |
119ae829ad9b
support for split assumptions in cases (hyps vs. prems);
wenzelm
parents:
13415
diff
changeset
|
633 |
|> (fn st => simple_have_thms name (the_facts st) st) |
119ae829ad9b
support for split assumptions in cases (hyps vs. prems);
wenzelm
parents:
13415
diff
changeset
|
634 |
|> map_context (ProofContext.restore_qualified (context_of state)) |
8374 | 635 |
end; |
636 |
||
637 |
||
5820 | 638 |
|
639 |
(** goals **) |
|
640 |
||
641 |
(* forward chaining *) |
|
642 |
||
643 |
fun chain state = |
|
644 |
state |
|
645 |
|> assert_forward |
|
6848 | 646 |
|> assert_facts |
5820 | 647 |
|> enter_forward_chain; |
648 |
||
649 |
fun from_facts facts state = |
|
650 |
state |
|
651 |
|> put_facts (Some facts) |
|
652 |
|> chain; |
|
653 |
||
654 |
||
655 |
(* setup goals *) |
|
656 |
||
11549 | 657 |
val rule_contextN = "rule_context"; |
8991 | 658 |
|
12971 | 659 |
fun setup_goal opt_block prepp autofix kind after_qed pr names raw_propp state = |
5820 | 660 |
let |
12146 | 661 |
val (state', (propss, gen_binds)) = |
5936 | 662 |
state |
663 |
|> assert_forward_or_chain |
|
664 |
|> enter_forward |
|
8617
33e2bd53aec3
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8582
diff
changeset
|
665 |
|> opt_block |
12534 | 666 |
|> map_context_result (fn ctxt => prepp (ctxt, raw_propp)); |
12808
a529b4b91888
RuleCases.make interface based on term instead of thm;
wenzelm
parents:
12760
diff
changeset
|
667 |
val sign' = sign_of state'; |
12146 | 668 |
|
669 |
val props = flat propss; |
|
12808
a529b4b91888
RuleCases.make interface based on term instead of thm;
wenzelm
parents:
12760
diff
changeset
|
670 |
val cprop = Thm.cterm_of sign' (Logic.mk_conjunction_list props); |
7556 | 671 |
val goal = Drule.mk_triv_goal cprop; |
10553 | 672 |
|
12146 | 673 |
val tvars = foldr Term.add_term_tvars (props, []); |
674 |
val vars = foldr Term.add_term_vars (props, []); |
|
5820 | 675 |
in |
10553 | 676 |
if null tvars then () |
677 |
else raise STATE ("Goal statement contains illegal schematic type variable(s): " ^ |
|
678 |
commas (map (Syntax.string_of_vname o #1) tvars), state); |
|
679 |
if null vars then () |
|
680 |
else warning ("Goal statement contains unbound schematic variable(s): " ^ |
|
12055 | 681 |
commas (map (ProofContext.string_of_term (context_of state')) vars)); |
5936 | 682 |
state' |
12146 | 683 |
|> map_context (autofix props) |
12971 | 684 |
|> put_goal (Some (((kind, names, propss), ([], goal)), |
685 |
(after_qed o map_context gen_binds, pr))) |
|
12167 | 686 |
|> map_context (ProofContext.add_cases |
12808
a529b4b91888
RuleCases.make interface based on term instead of thm;
wenzelm
parents:
12760
diff
changeset
|
687 |
(if length props = 1 then |
13425
119ae829ad9b
support for split assumptions in cases (hyps vs. prems);
wenzelm
parents:
13415
diff
changeset
|
688 |
RuleCases.make true None (Thm.sign_of_thm goal, Thm.prop_of goal) [rule_contextN] |
12167 | 689 |
else [(rule_contextN, RuleCases.empty)])) |
12146 | 690 |
|> auto_bind_goal props |
5820 | 691 |
|> (if is_chain state then use_facts else reset_facts) |
692 |
|> new_block |
|
693 |
|> enter_backward |
|
694 |
end; |
|
695 |
||
696 |
(*global goals*) |
|
12959 | 697 |
fun global_goal prep kind raw_locale a elems concl thy = |
12503 | 698 |
let |
12549 | 699 |
val init = init_state thy; |
13399
c136276dc847
support locale ``views'' (for cumulative predicates);
wenzelm
parents:
13377
diff
changeset
|
700 |
val (opt_name, view, locale_ctxt, elems_ctxt, propp) = |
12959 | 701 |
prep (apsome fst raw_locale) elems (map snd concl) (context_of init); |
12503 | 702 |
in |
12549 | 703 |
init |
704 |
|> open_block |
|
12511 | 705 |
|> map_context (K locale_ctxt) |
12065 | 706 |
|> open_block |
12511 | 707 |
|> map_context (K elems_ctxt) |
12959 | 708 |
|> setup_goal I ProofContext.bind_propp_schematic_i ProofContext.fix_frees |
13415 | 709 |
(Theorem {kind = kind, |
710 |
theory_spec = (a, map (snd o fst) concl), |
|
711 |
locale_spec = (case raw_locale of None => None | Some (_, x) => Some (the opt_name, x)), |
|
712 |
view = view}) |
|
12971 | 713 |
Seq.single true (map (fst o fst) concl) propp |
12065 | 714 |
end; |
5820 | 715 |
|
12534 | 716 |
val multi_theorem = global_goal Locale.read_context_statement; |
717 |
val multi_theorem_i = global_goal Locale.cert_context_statement; |
|
12146 | 718 |
|
5820 | 719 |
|
720 |
(*local goals*) |
|
12971 | 721 |
fun local_goal' prepp kind (check: bool -> state -> state) f pr args int state = |
7928 | 722 |
state |
12146 | 723 |
|> setup_goal open_block prepp (K I) (kind (map (snd o fst) args)) |
12971 | 724 |
f pr (map (fst o fst) args) (map snd args) |
10936 | 725 |
|> warn_extra_tfrees state |
726 |
|> check int; |
|
5820 | 727 |
|
12971 | 728 |
fun local_goal prepp kind f pr args = local_goal' prepp kind (K I) f pr args false; |
10936 | 729 |
|
730 |
val show = local_goal' ProofContext.bind_propp Show; |
|
731 |
val show_i = local_goal' ProofContext.bind_propp_i Show; |
|
732 |
val have = local_goal ProofContext.bind_propp Have; |
|
10380 | 733 |
val have_i = local_goal ProofContext.bind_propp_i Have; |
5820 | 734 |
|
735 |
||
736 |
||
737 |
(** conclusions **) |
|
738 |
||
739 |
(* current goal *) |
|
740 |
||
7176 | 741 |
fun current_goal (State (Node {context, goal = Some goal, ...}, _)) = (context, goal) |
5820 | 742 |
| current_goal state = raise STATE ("No current goal!", state); |
743 |
||
7176 | 744 |
fun assert_current_goal true (state as State (Node {goal = None, ...}, _)) = |
6404 | 745 |
raise STATE ("No goal in this block!", state) |
7176 | 746 |
| assert_current_goal false (state as State (Node {goal = Some _, ...}, _)) = |
6404 | 747 |
raise STATE ("Goal present in this block!", state) |
748 |
| assert_current_goal _ state = state; |
|
5820 | 749 |
|
12010 | 750 |
fun assert_bottom b (state as State (_, nodes)) = |
751 |
let val bot = (length nodes <= 2) in |
|
752 |
if b andalso not bot then raise STATE ("Not at bottom of proof!", state) |
|
753 |
else if not b andalso bot then raise STATE ("Already at bottom of proof!", state) |
|
754 |
else state |
|
755 |
end; |
|
5820 | 756 |
|
6404 | 757 |
val at_bottom = can (assert_bottom true o close_block); |
758 |
||
6932 | 759 |
fun end_proof bot state = |
5820 | 760 |
state |
761 |
|> assert_forward |
|
762 |
|> close_block |
|
763 |
|> assert_bottom bot |
|
7011 | 764 |
|> assert_current_goal true |
765 |
|> goal_facts (K []); |
|
5820 | 766 |
|
767 |
||
6404 | 768 |
(* local_qed *) |
5820 | 769 |
|
6982 | 770 |
fun finish_local (print_result, print_rule) state = |
5820 | 771 |
let |
12971 | 772 |
val (goal_ctxt, (((kind, names, tss), (_, raw_thm)), (after_qed, pr))) = current_goal state; |
8617
33e2bd53aec3
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8582
diff
changeset
|
773 |
val outer_state = state |> close_block; |
33e2bd53aec3
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8582
diff
changeset
|
774 |
val outer_ctxt = context_of outer_state; |
33e2bd53aec3
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8582
diff
changeset
|
775 |
|
12146 | 776 |
val ts = flat tss; |
777 |
val results = prep_result state ts raw_thm; |
|
778 |
val resultq = |
|
779 |
results |> map (ProofContext.export false goal_ctxt outer_ctxt) |
|
780 |
|> Seq.commute |> Seq.map (Library.unflat tss); |
|
9469 | 781 |
|
12146 | 782 |
val (attss, opt_solve) = |
5820 | 783 |
(case kind of |
12971 | 784 |
Show attss => (attss, |
785 |
export_goals goal_ctxt (if pr then print_rule else (K (K ()))) results) |
|
12146 | 786 |
| Have attss => (attss, Seq.single) |
6932 | 787 |
| _ => err_malformed "finish_local" state); |
5820 | 788 |
in |
12971 | 789 |
conditional pr (fn () => print_result goal_ctxt |
790 |
(kind_name (sign_of state) kind, names ~~ Library.unflat tss results)); |
|
8617
33e2bd53aec3
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8582
diff
changeset
|
791 |
outer_state |
12549 | 792 |
|> auto_bind_facts (ProofContext.generalize goal_ctxt outer_ctxt ts) |
9469 | 793 |
|> (fn st => Seq.map (fn res => |
12714 | 794 |
have_thmss_i ((names ~~ attss) ~~ map (single o Thm.no_attributes) res) st) resultq) |
9469 | 795 |
|> (Seq.flat o Seq.map opt_solve) |
7176 | 796 |
|> (Seq.flat o Seq.map after_qed) |
5820 | 797 |
end; |
798 |
||
6982 | 799 |
fun local_qed finalize print state = |
6404 | 800 |
state |
6932 | 801 |
|> end_proof false |
6871 | 802 |
|> finalize |
6982 | 803 |
|> (Seq.flat o Seq.map (finish_local print)); |
5820 | 804 |
|
805 |
||
12703
af5fec8a418f
refine_tac: Tactic.norm_hhf_tac before trying rule;
wenzelm
parents:
12698
diff
changeset
|
806 |
(* global_qed *) |
12065 | 807 |
|
6950 | 808 |
fun finish_global state = |
5820 | 809 |
let |
12146 | 810 |
val (goal_ctxt, (((kind, names, tss), (_, raw_thm)), _)) = current_goal state; |
12065 | 811 |
val locale_ctxt = context_of (state |> close_block); |
812 |
val theory_ctxt = context_of (state |> close_block |> close_block); |
|
13415 | 813 |
val {kind = k, theory_spec = ((name, atts), attss), locale_spec, view} = |
13399
c136276dc847
support locale ``views'' (for cumulative predicates);
wenzelm
parents:
13377
diff
changeset
|
814 |
(case kind of Theorem x => x | _ => err_malformed "finish_global" state); |
5820 | 815 |
|
12146 | 816 |
val ts = flat tss; |
13415 | 817 |
val locale_results = map (ProofContext.export_standard [] goal_ctxt locale_ctxt) |
13377 | 818 |
(prep_result state ts raw_thm); |
819 |
val results = map (Drule.strip_shyps_warning o |
|
13399
c136276dc847
support locale ``views'' (for cumulative predicates);
wenzelm
parents:
13377
diff
changeset
|
820 |
ProofContext.export_standard view locale_ctxt theory_ctxt) locale_results; |
12703
af5fec8a418f
refine_tac: Tactic.norm_hhf_tac before trying rule;
wenzelm
parents:
12698
diff
changeset
|
821 |
|
12959 | 822 |
val (theory', results') = |
823 |
theory_of state |
|
13415 | 824 |
|> (case locale_spec of None => I | Some (loc, (loc_atts, loc_attss)) => fn thy => |
12959 | 825 |
if length names <> length loc_attss then |
826 |
raise THEORY ("Bad number of locale attributes", [thy]) |
|
13335 | 827 |
else (thy, locale_ctxt) |
12959 | 828 |
|> Locale.add_thmss loc ((names ~~ Library.unflat tss locale_results) ~~ loc_attss) |
13335 | 829 |
|> (fn ((thy', ctxt'), res) => |
12959 | 830 |
if name = "" andalso null loc_atts then thy' |
13335 | 831 |
else (thy', ctxt') |
13377 | 832 |
|> (#1 o #1 o Locale.add_thmss loc [((name, flat (map #2 res)), loc_atts)]))) |
13415 | 833 |
|> Locale.smart_have_thmss k locale_spec |
12703
af5fec8a418f
refine_tac: Tactic.norm_hhf_tac before trying rule;
wenzelm
parents:
12698
diff
changeset
|
834 |
((names ~~ attss) ~~ map (single o Thm.no_attributes) (Library.unflat tss results)) |
12959 | 835 |
|> (fn (thy, res) => (thy, res) |
13415 | 836 |
|>> (#1 o Locale.smart_have_thmss k locale_spec |
12959 | 837 |
[((name, atts), [(flat (map #2 res), [])])])); |
838 |
in (theory', ((k, name), results')) end; |
|
839 |
||
5820 | 840 |
|
10553 | 841 |
(*note: clients should inspect first result only, as backtracking may destroy theory*) |
6950 | 842 |
fun global_qed finalize state = |
5820 | 843 |
state |
6932 | 844 |
|> end_proof true |
6871 | 845 |
|> finalize |
12065 | 846 |
|> Seq.map finish_global; |
5820 | 847 |
|
848 |
||
6896 | 849 |
|
850 |
(** blocks **) |
|
851 |
||
852 |
(* begin_block *) |
|
853 |
||
854 |
fun begin_block state = |
|
855 |
state |
|
856 |
|> assert_forward |
|
857 |
|> new_block |
|
858 |
|> open_block; |
|
859 |
||
860 |
||
861 |
(* end_block *) |
|
862 |
||
863 |
fun end_block state = |
|
864 |
state |
|
865 |
|> assert_forward |
|
866 |
|> close_block |
|
867 |
|> assert_current_goal false |
|
868 |
|> close_block |
|
6932 | 869 |
|> transfer_facts state; |
6896 | 870 |
|
871 |
||
872 |
(* next_block *) |
|
873 |
||
874 |
fun next_block state = |
|
875 |
state |
|
876 |
|> assert_forward |
|
877 |
|> close_block |
|
8718 | 878 |
|> new_block |
879 |
|> reset_facts; |
|
6896 | 880 |
|
881 |
||
5820 | 882 |
end; |
8152 | 883 |
|
884 |
structure BasicProof: BASIC_PROOF = Proof; |
|
885 |
open BasicProof; |