src/HOL/Codatatype/Tools/bnf_def.ML
changeset 49454 cca4390e8071
parent 49453 ff0e540d8758
child 49455 3cd2622d4466
equal deleted inserted replaced
49453:ff0e540d8758 49454:cca4390e8071
   575         val bs = if nwits = 1 then [fn () => Binding.suffix_name ("_" ^ witN) b]
   575         val bs = if nwits = 1 then [fn () => Binding.suffix_name ("_" ^ witN) b]
   576           else map (fn i => fn () => Binding.suffix_name ("_" ^ mk_witN i) b) (1 upto nwits);
   576           else map (fn i => fn () => Binding.suffix_name ("_" ^ mk_witN i) b) (1 upto nwits);
   577       in map2 pair bs wit_rhss end;
   577       in map2 pair bs wit_rhss end;
   578     val rel_bind_def = (fn () => Binding.suffix_name ("_" ^ relN) b, rel_rhs);
   578     val rel_bind_def = (fn () => Binding.suffix_name ("_" ^ relN) b, rel_rhs);
   579 
   579 
   580     (* TODO: ### Kill "needed_for_extra_facts" *)
       
   581     fun maybe_define needed_for_extra_facts (b, rhs) lthy =
   580     fun maybe_define needed_for_extra_facts (b, rhs) lthy =
   582       let
   581       let
   583         val inline =
   582         val inline =
   584           (not needed_for_extra_facts orelse fact_policy = Derive_Some_Facts) andalso
   583           (not needed_for_extra_facts orelse fact_policy = Derive_Some_Facts) andalso
   585           (case const_policy of
   584           (case const_policy of
   655     val dead = length deads;
   654     val dead = length deads;
   656 
   655 
   657     (*TODO: further checks of type of bnf_map*)
   656     (*TODO: further checks of type of bnf_map*)
   658     (*TODO: check types of bnf_sets*)
   657     (*TODO: check types of bnf_sets*)
   659     (*TODO: check type of bnf_bd*)
   658     (*TODO: check type of bnf_bd*)
       
   659     (*TODO: check type of bnf_rel*)
   660 
   660 
   661     val ((((((((((As', Bs'), Cs), Ds), B1Ts), B2Ts), domTs), ranTs), ranTs'), ranTs''),
   661     val ((((((((((As', Bs'), Cs), Ds), B1Ts), B2Ts), domTs), ranTs), ranTs'), ranTs''),
   662       (Ts, T)) = lthy'
   662       (Ts, T)) = lthy'
   663       |> mk_TFrees live
   663       |> mk_TFrees live
   664       ||>> mk_TFrees live
   664       ||>> mk_TFrees live
   729       ||>> mk_Frees "R" setRTs
   729       ||>> mk_Frees "R" setRTs
   730       ||>> mk_Frees "R" setRTs
   730       ||>> mk_Frees "R" setRTs
   731       ||>> mk_Frees "S" setRTsBsCs
   731       ||>> mk_Frees "S" setRTsBsCs
   732       ||>> mk_Frees' "Q" QTs;
   732       ||>> mk_Frees' "Q" QTs;
   733 
   733 
       
   734     val pred_rhs = fold absfree (y' :: x' :: rev Qs') (HOLogic.mk_mem (HOLogic.mk_prod (x, y),
       
   735       Term.list_comb (relAsBs, map3 (fn Q => fn T => fn U =>
       
   736         HOLogic.Collect_const (HOLogic.mk_prodT (T, U)) $ HOLogic.mk_split Q)
       
   737         Qs As' Bs')));
       
   738     val pred_bind_def = (fn () => Binding.suffix_name ("_" ^ predN) b, pred_rhs);
       
   739 
       
   740     val ((bnf_pred_term, raw_pred_def), (lthy''', lthy'')) =
       
   741       lthy
       
   742       |> maybe_define true pred_bind_def
       
   743       ||> `(maybe_restore lthy');
       
   744 
       
   745     val phi = Proof_Context.export_morphism lthy'' lthy''';
       
   746     val bnf_pred = Morphism.term phi bnf_pred_term;
       
   747 
       
   748     fun mk_bnf_pred QTs CA' CB' = normalize_pred lthy''' QTs CA' CB' bnf_pred;
       
   749 
       
   750     val pred = mk_bnf_pred QTs CA' CB';
       
   751     val bnf_pred_def =
       
   752       if fact_policy <> Derive_Some_Facts then
       
   753         mk_unabs_def (live + 2) (Morphism.thm phi raw_pred_def RS meta_eq_to_obj_eq)
       
   754       else
       
   755         no_fact;
       
   756 
   734     val goal_map_id =
   757     val goal_map_id =
   735       let
   758       let
   736         val bnf_map_app_id = Term.list_comb (bnf_map_AsAs, map HOLogic.id_const As');
   759         val bnf_map_app_id = Term.list_comb (bnf_map_AsAs, map HOLogic.id_const As');
   737       in
   760       in
   738         HOLogic.mk_Trueprop
   761         HOLogic.mk_Trueprop
   919         val map_id' = mk_lazy (fn () => mk_id' (#map_id axioms));
   942         val map_id' = mk_lazy (fn () => mk_id' (#map_id axioms));
   920         val map_comp' = mk_lazy (fn () => mk_comp' (#map_comp axioms));
   943         val map_comp' = mk_lazy (fn () => mk_comp' (#map_comp axioms));
   921 
   944 
   922         val set_natural' =
   945         val set_natural' =
   923           map (fn thm => mk_lazy (fn () => mk_set_natural' thm)) (#set_natural axioms);
   946           map (fn thm => mk_lazy (fn () => mk_set_natural' thm)) (#set_natural axioms);
   924 
       
   925         (* predicator *)
       
   926 
       
   927         val pred_rhs = fold absfree (y' :: x' :: rev Qs') (HOLogic.mk_mem (HOLogic.mk_prod (x, y),
       
   928           Term.list_comb (relAsBs, map3 (fn Q => fn T => fn U =>
       
   929             HOLogic.Collect_const (HOLogic.mk_prodT (T, U)) $ HOLogic.mk_split Q)
       
   930             Qs As' Bs')));
       
   931         val pred_bind_def = (fn () => Binding.suffix_name ("_" ^ predN) b, pred_rhs);
       
   932 
       
   933         val ((bnf_pred_term, raw_pred_def), (lthy, lthy_old)) =
       
   934           lthy
       
   935           |> maybe_define true pred_bind_def
       
   936           ||> `(maybe_restore lthy);
       
   937 
       
   938         (*transforms defined frees into consts*)
       
   939         val phi = Proof_Context.export_morphism lthy_old lthy;
       
   940         val bnf_pred = Morphism.term phi bnf_pred_term;
       
   941 
       
   942         fun mk_bnf_pred QTs CA' CB' = normalize_pred lthy QTs CA' CB' bnf_pred;
       
   943 
       
   944         val pred = mk_bnf_pred QTs CA' CB';
       
   945         val bnf_pred_def0 = Morphism.thm phi raw_pred_def;
       
   946         val bnf_pred_def =
       
   947           if fact_policy <> Derive_Some_Facts then
       
   948             mk_unabs_def (live + 2) (bnf_pred_def0 RS meta_eq_to_obj_eq)
       
   949           else
       
   950             no_fact;
       
   951 
   947 
   952         fun mk_map_wppull () =
   948         fun mk_map_wppull () =
   953           let
   949           let
   954             val prems = if live = 0 then [] else
   950             val prems = if live = 0 then [] else
   955               [HOLogic.mk_Trueprop (Library.foldr1 HOLogic.mk_conj
   951               [HOLogic.mk_Trueprop (Library.foldr1 HOLogic.mk_conj
  1164                 end
  1160                 end
  1165               else
  1161               else
  1166                 I))
  1162                 I))
  1167       end;
  1163       end;
  1168   in
  1164   in
  1169     (key, goals, wit_goalss, after_qed, lthy', one_step_defs)
  1165     (key, goals, wit_goalss, after_qed, lthy''', one_step_defs)
  1170   end;
  1166   end;
  1171 
  1167 
  1172 fun register_bnf key (bnf, lthy) =
  1168 fun register_bnf key (bnf, lthy) =
  1173   (bnf, Local_Theory.declaration {syntax = false, pervasive = true}
  1169   (bnf, Local_Theory.declaration {syntax = false, pervasive = true}
  1174     (fn phi => Data.map (Symtab.update_new (key, morph_bnf phi bnf))) lthy);
  1170     (fn phi => Data.map (Symtab.update_new (key, morph_bnf phi bnf))) lthy);