149 |
149 |
150 |
150 |
151 fun put_data kind f = map_context o ProofContext.put_data kind f; |
151 fun put_data kind f = map_context o ProofContext.put_data kind f; |
152 val declare_term = map_context o ProofContext.declare_term; |
152 val declare_term = map_context o ProofContext.declare_term; |
153 val add_binds = map_context o ProofContext.add_binds_i; |
153 val add_binds = map_context o ProofContext.add_binds_i; |
|
154 val auto_bind_goal = map_context o ProofContext.auto_bind_goal; |
|
155 val auto_bind_facts = map_context o ProofContext.auto_bind_facts; |
154 val put_thms = map_context o ProofContext.put_thms; |
156 val put_thms = map_context o ProofContext.put_thms; |
155 val put_thmss = map_context o ProofContext.put_thmss; |
157 val put_thmss = map_context o ProofContext.put_thmss; |
156 |
158 |
157 |
159 |
158 (* bind statements *) |
160 (* bind statements *) |
159 |
161 |
|
162 (* FIXME |
160 fun bind_props bs state = |
163 fun bind_props bs state = |
161 let val mk_bind = map (fn (x, t) => ((Syntax.binding x, 0), t)) o ObjectLogic.dest_statement |
164 state |> add_binds (flat (map ObjectLogic.statement_bindings bs)) end; |
162 in state |> add_binds (flat (map mk_bind bs)) end; |
|
163 |
165 |
164 fun bind_thms (name, thms) state = |
166 fun bind_thms (name, thms) state = |
165 let |
167 let |
166 val props = map (#prop o Thm.rep_thm) thms; |
168 val props = map (#prop o Thm.rep_thm) thms; |
167 val named_props = |
169 val named_props = |
172 |
174 |
173 fun let_thms name_thms state = |
175 fun let_thms name_thms state = |
174 state |
176 state |
175 |> put_thms name_thms |
177 |> put_thms name_thms |
176 |> bind_thms name_thms; |
178 |> bind_thms name_thms; |
|
179 *) |
|
180 |
|
181 (* FIXME elim (!?) *) |
|
182 |
|
183 fun let_thms name_thms state = |
|
184 state |
|
185 |> put_thms name_thms; |
177 |
186 |
178 |
187 |
179 (* facts *) |
188 (* facts *) |
180 |
189 |
181 fun the_facts (State ({facts = Some facts, ...}, _)) = facts |
190 fun the_facts (State ({facts = Some facts, ...}, _)) = facts |
350 thm |
359 thm |
351 |> Drule.forall_intr_list frees |
360 |> Drule.forall_intr_list frees |
352 |> Drule.forall_elim_vars (maxidx + 1) |
361 |> Drule.forall_elim_vars (maxidx + 1) |
353 end; |
362 end; |
354 |
363 |
|
364 fun varify_tfrees thm = |
|
365 let |
|
366 val {hyps, prop, ...} = Thm.rep_thm thm; |
|
367 val frees = foldr Term.add_term_frees (prop :: hyps, []); |
|
368 val leave_tfrees = foldr Term.add_term_tfree_names (frees, []); |
|
369 in thm |> Thm.varifyT' leave_tfrees end; |
|
370 |
355 fun implies_elim_hyps thm = |
371 fun implies_elim_hyps thm = |
356 foldl (uncurry Thm.implies_elim) (thm, map Thm.assume (Drule.cprems_of thm)); |
372 foldl (uncurry Thm.implies_elim) (thm, map Thm.assume (Drule.cprems_of thm)); |
357 |
373 |
358 fun prep_result state asms t raw_thm = |
374 fun prep_result state asms t raw_thm = |
359 let |
375 let |
368 val thm = |
384 val thm = |
369 raw_thm RS Drule.rev_triv_goal |
385 raw_thm RS Drule.rev_triv_goal |
370 |> implies_elim_hyps |
386 |> implies_elim_hyps |
371 |> Drule.implies_intr_list asms |
387 |> Drule.implies_intr_list asms |
372 |> varify_frees (ProofContext.fixed_names ctxt) |
388 |> varify_frees (ProofContext.fixed_names ctxt) |
373 |> Thm.varifyT; |
389 |> varify_tfrees; |
374 |
390 |
375 val {hyps, prop, sign, ...} = Thm.rep_thm thm; |
391 val {hyps, prop, sign, ...} = Thm.rep_thm thm; |
376 val tsig = Sign.tsig_of sign; |
392 val tsig = Sign.tsig_of sign; |
377 in |
393 in |
378 (* FIXME |
394 (* FIXME |
382 *) |
398 *) |
383 if not (null hyps) then |
399 if not (null hyps) then |
384 err ("Additional hypotheses:\n" ^ cat_lines (map (Sign.string_of_term sign) hyps)) |
400 err ("Additional hypotheses:\n" ^ cat_lines (map (Sign.string_of_term sign) hyps)) |
385 (* FIXME else if not (Pattern.matches tsig (t, Logic.skip_flexpairs prop)) then |
401 (* FIXME else if not (Pattern.matches tsig (t, Logic.skip_flexpairs prop)) then |
386 err ("Proved a different theorem: " ^ Sign.string_of_term sign prop) *) |
402 err ("Proved a different theorem: " ^ Sign.string_of_term sign prop) *) |
387 else thm |
403 else (thm, prop) |
388 end; |
404 end; |
389 |
405 |
390 |
406 |
391 (* prepare final result *) |
407 (* prepare final result *) |
392 |
408 |
507 val cprop = cterm_of prop; |
523 val cprop = cterm_of prop; |
508 val thm = Drule.mk_triv_goal cprop; |
524 val thm = Drule.mk_triv_goal cprop; |
509 in |
525 in |
510 state' |
526 state' |
511 |> put_goal (Some ((kind atts, (PureThy.default_name name), casms @ cprems, prop), ([], thm))) |
527 |> put_goal (Some ((kind atts, (PureThy.default_name name), casms @ cprems, prop), ([], thm))) |
512 |> bind_props [("thesis", prop)] |
528 |> auto_bind_goal prop |
513 |> (if is_chain state then use_facts else reset_facts) |
529 |> (if is_chain state then use_facts else reset_facts) |
514 |> new_block |
530 |> new_block |
515 |> enter_backward |
531 |> enter_backward |
516 end; |
532 end; |
517 |
533 |
612 (* local_qed *) |
628 (* local_qed *) |
613 |
629 |
614 fun finish_local print_result state = |
630 fun finish_local print_result state = |
615 let |
631 let |
616 val ((kind, name, asms, t), (_, raw_thm)) = current_goal state; |
632 val ((kind, name, asms, t), (_, raw_thm)) = current_goal state; |
617 val result = prep_result state asms t raw_thm; |
633 val (result, result_prop) = prep_result state asms t raw_thm; |
618 val (atts, opt_solve) = |
634 val (atts, opt_solve) = |
619 (case kind of |
635 (case kind of |
620 Goal atts => (atts, solve_goal result) |
636 Goal atts => (atts, solve_goal result) |
621 | Aux atts => (atts, Seq.single) |
637 | Aux atts => (atts, Seq.single) |
622 | _ => raise STATE ("No local goal!", state)); |
638 | _ => raise STATE ("No local goal!", state)); |
623 in |
639 in |
624 print_result {kind = kind_name kind, name = name, thm = result}; |
640 print_result {kind = kind_name kind, name = name, thm = result}; |
625 state |
641 state |
626 |> close_block |
642 |> close_block |
|
643 |> auto_bind_facts [result_prop] |
627 |> have_thmss name atts [Thm.no_attributes [result]] |
644 |> have_thmss name atts [Thm.no_attributes [result]] |
628 |> opt_solve |
645 |> opt_solve |
629 end; |
646 end; |
630 |
647 |
631 fun local_qed finalize print_result state = |
648 fun local_qed finalize print_result state = |
637 (* global_qed *) |
654 (* global_qed *) |
638 |
655 |
639 fun finish_global alt_name alt_atts state = |
656 fun finish_global alt_name alt_atts state = |
640 let |
657 let |
641 val ((kind, def_name, asms, t), (_, raw_thm)) = current_goal state; |
658 val ((kind, def_name, asms, t), (_, raw_thm)) = current_goal state; |
642 val result = final_result state (prep_result state asms t raw_thm); |
659 val result = final_result state (#1 (prep_result state asms t raw_thm)); |
643 |
660 |
644 val name = if_none alt_name def_name; |
661 val name = if_none alt_name def_name; |
645 val atts = |
662 val atts = |
646 (case kind of |
663 (case kind of |
647 Theorem atts => if_none alt_atts atts |
664 Theorem atts => if_none alt_atts atts |