src/HOL/BNF/Tools/bnf_comp.ML
changeset 51893 596baae88a88
parent 51837 087498724486
child 51895 e0bf21531ed5
equal deleted inserted replaced
51892:e5432ec161ff 51893:596baae88a88
    38 
    38 
    39 (* TODO: Replace by "BNF_Defs.defs list" *)
    39 (* TODO: Replace by "BNF_Defs.defs list" *)
    40 type unfold_set = {
    40 type unfold_set = {
    41   map_unfolds: thm list,
    41   map_unfolds: thm list,
    42   set_unfoldss: thm list list,
    42   set_unfoldss: thm list list,
    43   rel_unfolds: thm list,
    43   rel_unfolds: thm list
    44   srel_unfolds: thm list
       
    45 };
    44 };
    46 
    45 
    47 val empty_unfolds = {map_unfolds = [], set_unfoldss = [], rel_unfolds = [], srel_unfolds = []};
    46 val empty_unfolds = {map_unfolds = [], set_unfoldss = [], rel_unfolds = []};
    48 
    47 
    49 fun add_to_thms thms new = thms |> not (Thm.is_reflexive new) ? insert Thm.eq_thm new;
    48 fun add_to_thms thms new = thms |> not (Thm.is_reflexive new) ? insert Thm.eq_thm new;
    50 fun adds_to_thms thms news = insert (eq_set Thm.eq_thm) (no_reflexive news) thms;
    49 fun adds_to_thms thms news = insert (eq_set Thm.eq_thm) (no_reflexive news) thms;
    51 
    50 
    52 fun add_to_unfolds map sets rel srel
    51 fun add_to_unfolds map sets rel
    53   {map_unfolds, set_unfoldss, rel_unfolds, srel_unfolds} =
    52   {map_unfolds, set_unfoldss, rel_unfolds} =
    54   {map_unfolds = add_to_thms map_unfolds map,
    53   {map_unfolds = add_to_thms map_unfolds map,
    55     set_unfoldss = adds_to_thms set_unfoldss sets,
    54     set_unfoldss = adds_to_thms set_unfoldss sets,
    56     rel_unfolds = add_to_thms rel_unfolds rel,
    55     rel_unfolds = add_to_thms rel_unfolds rel};
    57     srel_unfolds = add_to_thms srel_unfolds srel};
       
    58 
    56 
    59 fun add_bnf_to_unfolds bnf =
    57 fun add_bnf_to_unfolds bnf =
    60   add_to_unfolds (map_def_of_bnf bnf) (set_defs_of_bnf bnf) (rel_def_of_bnf bnf)
    58   add_to_unfolds (map_def_of_bnf bnf) (set_defs_of_bnf bnf) (rel_def_of_bnf bnf);
    61     (srel_def_of_bnf bnf);
       
    62 
    59 
    63 val bdTN = "bdT";
    60 val bdTN = "bdT";
    64 
    61 
    65 fun mk_killN n = "_kill" ^ string_of_int n;
    62 fun mk_killN n = "_kill" ^ string_of_int n;
    66 fun mk_liftN n = "_lift" ^ string_of_int n;
    63 fun mk_liftN n = "_lift" ^ string_of_int n;
   219         (map bd_Cinfinite_of_bnf inners) (bd_Card_order_of_bnf outer);
   216         (map bd_Cinfinite_of_bnf inners) (bd_Card_order_of_bnf outer);
   220 
   217 
   221     fun map_wpull_tac _ =
   218     fun map_wpull_tac _ =
   222       mk_map_wpull_tac in_alt_thm (map map_wpull_of_bnf inners) (map_wpull_of_bnf outer);
   219       mk_map_wpull_tac in_alt_thm (map map_wpull_of_bnf inners) (map_wpull_of_bnf outer);
   223 
   220 
   224     fun srel_O_Gr_tac _ =
   221     fun rel_OO_Grp_tac _ =
   225       let
   222       let
   226         val basic_thms = @{thms mem_Collect_eq fst_conv snd_conv}; (*TODO: tune*)
   223         val outer_rel_Grp = rel_Grp_of_bnf outer RS sym;
   227         val outer_srel_Gr = srel_Gr_of_bnf outer RS sym;
   224         val outer_rel_cong = rel_cong_of_bnf outer;
   228         val outer_srel_cong = srel_cong_of_bnf outer;
       
   229         val thm =
   225         val thm =
   230           (trans OF [in_alt_thm RS @{thm O_Gr_cong},
   226           (trans OF [in_alt_thm RS @{thm OO_Grp_cong},
   231              trans OF [@{thm arg_cong2[of _ _ _ _ relcomp]} OF
   227              trans OF [@{thm arg_cong2[of _ _ _ _ relcompp]} OF
   232                [trans OF [outer_srel_Gr RS @{thm arg_cong[of _ _ converse]},
   228                [trans OF [outer_rel_Grp RS @{thm arg_cong[of _ _ conversep]},
   233                  srel_converse_of_bnf outer RS sym], outer_srel_Gr],
   229                  rel_conversep_of_bnf outer RS sym], outer_rel_Grp],
   234                trans OF [srel_O_of_bnf outer RS sym, outer_srel_cong OF
   230                trans OF [rel_OO_of_bnf outer RS sym, outer_rel_cong OF
   235                  (map (fn bnf => srel_O_Gr_of_bnf bnf RS sym) inners)]]] RS sym)
   231                  (map (fn bnf => rel_OO_Grp_of_bnf bnf RS sym) inners)]]] RS sym)
   236           |> unfold_thms lthy (basic_thms @ srel_def_of_bnf outer :: map srel_def_of_bnf inners);
   232           (*|> unfold_thms lthy (rel_def_of_bnf outer :: map rel_def_of_bnf inners)*);
   237       in
   233       in
   238         unfold_thms_tac lthy basic_thms THEN rtac thm 1
   234         rtac thm 1
   239       end;
   235       end;
   240 
   236 
   241     val tacs = zip_axioms map_id_tac map_comp_tac map_cong0_tac set_map_tacs bd_card_order_tac
   237     val tacs = zip_axioms map_id_tac map_comp_tac map_cong0_tac set_map_tacs bd_card_order_tac
   242       bd_cinfinite_tac set_bd_tacs in_bd_tac map_wpull_tac srel_O_Gr_tac;
   238       bd_cinfinite_tac set_bd_tacs in_bd_tac map_wpull_tac rel_OO_Grp_tac;
   243 
   239 
   244     val outer_wits = mk_wits_of_bnf (replicate onwits oDs) (replicate onwits CAs) outer;
   240     val outer_wits = mk_wits_of_bnf (replicate onwits oDs) (replicate onwits CAs) outer;
   245 
   241 
   246     val inner_witss = map (map (fn (I, wit) => Term.list_comb (wit, map (nth xs) I)))
   242     val inner_witss = map (map (fn (I, wit) => Term.list_comb (wit, map (nth xs) I)))
   247       (map3 (fn Ds => fn n => mk_wits_of_bnf (replicate n Ds) (replicate n As))
   243       (map3 (fn Ds => fn n => mk_wits_of_bnf (replicate n Ds) (replicate n As))
   330     fun in_bd_tac _ =
   326     fun in_bd_tac _ =
   331       mk_kill_in_bd_tac n (live > n) in_alt_thm (in_bd_of_bnf bnf) (bd_Card_order_of_bnf bnf)
   327       mk_kill_in_bd_tac n (live > n) in_alt_thm (in_bd_of_bnf bnf) (bd_Card_order_of_bnf bnf)
   332         (bd_Cinfinite_of_bnf bnf) (bd_Cnotzero_of_bnf bnf);
   328         (bd_Cinfinite_of_bnf bnf) (bd_Cnotzero_of_bnf bnf);
   333     fun map_wpull_tac _ = mk_map_wpull_tac in_alt_thm [] (map_wpull_of_bnf bnf);
   329     fun map_wpull_tac _ = mk_map_wpull_tac in_alt_thm [] (map_wpull_of_bnf bnf);
   334 
   330 
   335     fun srel_O_Gr_tac _ =
   331     fun rel_OO_Grp_tac _ =
   336       let
   332       let
   337         val srel_Gr = srel_Gr_of_bnf bnf RS sym
   333         val rel_Grp = rel_Grp_of_bnf bnf RS sym
   338         val thm =
   334         val thm =
   339           (trans OF [in_alt_thm RS @{thm O_Gr_cong},
   335           (trans OF [in_alt_thm RS @{thm OO_Grp_cong},
   340             trans OF [@{thm arg_cong2[of _ _ _ _ relcomp]} OF
   336             trans OF [@{thm arg_cong2[of _ _ _ _ relcompp]} OF
   341               [trans OF [srel_Gr RS @{thm arg_cong[of _ _ converse]},
   337               [trans OF [rel_Grp RS @{thm arg_cong[of _ _ conversep]},
   342                 srel_converse_of_bnf bnf RS sym], srel_Gr],
   338                 rel_conversep_of_bnf bnf RS sym], rel_Grp],
   343               trans OF [srel_O_of_bnf bnf RS sym, srel_cong_of_bnf bnf OF
   339               trans OF [rel_OO_of_bnf bnf RS sym, rel_cong_of_bnf bnf OF
   344                 (replicate n @{thm trans[OF Gr_UNIV_id[OF refl] Id_alt[symmetric]]} @
   340                 (replicate n @{thm trans[OF Grp_UNIV_id[OF refl] eq_alt[symmetric]]} @
   345                  replicate (live - n) @{thm Gr_fst_snd})]]] RS sym)
   341                  replicate (live - n) @{thm Grp_fst_snd})]]] RS sym)
   346           |> unfold_thms lthy (srel_def_of_bnf bnf :: @{thms Id_def' mem_Collect_eq split_conv});
   342           (*|> unfold_thms lthy (rel_def_of_bnf bnf :: @{thms Id_def' mem_Collect_eq split_conv})*);
   347       in
   343       in
   348         rtac thm 1
   344         rtac thm 1
   349       end;
   345       end;
   350 
   346 
   351     val tacs = zip_axioms map_id_tac map_comp_tac map_cong0_tac set_map_tacs bd_card_order_tac
   347     val tacs = zip_axioms map_id_tac map_comp_tac map_cong0_tac set_map_tacs bd_card_order_tac
   352       bd_cinfinite_tac set_bd_tacs in_bd_tac map_wpull_tac srel_O_Gr_tac;
   348       bd_cinfinite_tac set_bd_tacs in_bd_tac map_wpull_tac rel_OO_Grp_tac;
   353 
   349 
   354     val bnf_wits = mk_wits_of_bnf (replicate nwits Ds) (replicate nwits As) bnf;
   350     val bnf_wits = mk_wits_of_bnf (replicate nwits Ds) (replicate nwits As) bnf;
   355 
   351 
   356     val wits = map (fn t => fold absfree (Term.add_frees t []) t)
   352     val wits = map (fn t => fold absfree (Term.add_frees t []) t)
   357       (map (fn (I, wit) => Term.list_comb (wit, map (nth xs) I)) bnf_wits);
   353       (map (fn (I, wit) => Term.list_comb (wit, map (nth xs) I)) bnf_wits);
   430       end;
   426       end;
   431 
   427 
   432     fun in_bd_tac _ = mk_lift_in_bd_tac n in_alt_thm (in_bd_of_bnf bnf) (bd_Card_order_of_bnf bnf);
   428     fun in_bd_tac _ = mk_lift_in_bd_tac n in_alt_thm (in_bd_of_bnf bnf) (bd_Card_order_of_bnf bnf);
   433     fun map_wpull_tac _ = mk_map_wpull_tac in_alt_thm [] (map_wpull_of_bnf bnf);
   429     fun map_wpull_tac _ = mk_map_wpull_tac in_alt_thm [] (map_wpull_of_bnf bnf);
   434 
   430 
   435     fun srel_O_Gr_tac _ =
   431     fun rel_OO_Grp_tac _ = mk_simple_rel_OO_Grp_tac (rel_OO_Grp_of_bnf bnf) in_alt_thm;
   436       mk_simple_srel_O_Gr_tac lthy (srel_def_of_bnf bnf) (srel_O_Gr_of_bnf bnf) in_alt_thm;
       
   437 
   432 
   438     val tacs = zip_axioms map_id_tac map_comp_tac map_cong0_tac set_map_tacs bd_card_order_tac
   433     val tacs = zip_axioms map_id_tac map_comp_tac map_cong0_tac set_map_tacs bd_card_order_tac
   439       bd_cinfinite_tac set_bd_tacs in_bd_tac map_wpull_tac srel_O_Gr_tac;
   434       bd_cinfinite_tac set_bd_tacs in_bd_tac map_wpull_tac rel_OO_Grp_tac;
   440 
   435 
   441     val wits = map snd (mk_wits_of_bnf (replicate nwits Ds) (replicate nwits As) bnf);
   436     val wits = map snd (mk_wits_of_bnf (replicate nwits Ds) (replicate nwits As) bnf);
   442 
   437 
   443     fun wit_tac _ = mk_simple_wit_tac (wit_thms_of_bnf bnf);
   438     fun wit_tac _ = mk_simple_wit_tac (wit_thms_of_bnf bnf);
   444 
   439 
   507 
   502 
   508     fun in_bd_tac _ =
   503     fun in_bd_tac _ =
   509       mk_permute_in_bd_tac src dest in_alt_thm (in_bd_of_bnf bnf) (bd_Card_order_of_bnf bnf);
   504       mk_permute_in_bd_tac src dest in_alt_thm (in_bd_of_bnf bnf) (bd_Card_order_of_bnf bnf);
   510     fun map_wpull_tac _ = mk_map_wpull_tac in_alt_thm [] (map_wpull_of_bnf bnf);
   505     fun map_wpull_tac _ = mk_map_wpull_tac in_alt_thm [] (map_wpull_of_bnf bnf);
   511 
   506 
   512     fun srel_O_Gr_tac _ =
   507     fun rel_OO_Grp_tac _ = mk_simple_rel_OO_Grp_tac (rel_OO_Grp_of_bnf bnf) in_alt_thm;
   513       mk_simple_srel_O_Gr_tac lthy (srel_def_of_bnf bnf) (srel_O_Gr_of_bnf bnf) in_alt_thm;
       
   514 
   508 
   515     val tacs = zip_axioms map_id_tac map_comp_tac map_cong0_tac set_map_tacs bd_card_order_tac
   509     val tacs = zip_axioms map_id_tac map_comp_tac map_cong0_tac set_map_tacs bd_card_order_tac
   516       bd_cinfinite_tac set_bd_tacs in_bd_tac map_wpull_tac srel_O_Gr_tac;
   510       bd_cinfinite_tac set_bd_tacs in_bd_tac map_wpull_tac rel_OO_Grp_tac;
   517 
   511 
   518     val wits = map snd (mk_wits_of_bnf (replicate nwits Ds) (replicate nwits As) bnf);
   512     val wits = map snd (mk_wits_of_bnf (replicate nwits Ds) (replicate nwits As) bnf);
   519 
   513 
   520     fun wit_tac _ = mk_simple_wit_tac (wit_thms_of_bnf bnf);
   514     fun wit_tac _ = mk_simple_wit_tac (wit_thms_of_bnf bnf);
   521 
   515 
   596       (Variable.invent_types (replicate live HOLogic.typeS) lthy1);
   590       (Variable.invent_types (replicate live HOLogic.typeS) lthy1);
   597 
   591 
   598     val map_unfolds = #map_unfolds unfold_set;
   592     val map_unfolds = #map_unfolds unfold_set;
   599     val set_unfoldss = #set_unfoldss unfold_set;
   593     val set_unfoldss = #set_unfoldss unfold_set;
   600     val rel_unfolds = #rel_unfolds unfold_set;
   594     val rel_unfolds = #rel_unfolds unfold_set;
   601     val srel_unfolds = #srel_unfolds unfold_set;
       
   602 
   595 
   603     val expand_maps =
   596     val expand_maps =
   604       fold expand_term_const (map (single o Logic.dest_equals o Thm.prop_of) map_unfolds);
   597       fold expand_term_const (map (single o Logic.dest_equals o Thm.prop_of) map_unfolds);
   605     val expand_sets =
   598     val expand_sets =
   606       fold expand_term_const (map (map (Logic.dest_equals o Thm.prop_of)) set_unfoldss);
   599       fold expand_term_const (map (map (Logic.dest_equals o Thm.prop_of)) set_unfoldss);
   607     val expand_rels =
   600     val expand_rels =
   608       fold expand_term_const (map (single o Logic.dest_equals o Thm.prop_of) rel_unfolds);
   601       fold expand_term_const (map (single o Logic.dest_equals o Thm.prop_of) rel_unfolds);
   609     val unfold_maps = fold (unfold_thms lthy o single) map_unfolds;
   602     val unfold_maps = fold (unfold_thms lthy o single) map_unfolds;
   610     val unfold_sets = fold (unfold_thms lthy) set_unfoldss;
   603     val unfold_sets = fold (unfold_thms lthy) set_unfoldss;
   611     val unfold_rels = unfold_thms lthy rel_unfolds;
   604     val unfold_rels = unfold_thms lthy rel_unfolds;
   612     val unfold_srels = unfold_thms lthy srel_unfolds;
   605     val unfold_all = unfold_sets o unfold_maps o unfold_rels;
   613     val unfold_all = unfold_sets o unfold_maps o unfold_rels o unfold_srels;
       
   614     val bnf_map = expand_maps (mk_map_of_bnf Ds As Bs bnf);
   606     val bnf_map = expand_maps (mk_map_of_bnf Ds As Bs bnf);
   615     val bnf_sets = map (expand_maps o expand_sets)
   607     val bnf_sets = map (expand_maps o expand_sets)
   616       (mk_sets_of_bnf (replicate live Ds) (replicate live As) bnf);
   608       (mk_sets_of_bnf (replicate live Ds) (replicate live As) bnf);
   617     val bnf_bd = mk_bd_of_bnf Ds As bnf;
   609     val bnf_bd = mk_bd_of_bnf Ds As bnf;
   618     val bnf_rel = expand_rels (mk_rel_of_bnf Ds As Bs bnf);
   610     val bnf_rel = expand_rels (mk_rel_of_bnf Ds As Bs bnf);
   654 
   646 
   655     val tacs = zip_axioms (mk_tac (map_id_of_bnf bnf)) (mk_tac (map_comp_of_bnf bnf))
   647     val tacs = zip_axioms (mk_tac (map_id_of_bnf bnf)) (mk_tac (map_comp_of_bnf bnf))
   656       (mk_tac (map_cong0_of_bnf bnf)) (map mk_tac (set_map_of_bnf bnf))
   648       (mk_tac (map_cong0_of_bnf bnf)) (map mk_tac (set_map_of_bnf bnf))
   657       (K (rtac bd_card_order 1)) (K (rtac bd_cinfinite 1)) (map mk_tac set_bds) (mk_tac in_bd)
   649       (K (rtac bd_card_order 1)) (K (rtac bd_cinfinite 1)) (map mk_tac set_bds) (mk_tac in_bd)
   658       (mk_tac (map_wpull_of_bnf bnf))
   650       (mk_tac (map_wpull_of_bnf bnf))
   659       (mk_tac (unfold_thms lthy [srel_def_of_bnf bnf] (srel_O_Gr_of_bnf bnf)));
   651       (mk_tac (unfold_thms lthy [rel_def_of_bnf bnf] (rel_OO_Grp_of_bnf bnf)));
   660 
   652 
   661     val bnf_wits = map snd (mk_wits_of_bnf (replicate nwits Ds) (replicate nwits As) bnf);
   653     val bnf_wits = map snd (mk_wits_of_bnf (replicate nwits Ds) (replicate nwits As) bnf);
   662 
   654 
   663     fun wit_tac _ = mk_simple_wit_tac (map unfold_all (wit_thms_of_bnf bnf));
   655     fun wit_tac _ = mk_simple_wit_tac (map unfold_all (wit_thms_of_bnf bnf));
   664 
   656