src/HOL/Codatatype/Tools/bnf_comp.ML
changeset 49185 073d7d1b7488
parent 49155 f51ab68f882f
child 49186 4b5fa9d5e330
equal deleted inserted replaced
49184:83fdea0c4779 49185:073d7d1b7488
    21   val default_comp_sort: (string * sort) list list -> (string * sort) list
    21   val default_comp_sort: (string * sort) list list -> (string * sort) list
    22   val normalize_bnfs: (int -> binding -> binding) -> ''a list list -> ''a list ->
    22   val normalize_bnfs: (int -> binding -> binding) -> ''a list list -> ''a list ->
    23     (''a list list -> ''a list) -> BNF_Def.BNF list -> unfold_thms -> Proof.context ->
    23     (''a list list -> ''a list) -> BNF_Def.BNF list -> unfold_thms -> Proof.context ->
    24     (int list list * ''a list) * (BNF_Def.BNF list * (unfold_thms * Proof.context))
    24     (int list list * ''a list) * (BNF_Def.BNF list * (unfold_thms * Proof.context))
    25   val seal_bnf: unfold_thms -> binding -> typ list -> BNF_Def.BNF -> Proof.context ->
    25   val seal_bnf: unfold_thms -> binding -> typ list -> BNF_Def.BNF -> Proof.context ->
    26     BNF_Def.BNF * local_theory
    26     (BNF_Def.BNF * typ list) * local_theory
    27 end;
    27 end;
    28 
    28 
    29 structure BNF_Comp : BNF_COMP =
    29 structure BNF_Comp : BNF_COMP =
    30 struct
    30 struct
    31 
    31 
   654 
   654 
   655     (*bd should only depend on dead type variables!*)
   655     (*bd should only depend on dead type variables!*)
   656     val bd_repT = fst (dest_relT (fastype_of bnf_bd));
   656     val bd_repT = fst (dest_relT (fastype_of bnf_bd));
   657     val bdT_bind = Binding.suffix_name ("_" ^ bdTN) b;
   657     val bdT_bind = Binding.suffix_name ("_" ^ bdTN) b;
   658     val params = fold Term.add_tfreesT Ds [];
   658     val params = fold Term.add_tfreesT Ds [];
       
   659     val deads = map TFree params;
   659 
   660 
   660     val ((bdT_name, (bdT_glob_info, bdT_loc_info)), (lthy', lthy)) =
   661     val ((bdT_name, (bdT_glob_info, bdT_loc_info)), (lthy', lthy)) =
   661       lthy
   662       lthy
   662       |> Typedef.add_typedef true NONE (bdT_bind, params, NoSyn)
   663       |> Typedef.add_typedef true NONE (bdT_bind, params, NoSyn)
   663         (HOLogic.mk_UNIV bd_repT) NONE (EVERY' [rtac exI, rtac UNIV_I] 1)
   664         (HOLogic.mk_UNIV bd_repT) NONE (EVERY' [rtac exI, rtac UNIV_I] 1)
   664       ||> `Local_Theory.restore;
   665       ||> `Local_Theory.restore;
   665 
   666 
   666     val phi = Proof_Context.export_morphism lthy lthy';
   667     val phi = Proof_Context.export_morphism lthy lthy';
   667 
   668 
   668     val bnf_bd' = mk_dir_image bnf_bd
   669     val bnf_bd' = mk_dir_image bnf_bd
   669       (Const (#Abs_name bdT_glob_info, bd_repT --> Type (bdT_name, map TFree params)))
   670       (Const (#Abs_name bdT_glob_info, bd_repT --> Type (bdT_name, deads)))
   670 
   671 
   671     val set_def = Morphism.thm phi (the (#set_def bdT_loc_info));
   672     val set_def = Morphism.thm phi (the (#set_def bdT_loc_info));
   672     val Abs_inject = Morphism.thm phi (#Abs_inject bdT_loc_info);
   673     val Abs_inject = Morphism.thm phi (#Abs_inject bdT_loc_info);
   673     val Abs_cases = Morphism.thm phi (#Abs_cases bdT_loc_info);
   674     val Abs_cases = Morphism.thm phi (#Abs_cases bdT_loc_info);
   674 
   675 
   699 
   700 
   700     val bnf_wits = map snd (mk_wits_of_bnf (replicate nwits Ds) (replicate nwits As) bnf);
   701     val bnf_wits = map snd (mk_wits_of_bnf (replicate nwits Ds) (replicate nwits As) bnf);
   701 
   702 
   702     fun wit_tac _ = mk_simple_wit_tac (map unfold_defs (wit_thms_of_bnf bnf));
   703     fun wit_tac _ = mk_simple_wit_tac (map unfold_defs (wit_thms_of_bnf bnf));
   703 
   704 
   704     val (bnf', lthy') = bnf_def Hardly_Inline (K Derive_All_Facts) I tacs wit_tac NONE
   705     val (bnf', lthy') = bnf_def Hardly_Inline (K Derive_All_Facts) I tacs wit_tac (SOME deads)
   705         ((((b, bnf_map), bnf_sets), Term.absdummy T bnf_bd'), bnf_wits) lthy;
   706       ((((b, bnf_map), bnf_sets), Term.absdummy T bnf_bd'), bnf_wits) lthy;
   706 
   707 
   707     val defs' = filter_refl (map_def_of_bnf bnf' :: set_defs_of_bnf bnf');
   708     val defs' = filter_refl (map_def_of_bnf bnf' :: set_defs_of_bnf bnf');
   708     val unfold_defs' = unfold_defs o Local_Defs.unfold lthy' defs';
   709     val unfold_defs' = unfold_defs o Local_Defs.unfold lthy' defs';
   709 
   710 
   710     val rel_def = unfold_defs' (rel_def_of_bnf bnf');
   711     val rel_def = unfold_defs' (rel_def_of_bnf bnf');
   721       [(rel_unfoldN, [rel_unfold]),
   722       [(rel_unfoldN, [rel_unfold]),
   722       (pred_unfoldN, [pred_unfold])]
   723       (pred_unfoldN, [pred_unfold])]
   723       |> map (fn (thmN, thms) =>
   724       |> map (fn (thmN, thms) =>
   724         ((Binding.qualify true (Binding.name_of b) (Binding.name thmN), []), [(thms, [])]));
   725         ((Binding.qualify true (Binding.name_of b) (Binding.name thmN), []), [(thms, [])]));
   725   in
   726   in
   726     (bnf', lthy' |> Local_Theory.notes notes |> snd)
   727     ((bnf', deads), lthy' |> Local_Theory.notes notes |> snd)
   727   end;
   728   end;
   728 
   729 
   729 fun bnf_of_typ _ _ _ _ (T as TFree _) (unfold, lthy) =
   730 fun bnf_of_typ _ _ _ _ (T as TFree _) (unfold, lthy) =
   730     ((Basic_BNFs.ID_bnf, ([], [T])), (add_to_unfold_opt NONE NONE
   731     ((Basic_BNFs.ID_bnf, ([], [T])), (add_to_unfold_opt NONE NONE
   731       (SOME Basic_BNFs.ID_rel_def) (SOME Basic_BNFs.ID_pred_def) unfold, lthy))
   732       (SOME Basic_BNFs.ID_rel_def) (SOME Basic_BNFs.ID_pred_def) unfold, lthy))