src/HOL/Tools/BNF/bnf_comp.ML
changeset 60728 26ffdb966759
parent 60207 81a0900f0ddc
child 60752 b48830b670a1
equal deleted inserted replaced
60727:53697011b03a 60728:26ffdb966759
   251             |> Thm.close_derivation))
   251             |> Thm.close_derivation))
   252         end
   252         end
   253       else
   253       else
   254         (bd, NONE);
   254         (bd, NONE);
   255 
   255 
   256     fun map_id0_tac _ =
   256     fun map_id0_tac ctxt =
   257       mk_comp_map_id0_tac (map_id0_of_bnf outer) (map_cong0_of_bnf outer)
   257       mk_comp_map_id0_tac ctxt (map_id0_of_bnf outer) (map_cong0_of_bnf outer)
   258         (map map_id0_of_bnf inners);
   258         (map map_id0_of_bnf inners);
   259 
   259 
   260     fun map_comp0_tac _ =
   260     fun map_comp0_tac ctxt =
   261       mk_comp_map_comp0_tac (map_comp0_of_bnf outer) (map_cong0_of_bnf outer)
   261       mk_comp_map_comp0_tac ctxt (map_comp0_of_bnf outer) (map_cong0_of_bnf outer)
   262         (map map_comp0_of_bnf inners);
   262         (map map_comp0_of_bnf inners);
   263 
   263 
   264     fun mk_single_set_map0_tac i ctxt =
   264     fun mk_single_set_map0_tac i ctxt =
   265       mk_comp_set_map0_tac ctxt (nth set'_eq_sets i) (map_comp0_of_bnf outer)
   265       mk_comp_set_map0_tac ctxt (nth set'_eq_sets i) (map_comp0_of_bnf outer)
   266         (map_cong0_of_bnf outer) (collect_set_map_of_bnf outer)
   266         (map_cong0_of_bnf outer) (collect_set_map_of_bnf outer)
   267         (map ((fn thms => nth thms i) o set_map0_of_bnf) inners);
   267         (map ((fn thms => nth thms i) o set_map0_of_bnf) inners);
   268 
   268 
   269     val set_map0_tacs = map mk_single_set_map0_tac (0 upto ilive - 1);
   269     val set_map0_tacs = map mk_single_set_map0_tac (0 upto ilive - 1);
   270 
   270 
   271     fun bd_card_order_tac _ =
   271     fun bd_card_order_tac ctxt =
   272       mk_comp_bd_card_order_tac (map bd_card_order_of_bnf inners) (bd_card_order_of_bnf outer);
   272       mk_comp_bd_card_order_tac ctxt (map bd_card_order_of_bnf inners) (bd_card_order_of_bnf outer);
   273 
   273 
   274     fun bd_cinfinite_tac _ =
   274     fun bd_cinfinite_tac ctxt =
   275       mk_comp_bd_cinfinite_tac (bd_cinfinite_of_bnf inner) (bd_cinfinite_of_bnf outer);
   275       mk_comp_bd_cinfinite_tac ctxt (bd_cinfinite_of_bnf inner) (bd_cinfinite_of_bnf outer);
   276 
   276 
   277     val set_alt_thms =
   277     val set_alt_thms =
   278       if Config.get lthy quick_and_dirty then
   278       if Config.get lthy quick_and_dirty then
   279         []
   279         []
   280       else
   280       else
   317         Goal.prove_sorry lthy [] [] goal
   317         Goal.prove_sorry lthy [] [] goal
   318           (fn {context = ctxt, prems = _} => mk_comp_in_alt_tac ctxt set_alt_thms)
   318           (fn {context = ctxt, prems = _} => mk_comp_in_alt_tac ctxt set_alt_thms)
   319         |> Thm.close_derivation
   319         |> Thm.close_derivation
   320       end;
   320       end;
   321 
   321 
   322     fun le_rel_OO_tac _ = mk_le_rel_OO_tac (le_rel_OO_of_bnf outer) (rel_mono_of_bnf outer)
   322     fun le_rel_OO_tac ctxt = mk_le_rel_OO_tac ctxt (le_rel_OO_of_bnf outer) (rel_mono_of_bnf outer)
   323       (map le_rel_OO_of_bnf inners);
   323       (map le_rel_OO_of_bnf inners);
   324 
   324 
   325     fun rel_OO_Grp_tac ctxt =
   325     fun rel_OO_Grp_tac ctxt =
   326       let
   326       let
   327         val outer_rel_Grp = rel_Grp_of_bnf outer RS sym;
   327         val outer_rel_Grp = rel_Grp_of_bnf outer RS sym;
   332                [trans OF [outer_rel_Grp RS @{thm arg_cong[of _ _ conversep]},
   332                [trans OF [outer_rel_Grp RS @{thm arg_cong[of _ _ conversep]},
   333                  rel_conversep_of_bnf outer RS sym], outer_rel_Grp],
   333                  rel_conversep_of_bnf outer RS sym], outer_rel_Grp],
   334                trans OF [rel_OO_of_bnf outer RS sym, outer_rel_cong OF
   334                trans OF [rel_OO_of_bnf outer RS sym, outer_rel_cong OF
   335                  (map (fn bnf => rel_OO_Grp_of_bnf bnf RS sym) inners)]]] RS sym);
   335                  (map (fn bnf => rel_OO_Grp_of_bnf bnf RS sym) inners)]]] RS sym);
   336       in
   336       in
   337         unfold_thms_tac ctxt set'_eq_sets THEN rtac thm 1
   337         unfold_thms_tac ctxt set'_eq_sets THEN rtac ctxt thm 1
   338       end;
   338       end;
   339 
   339 
   340     val tacs = zip_axioms map_id0_tac map_comp0_tac map_cong0_tac set_map0_tacs bd_card_order_tac
   340     val tacs = zip_axioms map_id0_tac map_comp0_tac map_cong0_tac set_map0_tacs bd_card_order_tac
   341       bd_cinfinite_tac set_bd_tacs le_rel_OO_tac rel_OO_Grp_tac;
   341       bd_cinfinite_tac set_bd_tacs le_rel_OO_tac rel_OO_Grp_tac;
   342 
   342 
   406     val bnf_sets = mk_sets_of_bnf (replicate live Ds) (replicate live As) bnf;
   406     val bnf_sets = mk_sets_of_bnf (replicate live Ds) (replicate live As) bnf;
   407     val sets = drop n bnf_sets;
   407     val sets = drop n bnf_sets;
   408 
   408 
   409     val bd = mk_bd_of_bnf Ds As bnf;
   409     val bd = mk_bd_of_bnf Ds As bnf;
   410 
   410 
   411     fun map_id0_tac _ = rtac (map_id0_of_bnf bnf) 1;
   411     fun map_id0_tac ctxt = rtac ctxt (map_id0_of_bnf bnf) 1;
   412     fun map_comp0_tac ctxt =
   412     fun map_comp0_tac ctxt =
   413       unfold_thms_tac ctxt ((map_comp0_of_bnf bnf RS sym) ::
   413       unfold_thms_tac ctxt ((map_comp0_of_bnf bnf RS sym) ::
   414         @{thms comp_assoc id_comp comp_id}) THEN rtac refl 1;
   414         @{thms comp_assoc id_comp comp_id}) THEN rtac ctxt refl 1;
   415     fun map_cong0_tac ctxt =
   415     fun map_cong0_tac ctxt =
   416       mk_kill_map_cong0_tac ctxt n (live - n) (map_cong0_of_bnf bnf);
   416       mk_kill_map_cong0_tac ctxt n (live - n) (map_cong0_of_bnf bnf);
   417     val set_map0_tacs = map (fn thm => fn _ => rtac thm 1) (drop n (set_map0_of_bnf bnf));
   417     val set_map0_tacs = map (fn thm => fn ctxt => rtac ctxt thm 1) (drop n (set_map0_of_bnf bnf));
   418     fun bd_card_order_tac _ = rtac (bd_card_order_of_bnf bnf) 1;
   418     fun bd_card_order_tac ctxt = rtac ctxt (bd_card_order_of_bnf bnf) 1;
   419     fun bd_cinfinite_tac _ = rtac (bd_cinfinite_of_bnf bnf) 1;
   419     fun bd_cinfinite_tac ctxt = rtac ctxt (bd_cinfinite_of_bnf bnf) 1;
   420     val set_bd_tacs = map (fn thm => fn _ => rtac thm 1) (drop n (set_bd_of_bnf bnf));
   420     val set_bd_tacs = map (fn thm => fn ctxt => rtac ctxt thm 1) (drop n (set_bd_of_bnf bnf));
   421 
   421 
   422     val in_alt_thm =
   422     val in_alt_thm =
   423       let
   423       let
   424         val inx = mk_in Asets sets T;
   424         val inx = mk_in Asets sets T;
   425         val in_alt = mk_in (map HOLogic.mk_UNIV killedAs @ Asets) bnf_sets T;
   425         val in_alt = mk_in (map HOLogic.mk_UNIV killedAs @ Asets) bnf_sets T;
   426         val goal = fold_rev Logic.all Asets (mk_Trueprop_eq (inx, in_alt));
   426         val goal = fold_rev Logic.all Asets (mk_Trueprop_eq (inx, in_alt));
   427       in
   427       in
   428         Goal.prove_sorry lthy [] [] goal (K kill_in_alt_tac) |> Thm.close_derivation
   428         Goal.prove_sorry lthy [] [] goal (fn {context = ctxt, prems = _} =>
       
   429           kill_in_alt_tac ctxt) |> Thm.close_derivation
   429       end;
   430       end;
   430 
   431 
   431     fun le_rel_OO_tac ctxt =
   432     fun le_rel_OO_tac ctxt =
   432       EVERY' [rtac @{thm ord_le_eq_trans}, rtac (le_rel_OO_of_bnf bnf)] 1 THEN
   433       EVERY' [rtac ctxt @{thm ord_le_eq_trans}, rtac ctxt (le_rel_OO_of_bnf bnf)] 1 THEN
   433       unfold_thms_tac ctxt @{thms eq_OO} THEN rtac refl 1;
   434       unfold_thms_tac ctxt @{thms eq_OO} THEN rtac ctxt refl 1;
   434 
   435 
   435     fun rel_OO_Grp_tac _ =
   436     fun rel_OO_Grp_tac ctxt =
   436       let
   437       let
   437         val rel_Grp = rel_Grp_of_bnf bnf RS sym
   438         val rel_Grp = rel_Grp_of_bnf bnf RS sym
   438         val thm =
   439         val thm =
   439           (trans OF [in_alt_thm RS @{thm OO_Grp_cong},
   440           (trans OF [in_alt_thm RS @{thm OO_Grp_cong},
   440             trans OF [@{thm arg_cong2[of _ _ _ _ relcompp]} OF
   441             trans OF [@{thm arg_cong2[of _ _ _ _ relcompp]} OF
   442                 rel_conversep_of_bnf bnf RS sym], rel_Grp],
   443                 rel_conversep_of_bnf bnf RS sym], rel_Grp],
   443               trans OF [rel_OO_of_bnf bnf RS sym, rel_cong_of_bnf bnf OF
   444               trans OF [rel_OO_of_bnf bnf RS sym, rel_cong_of_bnf bnf OF
   444                 (replicate n @{thm trans[OF Grp_UNIV_id[OF refl] eq_alt[symmetric]]} @
   445                 (replicate n @{thm trans[OF Grp_UNIV_id[OF refl] eq_alt[symmetric]]} @
   445                  replicate (live - n) @{thm Grp_fst_snd})]]] RS sym);
   446                  replicate (live - n) @{thm Grp_fst_snd})]]] RS sym);
   446       in
   447       in
   447         rtac thm 1
   448         rtac ctxt thm 1
   448       end;
   449       end;
   449 
   450 
   450     val tacs = zip_axioms map_id0_tac map_comp0_tac map_cong0_tac set_map0_tacs bd_card_order_tac
   451     val tacs = zip_axioms map_id0_tac map_comp0_tac map_cong0_tac set_map0_tacs bd_card_order_tac
   451       bd_cinfinite_tac set_bd_tacs le_rel_OO_tac rel_OO_Grp_tac;
   452       bd_cinfinite_tac set_bd_tacs le_rel_OO_tac rel_OO_Grp_tac;
   452 
   453 
   504     val bnf_sets = mk_sets_of_bnf (replicate live Ds) (replicate live As) bnf;
   505     val bnf_sets = mk_sets_of_bnf (replicate live Ds) (replicate live As) bnf;
   505     val sets = map (fn A => absdummy T (HOLogic.mk_set A [])) newAs @ bnf_sets;
   506     val sets = map (fn A => absdummy T (HOLogic.mk_set A [])) newAs @ bnf_sets;
   506 
   507 
   507     val bd = mk_bd_of_bnf Ds As bnf;
   508     val bd = mk_bd_of_bnf Ds As bnf;
   508 
   509 
   509     fun map_id0_tac _ = rtac (map_id0_of_bnf bnf) 1;
   510     fun map_id0_tac ctxt = rtac ctxt (map_id0_of_bnf bnf) 1;
   510     fun map_comp0_tac ctxt =
   511     fun map_comp0_tac ctxt =
   511       unfold_thms_tac ctxt ((map_comp0_of_bnf bnf RS sym) ::
   512       unfold_thms_tac ctxt ((map_comp0_of_bnf bnf RS sym) ::
   512         @{thms comp_assoc id_comp comp_id}) THEN rtac refl 1;
   513         @{thms comp_assoc id_comp comp_id}) THEN rtac ctxt refl 1;
   513     fun map_cong0_tac ctxt =
   514     fun map_cong0_tac ctxt =
   514       rtac (map_cong0_of_bnf bnf) 1 THEN REPEAT_DETERM_N live (Goal.assume_rule_tac ctxt 1);
   515       rtac ctxt (map_cong0_of_bnf bnf) 1 THEN REPEAT_DETERM_N live (Goal.assume_rule_tac ctxt 1);
   515     val set_map0_tacs =
   516     val set_map0_tacs =
   516       if Config.get lthy quick_and_dirty then
   517       if Config.get lthy quick_and_dirty then
   517         replicate (n + live) (K all_tac)
   518         replicate (n + live) (K all_tac)
   518       else
   519       else
   519         replicate n (K empty_natural_tac) @
   520         replicate n empty_natural_tac @
   520         map (fn thm => fn _ => rtac thm 1) (set_map0_of_bnf bnf);
   521         map (fn thm => fn ctxt => rtac ctxt thm 1) (set_map0_of_bnf bnf);
   521     fun bd_card_order_tac _ = rtac (bd_card_order_of_bnf bnf) 1;
   522     fun bd_card_order_tac ctxt = rtac ctxt (bd_card_order_of_bnf bnf) 1;
   522     fun bd_cinfinite_tac _ = rtac (bd_cinfinite_of_bnf bnf) 1;
   523     fun bd_cinfinite_tac ctxt = rtac ctxt (bd_cinfinite_of_bnf bnf) 1;
   523     val set_bd_tacs =
   524     val set_bd_tacs =
   524       if Config.get lthy quick_and_dirty then
   525       if Config.get lthy quick_and_dirty then
   525         replicate (n + live) (K all_tac)
   526         replicate (n + live) (K all_tac)
   526       else
   527       else
   527         replicate n (K (mk_lift_set_bd_tac (bd_Card_order_of_bnf bnf))) @
   528         replicate n (fn ctxt => mk_lift_set_bd_tac ctxt (bd_Card_order_of_bnf bnf)) @
   528         (map (fn thm => fn _ => rtac thm 1) (set_bd_of_bnf bnf));
   529         (map (fn thm => fn ctxt => rtac ctxt thm 1) (set_bd_of_bnf bnf));
   529 
   530 
   530     val in_alt_thm =
   531     val in_alt_thm =
   531       let
   532       let
   532         val inx = mk_in Asets sets T;
   533         val inx = mk_in Asets sets T;
   533         val in_alt = mk_in (drop n Asets) bnf_sets T;
   534         val in_alt = mk_in (drop n Asets) bnf_sets T;
   534         val goal = fold_rev Logic.all Asets (mk_Trueprop_eq (inx, in_alt));
   535         val goal = fold_rev Logic.all Asets (mk_Trueprop_eq (inx, in_alt));
   535       in
   536       in
   536         Goal.prove_sorry lthy [] [] goal (K lift_in_alt_tac) |> Thm.close_derivation
   537         Goal.prove_sorry lthy [] [] goal (fn {context = ctxt, prems = _} => lift_in_alt_tac ctxt)
       
   538         |> Thm.close_derivation
   537       end;
   539       end;
   538 
   540 
   539     fun le_rel_OO_tac _ = rtac (le_rel_OO_of_bnf bnf) 1;
   541     fun le_rel_OO_tac ctxt = rtac ctxt (le_rel_OO_of_bnf bnf) 1;
   540 
   542 
   541     fun rel_OO_Grp_tac _ = mk_simple_rel_OO_Grp_tac (rel_OO_Grp_of_bnf bnf) in_alt_thm;
   543     fun rel_OO_Grp_tac ctxt = mk_simple_rel_OO_Grp_tac ctxt (rel_OO_Grp_of_bnf bnf) in_alt_thm;
   542 
   544 
   543     val tacs = zip_axioms map_id0_tac map_comp0_tac map_cong0_tac set_map0_tacs bd_card_order_tac
   545     val tacs = zip_axioms map_id0_tac map_comp0_tac map_cong0_tac set_map0_tacs bd_card_order_tac
   544       bd_cinfinite_tac set_bd_tacs le_rel_OO_tac rel_OO_Grp_tac;
   546       bd_cinfinite_tac set_bd_tacs le_rel_OO_tac rel_OO_Grp_tac;
   545 
   547 
   546     val wits = map snd (mk_wits_of_bnf (replicate nwits Ds) (replicate nwits As) bnf);
   548     val wits = map snd (mk_wits_of_bnf (replicate nwits Ds) (replicate nwits As) bnf);
   596     val bnf_sets = mk_sets_of_bnf (replicate live Ds) (replicate live As) bnf;
   598     val bnf_sets = mk_sets_of_bnf (replicate live Ds) (replicate live As) bnf;
   597     val sets = permute bnf_sets;
   599     val sets = permute bnf_sets;
   598 
   600 
   599     val bd = mk_bd_of_bnf Ds As bnf;
   601     val bd = mk_bd_of_bnf Ds As bnf;
   600 
   602 
   601     fun map_id0_tac _ = rtac (map_id0_of_bnf bnf) 1;
   603     fun map_id0_tac ctxt = rtac ctxt (map_id0_of_bnf bnf) 1;
   602     fun map_comp0_tac _ = rtac (map_comp0_of_bnf bnf) 1;
   604     fun map_comp0_tac ctxt = rtac ctxt (map_comp0_of_bnf bnf) 1;
   603     fun map_cong0_tac ctxt =
   605     fun map_cong0_tac ctxt =
   604       rtac (map_cong0_of_bnf bnf) 1 THEN REPEAT_DETERM_N live (Goal.assume_rule_tac ctxt 1);
   606       rtac ctxt (map_cong0_of_bnf bnf) 1 THEN REPEAT_DETERM_N live (Goal.assume_rule_tac ctxt 1);
   605     val set_map0_tacs = permute (map (fn thm => fn _ => rtac thm 1) (set_map0_of_bnf bnf));
   607     val set_map0_tacs = permute (map (fn thm => fn ctxt => rtac ctxt thm 1) (set_map0_of_bnf bnf));
   606     fun bd_card_order_tac _ = rtac (bd_card_order_of_bnf bnf) 1;
   608     fun bd_card_order_tac ctxt = rtac ctxt (bd_card_order_of_bnf bnf) 1;
   607     fun bd_cinfinite_tac _ = rtac (bd_cinfinite_of_bnf bnf) 1;
   609     fun bd_cinfinite_tac ctxt = rtac ctxt (bd_cinfinite_of_bnf bnf) 1;
   608     val set_bd_tacs = permute (map (fn thm => fn _ => rtac thm 1) (set_bd_of_bnf bnf));
   610     val set_bd_tacs = permute (map (fn thm => fn ctxt => rtac ctxt thm 1) (set_bd_of_bnf bnf));
   609 
   611 
   610     val in_alt_thm =
   612     val in_alt_thm =
   611       let
   613       let
   612         val inx = mk_in Asets sets T;
   614         val inx = mk_in Asets sets T;
   613         val in_alt = mk_in (unpermute Asets) bnf_sets T;
   615         val in_alt = mk_in (unpermute Asets) bnf_sets T;
   614         val goal = fold_rev Logic.all Asets (mk_Trueprop_eq (inx, in_alt));
   616         val goal = fold_rev Logic.all Asets (mk_Trueprop_eq (inx, in_alt));
   615       in
   617       in
   616         Goal.prove_sorry lthy [] [] goal (K (mk_permute_in_alt_tac src dest))
   618         Goal.prove_sorry lthy [] [] goal (fn {context = ctxt, prems = _} =>
       
   619           mk_permute_in_alt_tac ctxt src dest)
   617         |> Thm.close_derivation
   620         |> Thm.close_derivation
   618       end;
   621       end;
   619 
   622 
   620     fun le_rel_OO_tac _ = rtac (le_rel_OO_of_bnf bnf) 1;
   623     fun le_rel_OO_tac ctxt = rtac ctxt (le_rel_OO_of_bnf bnf) 1;
   621 
   624 
   622     fun rel_OO_Grp_tac _ = mk_simple_rel_OO_Grp_tac (rel_OO_Grp_of_bnf bnf) in_alt_thm;
   625     fun rel_OO_Grp_tac ctxt = mk_simple_rel_OO_Grp_tac ctxt (rel_OO_Grp_of_bnf bnf) in_alt_thm;
   623 
   626 
   624     val tacs = zip_axioms map_id0_tac map_comp0_tac map_cong0_tac set_map0_tacs bd_card_order_tac
   627     val tacs = zip_axioms map_id0_tac map_comp0_tac map_cong0_tac set_map0_tacs bd_card_order_tac
   625       bd_cinfinite_tac set_bd_tacs le_rel_OO_tac rel_OO_Grp_tac;
   628       bd_cinfinite_tac set_bd_tacs le_rel_OO_tac rel_OO_Grp_tac;
   626 
   629 
   627     val wits = map snd (mk_wits_of_bnf (replicate nwits Ds) (replicate nwits As) bnf);
   630     val wits = map snd (mk_wits_of_bnf (replicate nwits Ds) (replicate nwits As) bnf);
   794     val TA_params =
   797     val TA_params =
   795       (if has_live_phantoms then all_TA_params_in_order
   798       (if has_live_phantoms then all_TA_params_in_order
   796        else inter (op =) (Term.add_tfreesT repTA []) all_TA_params_in_order);
   799        else inter (op =) (Term.add_tfreesT repTA []) all_TA_params_in_order);
   797     val ((TA, (Rep_name, Abs_name, type_definition, Abs_inverse, Abs_inject, _)), lthy) =
   800     val ((TA, (Rep_name, Abs_name, type_definition, Abs_inverse, Abs_inject, _)), lthy) =
   798       maybe_typedef lthy has_live_phantoms (T_bind, TA_params, NoSyn) (HOLogic.mk_UNIV repTA) NONE
   801       maybe_typedef lthy has_live_phantoms (T_bind, TA_params, NoSyn) (HOLogic.mk_UNIV repTA) NONE
   799         (fn _ => EVERY' [rtac exI, rtac UNIV_I] 1) lthy;
   802         (fn ctxt => EVERY' [rtac ctxt exI, rtac ctxt UNIV_I] 1) lthy;
   800 
   803 
   801     val repTB = mk_T_of_bnf Ds Bs bnf;
   804     val repTB = mk_T_of_bnf Ds Bs bnf;
   802     val TB = Term.typ_subst_atomic (As ~~ Bs) TA;
   805     val TB = Term.typ_subst_atomic (As ~~ Bs) TA;
   803     val RepA = Const (Rep_name, TA --> repTA);
   806     val RepA = Const (Rep_name, TA --> repTA);
   804     val RepB = Const (Rep_name, TB --> repTB);
   807     val RepB = Const (Rep_name, TB --> repTB);
   824     val params = Term.add_tfreesT bd_repT [];
   827     val params = Term.add_tfreesT bd_repT [];
   825     val all_deads = map TFree (fold Term.add_tfreesT Ds []);
   828     val all_deads = map TFree (fold Term.add_tfreesT Ds []);
   826 
   829 
   827     val ((bdT, (_, Abs_bd_name, _, _, Abs_bdT_inject, Abs_bdT_cases)), lthy) =
   830     val ((bdT, (_, Abs_bd_name, _, _, Abs_bdT_inject, Abs_bdT_cases)), lthy) =
   828       maybe_typedef lthy false (bdT_bind, params, NoSyn)
   831       maybe_typedef lthy false (bdT_bind, params, NoSyn)
   829         (HOLogic.mk_UNIV bd_repT) NONE (fn _ => EVERY' [rtac exI, rtac UNIV_I] 1) lthy;
   832         (HOLogic.mk_UNIV bd_repT) NONE (fn ctxt => EVERY' [rtac ctxt exI, rtac ctxt UNIV_I] 1) lthy;
   830 
   833 
   831     val (bnf_bd', bd_ordIso, bd_card_order, bd_cinfinite) =
   834     val (bnf_bd', bd_ordIso, bd_card_order, bd_cinfinite) =
   832       if bdT = bd_repT then (bnf_bd, bd_Card_order_of_bnf bnf RS @{thm ordIso_refl},
   835       if bdT = bd_repT then (bnf_bd, bd_Card_order_of_bnf bnf RS @{thm ordIso_refl},
   833         bd_card_order_of_bnf bnf, bd_cinfinite_of_bnf bnf)
   836         bd_card_order_of_bnf bnf, bd_cinfinite_of_bnf bnf)
   834       else
   837       else
   845             (@{thm Cinfinite_cong} OF [bd_ordIso, bd_Cinfinite_of_bnf bnf]) RS conjunct1;
   848             (@{thm Cinfinite_cong} OF [bd_ordIso, bd_Cinfinite_of_bnf bnf]) RS conjunct1;
   846         in
   849         in
   847           (bnf_bd', bd_ordIso, bd_card_order, bd_cinfinite)
   850           (bnf_bd', bd_ordIso, bd_card_order, bd_cinfinite)
   848         end;
   851         end;
   849 
   852 
   850     fun map_id0_tac _ =
   853     fun map_id0_tac ctxt =
   851       rtac (@{thm type_copy_map_id0} OF [type_definition, map_id0_of_bnf bnf]) 1;
   854       rtac ctxt (@{thm type_copy_map_id0} OF [type_definition, map_id0_of_bnf bnf]) 1;
   852     fun map_comp0_tac _ =
   855     fun map_comp0_tac ctxt =
   853       rtac (@{thm type_copy_map_comp0} OF [type_definition, map_comp0_of_bnf bnf]) 1;
   856       rtac ctxt (@{thm type_copy_map_comp0} OF [type_definition, map_comp0_of_bnf bnf]) 1;
   854     fun map_cong0_tac _ =
   857     fun map_cong0_tac ctxt =
   855       EVERY' (rtac @{thm type_copy_map_cong0} :: rtac (map_cong0_of_bnf bnf) ::
   858       EVERY' (rtac ctxt @{thm type_copy_map_cong0} :: rtac ctxt (map_cong0_of_bnf bnf) ::
   856         map (fn i => EVERY' [select_prem_tac live (dtac meta_spec) i, etac meta_mp,
   859         map (fn i => EVERY' [select_prem_tac ctxt live (dtac ctxt meta_spec) i, etac ctxt meta_mp,
   857           etac (o_apply RS equalityD2 RS set_mp)]) (1 upto live)) 1;
   860           etac ctxt (o_apply RS equalityD2 RS set_mp)]) (1 upto live)) 1;
   858     fun set_map0_tac thm _ =
   861     fun set_map0_tac thm ctxt =
   859       rtac (@{thm type_copy_set_map0} OF [type_definition, thm]) 1;
   862       rtac ctxt (@{thm type_copy_set_map0} OF [type_definition, thm]) 1;
   860     val set_bd_tacs = map (fn thm => fn _ => rtac (@{thm ordLeq_ordIso_trans} OF
   863     val set_bd_tacs = map (fn thm => fn ctxt => rtac ctxt (@{thm ordLeq_ordIso_trans} OF
   861         [thm, bd_ordIso] RS @{thm type_copy_set_bd}) 1) (set_bd_of_bnf bnf);
   864         [thm, bd_ordIso] RS @{thm type_copy_set_bd}) 1) (set_bd_of_bnf bnf);
   862     fun le_rel_OO_tac _ =
   865     fun le_rel_OO_tac ctxt =
   863       rtac (le_rel_OO_of_bnf bnf RS @{thm vimage2p_relcompp_mono}) 1;
   866       rtac ctxt (le_rel_OO_of_bnf bnf RS @{thm vimage2p_relcompp_mono}) 1;
   864     fun rel_OO_Grp_tac ctxt =
   867     fun rel_OO_Grp_tac ctxt =
   865       (rtac (rel_OO_Grp_of_bnf bnf RS @{thm vimage2p_cong} RS trans) THEN'
   868       (rtac ctxt (rel_OO_Grp_of_bnf bnf RS @{thm vimage2p_cong} RS trans) THEN'
   866        (if has_live_phantoms then subst_tac ctxt NONE else SELECT_GOAL o unfold_thms_tac ctxt)
   869        (if has_live_phantoms then subst_tac ctxt NONE else SELECT_GOAL o unfold_thms_tac ctxt)
   867          [type_definition RS @{thm vimage2p_relcompp_converse}] THEN'
   870          [type_definition RS @{thm vimage2p_relcompp_converse}] THEN'
   868        SELECT_GOAL (unfold_thms_tac ctxt [o_apply,
   871        SELECT_GOAL (unfold_thms_tac ctxt [o_apply,
   869          type_definition RS @{thm type_copy_vimage2p_Grp_Rep},
   872          type_definition RS @{thm type_copy_vimage2p_Grp_Rep},
   870          type_definition RS @{thm vimage2p_relcompp_converse}]) THEN'
   873          type_definition RS @{thm vimage2p_relcompp_converse}]) THEN'
   871        rtac refl) 1;
   874        rtac ctxt refl) 1;
   872 
   875 
   873     val tacs = zip_axioms map_id0_tac map_comp0_tac map_cong0_tac
   876     val tacs = zip_axioms map_id0_tac map_comp0_tac map_cong0_tac
   874       (map set_map0_tac (set_map0_of_bnf bnf)) (K (rtac bd_card_order 1)) (K (rtac bd_cinfinite 1))
   877       (map set_map0_tac (set_map0_of_bnf bnf))
       
   878       (fn ctxt => rtac ctxt bd_card_order 1) (fn ctxt => rtac ctxt bd_cinfinite 1)
   875       set_bd_tacs le_rel_OO_tac rel_OO_Grp_tac;
   879       set_bd_tacs le_rel_OO_tac rel_OO_Grp_tac;
   876 
   880 
   877     val bnf_wits = map (fn (I, t) =>
   881     val bnf_wits = map (fn (I, t) =>
   878         fold Term.absdummy (map (nth As) I)
   882         fold Term.absdummy (map (nth As) I)
   879           (AbsA $ Term.list_comb (t, map Bound (0 upto length I - 1))))
   883           (AbsA $ Term.list_comb (t, map Bound (0 upto length I - 1))))
   880       (mk_wits_of_bnf (replicate nwits Ds) (replicate nwits As) bnf);
   884       (mk_wits_of_bnf (replicate nwits Ds) (replicate nwits As) bnf);
   881 
   885 
   882     fun wit_tac _ = ALLGOALS (dtac (type_definition RS @{thm type_copy_wit})) THEN
   886     fun wit_tac ctxt = ALLGOALS (dtac ctxt (type_definition RS @{thm type_copy_wit})) THEN
   883       mk_simple_wit_tac (wit_thms_of_bnf bnf);
   887       mk_simple_wit_tac (wit_thms_of_bnf bnf);
   884 
   888 
   885     val (bnf', lthy') =
   889     val (bnf', lthy') =
   886       bnf_def Hardly_Inline (user_policy Dont_Note) true qualify tacs wit_tac (SOME all_deads)
   890       bnf_def Hardly_Inline (user_policy Dont_Note) true qualify tacs wit_tac (SOME all_deads)
   887         Binding.empty Binding.empty []
   891         Binding.empty Binding.empty []