725 | Equations of thm * bool list |
725 | Equations of thm * bool list |
726 | Projection of term * string |
726 | Projection of term * string |
727 | Abstract of thm * string |
727 | Abstract of thm * string |
728 with |
728 with |
729 |
729 |
730 fun dummy_thm thy c = |
730 fun dummy_thm ctxt c = |
731 let |
731 let |
|
732 val thy = Proof_Context.theory_of ctxt; |
732 val raw_ty = devarify (const_typ thy c); |
733 val raw_ty = devarify (const_typ thy c); |
733 val (vs, _) = typscheme thy (c, raw_ty); |
734 val (vs, _) = typscheme thy (c, raw_ty); |
734 val sortargs = case Axclass.class_of_param thy c |
735 val sortargs = case Axclass.class_of_param thy c |
735 of SOME class => [[class]] |
736 of SOME class => [[class]] |
736 | NONE => (case get_type_of_constr_or_abstr thy c |
737 | NONE => (case get_type_of_constr_or_abstr thy c |
740 val the_sort = the o AList.lookup (op =) (map fst vs ~~ sortargs); |
741 val the_sort = the o AList.lookup (op =) (map fst vs ~~ sortargs); |
741 val ty = map_type_tfree (fn (v, _) => TFree (v, the_sort v)) raw_ty |
742 val ty = map_type_tfree (fn (v, _) => TFree (v, the_sort v)) raw_ty |
742 val chead = build_head thy (c, ty); |
743 val chead = build_head thy (c, ty); |
743 in Thm.weaken chead Drule.dummy_thm end; |
744 in Thm.weaken chead Drule.dummy_thm end; |
744 |
745 |
745 fun nothing_cert thy c = Nothing (dummy_thm thy c); |
746 fun nothing_cert ctxt c = Nothing (dummy_thm ctxt c); |
746 |
747 |
747 fun cert_of_eqns thy c [] = Equations (dummy_thm thy c, []) |
748 fun cert_of_eqns ctxt c [] = Equations (dummy_thm ctxt c, []) |
748 | cert_of_eqns thy c raw_eqns = |
749 | cert_of_eqns ctxt c raw_eqns = |
749 let |
750 let |
|
751 val thy = Proof_Context.theory_of ctxt; |
750 val eqns = burrow_fst (canonize_thms thy) raw_eqns; |
752 val eqns = burrow_fst (canonize_thms thy) raw_eqns; |
751 val _ = map (assert_eqn thy) eqns; |
753 val _ = map (assert_eqn thy) eqns; |
752 val (thms, propers) = split_list eqns; |
754 val (thms, propers) = split_list eqns; |
753 val _ = map (fn thm => if c = const_eqn thy thm then () |
755 val _ = map (fn thm => if c = const_eqn thy thm then () |
754 else error ("Wrong head of code equation,\nexpected constant " |
756 else error ("Wrong head of code equation,\nexpected constant " |
898 fun lhs_conv ct = if can Thm.dest_comb ct |
900 fun lhs_conv ct = if can Thm.dest_comb ct |
899 then Conv.combination_conv lhs_conv conv ct |
901 then Conv.combination_conv lhs_conv conv ct |
900 else Conv.all_conv ct; |
902 else Conv.all_conv ct; |
901 in Conv.combination_conv (Conv.arg_conv lhs_conv) conv ct end; |
903 in Conv.combination_conv (Conv.arg_conv lhs_conv) conv ct end; |
902 |
904 |
903 fun rewrite_eqn thy conv ss = |
905 fun rewrite_eqn conv ctxt = |
904 let |
906 singleton (Variable.trade (K (map (Conv.fconv_rule (conv (Simplifier.rewrite ctxt))))) ctxt) |
905 val ctxt = Proof_Context.init_global thy; |
907 |
906 val rewrite = Conv.fconv_rule (conv (Simplifier.rewrite (put_simpset ss ctxt))); |
908 fun preprocess conv ctxt = |
907 in singleton (Variable.trade (K (map rewrite)) ctxt) end; |
909 let |
908 |
910 val thy = Proof_Context.theory_of ctxt; |
909 fun preprocess thy conv ss = |
911 in |
910 Thm.transfer thy |
912 Thm.transfer thy |
911 #> rewrite_eqn thy conv ss |
913 #> rewrite_eqn conv ctxt |
912 #> Axclass.unoverload thy |
914 #> Axclass.unoverload thy |
913 |
915 end; |
914 fun cert_of_eqns_preprocess thy functrans ss c = |
916 |
|
917 fun cert_of_eqns_preprocess ctxt functrans c = |
915 perhaps (perhaps_loop (perhaps_apply functrans)) |
918 perhaps (perhaps_loop (perhaps_apply functrans)) |
916 #> (map o apfst) (preprocess thy eqn_conv ss) |
919 #> (map o apfst) (preprocess eqn_conv ctxt) |
917 #> cert_of_eqns thy c; |
920 #> cert_of_eqns ctxt c; |
918 |
921 |
919 fun get_cert thy { functrans, ss } c = |
922 fun get_cert thy { functrans, ss } c = |
920 case retrieve_raw thy c |
923 let |
921 of Default (eqns, eqns_lazy) => Lazy.force eqns_lazy |
924 val ctxt = thy |> Proof_Context.init_global |> put_simpset ss; |
922 |> cert_of_eqns_preprocess thy functrans ss c |
925 in |
|
926 case retrieve_raw thy c of |
|
927 Default (_, eqns_lazy) => Lazy.force eqns_lazy |
|
928 |> cert_of_eqns_preprocess ctxt functrans c |
923 | Eqns eqns => eqns |
929 | Eqns eqns => eqns |
924 |> cert_of_eqns_preprocess thy functrans ss c |
930 |> cert_of_eqns_preprocess ctxt functrans c |
925 | None => nothing_cert thy c |
931 | None => nothing_cert ctxt c |
926 | Proj (_, tyco) => cert_of_proj thy c tyco |
932 | Proj (_, tyco) => cert_of_proj thy c tyco |
927 | Abstr (abs_thm, tyco) => abs_thm |
933 | Abstr (abs_thm, tyco) => abs_thm |
928 |> preprocess thy Conv.arg_conv ss |
934 |> preprocess Conv.arg_conv ctxt |
929 |> cert_of_abs thy tyco c; |
935 |> cert_of_abs thy tyco c |
|
936 end; |
930 |
937 |
931 |
938 |
932 (* cases *) |
939 (* cases *) |
933 |
940 |
934 fun case_certificate thm = |
941 fun case_certificate thm = |