author  wenzelm 
Mon, 31 May 1999 23:09:13 +0200  
changeset 6752  0545b77f864e 
parent 6731  57e761134c85 
child 6756  fe6eb161df3e 
permissions  rwrr 
5820  1 
(* Title: Pure/Isar/proof.ML 
2 
ID: $Id$ 

3 
Author: Markus Wenzel, TU Muenchen 

4 

5 
Proof states and methods. 

6 
*) 

7 

8 
signature PROOF = 

9 
sig 

10 
type context 

11 
type state 

12 
exception STATE of string * state 

13 
val context_of: state > context 

14 
val theory_of: state > theory 

15 
val sign_of: state > Sign.sg 

6091  16 
val the_facts: state > thm list 
17 
val goal_facts: (state > thm list) > state > state 

5820  18 
val use_facts: state > state 
19 
val reset_facts: state > state 

20 
val assert_backward: state > state 

21 
val enter_forward: state > state 

6529  22 
val verbose: bool ref 
5820  23 
val print_state: state > unit 
24 
type method 

6091  25 
val method: (thm list > thm > 
26 
(thm * (indexname * term) list * (string * thm list) list) Seq.seq) > method 

5820  27 
val refine: (context > method) > state > state Seq.seq 
28 
val bind: (indexname * string) list > state > state 

29 
val bind_i: (indexname * term) list > state > state 

5936  30 
val match_bind: (string list * string) list > state > state 
31 
val match_bind_i: (term list * term) list > state > state 

6091  32 
val have_thmss: string > context attribute list > 
33 
(thm list * context attribute list) list > state > state 

5936  34 
val assume: string > context attribute list > (string * string list) list > state > state 
35 
val assume_i: string > context attribute list > (term * term list) list > state > state 

5820  36 
val fix: (string * string option) list > state > state 
37 
val fix_i: (string * typ) list > state > state 

5936  38 
val theorem: bstring > theory attribute list > string * string list > theory > state 
39 
val theorem_i: bstring > theory attribute list > term * term list > theory > state 

40 
val lemma: bstring > theory attribute list > string * string list > theory > state 

41 
val lemma_i: bstring > theory attribute list > term * term list > theory > state 

5820  42 
val chain: state > state 
6091  43 
val from_facts: thm list > state > state 
5936  44 
val show: string > context attribute list > string * string list > state > state 
45 
val show_i: string > context attribute list > term * term list > state > state 

46 
val have: string > context attribute list > string * string list > state > state 

47 
val have_i: string > context attribute list > term * term list > state > state 

5820  48 
val begin_block: state > state 
49 
val next_block: state > state 

6404  50 
val end_block: state > state 
51 
val at_bottom: state > bool 

6731  52 
val local_qed: (state > state Seq.seq) > ({kind: string, name: string, thm: thm} > unit) 
53 
> state > state Seq.seq 

6404  54 
val global_qed: (state > state Seq.seq) > bstring option 
6529  55 
> theory attribute list option > state > theory * {kind: string, name: string, thm: thm} 
5820  56 
end; 
57 

58 
signature PROOF_PRIVATE = 

59 
sig 

60 
include PROOF 

