author  wenzelm 
Tue, 01 Jun 1999 19:46:52 +0200  
changeset 6756  fe6eb161df3e 
parent 6752  0545b77f864e 
child 6776  55f1e6b639a4 
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 

6756  263 
fun print_facts _ None = () 
264 
 print_facts s (Some ths) = 

265 
Pretty.writeln (Pretty.big_list (s ^ " facts:") (map Display.pretty_thm ths)); 

266 

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

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

269 
val ref (_, _, begin_goal) = Goals.current_goals_markers; 
5820  270 

271 
fun levels_up 0 = "" 

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

273 

6756  274 
fun print_goal (i, ((kind, name, _, _), (goal_facts, thm))) = 
275 
(print_facts "Using" (if null goal_facts then None else Some goal_facts); 

276 
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

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

285 
writeln ""; 

6756  286 
print_facts "Current" facts; 
6529  287 
print_goal (find_goal 0 state)) 
6756  288 
else if mode = ForwardChain then print_facts "Picking" facts 
6529  289 
else print_goal (find_goal 0 state) 
5820  290 
end; 
291 

292 

293 

294 
(** proof steps **) 

295 

296 
(* datatype method *) 

297 

298 
datatype method = Method of 

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

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

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

306 
val method = Method; 

307 

308 

309 
(* refine goal *) 

310 

311 
fun check_sign sg state = 

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

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

314 

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

316 
let 

317 
val Method meth = meth_fun context; 

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

319 

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

321 
state 

