806 ((if internal then Local_Theory.define_internal else Local_Theory.define) |
806 ((if internal then Local_Theory.define_internal else Local_Theory.define) |
807 ((b, NoSyn), ((Thm.def_binding b, []), rhs)) lthy) |
807 ((b, NoSyn), ((Thm.def_binding b, []), rhs)) lthy) |
808 end |
808 end |
809 end; |
809 end; |
810 |
810 |
811 fun maybe_restore lthy_old lthy = |
|
812 lthy |> not (Context.eq_thy (apply2 Proof_Context.theory_of (lthy_old, lthy))) |
|
813 ? Local_Theory.restore; |
|
814 |
|
815 val map_bind_def = |
811 val map_bind_def = |
816 (fn () => def_qualify (if Binding.is_empty map_b then mk_prefix_binding mapN else map_b), |
812 (fn () => def_qualify (if Binding.is_empty map_b then mk_prefix_binding mapN else map_b), |
817 map_rhs); |
813 map_rhs); |
818 val set_binds_defs = |
814 val set_binds_defs = |
819 let |
815 let |
828 |
824 |
829 val ((((bnf_map_term, raw_map_def), |
825 val ((((bnf_map_term, raw_map_def), |
830 (bnf_set_terms, raw_set_defs)), |
826 (bnf_set_terms, raw_set_defs)), |
831 (bnf_bd_term, raw_bd_def)), (lthy, lthy_old)) = |
827 (bnf_bd_term, raw_bd_def)), (lthy, lthy_old)) = |
832 no_defs_lthy |
828 no_defs_lthy |
|
829 |> Local_Theory.open_target |> snd |
833 |> maybe_define true map_bind_def |
830 |> maybe_define true map_bind_def |
834 ||>> apfst split_list o fold_map (maybe_define true) set_binds_defs |
831 ||>> apfst split_list o fold_map (maybe_define true) set_binds_defs |
835 ||>> maybe_define true bd_bind_def |
832 ||>> maybe_define true bd_bind_def |
836 ||> `(maybe_restore no_defs_lthy); |
833 ||> `Local_Theory.close_target; |
837 |
834 |
838 val phi = Proof_Context.export_morphism lthy_old lthy; |
835 val phi = Proof_Context.export_morphism lthy_old lthy; |
839 |
836 |
840 val bnf_map_def = Morphism.thm phi raw_map_def; |
837 val bnf_map_def = Morphism.thm phi raw_map_def; |
841 val bnf_set_defs = map (Morphism.thm phi) raw_set_defs; |
838 val bnf_set_defs = map (Morphism.thm phi) raw_set_defs; |
927 else map (fn i => fn () => def_qualify (mk_prefix_binding (mk_witN i))) (1 upto nwits); |
924 else map (fn i => fn () => def_qualify (mk_prefix_binding (mk_witN i))) (1 upto nwits); |
928 in bs ~~ wit_rhss end; |
925 in bs ~~ wit_rhss end; |
929 |
926 |
930 val (((bnf_rel_term, raw_rel_def), (bnf_wit_terms, raw_wit_defs)), (lthy, lthy_old)) = |
927 val (((bnf_rel_term, raw_rel_def), (bnf_wit_terms, raw_wit_defs)), (lthy, lthy_old)) = |
931 lthy |
928 lthy |
|
929 |> Local_Theory.open_target |> snd |
932 |> maybe_define (is_some rel_rhs_opt) rel_bind_def |
930 |> maybe_define (is_some rel_rhs_opt) rel_bind_def |
933 ||>> apfst split_list o fold_map (maybe_define (not (null wit_rhss))) wit_binds_defs |
931 ||>> apfst split_list o fold_map (maybe_define (not (null wit_rhss))) wit_binds_defs |
934 ||> `(maybe_restore lthy); |
932 ||> `Local_Theory.close_target; |
935 |
933 |
936 val phi = Proof_Context.export_morphism lthy_old lthy; |
934 val phi = Proof_Context.export_morphism lthy_old lthy; |
937 val bnf_rel_def = Morphism.thm phi raw_rel_def; |
935 val bnf_rel_def = Morphism.thm phi raw_rel_def; |
938 val bnf_rel = Morphism.term phi bnf_rel_term; |
936 val bnf_rel = Morphism.term phi bnf_rel_term; |
939 fun mk_bnf_rel Ds As' Bs' = |
937 fun mk_bnf_rel Ds As' Bs' = |