396 val refine_end = gen_refine false; |
395 val refine_end = gen_refine false; |
397 |
396 |
398 end; |
397 end; |
399 |
398 |
400 |
399 |
401 (* tacticals *) |
400 (* goal addressing *) |
402 |
|
403 fun RANGE [] _ = all_tac |
|
404 | RANGE (tac :: tacs) i = RANGE tacs (i + 1) THEN tac i; |
|
405 |
401 |
406 fun FINDGOAL tac st = |
402 fun FINDGOAL tac st = |
407 let fun find (i, n) = if i > n then Seq.fail else Seq.APPEND (tac i, find (i + 1, n)) |
403 let fun find (i, n) = if i > n then Seq.fail else Seq.APPEND (tac i, find (i + 1, n)) |
408 in find (1, Thm.nprems_of st) st end; |
404 in find (1, Thm.nprems_of st) st end; |
409 |
405 |
513 val fix_i = gen_fix ProofContext.fix_i; |
509 val fix_i = gen_fix ProofContext.fix_i; |
514 |
510 |
515 |
511 |
516 (* assume and presume *) |
512 (* assume and presume *) |
517 |
513 |
518 local |
|
519 |
|
520 fun gen_assume f exp args state = |
514 fun gen_assume f exp args state = |
521 state |
515 state |
522 |> assert_forward |
516 |> assert_forward |
523 |> map_context_result (f exp args) |
517 |> map_context_result (f exp args) |
524 |> (fn (st, (factss, prems)) => |
518 |> (fn (st, (factss, prems)) => |
525 these_factss (st, factss) |
519 these_factss (st, factss) |
526 |> put_thms ("prems", prems)); |
520 |> put_thms ("prems", prems)); |
527 |
521 |
528 fun export_assume true = Seq.single oo Drule.implies_intr_goals |
|
529 | export_assume false = Seq.single oo Drule.implies_intr_list; |
|
530 |
|
531 fun export_presume _ = export_assume false; |
|
532 |
|
533 in |
|
534 |
|
535 val assm = gen_assume ProofContext.assume; |
522 val assm = gen_assume ProofContext.assume; |
536 val assm_i = gen_assume ProofContext.assume_i; |
523 val assm_i = gen_assume ProofContext.assume_i; |
537 val assume = assm export_assume; |
524 val assume = assm ProofContext.export_assume; |
538 val assume_i = assm_i export_assume; |
525 val assume_i = assm_i ProofContext.export_assume; |
539 val presume = assm export_presume; |
526 val presume = assm ProofContext.export_presume; |
540 val presume_i = assm_i export_presume; |
527 val presume_i = assm_i ProofContext.export_presume; |
541 |
528 |
542 end; |
|
543 |
529 |
544 |
530 |
545 (** local definitions **) |
531 (** local definitions **) |
546 |
|
547 local |
|
548 |
|
549 fun dest_lhs cprop = |
|
550 let val x = #1 (Logic.dest_equals (Thm.term_of cprop)) |
|
551 in Term.dest_Free x; Thm.cterm_of (Thm.sign_of_cterm cprop) x end |
|
552 handle TERM _ => raise TERM ("Malformed definitional assumption encountered:\n" ^ |
|
553 quote (Display.string_of_cterm cprop), []); |
|
554 |
|
555 fun export_def _ cprops thm = |
|
556 thm |
|
557 |> Drule.implies_intr_list cprops |
|
558 |> Drule.forall_intr_list (map dest_lhs cprops) |
|
559 |> Drule.forall_elim_vars 0 |
|
560 |> RANGE (replicate (length cprops) (Tactic.rtac Drule.reflexive_thm)) 1; |
|
561 |
532 |
562 fun gen_def fix prep_term prep_pats raw_name atts (x, (raw_rhs, raw_pats)) state = |
533 fun gen_def fix prep_term prep_pats raw_name atts (x, (raw_rhs, raw_pats)) state = |
563 let |
534 let |
564 val _ = assert_forward state; |
535 val _ = assert_forward state; |
565 val ctxt = context_of state; |
536 val ctxt = context_of state; |
574 val lhs = ProofContext.bind_skolem ctxt [x] (Free (x, T)); |
545 val lhs = ProofContext.bind_skolem ctxt [x] (Free (x, T)); |
575 in |
546 in |
576 state |
547 state |
577 |> fix [([x], None)] |
548 |> fix [([x], None)] |
578 |> match_bind_i [(pats, rhs)] |
549 |> match_bind_i [(pats, rhs)] |
579 |> assm_i export_def [((name, atts), [(Logic.mk_equals (lhs, rhs), ([], []))])] |
550 |> assm_i ProofContext.export_def [((name, atts), [(Logic.mk_equals (lhs, rhs), ([], []))])] |
580 end; |
551 end; |
581 |
|
582 in |
|
583 |
552 |
584 val def = gen_def fix ProofContext.read_term ProofContext.read_term_pats; |
553 val def = gen_def fix ProofContext.read_term ProofContext.read_term_pats; |
585 val def_i = gen_def fix_i ProofContext.cert_term ProofContext.cert_term_pats; |
554 val def_i = gen_def fix_i ProofContext.cert_term ProofContext.cert_term_pats; |
586 |
|
587 end; |
|
588 |
555 |
589 |
556 |
590 (* invoke_case *) |
557 (* invoke_case *) |
591 |
558 |
592 fun invoke_case (name, xs, atts) state = |
559 fun invoke_case (name, xs, atts) state = |