322 
> check_sign (sign_of_thm thm') 

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

324 
> add_binds new_binds 

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

328 

329 
(* prepare result *) 

330 

331 
fun varify_frees names thm = 

332 
let 

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

334 
 get_free _ (opt, _) = opt; 

335 

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

337 

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

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

340 
in 

341 
thm 

342 
> Drule.forall_intr_list frees 

343 
> Drule.forall_elim_vars (maxidx + 1) 

344 
end; 

345 

346 
fun implies_elim_hyps thm = 

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

348 

349 
fun prep_result state asms t raw_thm = 

350 
let 

351 
val ctxt = context_of state; 

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

353 

354 
val ngoals = Thm.nprems_of raw_thm; 

355 
val _ = 

356 
if ngoals = 0 then () 

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

358 

359 
val thm = 

360 
raw_thm RS Drule.rev_triv_goal 

361 
> implies_elim_hyps 

362 
> Drule.implies_intr_list asms 

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

5820  365 

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

367 
val tsig = Sign.tsig_of sign; 

368 
in 

369 
(* FIXME 

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

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

372 
else (); 

373 
*) 

374 
if not (null hyps) then 

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

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

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

378 
else thm 

379 
end; 

380 

381 

382 
(* prepare final result *) 

383 

384 
fun strip_flexflex thm = 

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

386 

387 
fun final_result state pre_thm = 

388 
let 

389 
val thm = 

390 
pre_thm 

391 
> strip_flexflex 

392 
> Thm.strip_shyps 

393 
> Drule.standard; 

394 

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

396 
val xshyps = Thm.extra_shyps thm; 

397 
in 

398 
if not (null xshyps) then 

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

400 
else thm 

401 
end; 

402 

403 

404 
(* solve goal *) 

405 

406 
fun solve_goal rule state = 

407 
let 

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

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

412 

413 

414 
(*** structured proof commands ***) 

415 

416 
(** context **) 

417 

418 
(* bind *) 

419 

420 
fun gen_bind f x state = 

421 
state 

422 
> assert_forward 

423 
> map_context (f x) 

424 
> reset_facts; 

425 

426 
val bind = gen_bind ProofContext.add_binds; 

427 
val bind_i = gen_bind ProofContext.add_binds_i; 

428 

429 
val match_bind = gen_bind ProofContext.match_binds; 

430 
val match_bind_i = gen_bind ProofContext.match_binds_i; 

431 

432 

6091  433 
(* have_thmss *) 
5820  434 

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

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

441 

442 
(* fix *) 

443 

444 
fun gen_fix f xs state = 

445 
state 

446 
> assert_forward 

447 
> map_context (f xs) 

448 
> reset_facts; 

449 

450 
val fix = gen_fix ProofContext.fix; 

451 
val fix_i = gen_fix ProofContext.fix_i; 

452 

453 

454 
(* assume *) 

455 

456 
fun gen_assume f name atts props state = 

457 
state 

458 
> assert_forward 

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

463 
val assume = gen_assume ProofContext.assume; 

464 
val assume_i = gen_assume ProofContext.assume_i; 

465 

466 

467 

468 
(** goals **) 

469 

470 
(* forward chaining *) 

471 

472 
fun chain state = 

473 
state 

474 
> assert_forward 

475 
> enter_forward_chain; 

476 

477 
fun from_facts facts state = 

478 
state 

479 
> put_facts (Some facts) 

480 
> chain; 

481 

482 

483 
(* setup goals *) 

484 

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

489 
> assert_forward_or_chain 

490 
> enter_forward 

491 
> opt_block 

492 
> 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

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

6091  495 
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

496 
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

497 
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

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

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

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

505 
> new_block 

506 
> enter_backward 

507 
end; 

508 

509 

510 
(*global goals*) 

511 
fun global_goal prep kind name atts x thy = 

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

513 

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

516 
val lemma = global_goal ProofContext.bind_propp Lemma; 

517 
val lemma_i = global_goal ProofContext.bind_propp_i Lemma; 

5820  518 

519 

520 
(*local goals*) 

521 
fun local_goal prep kind name atts x = 

522 
setup_goal open_block prep kind name atts x; 

523 

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

526 
val have = local_goal ProofContext.bind_propp Aux; 

527 
val have_i = local_goal ProofContext.bind_propp_i Aux; 

5820  528 

529 

530 

531 
(** blocks **) 

532 

533 
(* begin_block *) 

534 

535 
fun begin_block state = 

536 
state 

537 
> assert_forward 

538 
> new_block 

539 
> reset_facts 

540 
> open_block; 

541 

542 

543 
(* next_block *) 

544 

545 
fun next_block state = 

546 
state 

547 
> assert_forward 

548 
> close_block 

549 
> new_block; 

550 

551 

552 

553 
(** conclusions **) 

554 

555 
(* current goal *) 

556 

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

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

559 

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

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

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

564 
 assert_current_goal _ state = state; 

5820  565 

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

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

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

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

570 
 assert_bottom _ state = state; 

571 

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

5820  574 

575 
(* finish proof *) 

576 

577 
fun check_finished state states = 

578 
(case Seq.pull states of 

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

580 
 Some s_sq => Seq.cons s_sq); 

581 

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

585 
> close_block 

586 
> assert_bottom bot 

6404  587 
> assert_current_goal true 
588 
> finalize 

5820  589 
> check_finished state; 
590 

591 

6404  592 
(* end_block *) 
593 

594 
fun end_block state = 

595 
state 

596 
> assert_forward 

597 
> close_block 

598 
> assert_current_goal false 

599 
> close_block 

600 
> fetch_facts state; 

601 

602 

603 
(* local_qed *) 

5820  604 

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

608 
val result = prep_result state asms t raw_thm; 

609 
val (atts, opt_solve) = 

610 
(case kind of 

611 
Goal atts => (atts, solve_goal result) 

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

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

614 
in 

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

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

621 

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

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

627 

6404  628 
(* global_qed *) 
5820  629 

630 
fun finish_global alt_name alt_atts state = 

631 
let 

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

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

634 

635 
val name = if_none alt_name def_name; 

636 
val atts = 

637 
(case kind of 

638 
Theorem atts => if_none alt_atts atts 

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

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

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

650 

651 

652 
end; 