61 
val put_data: Object.kind > ('a > Object.T) > 'a > state > state 

62 
end; 

63 

64 
structure Proof: PROOF_PRIVATE = 

65 
struct 

66 

67 

68 
(** proof state **) 

69 

70 
type context = ProofContext.context; 

71 

72 

73 
(* type goal *) 

74 

75 
datatype kind = 

76 
Theorem of theory attribute list  (*toplevel theorem*) 

77 
Lemma of theory attribute list  (*toplevel lemma*) 

78 
Goal of context attribute list  (*intermediate result, solving subgoal*) 

79 
Aux of context attribute list ; (*intermediate result*) 

80 

81 
val kind_name = 

6001  82 
fn Theorem _ => "theorem"  Lemma _ => "lemma"  Goal _ => "show"  Aux _ => "have"; 
5820  83 

84 
type goal = 

6091  85 
(kind * (*result kind*) 
5820  86 
string * (*result name*) 
87 
cterm list * (*result assumptions*) 

88 
term) * (*result statement*) 

6091  89 
(thm list * (*use facts*) 
5820  90 
thm); (*goal: subgoals ==> statement*) 
91 

92 

93 
(* type mode *) 

94 

95 
datatype mode = Forward  ForwardChain  Backward; 

96 

97 
val mode_name = 

6030  98 
fn Forward => "state"  ForwardChain => "chain"  Backward => "prove"; 
5820  99 

100 

101 
(* type node *) 

102 

103 
type node = 

104 
{context: context, 

6091  105 
facts: thm list option, 
5820  106 
mode: mode, 
107 
goal: goal option}; 

108 

109 
fun make_node (context, facts, mode, goal) = 

110 
{context = context, facts = facts, mode = mode, goal = goal}: node; 

111 

112 

113 
(* datatype state *) 

114 

115 
datatype state = 

116 
State of 

117 
node * (*current*) 

118 
node list; (*parents wrt. block structure*) 

119 

120 
exception STATE of string * state; 

121 

122 
fun err_malformed name state = 

123 
raise STATE (name ^ ": internal error  malformed proof state", state); 

124 

125 

126 
fun map_current f (State ({context, facts, mode, goal}, nodes)) = 

127 
State (make_node (f (context, facts, mode, goal)), nodes); 

128 

129 
fun init_state thy = 

5875  130 
State (make_node (ProofContext.init thy, None, Forward, None), []); 
5820  131 

132 

133 

134 
(** basic proof state operations **) 

135 

136 
(* context *) 

137 

138 
fun context_of (State ({context, ...}, _)) = context; 

139 
val theory_of = ProofContext.theory_of o context_of; 

140 
val sign_of = ProofContext.sign_of o context_of; 

141 

142 
fun map_context f = map_current (fn (ctxt, facts, mode, goal) => (f ctxt, facts, mode, goal)); 

143 

144 
fun map_context_result f (state as State ({context, facts, mode, goal}, nodes)) = 

145 
let val (context', result) = f context 

146 
in (State (make_node (context', facts, mode, goal), nodes), result) end; 

147 

148 

149 
fun put_data kind f = map_context o ProofContext.put_data kind f; 

150 
val declare_term = map_context o ProofContext.declare_term; 

151 
val add_binds = map_context o ProofContext.add_binds_i; 

6091  152 
val put_thms = map_context o ProofContext.put_thms; 
153 
val put_thmss = map_context o ProofContext.put_thmss; 

5820  154 

155 

156 
(* bind statements *) 

157 

158 
fun bind_props bs state = 

159 
let val mk_bind = map (fn (x, t) => ((Syntax.binding x, 0), t)) o ObjectLogic.dest_statement 

160 
in state > add_binds (flat (map mk_bind bs)) end; 

161 

6091  162 
fun bind_thms (name, thms) state = 
5820  163 
let 
6091  164 
val props = map (#prop o Thm.rep_thm) thms; 
5820  165 
val named_props = 
166 
(case props of 

167 
[prop] => [(name, prop)] 

168 
 props => map2 (fn (i, t) => (name ^ string_of_int i, t)) (1 upto length props, props)); 

169 
in state > bind_props named_props end; 

170 

6091  171 
fun let_thms name_thms state = 
5820  172 
state 
6091  173 
> put_thms name_thms 
174 
> bind_thms name_thms; 

5820  175 

176 

177 
(* facts *) 

178 

179 
fun the_facts (State ({facts = Some facts, ...}, _)) = facts 

180 
 the_facts state = raise STATE ("No current facts available", state); 

181 

182 
fun put_facts facts state = 

183 
state 

184 
> map_current (fn (ctxt, _, mode, goal) => (ctxt, facts, mode, goal)) 

6091  185 
> let_thms ("facts", if_none facts []); 
5820  186 

187 
val reset_facts = put_facts None; 

188 

189 
fun have_facts (name, facts) state = 

190 
state 

191 
> put_facts (Some facts) 

6091  192 
> let_thms (name, facts); 
5820  193 

194 
fun these_facts (state, ths) = have_facts ths state; 

195 
fun fetch_facts (State ({facts, ...}, _)) = put_facts facts; 

196 

197 

198 
(* goal *) 

199 

200 
fun find_goal i (State ({goal = Some goal, ...}, _)) = (i, goal) 

201 
 find_goal i (State ({goal = None, ...}, node :: nodes)) = 

202 
find_goal (i + 1) (State (node, nodes)) 

203 
 find_goal _ (state as State (_, [])) = err_malformed "find_goal" state; 

204 

205 
fun put_goal goal = map_current (fn (ctxt, facts, mode, _) => (ctxt, facts, mode, goal)); 

206 

207 
fun map_goal f (State ({context, facts, mode, goal = Some goal}, nodes)) = 

208 
State (make_node (context, facts, mode, Some (f goal)), nodes) 

209 
 map_goal f (State (nd, node :: nodes)) = 

210 
let val State (node', nodes') = map_goal f (State (node, nodes)) 

211 
in State (nd, node' :: nodes') end 

212 
 map_goal _ state = state; 

213 

214 
fun goal_facts get state = 

215 
state 

216 
> map_goal (fn (result, (_, thm)) => (result, (get state, thm))); 

217 

218 
fun use_facts state = 

219 
state 

220 
> goal_facts the_facts 

221 
> reset_facts; 

222 

223 

224 
(* mode *) 

225 

226 
fun get_mode (State ({mode, ...}, _)) = mode; 

227 
fun put_mode mode = map_current (fn (ctxt, facts, _, goal) => (ctxt, facts, mode, goal)); 

228 

229 
val enter_forward = put_mode Forward; 

230 
val enter_forward_chain = put_mode ForwardChain; 

231 
val enter_backward = put_mode Backward; 

232 

233 
fun assert_mode pred state = 

234 
let val mode = get_mode state in 

235 
if pred mode then state 

6731  236 
else raise STATE ("Illegal application of proof command in " ^ mode_name mode ^ " mode", state) 
5820  237 
end; 
238 

239 
fun is_chain state = get_mode state = ForwardChain; 

240 
val assert_forward = assert_mode (equal Forward); 

241 
val assert_forward_or_chain = assert_mode (equal Forward orf equal ForwardChain); 

242 
val assert_backward = assert_mode (equal Backward); 

243 

244 

245 
(* blocks *) 

246 

247 
fun open_block (State (node, nodes)) = State (node, node :: nodes); 

248 

249 
fun new_block state = 

250 
state 

251 
> open_block 

252 
> put_goal None; 

253 

254 
fun close_block (State (_, node :: nodes)) = State (node, nodes) 

255 
 close_block state = raise STATE ("Unbalanced block parentheses", state); 

256 

257 

258 

259 
(** print_state **) 

260 

6529  261 
val verbose = ProofContext.verbose; 
262 

5820  263 
fun print_state (state as State ({context, facts, mode, goal = _}, nodes)) = 
264 
let 

5945
63184e276c1d
print_state: use begin_goal from Goals.current_goals_markers;
wenzelm
parents:
5936
diff
changeset

265 
val ref (_, _, begin_goal) = Goals.current_goals_markers; 
5820  266 

267 
fun print_facts None = () 

268 
 print_facts (Some ths) = 

6091  269 
Pretty.writeln (Pretty.big_list "Current facts:" (map Display.pretty_thm ths)); 
5820  270 

271 
fun levels_up 0 = "" 

272 
 levels_up i = " (" ^ string_of_int i ^ " levels up)"; 

273 

274 
fun print_goal (i, ((kind, name, _, _), (_, thm))) = 

6262  275 
(writeln (kind_name kind ^ " " ^ quote name ^ levels_up (i div 2) ^ ":"); 
5945
63184e276c1d
print_state: use begin_goal from Goals.current_goals_markers;
wenzelm
parents:
5936
diff
changeset

276 
Locale.print_goals_marker begin_goal (! goals_limit) thm); 
5820  277 
in 
6262  278 
writeln ("Nesting level: " ^ string_of_int (length nodes div 2)); 
5820  279 
writeln ""; 
6529  280 
writeln (enclose "`" "'" (mode_name mode) ^ " mode"); 
5993  281 
writeln ""; 
6529  282 
if ! verbose orelse mode = Forward then 
283 
(ProofContext.print_context context; 

284 
writeln ""; 

285 
print_facts facts; 

286 
print_goal (find_goal 0 state)) 

287 
else if mode = ForwardChain then print_facts facts 

288 
else print_goal (find_goal 0 state) 

5820  289 
end; 
290 

291 

292 

293 
(** proof steps **) 

294 

295 
(* datatype method *) 

296 

297 
datatype method = Method of 

6091  298 
thm list > (*use facts*) 
5820  299 
thm (*goal: subgoals ==> statement*) 
300 
> (thm * (*refined goal*) 

301 
(indexname * term) list * (*new bindings*) 

6091  302 
(string * thm list) list) (*new thms*) 
5820  303 
Seq.seq; 
304 

305 
val method = Method; 

306 

307 

308 
(* refine goal *) 

309 

310 
fun check_sign sg state = 

311 
if Sign.subsig (sg, sign_of state) then state 

312 
else raise STATE ("Bad signature of result: " ^ Sign.str_of_sg sg, state); 

313 

314 
fun refine meth_fun (state as State ({context, ...}, _)) = 

315 
let 

316 
val Method meth = meth_fun context; 

317 
val (_, (result, (facts, thm))) = find_goal 0 state; 

318 

319 
fun refn (thm', new_binds, new_thms) = 

320 
state 

321 
> check_sign (sign_of_thm thm') 

322 
> map_goal (K (result, (facts, thm'))) 

323 
> add_binds new_binds 

6091  324 
> put_thmss new_thms; 
5820  325 
in Seq.map refn (meth facts thm) end; 
326 

327 

328 
(* prepare result *) 

329 

330 
fun varify_frees names thm = 

331 
let 

332 
fun get_free x (None, t as Free (y, _)) = if x = y then Some t else None 

333 
 get_free _ (opt, _) = opt; 

334 

335 
fun find_free t x = foldl_aterms (get_free x) (None, t); 

336 

337 
val {sign, maxidx, prop, ...} = Thm.rep_thm thm; 

338 
val frees = map (Thm.cterm_of sign) (mapfilter (find_free prop) names); 

339 
in 

340 
thm 

341 
> Drule.forall_intr_list frees 

342 
> Drule.forall_elim_vars (maxidx + 1) 

343 
end; 

344 

345 
fun implies_elim_hyps thm = 

346 
foldl (uncurry Thm.implies_elim) (thm, map Thm.assume (Drule.cprems_of thm)); 

347 

348 
fun prep_result state asms t raw_thm = 

349 
let 

350 
val ctxt = context_of state; 

351 
fun err msg = raise STATE (msg, state); 

352 

353 
val ngoals = Thm.nprems_of raw_thm; 

354 
val _ = 

355 
if ngoals = 0 then () 

356 
else (Locale.print_goals ngoals raw_thm; err (string_of_int ngoals ^ " unsolved goal(s)!")); 

357 

358 
val thm = 

359 
raw_thm RS Drule.rev_triv_goal 

360 
> implies_elim_hyps 

361 
> Drule.implies_intr_list asms 

6731  362 
> varify_frees (ProofContext.fixed_names ctxt) 
363 
> Thm.varifyT; 

5820  364 

365 
val {hyps, prop, sign, ...} = Thm.rep_thm thm; 

366 
val tsig = Sign.tsig_of sign; 

367 
in 

368 
(* FIXME 

369 
if not (Pattern.matches tsig (t, Logic.skip_flexpairs prop)) then 

370 
warning ("Proved a different theorem: " ^ Sign.string_of_term sign prop) 

371 
else (); 

372 
*) 

373 
if not (null hyps) then 

374 
err ("Additional hypotheses:\n" ^ cat_lines (map (Sign.string_of_term sign) hyps)) 

375 
(* FIXME else if not (Pattern.matches tsig (t, Logic.skip_flexpairs prop)) then 

376 
err ("Proved a different theorem: " ^ Sign.string_of_term sign prop) *) 

377 
else thm 

378 
end; 

379 

380 

381 
(* prepare final result *) 

382 

383 
fun strip_flexflex thm = 

384 
Seq.hd (Thm.flexflex_rule thm) handle THM _ => thm; 

385 

386 
fun final_result state pre_thm = 

387 
let 

388 
val thm = 

389 
pre_thm 

390 
> strip_flexflex 

391 
> Thm.strip_shyps 

392 
> Drule.standard; 

393 

394 
val str_of_sort = Sign.str_of_sort (Thm.sign_of_thm thm); 

395 
val xshyps = Thm.extra_shyps thm; 

396 
in 

397 
if not (null xshyps) then 

398 
raise STATE ("Extra sort hypotheses: " ^ commas (map str_of_sort xshyps), state) 

399 
else thm 

400 
end; 

401 

402 

403 
(* solve goal *) 

404 

405 
fun solve_goal rule state = 

406 
let 

407 
val (_, (result, (facts, thm))) = find_goal 0 state; 

5993  408 
val thms' = FIRSTGOAL (rtac rule THEN_ALL_NEW (TRY o assume_tac)) thm; 
5820  409 
in Seq.map (fn thm' => map_goal (K (result, (facts, thm'))) state) thms' end; 
410 

411 

412 

413 
(*** structured proof commands ***) 

414 

415 
(** context **) 

416 

417 
(* bind *) 

418 

419 
fun gen_bind f x state = 

420 
state 

421 
> assert_forward 

422 
> map_context (f x) 

423 
> reset_facts; 

424 

425 
val bind = gen_bind ProofContext.add_binds; 

426 
val bind_i = gen_bind ProofContext.add_binds_i; 

427 

428 
val match_bind = gen_bind ProofContext.match_binds; 

429 
val match_bind_i = gen_bind ProofContext.match_binds_i; 

430 

431 

6091  432 
(* have_thmss *) 
5820  433 

6091  434 
fun have_thmss name atts ths_atts state = 
5820  435 
state 
436 
> assert_forward 

6091  437 
> map_context_result (ProofContext.have_thmss (PureThy.default_name name) atts ths_atts) 
5820  438 
> these_facts; 
439 

440 

441 
(* fix *) 

442 

443 
fun gen_fix f xs state = 

444 
state 

445 
> assert_forward 

446 
> map_context (f xs) 

447 
> reset_facts; 

448 

449 
val fix = gen_fix ProofContext.fix; 

450 
val fix_i = gen_fix ProofContext.fix_i; 

451 

452 

453 
(* assume *) 

454 

455 
fun gen_assume f name atts props state = 

456 
state 

457 
> assert_forward 

5918  458 
> map_context_result (f (PureThy.default_name name) atts props) 
5820  459 
> these_facts 
6091  460 
> (fn st => let_thms ("prems", ProofContext.assumptions (context_of st)) st); 
5820  461 

462 
val assume = gen_assume ProofContext.assume; 

463 
val assume_i = gen_assume ProofContext.assume_i; 

464 

465 

466 

467 
(** goals **) 

468 

469 
(* forward chaining *) 

470 

471 
fun chain state = 

472 
state 

473 
> assert_forward 

474 
> enter_forward_chain; 

475 

476 
fun from_facts facts state = 

477 
state 

478 
> put_facts (Some facts) 

479 
> chain; 

480 

481 

482 
(* setup goals *) 

483 

5936  484 
fun setup_goal opt_block prepp kind name atts raw_propp state = 
5820  485 
let 
5936  486 
val (state', concl) = 
487 
state 

488 
> assert_forward_or_chain 

489 
> enter_forward 

490 
> opt_block 

491 
> map_context_result (fn c => prepp (c, raw_propp)); 

6752
0545b77f864e
setup_goal: proper handling of nonatomic goals (include cprems into asms);
wenzelm
parents:
6731
diff
changeset

492 
val cterm_of = Thm.cterm_of (sign_of state); 
5820  493 

6091  494 
val casms = map (#prop o Thm.crep_thm) (ProofContext.assumptions (context_of state')); 
6752
0545b77f864e
setup_goal: proper handling of nonatomic goals (include cprems into asms);
wenzelm
parents:
6731
diff
changeset

495 
val cprems = map cterm_of (Logic.strip_imp_prems concl); 
0545b77f864e
setup_goal: proper handling of nonatomic goals (include cprems into asms);
wenzelm
parents:
6731
diff
changeset

496 
val prop = Logic.list_implies (map Thm.term_of casms, concl); 
0545b77f864e
setup_goal: proper handling of nonatomic goals (include cprems into asms);
wenzelm
parents:
6731
diff
changeset

497 
val cprop = cterm_of prop; 
5820  498 
val thm = Drule.mk_triv_goal cprop; 
499 
in 

5936  500 
state' 
6752
0545b77f864e
setup_goal: proper handling of nonatomic goals (include cprems into asms);
wenzelm
parents:
6731
diff
changeset

501 
> put_goal (Some ((kind atts, (PureThy.default_name name), casms @ cprems, prop), ([], thm))) 
5820  502 
> bind_props [("thesis", prop)] 
503 
> (if is_chain state then use_facts else reset_facts) 

504 
> new_block 

505 
> enter_backward 

506 
end; 

507 

508 

509 
(*global goals*) 

510 
fun global_goal prep kind name atts x thy = 

511 
setup_goal I prep kind name atts x (init_state thy); 

512 

5936  513 
val theorem = global_goal ProofContext.bind_propp Theorem; 
514 
val theorem_i = global_goal ProofContext.bind_propp_i Theorem; 

515 
val lemma = global_goal ProofContext.bind_propp Lemma; 

516 
val lemma_i = global_goal ProofContext.bind_propp_i Lemma; 

5820  517 

518 

519 
(*local goals*) 

520 
fun local_goal prep kind name atts x = 

521 
setup_goal open_block prep kind name atts x; 

522 

5936  523 
val show = local_goal ProofContext.bind_propp Goal; 
524 
val show_i = local_goal ProofContext.bind_propp_i Goal; 

525 
val have = local_goal ProofContext.bind_propp Aux; 

526 
val have_i = local_goal ProofContext.bind_propp_i Aux; 

5820  527 

528 

529 

530 
(** blocks **) 

531 

532 
(* begin_block *) 

533 

534 
fun begin_block state = 

535 
state 

536 
> assert_forward 

537 
> new_block 

538 
> reset_facts 

539 
> open_block; 

540 

541 

542 
(* next_block *) 

543 

544 
fun next_block state = 

545 
state 

546 
> assert_forward 

547 
> close_block 

548 
> new_block; 

549 

550 

551 

552 
(** conclusions **) 

553 

554 
(* current goal *) 

555 

556 
fun current_goal (State ({goal = Some goal, ...}, _)) = goal 

557 
 current_goal state = raise STATE ("No current goal!", state); 

558 

6404  559 
fun assert_current_goal true (state as State ({goal = None, ...}, _)) = 
560 
raise STATE ("No goal in this block!", state) 

561 
 assert_current_goal false (state as State ({goal = Some _, ...}, _)) = 

562 
raise STATE ("Goal present in this block!", state) 

563 
 assert_current_goal _ state = state; 

5820  564 

565 
fun assert_bottom true (state as State (_, _ :: _)) = 

566 
raise STATE ("Not at bottom of proof!", state) 

567 
 assert_bottom false (state as State (_, [])) = 

568 
raise STATE ("Already at bottom of proof!", state) 

569 
 assert_bottom _ state = state; 

570 

6404  571 
val at_bottom = can (assert_bottom true o close_block); 
572 

5820  573 

574 
(* finish proof *) 

575 

576 
fun check_finished state states = 

577 
(case Seq.pull states of 

578 
None => raise STATE ("Failed to finish proof", state) 

579 
 Some s_sq => Seq.cons s_sq); 

580 

6404  581 
fun finish_proof bot finalize state = 
5820  582 
state 
583 
> assert_forward 

584 
> close_block 

585 
> assert_bottom bot 

6404  586 
> assert_current_goal true 
587 
> finalize 

5820  588 
> check_finished state; 
589 

590 

6404  591 
(* end_block *) 
592 

593 
fun end_block state = 

594 
state 

595 
> assert_forward 

596 
> close_block 

597 
> assert_current_goal false 

598 
> close_block 

599 
> fetch_facts state; 

600 

601 

602 
(* local_qed *) 

5820  603 

6731  604 
fun finish_local print_result state = 
5820  605 
let 
606 
val ((kind, name, asms, t), (_, raw_thm)) = current_goal state; 

607 
val result = prep_result state asms t raw_thm; 

608 
val (atts, opt_solve) = 

609 
(case kind of 

610 
Goal atts => (atts, solve_goal result) 

611 
 Aux atts => (atts, Seq.single) 

612 
 _ => raise STATE ("No local goal!", state)); 

613 
in 

6731  614 
print_result {kind = kind_name kind, name = name, thm = result}; 
5820  615 
state 
616 
> close_block 

6091  617 
> have_thmss name atts [Thm.no_attributes [result]] 
5820  618 
> opt_solve 
619 
end; 

620 

6731  621 
fun local_qed finalize print_result state = 
6404  622 
state 
623 
> finish_proof false finalize 

6731  624 
> (Seq.flat o Seq.map (finish_local print_result)); 
5820  625 

626 

6404  627 
(* global_qed *) 
5820  628 

629 
fun finish_global alt_name alt_atts state = 

630 
let 

631 
val ((kind, def_name, asms, t), (_, raw_thm)) = current_goal state; 

632 
val result = final_result state (prep_result state asms t raw_thm); 

633 

634 
val name = if_none alt_name def_name; 

635 
val atts = 

636 
(case kind of 

637 
Theorem atts => if_none alt_atts atts 

6091  638 
 Lemma atts => (if_none alt_atts atts) @ [Drule.tag_lemma] 
5820  639 
 _ => raise STATE ("No global goal!", state)); 
640 

6091  641 
val (thy', result') = PureThy.store_thm ((name, result), atts) (theory_of state); 
6529  642 
in (thy', {kind = kind_name kind, name = name, thm = result'}) end; 
5820  643 

6404  644 
fun global_qed finalize alt_name alt_atts state = 
5820  645 
state 
6404  646 
> finish_proof true finalize 
5820  647 
> Seq.hd 
648 
> finish_global alt_name alt_atts; 

649 

650 

651 
end; 