39 type thm |
39 type thm |
40 type conv = cterm -> thm |
40 type conv = cterm -> thm |
41 type attribute = Context.generic * thm -> Context.generic * thm |
41 type attribute = Context.generic * thm -> Context.generic * thm |
42 val rep_thm: thm -> |
42 val rep_thm: thm -> |
43 {thy_ref: theory_ref, |
43 {thy_ref: theory_ref, |
44 der: bool * Proofterm.proof, |
44 der: Deriv.T, |
45 tags: Properties.T, |
45 tags: Properties.T, |
46 maxidx: int, |
46 maxidx: int, |
47 shyps: sort list, |
47 shyps: sort list, |
48 hyps: term list, |
48 hyps: term list, |
49 tpairs: (term * term) list, |
49 tpairs: (term * term) list, |
50 prop: term} |
50 prop: term} |
51 val crep_thm: thm -> |
51 val crep_thm: thm -> |
52 {thy_ref: theory_ref, |
52 {thy_ref: theory_ref, |
53 der: bool * Proofterm.proof, |
53 der: Deriv.T, |
54 tags: Properties.T, |
54 tags: Properties.T, |
55 maxidx: int, |
55 maxidx: int, |
56 shyps: sort list, |
56 shyps: sort list, |
57 hyps: cterm list, |
57 hyps: cterm list, |
58 tpairs: (cterm * cterm) list, |
58 tpairs: (cterm * cterm) list, |
335 |
335 |
336 (*** Meta theorems ***) |
336 (*** Meta theorems ***) |
337 |
337 |
338 abstype thm = Thm of |
338 abstype thm = Thm of |
339 {thy_ref: theory_ref, (*dynamic reference to theory*) |
339 {thy_ref: theory_ref, (*dynamic reference to theory*) |
340 der: bool * Pt.proof, (*derivation*) |
340 der: Deriv.T, (*derivation*) |
341 tags: Properties.T, (*additional annotations/comments*) |
341 tags: Properties.T, (*additional annotations/comments*) |
342 maxidx: int, (*maximum index of any Var or TVar*) |
342 maxidx: int, (*maximum index of any Var or TVar*) |
343 shyps: sort list, (*sort hypotheses as ordered list*) |
343 shyps: sort list, (*sort hypotheses as ordered list*) |
344 hyps: term list, (*hypotheses as ordered list*) |
344 hyps: term list, (*hypotheses as ordered list*) |
345 tpairs: (term * term) list, (*flex-flex pairs*) |
345 tpairs: (term * term) list, (*flex-flex pairs*) |
392 fun theory_of_thm (Thm {thy_ref, ...}) = Theory.deref thy_ref; |
392 fun theory_of_thm (Thm {thy_ref, ...}) = Theory.deref thy_ref; |
393 fun maxidx_of (Thm {maxidx, ...}) = maxidx; |
393 fun maxidx_of (Thm {maxidx, ...}) = maxidx; |
394 fun maxidx_thm th i = Int.max (maxidx_of th, i); |
394 fun maxidx_thm th i = Int.max (maxidx_of th, i); |
395 fun hyps_of (Thm {hyps, ...}) = hyps; |
395 fun hyps_of (Thm {hyps, ...}) = hyps; |
396 fun prop_of (Thm {prop, ...}) = prop; |
396 fun prop_of (Thm {prop, ...}) = prop; |
397 fun proof_of (Thm {der = (_, proof), ...}) = proof; |
397 fun proof_of (Thm {der, ...}) = Deriv.proof_of der; |
398 fun tpairs_of (Thm {tpairs, ...}) = tpairs; |
398 fun tpairs_of (Thm {tpairs, ...}) = tpairs; |
399 |
399 |
400 val concl_of = Logic.strip_imp_concl o prop_of; |
400 val concl_of = Logic.strip_imp_concl o prop_of; |
401 val prems_of = Logic.strip_imp_prems o prop_of; |
401 val prems_of = Logic.strip_imp_prems o prop_of; |
402 val nprems_of = Logic.count_prems o prop_of; |
402 val nprems_of = Logic.count_prems o prop_of; |
490 let |
490 let |
491 fun get_ax thy = |
491 fun get_ax thy = |
492 Symtab.lookup (Theory.axiom_table thy) name |
492 Symtab.lookup (Theory.axiom_table thy) name |
493 |> Option.map (fn prop => |
493 |> Option.map (fn prop => |
494 let |
494 let |
495 val der = Pt.infer_derivs' I (false, Pt.axm_proof name prop); |
495 val der = Deriv.rule0 (Pt.axm_proof name prop); |
496 val maxidx = maxidx_of_term prop; |
496 val maxidx = maxidx_of_term prop; |
497 val shyps = Sorts.insert_term prop []; |
497 val shyps = Sorts.insert_term prop []; |
498 in |
498 in |
499 Thm {thy_ref = Theory.check_thy thy, der = der, tags = [], |
499 Thm {thy_ref = Theory.check_thy thy, der = der, tags = [], |
500 maxidx = maxidx, shyps = shyps, hyps = [], tpairs = [], prop = prop} |
500 maxidx = maxidx, shyps = shyps, hyps = [], tpairs = [], prop = prop} |
521 map (fn s => (s, get_axiom_i thy s)) (Symtab.keys (Theory.axiom_table thy)); |
521 map (fn s => (s, get_axiom_i thy s)) (Symtab.keys (Theory.axiom_table thy)); |
522 |
522 |
523 |
523 |
524 (* official name and additional tags *) |
524 (* official name and additional tags *) |
525 |
525 |
526 fun get_name (Thm {hyps, prop, der = (_, prf), ...}) = |
526 fun get_name (Thm {hyps, prop, der, ...}) = |
527 Pt.get_name hyps prop prf; |
527 Pt.get_name hyps prop (Deriv.proof_of der); |
528 |
528 |
529 fun put_name name (Thm {thy_ref, der = (ora, prf), tags, maxidx, shyps, hyps, tpairs = [], prop}) = |
529 fun put_name name (Thm {thy_ref, der, tags, maxidx, shyps, hyps, tpairs = [], prop}) = |
530 let |
530 let |
531 val thy = Theory.deref thy_ref; |
531 val thy = Theory.deref thy_ref; |
532 val der = (ora, Pt.thm_proof thy name hyps prop prf); |
532 val der' = Deriv.uncond_rule (Pt.thm_proof thy name hyps prop) der; |
533 in |
533 in |
534 Thm {thy_ref = Theory.check_thy thy, der = der, tags = tags, maxidx = maxidx, |
534 Thm {thy_ref = Theory.check_thy thy, der = der', tags = tags, maxidx = maxidx, |
535 shyps = shyps, hyps = hyps, tpairs = [], prop = prop} |
535 shyps = shyps, hyps = hyps, tpairs = [], prop = prop} |
536 end |
536 end |
537 | put_name _ thm = raise THM ("name_thm: unsolved flex-flex constraints", 0, [thm]); |
537 | put_name _ thm = raise THM ("name_thm: unsolved flex-flex constraints", 0, [thm]); |
538 |
538 |
539 val get_tags = #tags o rep_thm; |
539 val get_tags = #tags o rep_thm; |
544 |
544 |
545 |
545 |
546 fun norm_proof (Thm {thy_ref, der, tags, maxidx, shyps, hyps, tpairs, prop}) = |
546 fun norm_proof (Thm {thy_ref, der, tags, maxidx, shyps, hyps, tpairs, prop}) = |
547 let |
547 let |
548 val thy = Theory.deref thy_ref; |
548 val thy = Theory.deref thy_ref; |
549 val der = Pt.infer_derivs' (Pt.rew_proof thy) der; |
549 val der' = Deriv.rule1 (Pt.rew_proof thy) der; |
550 in |
550 in |
551 Thm {thy_ref = Theory.check_thy thy, der = der, tags = tags, maxidx = maxidx, |
551 Thm {thy_ref = Theory.check_thy thy, der = der', tags = tags, maxidx = maxidx, |
552 shyps = shyps, hyps = hyps, tpairs = tpairs, prop = prop} |
552 shyps = shyps, hyps = hyps, tpairs = tpairs, prop = prop} |
553 end; |
553 end; |
554 |
554 |
555 fun adjust_maxidx_thm i (th as Thm {thy_ref, der, tags, maxidx, shyps, hyps, tpairs, prop}) = |
555 fun adjust_maxidx_thm i (th as Thm {thy_ref, der, tags, maxidx, shyps, hyps, tpairs, prop}) = |
556 if maxidx = i then th |
556 if maxidx = i then th |
573 if T <> propT then |
573 if T <> propT then |
574 raise THM ("assume: prop", 0, []) |
574 raise THM ("assume: prop", 0, []) |
575 else if maxidx <> ~1 then |
575 else if maxidx <> ~1 then |
576 raise THM ("assume: variables", maxidx, []) |
576 raise THM ("assume: variables", maxidx, []) |
577 else Thm {thy_ref = thy_ref, |
577 else Thm {thy_ref = thy_ref, |
578 der = Pt.infer_derivs' I (false, Pt.Hyp prop), |
578 der = Deriv.rule0 (Pt.Hyp prop), |
579 tags = [], |
579 tags = [], |
580 maxidx = ~1, |
580 maxidx = ~1, |
581 shyps = sorts, |
581 shyps = sorts, |
582 hyps = [prop], |
582 hyps = [prop], |
583 tpairs = [], |
583 tpairs = [], |
596 (th as Thm {der, maxidx, hyps, shyps, tpairs, prop, ...}) = |
596 (th as Thm {der, maxidx, hyps, shyps, tpairs, prop, ...}) = |
597 if T <> propT then |
597 if T <> propT then |
598 raise THM ("implies_intr: assumptions must have type prop", 0, [th]) |
598 raise THM ("implies_intr: assumptions must have type prop", 0, [th]) |
599 else |
599 else |
600 Thm {thy_ref = merge_thys1 ct th, |
600 Thm {thy_ref = merge_thys1 ct th, |
601 der = Pt.infer_derivs' (Pt.implies_intr_proof A) der, |
601 der = Deriv.rule1 (Pt.implies_intr_proof A) der, |
602 tags = [], |
602 tags = [], |
603 maxidx = Int.max (maxidxA, maxidx), |
603 maxidx = Int.max (maxidxA, maxidx), |
604 shyps = Sorts.union sorts shyps, |
604 shyps = Sorts.union sorts shyps, |
605 hyps = OrdList.remove Term.fast_term_ord A hyps, |
605 hyps = OrdList.remove Term.fast_term_ord A hyps, |
606 tpairs = tpairs, |
606 tpairs = tpairs, |
621 in |
621 in |
622 case prop of |
622 case prop of |
623 Const ("==>", _) $ A $ B => |
623 Const ("==>", _) $ A $ B => |
624 if A aconv propA then |
624 if A aconv propA then |
625 Thm {thy_ref = merge_thys2 thAB thA, |
625 Thm {thy_ref = merge_thys2 thAB thA, |
626 der = Pt.infer_derivs (curry Pt.%%) der derA, |
626 der = Deriv.rule2 (curry Pt.%%) der derA, |
627 tags = [], |
627 tags = [], |
628 maxidx = Int.max (maxA, maxidx), |
628 maxidx = Int.max (maxA, maxidx), |
629 shyps = Sorts.union shypsA shyps, |
629 shyps = Sorts.union shypsA shyps, |
630 hyps = union_hyps hypsA hyps, |
630 hyps = union_hyps hypsA hyps, |
631 tpairs = union_tpairs tpairsA tpairs, |
631 tpairs = union_tpairs tpairsA tpairs, |
645 (ct as Cterm {t = x, T, sorts, ...}) |
645 (ct as Cterm {t = x, T, sorts, ...}) |
646 (th as Thm {der, maxidx, shyps, hyps, tpairs, prop, ...}) = |
646 (th as Thm {der, maxidx, shyps, hyps, tpairs, prop, ...}) = |
647 let |
647 let |
648 fun result a = |
648 fun result a = |
649 Thm {thy_ref = merge_thys1 ct th, |
649 Thm {thy_ref = merge_thys1 ct th, |
650 der = Pt.infer_derivs' (Pt.forall_intr_proof x a) der, |
650 der = Deriv.rule1 (Pt.forall_intr_proof x a) der, |
651 tags = [], |
651 tags = [], |
652 maxidx = maxidx, |
652 maxidx = maxidx, |
653 shyps = Sorts.union sorts shyps, |
653 shyps = Sorts.union sorts shyps, |
654 hyps = hyps, |
654 hyps = hyps, |
655 tpairs = tpairs, |
655 tpairs = tpairs, |
677 Const ("all", Type ("fun", [Type ("fun", [qary, _]), _])) $ A => |
677 Const ("all", Type ("fun", [Type ("fun", [qary, _]), _])) $ A => |
678 if T <> qary then |
678 if T <> qary then |
679 raise THM ("forall_elim: type mismatch", 0, [th]) |
679 raise THM ("forall_elim: type mismatch", 0, [th]) |
680 else |
680 else |
681 Thm {thy_ref = merge_thys1 ct th, |
681 Thm {thy_ref = merge_thys1 ct th, |
682 der = Pt.infer_derivs' (Pt.% o rpair (SOME t)) der, |
682 der = Deriv.rule1 (Pt.% o rpair (SOME t)) der, |
683 tags = [], |
683 tags = [], |
684 maxidx = Int.max (maxidx, maxt), |
684 maxidx = Int.max (maxidx, maxt), |
685 shyps = Sorts.union sorts shyps, |
685 shyps = Sorts.union sorts shyps, |
686 hyps = hyps, |
686 hyps = hyps, |
687 tpairs = tpairs, |
687 tpairs = tpairs, |
694 (*Reflexivity |
694 (*Reflexivity |
695 t == t |
695 t == t |
696 *) |
696 *) |
697 fun reflexive (ct as Cterm {thy_ref, t, T, maxidx, sorts}) = |
697 fun reflexive (ct as Cterm {thy_ref, t, T, maxidx, sorts}) = |
698 Thm {thy_ref = thy_ref, |
698 Thm {thy_ref = thy_ref, |
699 der = Pt.infer_derivs' I (false, Pt.reflexive), |
699 der = Deriv.rule0 Pt.reflexive, |
700 tags = [], |
700 tags = [], |
701 maxidx = maxidx, |
701 maxidx = maxidx, |
702 shyps = sorts, |
702 shyps = sorts, |
703 hyps = [], |
703 hyps = [], |
704 tpairs = [], |
704 tpairs = [], |
711 *) |
711 *) |
712 fun symmetric (th as Thm {thy_ref, der, maxidx, shyps, hyps, tpairs, prop, ...}) = |
712 fun symmetric (th as Thm {thy_ref, der, maxidx, shyps, hyps, tpairs, prop, ...}) = |
713 (case prop of |
713 (case prop of |
714 (eq as Const ("==", Type (_, [T, _]))) $ t $ u => |
714 (eq as Const ("==", Type (_, [T, _]))) $ t $ u => |
715 Thm {thy_ref = thy_ref, |
715 Thm {thy_ref = thy_ref, |
716 der = Pt.infer_derivs' Pt.symmetric der, |
716 der = Deriv.rule1 Pt.symmetric der, |
717 tags = [], |
717 tags = [], |
718 maxidx = maxidx, |
718 maxidx = maxidx, |
719 shyps = shyps, |
719 shyps = shyps, |
720 hyps = hyps, |
720 hyps = hyps, |
721 tpairs = tpairs, |
721 tpairs = tpairs, |
738 case (prop1, prop2) of |
738 case (prop1, prop2) of |
739 ((eq as Const ("==", Type (_, [T, _]))) $ t1 $ u, Const ("==", _) $ u' $ t2) => |
739 ((eq as Const ("==", Type (_, [T, _]))) $ t1 $ u, Const ("==", _) $ u' $ t2) => |
740 if not (u aconv u') then err "middle term" |
740 if not (u aconv u') then err "middle term" |
741 else |
741 else |
742 Thm {thy_ref = merge_thys2 th1 th2, |
742 Thm {thy_ref = merge_thys2 th1 th2, |
743 der = Pt.infer_derivs (Pt.transitive u T) der1 der2, |
743 der = Deriv.rule2 (Pt.transitive u T) der1 der2, |
744 tags = [], |
744 tags = [], |
745 maxidx = Int.max (max1, max2), |
745 maxidx = Int.max (max1, max2), |
746 shyps = Sorts.union shyps1 shyps2, |
746 shyps = Sorts.union shyps1 shyps2, |
747 hyps = union_hyps hyps1 hyps2, |
747 hyps = union_hyps hyps1 hyps2, |
748 tpairs = union_tpairs tpairs1 tpairs2, |
748 tpairs = union_tpairs tpairs1 tpairs2, |
760 else |
760 else |
761 (case t of Abs (_, _, bodt) $ u => subst_bound (u, bodt) |
761 (case t of Abs (_, _, bodt) $ u => subst_bound (u, bodt) |
762 | _ => raise THM ("beta_conversion: not a redex", 0, [])); |
762 | _ => raise THM ("beta_conversion: not a redex", 0, [])); |
763 in |
763 in |
764 Thm {thy_ref = thy_ref, |
764 Thm {thy_ref = thy_ref, |
765 der = Pt.infer_derivs' I (false, Pt.reflexive), |
765 der = Deriv.rule0 Pt.reflexive, |
766 tags = [], |
766 tags = [], |
767 maxidx = maxidx, |
767 maxidx = maxidx, |
768 shyps = sorts, |
768 shyps = sorts, |
769 hyps = [], |
769 hyps = [], |
770 tpairs = [], |
770 tpairs = [], |
771 prop = Logic.mk_equals (t, t')} |
771 prop = Logic.mk_equals (t, t')} |
772 end; |
772 end; |
773 |
773 |
774 fun eta_conversion (Cterm {thy_ref, t, T, maxidx, sorts}) = |
774 fun eta_conversion (Cterm {thy_ref, t, T, maxidx, sorts}) = |
775 Thm {thy_ref = thy_ref, |
775 Thm {thy_ref = thy_ref, |
776 der = Pt.infer_derivs' I (false, Pt.reflexive), |
776 der = Deriv.rule0 Pt.reflexive, |
777 tags = [], |
777 tags = [], |
778 maxidx = maxidx, |
778 maxidx = maxidx, |
779 shyps = sorts, |
779 shyps = sorts, |
780 hyps = [], |
780 hyps = [], |
781 tpairs = [], |
781 tpairs = [], |
782 prop = Logic.mk_equals (t, Envir.eta_contract t)}; |
782 prop = Logic.mk_equals (t, Envir.eta_contract t)}; |
783 |
783 |
784 fun eta_long_conversion (Cterm {thy_ref, t, T, maxidx, sorts}) = |
784 fun eta_long_conversion (Cterm {thy_ref, t, T, maxidx, sorts}) = |
785 Thm {thy_ref = thy_ref, |
785 Thm {thy_ref = thy_ref, |
786 der = Pt.infer_derivs' I (false, Pt.reflexive), |
786 der = Deriv.rule0 Pt.reflexive, |
787 tags = [], |
787 tags = [], |
788 maxidx = maxidx, |
788 maxidx = maxidx, |
789 shyps = sorts, |
789 shyps = sorts, |
790 hyps = [], |
790 hyps = [], |
791 tpairs = [], |
791 tpairs = [], |
803 let |
803 let |
804 val (t, u) = Logic.dest_equals prop |
804 val (t, u) = Logic.dest_equals prop |
805 handle TERM _ => raise THM ("abstract_rule: premise not an equality", 0, [th]); |
805 handle TERM _ => raise THM ("abstract_rule: premise not an equality", 0, [th]); |
806 val result = |
806 val result = |
807 Thm {thy_ref = thy_ref, |
807 Thm {thy_ref = thy_ref, |
808 der = Pt.infer_derivs' (Pt.abstract_rule x a) der, |
808 der = Deriv.rule1 (Pt.abstract_rule x a) der, |
809 tags = [], |
809 tags = [], |
810 maxidx = maxidx, |
810 maxidx = maxidx, |
811 shyps = Sorts.union sorts shyps, |
811 shyps = Sorts.union sorts shyps, |
812 hyps = hyps, |
812 hyps = hyps, |
813 tpairs = tpairs, |
813 tpairs = tpairs, |
846 case (prop1, prop2) of |
846 case (prop1, prop2) of |
847 (Const ("==", Type ("fun", [fT, _])) $ f $ g, |
847 (Const ("==", Type ("fun", [fT, _])) $ f $ g, |
848 Const ("==", Type ("fun", [tT, _])) $ t $ u) => |
848 Const ("==", Type ("fun", [tT, _])) $ t $ u) => |
849 (chktypes fT tT; |
849 (chktypes fT tT; |
850 Thm {thy_ref = merge_thys2 th1 th2, |
850 Thm {thy_ref = merge_thys2 th1 th2, |
851 der = Pt.infer_derivs (Pt.combination f g t u fT) der1 der2, |
851 der = Deriv.rule2 (Pt.combination f g t u fT) der1 der2, |
852 tags = [], |
852 tags = [], |
853 maxidx = Int.max (max1, max2), |
853 maxidx = Int.max (max1, max2), |
854 shyps = Sorts.union shyps1 shyps2, |
854 shyps = Sorts.union shyps1 shyps2, |
855 hyps = union_hyps hyps1 hyps2, |
855 hyps = union_hyps hyps1 hyps2, |
856 tpairs = union_tpairs tpairs1 tpairs2, |
856 tpairs = union_tpairs tpairs1 tpairs2, |
873 in |
873 in |
874 case (prop1, prop2) of |
874 case (prop1, prop2) of |
875 (Const("==>", _) $ A $ B, Const("==>", _) $ B' $ A') => |
875 (Const("==>", _) $ A $ B, Const("==>", _) $ B' $ A') => |
876 if A aconv A' andalso B aconv B' then |
876 if A aconv A' andalso B aconv B' then |
877 Thm {thy_ref = merge_thys2 th1 th2, |
877 Thm {thy_ref = merge_thys2 th1 th2, |
878 der = Pt.infer_derivs (Pt.equal_intr A B) der1 der2, |
878 der = Deriv.rule2 (Pt.equal_intr A B) der1 der2, |
879 tags = [], |
879 tags = [], |
880 maxidx = Int.max (max1, max2), |
880 maxidx = Int.max (max1, max2), |
881 shyps = Sorts.union shyps1 shyps2, |
881 shyps = Sorts.union shyps1 shyps2, |
882 hyps = union_hyps hyps1 hyps2, |
882 hyps = union_hyps hyps1 hyps2, |
883 tpairs = union_tpairs tpairs1 tpairs2, |
883 tpairs = union_tpairs tpairs1 tpairs2, |
901 in |
901 in |
902 case prop1 of |
902 case prop1 of |
903 Const ("==", _) $ A $ B => |
903 Const ("==", _) $ A $ B => |
904 if prop2 aconv A then |
904 if prop2 aconv A then |
905 Thm {thy_ref = merge_thys2 th1 th2, |
905 Thm {thy_ref = merge_thys2 th1 th2, |
906 der = Pt.infer_derivs (Pt.equal_elim A B) der1 der2, |
906 der = Deriv.rule2 (Pt.equal_elim A B) der1 der2, |
907 tags = [], |
907 tags = [], |
908 maxidx = Int.max (max1, max2), |
908 maxidx = Int.max (max1, max2), |
909 shyps = Sorts.union shyps1 shyps2, |
909 shyps = Sorts.union shyps1 shyps2, |
910 hyps = union_hyps hyps1 hyps2, |
910 hyps = union_hyps hyps1 hyps2, |
911 tpairs = union_tpairs tpairs1 tpairs2, |
911 tpairs = union_tpairs tpairs1 tpairs2, |
930 else |
930 else |
931 let |
931 let |
932 val tpairs' = tpairs |> map (pairself (Envir.norm_term env)) |
932 val tpairs' = tpairs |> map (pairself (Envir.norm_term env)) |
933 (*remove trivial tpairs, of the form t==t*) |
933 (*remove trivial tpairs, of the form t==t*) |
934 |> filter_out (op aconv); |
934 |> filter_out (op aconv); |
935 val der = Pt.infer_derivs' (Pt.norm_proof' env) der; |
935 val der = Deriv.rule1 (Pt.norm_proof' env) der; |
936 val prop' = Envir.norm_term env prop; |
936 val prop' = Envir.norm_term env prop; |
937 val maxidx = maxidx_tpairs tpairs' (maxidx_of_term prop'); |
937 val maxidx = maxidx_tpairs tpairs' (maxidx_of_term prop'); |
938 val shyps = Envir.insert_sorts env shyps; |
938 val shyps = Envir.insert_sorts env shyps; |
939 in |
939 in |
940 Thm {thy_ref = Theory.check_thy thy, der = der, tags = [], maxidx = maxidx, |
940 Thm {thy_ref = Theory.check_thy thy, der = der, tags = [], maxidx = maxidx, |
1042 val (prop', maxidx1) = subst prop ~1; |
1042 val (prop', maxidx1) = subst prop ~1; |
1043 val (tpairs', maxidx') = |
1043 val (tpairs', maxidx') = |
1044 fold_map (fn (t, u) => fn i => subst t i ||>> subst u) tpairs maxidx1; |
1044 fold_map (fn (t, u) => fn i => subst t i ||>> subst u) tpairs maxidx1; |
1045 in |
1045 in |
1046 Thm {thy_ref = thy_ref', |
1046 Thm {thy_ref = thy_ref', |
1047 der = Pt.infer_derivs' (fn d => |
1047 der = Deriv.rule1 (fn d => |
1048 Pt.instantiate (map (apsnd #1) instT', map (apsnd #1) inst') d) der, |
1048 Pt.instantiate (map (apsnd #1) instT', map (apsnd #1) inst') d) der, |
1049 tags = [], |
1049 tags = [], |
1050 maxidx = maxidx', |
1050 maxidx = maxidx', |
1051 shyps = shyps', |
1051 shyps = shyps', |
1052 hyps = hyps, |
1052 hyps = hyps, |
1076 fun trivial (Cterm {thy_ref, t =A, T, maxidx, sorts}) = |
1076 fun trivial (Cterm {thy_ref, t =A, T, maxidx, sorts}) = |
1077 if T <> propT then |
1077 if T <> propT then |
1078 raise THM ("trivial: the term must have type prop", 0, []) |
1078 raise THM ("trivial: the term must have type prop", 0, []) |
1079 else |
1079 else |
1080 Thm {thy_ref = thy_ref, |
1080 Thm {thy_ref = thy_ref, |
1081 der = Pt.infer_derivs' I (false, Pt.AbsP ("H", NONE, Pt.PBound 0)), |
1081 der = Deriv.rule0 (Pt.AbsP ("H", NONE, Pt.PBound 0)), |
1082 tags = [], |
1082 tags = [], |
1083 maxidx = maxidx, |
1083 maxidx = maxidx, |
1084 shyps = sorts, |
1084 shyps = sorts, |
1085 hyps = [], |
1085 hyps = [], |
1086 tpairs = [], |
1086 tpairs = [], |
1090 fun class_triv thy c = |
1090 fun class_triv thy c = |
1091 let |
1091 let |
1092 val Cterm {t, maxidx, sorts, ...} = |
1092 val Cterm {t, maxidx, sorts, ...} = |
1093 cterm_of thy (Logic.mk_inclass (TVar ((Name.aT, 0), [c]), Sign.certify_class thy c)) |
1093 cterm_of thy (Logic.mk_inclass (TVar ((Name.aT, 0), [c]), Sign.certify_class thy c)) |
1094 handle TERM (msg, _) => raise THM ("class_triv: " ^ msg, 0, []); |
1094 handle TERM (msg, _) => raise THM ("class_triv: " ^ msg, 0, []); |
1095 val der = Pt.infer_derivs' I (false, Pt.PAxm ("Pure.class_triv:" ^ c, t, SOME [])); |
1095 val der = Deriv.rule0 (Pt.PAxm ("Pure.class_triv:" ^ c, t, SOME [])); |
1096 in |
1096 in |
1097 Thm {thy_ref = Theory.check_thy thy, der = der, tags = [], maxidx = maxidx, |
1097 Thm {thy_ref = Theory.check_thy thy, der = der, tags = [], maxidx = maxidx, |
1098 shyps = sorts, hyps = [], tpairs = [], prop = t} |
1098 shyps = sorts, hyps = [], tpairs = [], prop = t} |
1099 end; |
1099 end; |
1100 |
1100 |
1108 val T' = TVar ((x, i), []); |
1108 val T' = TVar ((x, i), []); |
1109 val unconstrain = Term.map_types (Term.map_atyps (fn U => if U = T then T' else U)); |
1109 val unconstrain = Term.map_types (Term.map_atyps (fn U => if U = T then T' else U)); |
1110 val constraints = map (curry Logic.mk_inclass T') S; |
1110 val constraints = map (curry Logic.mk_inclass T') S; |
1111 in |
1111 in |
1112 Thm {thy_ref = Theory.merge_refs (thy_ref1, thy_ref2), |
1112 Thm {thy_ref = Theory.merge_refs (thy_ref1, thy_ref2), |
1113 der = Pt.infer_derivs' I (false, Pt.PAxm ("Pure.unconstrainT", prop, SOME [])), |
1113 der = Deriv.rule0 (Pt.PAxm ("Pure.unconstrainT", prop, SOME [])), |
1114 tags = [], |
1114 tags = [], |
1115 maxidx = Int.max (maxidx, i), |
1115 maxidx = Int.max (maxidx, i), |
1116 shyps = Sorts.remove_sort S shyps, |
1116 shyps = Sorts.remove_sort S shyps, |
1117 hyps = hyps, |
1117 hyps = hyps, |
1118 tpairs = map (pairself unconstrain) tpairs, |
1118 tpairs = map (pairself unconstrain) tpairs, |
1126 val prop1 = attach_tpairs tpairs prop; |
1126 val prop1 = attach_tpairs tpairs prop; |
1127 val (al, prop2) = Type.varify tfrees prop1; |
1127 val (al, prop2) = Type.varify tfrees prop1; |
1128 val (ts, prop3) = Logic.strip_prems (length tpairs, [], prop2); |
1128 val (ts, prop3) = Logic.strip_prems (length tpairs, [], prop2); |
1129 in |
1129 in |
1130 (al, Thm {thy_ref = thy_ref, |
1130 (al, Thm {thy_ref = thy_ref, |
1131 der = Pt.infer_derivs' (Pt.varify_proof prop tfrees) der, |
1131 der = Deriv.rule1 (Pt.varify_proof prop tfrees) der, |
1132 tags = [], |
1132 tags = [], |
1133 maxidx = Int.max (0, maxidx), |
1133 maxidx = Int.max (0, maxidx), |
1134 shyps = shyps, |
1134 shyps = shyps, |
1135 hyps = hyps, |
1135 hyps = hyps, |
1136 tpairs = rev (map Logic.dest_equals ts), |
1136 tpairs = rev (map Logic.dest_equals ts), |
1145 val prop1 = attach_tpairs tpairs prop; |
1145 val prop1 = attach_tpairs tpairs prop; |
1146 val prop2 = Type.freeze prop1; |
1146 val prop2 = Type.freeze prop1; |
1147 val (ts, prop3) = Logic.strip_prems (length tpairs, [], prop2); |
1147 val (ts, prop3) = Logic.strip_prems (length tpairs, [], prop2); |
1148 in |
1148 in |
1149 Thm {thy_ref = thy_ref, |
1149 Thm {thy_ref = thy_ref, |
1150 der = Pt.infer_derivs' (Pt.freezeT prop1) der, |
1150 der = Deriv.rule1 (Pt.freezeT prop1) der, |
1151 tags = [], |
1151 tags = [], |
1152 maxidx = maxidx_of_term prop2, |
1152 maxidx = maxidx_of_term prop2, |
1153 shyps = shyps, |
1153 shyps = shyps, |
1154 hyps = hyps, |
1154 hyps = hyps, |
1155 tpairs = rev (map Logic.dest_equals ts), |
1155 tpairs = rev (map Logic.dest_equals ts), |
1178 val (As, B) = Logic.strip_horn prop; |
1178 val (As, B) = Logic.strip_horn prop; |
1179 in |
1179 in |
1180 if T <> propT then raise THM ("lift_rule: the term must have type prop", 0, []) |
1180 if T <> propT then raise THM ("lift_rule: the term must have type prop", 0, []) |
1181 else |
1181 else |
1182 Thm {thy_ref = merge_thys1 goal orule, |
1182 Thm {thy_ref = merge_thys1 goal orule, |
1183 der = Pt.infer_derivs' (Pt.lift_proof gprop inc prop) der, |
1183 der = Deriv.rule1 (Pt.lift_proof gprop inc prop) der, |
1184 tags = [], |
1184 tags = [], |
1185 maxidx = maxidx + inc, |
1185 maxidx = maxidx + inc, |
1186 shyps = Sorts.union shyps sorts, (*sic!*) |
1186 shyps = Sorts.union shyps sorts, (*sic!*) |
1187 hyps = hyps, |
1187 hyps = hyps, |
1188 tpairs = map (pairself lift_abs) tpairs, |
1188 tpairs = map (pairself lift_abs) tpairs, |
1192 fun incr_indexes i (thm as Thm {thy_ref, der, maxidx, shyps, hyps, tpairs, prop, ...}) = |
1192 fun incr_indexes i (thm as Thm {thy_ref, der, maxidx, shyps, hyps, tpairs, prop, ...}) = |
1193 if i < 0 then raise THM ("negative increment", 0, [thm]) |
1193 if i < 0 then raise THM ("negative increment", 0, [thm]) |
1194 else if i = 0 then thm |
1194 else if i = 0 then thm |
1195 else |
1195 else |
1196 Thm {thy_ref = thy_ref, |
1196 Thm {thy_ref = thy_ref, |
1197 der = Pt.infer_derivs' |
1197 der = Deriv.rule1 (Pt.map_proof_terms (Logic.incr_indexes ([], i)) (Logic.incr_tvar i)) der, |
1198 (Pt.map_proof_terms (Logic.incr_indexes ([], i)) (Logic.incr_tvar i)) der, |
|
1199 tags = [], |
1198 tags = [], |
1200 maxidx = maxidx + i, |
1199 maxidx = maxidx + i, |
1201 shyps = shyps, |
1200 shyps = shyps, |
1202 hyps = hyps, |
1201 hyps = hyps, |
1203 tpairs = map (pairself (Logic.incr_indexes ([], i))) tpairs, |
1202 tpairs = map (pairself (Logic.incr_indexes ([], i))) tpairs, |
1209 val Thm {thy_ref, der, maxidx, shyps, hyps, prop, ...} = state; |
1208 val Thm {thy_ref, der, maxidx, shyps, hyps, prop, ...} = state; |
1210 val thy = Theory.deref thy_ref; |
1209 val thy = Theory.deref thy_ref; |
1211 val (tpairs, Bs, Bi, C) = dest_state (state, i); |
1210 val (tpairs, Bs, Bi, C) = dest_state (state, i); |
1212 fun newth n (env as Envir.Envir {maxidx, ...}, tpairs) = |
1211 fun newth n (env as Envir.Envir {maxidx, ...}, tpairs) = |
1213 Thm { |
1212 Thm { |
1214 der = Pt.infer_derivs' |
1213 der = Deriv.rule1 |
1215 ((if Envir.is_empty env then I else (Pt.norm_proof' env)) o |
1214 ((if Envir.is_empty env then I else (Pt.norm_proof' env)) o |
1216 Pt.assumption_proof Bs Bi n) der, |
1215 Pt.assumption_proof Bs Bi n) der, |
1217 tags = [], |
1216 tags = [], |
1218 maxidx = maxidx, |
1217 maxidx = maxidx, |
1219 shyps = Envir.insert_sorts env shyps, |
1218 shyps = Envir.insert_sorts env shyps, |
1243 in |
1242 in |
1244 (case find_index Pattern.aeconv (Logic.assum_pairs (~1, Bi)) of |
1243 (case find_index Pattern.aeconv (Logic.assum_pairs (~1, Bi)) of |
1245 ~1 => raise THM ("eq_assumption", 0, [state]) |
1244 ~1 => raise THM ("eq_assumption", 0, [state]) |
1246 | n => |
1245 | n => |
1247 Thm {thy_ref = thy_ref, |
1246 Thm {thy_ref = thy_ref, |
1248 der = Pt.infer_derivs' (Pt.assumption_proof Bs Bi (n + 1)) der, |
1247 der = Deriv.rule1 (Pt.assumption_proof Bs Bi (n + 1)) der, |
1249 tags = [], |
1248 tags = [], |
1250 maxidx = maxidx, |
1249 maxidx = maxidx, |
1251 shyps = shyps, |
1250 shyps = shyps, |
1252 hyps = hyps, |
1251 hyps = hyps, |
1253 tpairs = tpairs, |
1252 tpairs = tpairs, |
1272 let val (ps, qs) = chop m asms |
1271 let val (ps, qs) = chop m asms |
1273 in list_all (params, Logic.list_implies (qs @ ps, concl)) end |
1272 in list_all (params, Logic.list_implies (qs @ ps, concl)) end |
1274 else raise THM ("rotate_rule", k, [state]); |
1273 else raise THM ("rotate_rule", k, [state]); |
1275 in |
1274 in |
1276 Thm {thy_ref = thy_ref, |
1275 Thm {thy_ref = thy_ref, |
1277 der = Pt.infer_derivs' (Pt.rotate_proof Bs Bi m) der, |
1276 der = Deriv.rule1 (Pt.rotate_proof Bs Bi m) der, |
1278 tags = [], |
1277 tags = [], |
1279 maxidx = maxidx, |
1278 maxidx = maxidx, |
1280 shyps = shyps, |
1279 shyps = shyps, |
1281 hyps = hyps, |
1280 hyps = hyps, |
1282 tpairs = tpairs, |
1281 tpairs = tpairs, |
1303 let val (ps, qs) = chop m moved_prems |
1302 let val (ps, qs) = chop m moved_prems |
1304 in Logic.list_implies (fixed_prems @ qs @ ps, concl) end |
1303 in Logic.list_implies (fixed_prems @ qs @ ps, concl) end |
1305 else raise THM ("permute_prems: k", k, [rl]); |
1304 else raise THM ("permute_prems: k", k, [rl]); |
1306 in |
1305 in |
1307 Thm {thy_ref = thy_ref, |
1306 Thm {thy_ref = thy_ref, |
1308 der = Pt.infer_derivs' (Pt.permute_prems_prf prems j m) der, |
1307 der = Deriv.rule1 (Pt.permute_prems_prf prems j m) der, |
1309 tags = [], |
1308 tags = [], |
1310 maxidx = maxidx, |
1309 maxidx = maxidx, |
1311 shyps = shyps, |
1310 shyps = shyps, |
1312 hyps = hyps, |
1311 hyps = hyps, |
1313 tpairs = tpairs, |
1312 tpairs = tpairs, |
1468 else if match then raise COMPOSE |
1467 else if match then raise COMPOSE |
1469 else (*normalize the new rule fully*) |
1468 else (*normalize the new rule fully*) |
1470 (ntps, (map normt (Bs @ As), normt C)) |
1469 (ntps, (map normt (Bs @ As), normt C)) |
1471 end |
1470 end |
1472 val th = |
1471 val th = |
1473 Thm{der = Pt.infer_derivs |
1472 Thm{der = Deriv.rule2 |
1474 ((if Envir.is_empty env then I |
1473 ((if Envir.is_empty env then I |
1475 else if Envir.above env smax then |
1474 else if Envir.above env smax then |
1476 (fn f => fn der => f (Pt.norm_proof' env der)) |
1475 (fn f => fn der => f (Pt.norm_proof' env der)) |
1477 else |
1476 else |
1478 curry op oo (Pt.norm_proof' env)) |
1477 curry op oo (Pt.norm_proof' env)) |
1490 (*Modify assumptions, deleting n-th if n>0 for e-resolution*) |
1489 (*Modify assumptions, deleting n-th if n>0 for e-resolution*) |
1491 fun newAs(As0, n, dpairs, tpairs) = |
1490 fun newAs(As0, n, dpairs, tpairs) = |
1492 let val (As1, rder') = |
1491 let val (As1, rder') = |
1493 if not lifted then (As0, rder) |
1492 if not lifted then (As0, rder) |
1494 else (map (rename_bvars(dpairs,tpairs,B)) As0, |
1493 else (map (rename_bvars(dpairs,tpairs,B)) As0, |
1495 Pt.infer_derivs' (Pt.map_proof_terms |
1494 Deriv.rule1 (Pt.map_proof_terms |
1496 (rename_bvars (dpairs, tpairs, Bound 0)) I) rder); |
1495 (rename_bvars (dpairs, tpairs, Bound 0)) I) rder); |
1497 in (map (if flatten then (Logic.flatten_params n) else I) As1, As1, rder', n) |
1496 in (map (if flatten then (Logic.flatten_params n) else I) As1, As1, rder', n) |
1498 handle TERM _ => |
1497 handle TERM _ => |
1499 raise THM("bicompose: 1st premise", 0, [orule]) |
1498 raise THM("bicompose: 1st premise", 0, [orule]) |
1500 end; |
1499 end; |
1569 fn (thy2, data) => |
1568 fn (thy2, data) => |
1570 let |
1569 let |
1571 val thy' = Theory.merge (Theory.deref thy_ref1, thy2); |
1570 val thy' = Theory.merge (Theory.deref thy_ref1, thy2); |
1572 val (prop, T, maxidx) = Sign.certify_term thy' (oracle (thy', data)); |
1571 val (prop, T, maxidx) = Sign.certify_term thy' (oracle (thy', data)); |
1573 val shyps' = Sorts.insert_term prop []; |
1572 val shyps' = Sorts.insert_term prop []; |
1574 val der = (true, Pt.oracle_proof name prop); |
1573 val der = Deriv.oracle name prop; |
1575 in |
1574 in |
1576 if T <> propT then |
1575 if T <> propT then |
1577 raise THM ("Oracle's result must have type prop: " ^ name, 0, []) |
1576 raise THM ("Oracle's result must have type prop: " ^ name, 0, []) |
1578 else |
1577 else |
1579 Thm {thy_ref = Theory.check_thy thy', der = der, tags = [], |
1578 Thm {thy_ref = Theory.check_thy thy', der = der, tags = [], |