47 val abstype_interpretation: |
47 val abstype_interpretation: |
48 (string * ((string * sort) list * ((string * ((string * sort) list * typ)) * (string * thm))) |
48 (string * ((string * sort) list * ((string * ((string * sort) list * typ)) * (string * thm))) |
49 -> theory -> theory) -> theory -> theory |
49 -> theory -> theory) -> theory -> theory |
50 val add_eqn: thm -> theory -> theory |
50 val add_eqn: thm -> theory -> theory |
51 val add_nbe_eqn: thm -> theory -> theory |
51 val add_nbe_eqn: thm -> theory -> theory |
|
52 val add_abs_eqn: thm -> theory -> theory |
52 val add_default_eqn: thm -> theory -> theory |
53 val add_default_eqn: thm -> theory -> theory |
53 val add_default_eqn_attribute: attribute |
54 val add_default_eqn_attribute: attribute |
54 val add_default_eqn_attrib: Attrib.src |
55 val add_default_eqn_attrib: Attrib.src |
55 val add_nbe_default_eqn: thm -> theory -> theory |
56 val add_nbe_default_eqn: thm -> theory -> theory |
56 val add_nbe_default_eqn_attribute: attribute |
57 val add_nbe_default_eqn_attribute: attribute |
515 val (full_lhs, rhs) = (Logic.dest_equals o Thm.plain_prop_of) thm |
514 val (full_lhs, rhs) = (Logic.dest_equals o Thm.plain_prop_of) thm |
516 handle TERM _ => bad "Not an equation" |
515 handle TERM _ => bad "Not an equation" |
517 | THM _ => bad "Not a proper equation"; |
516 | THM _ => bad "Not a proper equation"; |
518 val (rep, lhs) = dest_comb full_lhs |
517 val (rep, lhs) = dest_comb full_lhs |
519 handle TERM _ => bad "Not an abstract equation"; |
518 handle TERM _ => bad "Not an abstract equation"; |
520 val (rep_const, ty) = dest_Const rep; |
519 val (rep_const, ty) = dest_Const rep |
|
520 handle TERM _ => bad "Not an abstract equation"; |
521 val (tyco, Ts) = (dest_Type o domain_type) ty |
521 val (tyco, Ts) = (dest_Type o domain_type) ty |
522 handle TERM _ => bad "Not an abstract equation" |
522 handle TERM _ => bad "Not an abstract equation" |
523 | TYPE _ => bad "Not an abstract equation"; |
523 | TYPE _ => bad "Not an abstract equation"; |
524 val _ = case some_tyco of SOME tyco' => if tyco = tyco' then () |
524 val _ = case some_tyco of SOME tyco' => if tyco = tyco' then () |
525 else bad ("Abstract type mismatch:" ^ quote tyco ^ " vs. " ^ quote tyco') |
525 else bad ("Abstract type mismatch:" ^ quote tyco ^ " vs. " ^ quote tyco') |
695 fun add_const (Const (c, ty)) = insert (op =) (c, Sign.const_typargs thy (c, ty)) |
695 fun add_const (Const (c, ty)) = insert (op =) (c, Sign.const_typargs thy (c, ty)) |
696 | add_const _ = I |
696 | add_const _ = I |
697 val add_consts = fold_aterms add_const |
697 val add_consts = fold_aterms add_const |
698 in add_consts rhs o fold add_consts args end; |
698 in add_consts rhs o fold add_consts args end; |
699 |
699 |
700 fun dest_eqn thy = |
700 val dest_eqn = apfst (snd o strip_comb) o Logic.dest_equals o Logic.unvarify_global; |
701 apfst (snd o strip_comb) o Logic.dest_equals o Logic.unvarify_global; |
|
702 |
701 |
703 abstype cert = Equations of thm * bool list |
702 abstype cert = Equations of thm * bool list |
704 | Projection of term * string |
703 | Projection of term * string |
705 | Abstract of thm * string |
704 | Abstract of thm * string |
706 with |
705 with |
807 cert_thm |
806 cert_thm |
808 |> Local_Defs.expand [snd (get_head thy cert_thm)] |
807 |> Local_Defs.expand [snd (get_head thy cert_thm)] |
809 |> Thm.varifyT_global |
808 |> Thm.varifyT_global |
810 |> Conjunction.elim_balanced (length propers); |
809 |> Conjunction.elim_balanced (length propers); |
811 fun abstractions (args, rhs) = (map (rpair NONE) args, (rhs, NONE)); |
810 fun abstractions (args, rhs) = (map (rpair NONE) args, (rhs, NONE)); |
812 in (tyscm, map (abstractions o dest_eqn thy o Thm.prop_of) thms ~~ (map SOME thms ~~ propers)) end |
811 in (tyscm, map (abstractions o dest_eqn o Thm.prop_of) thms ~~ (map SOME thms ~~ propers)) end |
813 | equations_of_cert thy (Projection (t, tyco)) = |
812 | equations_of_cert thy (Projection (t, tyco)) = |
814 let |
813 let |
815 val (_, ((abs, _), _)) = get_abstype_spec thy tyco; |
814 val (_, ((abs, _), _)) = get_abstype_spec thy tyco; |
816 val tyscm = typscheme_projection thy t; |
815 val tyscm = typscheme_projection thy t; |
817 val t' = Logic.varify_types_global t; |
816 val t' = Logic.varify_types_global t; |
818 fun abstractions (args, rhs) = (map (rpair (SOME abs)) args, (rhs, NONE)); |
817 fun abstractions (args, rhs) = (map (rpair (SOME abs)) args, (rhs, NONE)); |
819 in (tyscm, [((abstractions o dest_eqn thy) t', (NONE, true))]) end |
818 in (tyscm, [((abstractions o dest_eqn) t', (NONE, true))]) end |
820 | equations_of_cert thy (Abstract (abs_thm, tyco)) = |
819 | equations_of_cert thy (Abstract (abs_thm, tyco)) = |
821 let |
820 let |
822 val tyscm = typscheme_abs thy abs_thm; |
821 val tyscm = typscheme_abs thy abs_thm; |
823 val (abs, concrete_thm) = concretify_abs thy tyco abs_thm; |
822 val (abs, concrete_thm) = concretify_abs thy tyco abs_thm; |
824 fun abstractions (args, rhs) = (map (rpair NONE) args, (rhs, (SOME abs))); |
823 fun abstractions (args, rhs) = (map (rpair NONE) args, (rhs, (SOME abs))); |
825 in |
824 in |
826 (tyscm, [((abstractions o dest_eqn thy o Thm.prop_of) concrete_thm, |
825 (tyscm, [((abstractions o dest_eqn o Thm.prop_of) concrete_thm, |
827 (SOME (Thm.varifyT_global abs_thm), true))]) |
826 (SOME (Thm.varifyT_global abs_thm), true))]) |
828 end; |
827 end; |
829 |
828 |
830 fun pretty_cert thy (cert as Equations _) = |
829 fun pretty_cert thy (cert as Equations _) = |
831 (map_filter (Option.map (Display.pretty_thm_global thy o AxClass.overload thy) o fst o snd) |
830 (map_filter (Option.map (Display.pretty_thm_global thy o AxClass.overload thy) o fst o snd) |