814 | [] => raise THM ("comp_no_flatten", i, [th, rule]) |
814 | [] => raise THM ("comp_no_flatten", i, [th, rule]) |
815 | _ => raise THM ("comp_no_flatten: unique result expected", i, [th, rule])); |
815 | _ => raise THM ("comp_no_flatten: unique result expected", i, [th, rule])); |
816 |
816 |
817 |
817 |
818 |
818 |
819 (*** Instantiate theorem th, reading instantiations in theory thy ****) |
819 (** variations on Thm.instantiate **) |
820 |
820 |
821 fun instantiate_normalize instpair th = |
821 fun instantiate_normalize instpair th = |
822 Thm.adjust_maxidx_thm ~1 (Thm.instantiate instpair th COMP_INCR asm_rl); |
822 Thm.adjust_maxidx_thm ~1 (Thm.instantiate instpair th COMP_INCR asm_rl); |
823 |
823 |
824 (*Left-to-right replacements: tpairs = [..., (vi, ti), ...]. |
824 (*Left-to-right replacements: tpairs = [..., (vi, ti), ...]. |
841 [T, U], [t, u]) |
841 [T, U], [t, u]) |
842 in (thy', tye', maxi') end; |
842 in (thy', tye', maxi') end; |
843 in |
843 in |
844 |
844 |
845 fun cterm_instantiate [] th = th |
845 fun cterm_instantiate [] th = th |
846 | cterm_instantiate ctpairs0 th = |
846 | cterm_instantiate ctpairs th = |
847 let |
847 let |
848 val (thy, tye, _) = fold_rev add_types ctpairs0 (Thm.theory_of_thm th, Vartab.empty, 0); |
848 val (thy, tye, _) = fold_rev add_types ctpairs (Thm.theory_of_thm th, Vartab.empty, 0); |
849 val certT = ctyp_of thy; |
849 val certT = ctyp_of thy; |
850 fun instT (ct, cu) = |
850 val instT = |
851 let val inst = cterm_of thy o Term.map_types (Envir.norm_type tye) o term_of |
851 Vartab.fold (fn (xi, (S, T)) => |
852 in (inst ct, inst cu) end; |
852 cons (certT (TVar (xi, S)), certT (Envir.norm_type tye T))) tye []; |
853 fun ctyp2 (ixn, (S, T)) = (certT (TVar (ixn, S)), certT (Envir.norm_type tye T)); |
853 val inst = map (pairself (Thm.instantiate_cterm (instT, []))) ctpairs; |
854 in instantiate_normalize (map ctyp2 (Vartab.dest tye), map instT ctpairs0) th end |
854 in instantiate_normalize (instT, inst) th end |
855 handle TERM _ => raise THM ("cterm_instantiate: incompatible theories", 0, [th]) |
855 handle TERM (msg, _) => raise THM (msg, 0, [th]) |
856 | TYPE (msg, _, _) => raise THM (msg, 0, [th]); |
856 | TYPE (msg, _, _) => raise THM (msg, 0, [th]); |
857 end; |
857 end; |
858 |
858 |
859 |
|
860 |
|
861 (** variations on instantiate **) |
|
862 |
859 |
863 (* instantiate by left-to-right occurrence of variables *) |
860 (* instantiate by left-to-right occurrence of variables *) |
864 |
861 |
865 fun instantiate' cTs cts thm = |
862 fun instantiate' cTs cts thm = |
866 let |
863 let |