770 B |
770 B |
771 ------- |
771 ------- |
772 A \<Longrightarrow> B |
772 A \<Longrightarrow> B |
773 *) |
773 *) |
774 fun implies_intr |
774 fun implies_intr |
775 (ct as Cterm {t = A, T, maxidx = maxidxA, sorts, ...}) |
775 (ct as Cterm {t = A, T, maxidx = maxidx1, sorts, ...}) |
776 (th as Thm (der, {maxidx, hyps, shyps, tpairs, prop, ...})) = |
776 (th as Thm (der, {maxidx = maxidx2, hyps, shyps, tpairs, prop, ...})) = |
777 if T <> propT then |
777 if T <> propT then |
778 raise THM ("implies_intr: assumptions must have type prop", 0, [th]) |
778 raise THM ("implies_intr: assumptions must have type prop", 0, [th]) |
779 else |
779 else |
780 Thm (deriv_rule1 (Proofterm.implies_intr_proof A) der, |
780 Thm (deriv_rule1 (Proofterm.implies_intr_proof A) der, |
781 {cert = join_certificate1 (ct, th), |
781 {cert = join_certificate1 (ct, th), |
782 tags = [], |
782 tags = [], |
783 maxidx = Int.max (maxidxA, maxidx), |
783 maxidx = Int.max (maxidx1, maxidx2), |
784 shyps = Sorts.union sorts shyps, |
784 shyps = Sorts.union sorts shyps, |
785 hyps = remove_hyps A hyps, |
785 hyps = remove_hyps A hyps, |
786 tpairs = tpairs, |
786 tpairs = tpairs, |
787 prop = Logic.mk_implies (A, prop)}); |
787 prop = Logic.mk_implies (A, prop)}); |
788 |
788 |
792 ------------ |
792 ------------ |
793 B |
793 B |
794 *) |
794 *) |
795 fun implies_elim thAB thA = |
795 fun implies_elim thAB thA = |
796 let |
796 let |
797 val Thm (derA, {maxidx = maxA, hyps = hypsA, shyps = shypsA, tpairs = tpairsA, |
797 val Thm (derA, {maxidx = maxidx1, hyps = hypsA, shyps = shypsA, tpairs = tpairsA, |
798 prop = propA, ...}) = thA |
798 prop = propA, ...}) = thA |
799 and Thm (der, {maxidx, hyps, shyps, tpairs, prop, ...}) = thAB; |
799 and Thm (der, {maxidx = maxidx2, hyps, shyps, tpairs, prop, ...}) = thAB; |
800 fun err () = raise THM ("implies_elim: major premise", 0, [thAB, thA]); |
800 fun err () = raise THM ("implies_elim: major premise", 0, [thAB, thA]); |
801 in |
801 in |
802 case prop of |
802 case prop of |
803 Const ("Pure.imp", _) $ A $ B => |
803 Const ("Pure.imp", _) $ A $ B => |
804 if A aconv propA then |
804 if A aconv propA then |
805 Thm (deriv_rule2 (curry Proofterm.%%) der derA, |
805 Thm (deriv_rule2 (curry Proofterm.%%) der derA, |
806 {cert = join_certificate2 (thAB, thA), |
806 {cert = join_certificate2 (thAB, thA), |
807 tags = [], |
807 tags = [], |
808 maxidx = Int.max (maxA, maxidx), |
808 maxidx = Int.max (maxidx1, maxidx2), |
809 shyps = Sorts.union shypsA shyps, |
809 shyps = Sorts.union shypsA shyps, |
810 hyps = union_hyps hypsA hyps, |
810 hyps = union_hyps hypsA hyps, |
811 tpairs = union_tpairs tpairsA tpairs, |
811 tpairs = union_tpairs tpairsA tpairs, |
812 prop = B}) |
812 prop = B}) |
813 else err () |
813 else err () |
849 \<And>x. A |
849 \<And>x. A |
850 ------ |
850 ------ |
851 A[t/x] |
851 A[t/x] |
852 *) |
852 *) |
853 fun forall_elim |
853 fun forall_elim |
854 (ct as Cterm {t, T, maxidx = maxt, sorts, ...}) |
854 (ct as Cterm {t, T, maxidx = maxidx1, sorts, ...}) |
855 (th as Thm (der, {maxidx, shyps, hyps, tpairs, prop, ...})) = |
855 (th as Thm (der, {maxidx = maxidx2, shyps, hyps, tpairs, prop, ...})) = |
856 (case prop of |
856 (case prop of |
857 Const ("Pure.all", Type ("fun", [Type ("fun", [qary, _]), _])) $ A => |
857 Const ("Pure.all", Type ("fun", [Type ("fun", [qary, _]), _])) $ A => |
858 if T <> qary then |
858 if T <> qary then |
859 raise THM ("forall_elim: type mismatch", 0, [th]) |
859 raise THM ("forall_elim: type mismatch", 0, [th]) |
860 else |
860 else |
861 Thm (deriv_rule1 (Proofterm.% o rpair (SOME t)) der, |
861 Thm (deriv_rule1 (Proofterm.% o rpair (SOME t)) der, |
862 {cert = join_certificate1 (ct, th), |
862 {cert = join_certificate1 (ct, th), |
863 tags = [], |
863 tags = [], |
864 maxidx = Int.max (maxidx, maxt), |
864 maxidx = Int.max (maxidx1, maxidx2), |
865 shyps = Sorts.union sorts shyps, |
865 shyps = Sorts.union sorts shyps, |
866 hyps = hyps, |
866 hyps = hyps, |
867 tpairs = tpairs, |
867 tpairs = tpairs, |
868 prop = Term.betapply (A, t)}) |
868 prop = Term.betapply (A, t)}) |
869 | _ => raise THM ("forall_elim: not quantified", 0, [th])); |
869 | _ => raise THM ("forall_elim: not quantified", 0, [th])); |
907 ------------------ |
907 ------------------ |
908 t1 \<equiv> t2 |
908 t1 \<equiv> t2 |
909 *) |
909 *) |
910 fun transitive th1 th2 = |
910 fun transitive th1 th2 = |
911 let |
911 let |
912 val Thm (der1, {maxidx = max1, hyps = hyps1, shyps = shyps1, tpairs = tpairs1, |
912 val Thm (der1, {maxidx = maxidx1, hyps = hyps1, shyps = shyps1, tpairs = tpairs1, |
913 prop = prop1, ...}) = th1 |
913 prop = prop1, ...}) = th1 |
914 and Thm (der2, {maxidx = max2, hyps = hyps2, shyps = shyps2, tpairs = tpairs2, |
914 and Thm (der2, {maxidx = maxidx2, hyps = hyps2, shyps = shyps2, tpairs = tpairs2, |
915 prop = prop2, ...}) = th2; |
915 prop = prop2, ...}) = th2; |
916 fun err msg = raise THM ("transitive: " ^ msg, 0, [th1, th2]); |
916 fun err msg = raise THM ("transitive: " ^ msg, 0, [th1, th2]); |
917 in |
917 in |
918 case (prop1, prop2) of |
918 case (prop1, prop2) of |
919 ((eq as Const ("Pure.eq", Type (_, [T, _]))) $ t1 $ u, Const ("Pure.eq", _) $ u' $ t2) => |
919 ((eq as Const ("Pure.eq", Type (_, [T, _]))) $ t1 $ u, Const ("Pure.eq", _) $ u' $ t2) => |
920 if not (u aconv u') then err "middle term" |
920 if not (u aconv u') then err "middle term" |
921 else |
921 else |
922 Thm (deriv_rule2 (Proofterm.transitive u T) der1 der2, |
922 Thm (deriv_rule2 (Proofterm.transitive u T) der1 der2, |
923 {cert = join_certificate2 (th1, th2), |
923 {cert = join_certificate2 (th1, th2), |
924 tags = [], |
924 tags = [], |
925 maxidx = Int.max (max1, max2), |
925 maxidx = Int.max (maxidx1, maxidx2), |
926 shyps = Sorts.union shyps1 shyps2, |
926 shyps = Sorts.union shyps1 shyps2, |
927 hyps = union_hyps hyps1 hyps2, |
927 hyps = union_hyps hyps1 hyps2, |
928 tpairs = union_tpairs tpairs1 tpairs2, |
928 tpairs = union_tpairs tpairs1 tpairs2, |
929 prop = eq $ t1 $ t2}) |
929 prop = eq $ t1 $ t2}) |
930 | _ => err "premises" |
930 | _ => err "premises" |
1009 ------------- |
1009 ------------- |
1010 f t \<equiv> g u |
1010 f t \<equiv> g u |
1011 *) |
1011 *) |
1012 fun combination th1 th2 = |
1012 fun combination th1 th2 = |
1013 let |
1013 let |
1014 val Thm (der1, {maxidx = max1, shyps = shyps1, hyps = hyps1, tpairs = tpairs1, |
1014 val Thm (der1, {maxidx = maxidx1, shyps = shyps1, hyps = hyps1, tpairs = tpairs1, |
1015 prop = prop1, ...}) = th1 |
1015 prop = prop1, ...}) = th1 |
1016 and Thm (der2, {maxidx = max2, shyps = shyps2, hyps = hyps2, tpairs = tpairs2, |
1016 and Thm (der2, {maxidx = maxidx2, shyps = shyps2, hyps = hyps2, tpairs = tpairs2, |
1017 prop = prop2, ...}) = th2; |
1017 prop = prop2, ...}) = th2; |
1018 fun chktypes fT tT = |
1018 fun chktypes fT tT = |
1019 (case fT of |
1019 (case fT of |
1020 Type ("fun", [T1, _]) => |
1020 Type ("fun", [T1, _]) => |
1021 if T1 <> tT then |
1021 if T1 <> tT then |
1028 Const ("Pure.eq", Type ("fun", [tT, _])) $ t $ u) => |
1028 Const ("Pure.eq", Type ("fun", [tT, _])) $ t $ u) => |
1029 (chktypes fT tT; |
1029 (chktypes fT tT; |
1030 Thm (deriv_rule2 (Proofterm.combination f g t u fT) der1 der2, |
1030 Thm (deriv_rule2 (Proofterm.combination f g t u fT) der1 der2, |
1031 {cert = join_certificate2 (th1, th2), |
1031 {cert = join_certificate2 (th1, th2), |
1032 tags = [], |
1032 tags = [], |
1033 maxidx = Int.max (max1, max2), |
1033 maxidx = Int.max (maxidx1, maxidx2), |
1034 shyps = Sorts.union shyps1 shyps2, |
1034 shyps = Sorts.union shyps1 shyps2, |
1035 hyps = union_hyps hyps1 hyps2, |
1035 hyps = union_hyps hyps1 hyps2, |
1036 tpairs = union_tpairs tpairs1 tpairs2, |
1036 tpairs = union_tpairs tpairs1 tpairs2, |
1037 prop = Logic.mk_equals (f $ t, g $ u)})) |
1037 prop = Logic.mk_equals (f $ t, g $ u)})) |
1038 | _ => raise THM ("combination: premises", 0, [th1, th2])) |
1038 | _ => raise THM ("combination: premises", 0, [th1, th2])) |
1043 ---------------- |
1043 ---------------- |
1044 A \<equiv> B |
1044 A \<equiv> B |
1045 *) |
1045 *) |
1046 fun equal_intr th1 th2 = |
1046 fun equal_intr th1 th2 = |
1047 let |
1047 let |
1048 val Thm (der1, {maxidx = max1, shyps = shyps1, hyps = hyps1, tpairs = tpairs1, |
1048 val Thm (der1, {maxidx = maxidx1, shyps = shyps1, hyps = hyps1, tpairs = tpairs1, |
1049 prop = prop1, ...}) = th1 |
1049 prop = prop1, ...}) = th1 |
1050 and Thm (der2, {maxidx = max2, shyps = shyps2, hyps = hyps2, tpairs = tpairs2, |
1050 and Thm (der2, {maxidx = maxidx2, shyps = shyps2, hyps = hyps2, tpairs = tpairs2, |
1051 prop = prop2, ...}) = th2; |
1051 prop = prop2, ...}) = th2; |
1052 fun err msg = raise THM ("equal_intr: " ^ msg, 0, [th1, th2]); |
1052 fun err msg = raise THM ("equal_intr: " ^ msg, 0, [th1, th2]); |
1053 in |
1053 in |
1054 (case (prop1, prop2) of |
1054 (case (prop1, prop2) of |
1055 (Const("Pure.imp", _) $ A $ B, Const("Pure.imp", _) $ B' $ A') => |
1055 (Const("Pure.imp", _) $ A $ B, Const("Pure.imp", _) $ B' $ A') => |
1056 if A aconv A' andalso B aconv B' then |
1056 if A aconv A' andalso B aconv B' then |
1057 Thm (deriv_rule2 (Proofterm.equal_intr A B) der1 der2, |
1057 Thm (deriv_rule2 (Proofterm.equal_intr A B) der1 der2, |
1058 {cert = join_certificate2 (th1, th2), |
1058 {cert = join_certificate2 (th1, th2), |
1059 tags = [], |
1059 tags = [], |
1060 maxidx = Int.max (max1, max2), |
1060 maxidx = Int.max (maxidx1, maxidx2), |
1061 shyps = Sorts.union shyps1 shyps2, |
1061 shyps = Sorts.union shyps1 shyps2, |
1062 hyps = union_hyps hyps1 hyps2, |
1062 hyps = union_hyps hyps1 hyps2, |
1063 tpairs = union_tpairs tpairs1 tpairs2, |
1063 tpairs = union_tpairs tpairs1 tpairs2, |
1064 prop = Logic.mk_equals (A, B)}) |
1064 prop = Logic.mk_equals (A, B)}) |
1065 else err "not equal" |
1065 else err "not equal" |
1071 --------- |
1071 --------- |
1072 B |
1072 B |
1073 *) |
1073 *) |
1074 fun equal_elim th1 th2 = |
1074 fun equal_elim th1 th2 = |
1075 let |
1075 let |
1076 val Thm (der1, {maxidx = max1, shyps = shyps1, hyps = hyps1, |
1076 val Thm (der1, {maxidx = maxidx1, shyps = shyps1, hyps = hyps1, |
1077 tpairs = tpairs1, prop = prop1, ...}) = th1 |
1077 tpairs = tpairs1, prop = prop1, ...}) = th1 |
1078 and Thm (der2, {maxidx = max2, shyps = shyps2, hyps = hyps2, |
1078 and Thm (der2, {maxidx = maxidx2, shyps = shyps2, hyps = hyps2, |
1079 tpairs = tpairs2, prop = prop2, ...}) = th2; |
1079 tpairs = tpairs2, prop = prop2, ...}) = th2; |
1080 fun err msg = raise THM ("equal_elim: " ^ msg, 0, [th1, th2]); |
1080 fun err msg = raise THM ("equal_elim: " ^ msg, 0, [th1, th2]); |
1081 in |
1081 in |
1082 (case prop1 of |
1082 (case prop1 of |
1083 Const ("Pure.eq", _) $ A $ B => |
1083 Const ("Pure.eq", _) $ A $ B => |
1084 if prop2 aconv A then |
1084 if prop2 aconv A then |
1085 Thm (deriv_rule2 (Proofterm.equal_elim A B) der1 der2, |
1085 Thm (deriv_rule2 (Proofterm.equal_elim A B) der1 der2, |
1086 {cert = join_certificate2 (th1, th2), |
1086 {cert = join_certificate2 (th1, th2), |
1087 tags = [], |
1087 tags = [], |
1088 maxidx = Int.max (max1, max2), |
1088 maxidx = Int.max (maxidx1, maxidx2), |
1089 shyps = Sorts.union shyps1 shyps2, |
1089 shyps = Sorts.union shyps1 shyps2, |
1090 hyps = union_hyps hyps1 hyps2, |
1090 hyps = union_hyps hyps1 hyps2, |
1091 tpairs = union_tpairs tpairs1 tpairs2, |
1091 tpairs = union_tpairs tpairs1 tpairs2, |
1092 prop = B}) |
1092 prop = B}) |
1093 else err "not equal" |
1093 else err "not equal" |