src/HOL/Tools/BNF/bnf_lfp.ML
changeset 59580 cbc38731d42f
parent 59498 50b60f501b05
child 59621 291934bac95e
equal deleted inserted replaced
59579:d8fff0b94c53 59580:cbc38731d42f
   605             |> singleton (Proof_Context.export names_lthy lthy))
   605             |> singleton (Proof_Context.export names_lthy lthy))
   606           (map mk_mono_goal min_algss) min_algs_thms;
   606           (map mk_mono_goal min_algss) min_algs_thms;
   607 
   607 
   608         fun mk_card_conjunct min_alg = mk_ordLeq (mk_card_of min_alg) Asuc_bd;
   608         fun mk_card_conjunct min_alg = mk_ordLeq (mk_card_of min_alg) Asuc_bd;
   609         val card_conjunction = Library.foldr1 HOLogic.mk_conj (map mk_card_conjunct min_algss);
   609         val card_conjunction = Library.foldr1 HOLogic.mk_conj (map mk_card_conjunct min_algss);
   610         val card_cT = certifyT lthy suc_bdT;
   610         val card_cT = Proof_Context.ctyp_of lthy suc_bdT;
   611         val card_ct = certify lthy (Term.absfree idx' card_conjunction);
   611         val card_ct = Proof_Context.cterm_of lthy (Term.absfree idx' card_conjunction);
   612 
   612 
   613         val card_of =
   613         val card_of =
   614           Goal.prove_sorry lthy [] []
   614           Goal.prove_sorry lthy [] []
   615             (HOLogic.mk_Trueprop (HOLogic.mk_imp (i_field, card_conjunction)))
   615             (HOLogic.mk_Trueprop (HOLogic.mk_imp (i_field, card_conjunction)))
   616             (K (mk_min_algs_card_of_tac card_cT card_ct
   616             (K (mk_min_algs_card_of_tac card_cT card_ct
   620           |> Thm.close_derivation
   620           |> Thm.close_derivation
   621           |> singleton (Proof_Context.export names_lthy lthy);
   621           |> singleton (Proof_Context.export names_lthy lthy);
   622 
   622 
   623         val least_prem = HOLogic.mk_Trueprop (mk_alg Bs ss);
   623         val least_prem = HOLogic.mk_Trueprop (mk_alg Bs ss);
   624         val least_conjunction = Library.foldr1 HOLogic.mk_conj (map2 mk_leq min_algss Bs);
   624         val least_conjunction = Library.foldr1 HOLogic.mk_conj (map2 mk_leq min_algss Bs);
   625         val least_cT = certifyT lthy suc_bdT;
   625         val least_cT = Proof_Context.ctyp_of lthy suc_bdT;
   626         val least_ct = certify lthy (Term.absfree idx' least_conjunction);
   626         val least_ct = Proof_Context.cterm_of lthy (Term.absfree idx' least_conjunction);
   627 
   627 
   628         val least =
   628         val least =
   629           (Goal.prove_sorry lthy [] []
   629           (Goal.prove_sorry lthy [] []
   630             (Logic.mk_implies (least_prem,
   630             (Logic.mk_implies (least_prem,
   631               HOLogic.mk_Trueprop (HOLogic.mk_imp (i_field, least_conjunction))))
   631               HOLogic.mk_Trueprop (HOLogic.mk_imp (i_field, least_conjunction))))
   777     val str_init_defs = map (fn def =>
   777     val str_init_defs = map (fn def =>
   778       mk_unabs_def 2 (Morphism.thm phi def RS meta_eq_to_obj_eq)) str_init_def_frees;
   778       mk_unabs_def 2 (Morphism.thm phi def RS meta_eq_to_obj_eq)) str_init_def_frees;
   779 
   779 
   780     val car_inits = map (mk_min_alg str_inits) ks;
   780     val car_inits = map (mk_min_alg str_inits) ks;
   781 
   781 
   782     val alg_init_thm = cterm_instantiate_pos (map (SOME o certify lthy) str_inits) alg_min_alg_thm;
   782     val alg_init_thm = cterm_instantiate_pos (map (SOME o Proof_Context.cterm_of lthy) str_inits) alg_min_alg_thm;
   783 
   783 
   784     val alg_select_thm = Goal.prove_sorry lthy [] []
   784     val alg_select_thm = Goal.prove_sorry lthy [] []
   785       (HOLogic.mk_Trueprop (mk_Ball II
   785       (HOLogic.mk_Trueprop (mk_Ball II
   786         (Term.absfree iidx' (mk_alg select_Bs select_ss))))
   786         (Term.absfree iidx' (mk_alg select_Bs select_ss))))
   787       (fn {context = ctxt, prems = _} => mk_alg_select_tac ctxt Abs_IIT_inverse_thm)
   787       (fn {context = ctxt, prems = _} => mk_alg_select_tac ctxt Abs_IIT_inverse_thm)
   810           [mk_mor car_inits str_inits Bs ss init_fs,
   810           [mk_mor car_inits str_inits Bs ss init_fs,
   811           mk_mor car_inits str_inits Bs ss init_fs_copy];
   811           mk_mor car_inits str_inits Bs ss init_fs_copy];
   812         fun mk_fun_eq f g x = HOLogic.mk_eq (f $ x, g $ x);
   812         fun mk_fun_eq f g x = HOLogic.mk_eq (f $ x, g $ x);
   813         val unique = HOLogic.mk_Trueprop
   813         val unique = HOLogic.mk_Trueprop
   814           (Library.foldr1 HOLogic.mk_conj (@{map 3} mk_fun_eq init_fs init_fs_copy init_xs));
   814           (Library.foldr1 HOLogic.mk_conj (@{map 3} mk_fun_eq init_fs init_fs_copy init_xs));
   815         val cts = map (certify lthy) ss;
   815         val cts = map (Proof_Context.cterm_of lthy) ss;
   816         val unique_mor =
   816         val unique_mor =
   817           Goal.prove_sorry lthy [] [] (Logic.list_implies (prems @ mor_prems, unique))
   817           Goal.prove_sorry lthy [] [] (Logic.list_implies (prems @ mor_prems, unique))
   818             (K (mk_init_unique_mor_tac cts m alg_def alg_init_thm least_min_alg_thms
   818             (K (mk_init_unique_mor_tac cts m alg_def alg_init_thm least_min_alg_thms
   819               in_mono'_thms alg_set_thms morE_thms map_cong0s))
   819               in_mono'_thms alg_set_thms morE_thms map_cong0s))
   820           |> Thm.close_derivation
   820           |> Thm.close_derivation
   944             (fn {context = ctxt, prems = _} => mk_mor_Rep_tac ctxt m defs Reps Abs_inverses
   944             (fn {context = ctxt, prems = _} => mk_mor_Rep_tac ctxt m defs Reps Abs_inverses
   945               alg_min_alg_thm alg_set_thms set_mapss)
   945               alg_min_alg_thm alg_set_thms set_mapss)
   946           |> Thm.close_derivation;
   946           |> Thm.close_derivation;
   947 
   947 
   948         fun mk_ct initFT str abs = Term.absdummy initFT (abs $ (str $ Bound 0))
   948         fun mk_ct initFT str abs = Term.absdummy initFT (abs $ (str $ Bound 0))
   949         val cts = @{map 3} (certify lthy ooo mk_ct) init_FTs str_inits Abs_Ts;
   949         val cts = @{map 3} (Proof_Context.cterm_of lthy ooo mk_ct) init_FTs str_inits Abs_Ts;
   950 
   950 
   951         val mor_Abs =
   951         val mor_Abs =
   952           Goal.prove_sorry lthy [] []
   952           Goal.prove_sorry lthy [] []
   953             (HOLogic.mk_Trueprop (mk_mor car_inits str_inits UNIVs ctors Abs_Ts))
   953             (HOLogic.mk_Trueprop (mk_mor car_inits str_inits UNIVs ctors Abs_Ts))
   954             (fn {context = ctxt, prems = _} => mk_mor_Abs_tac ctxt cts defs Abs_inverses
   954             (fn {context = ctxt, prems = _} => mk_mor_Abs_tac ctxt cts defs Abs_inverses
  1018       end;
  1018       end;
  1019 
  1019 
  1020     val mor_fold_thm =
  1020     val mor_fold_thm =
  1021       let
  1021       let
  1022         val mor_cong = mor_cong_thm OF (map (mk_nth_conv n) ks);
  1022         val mor_cong = mor_cong_thm OF (map (mk_nth_conv n) ks);
  1023         val cT = certifyT lthy foldT;
  1023         val cT = Proof_Context.ctyp_of lthy foldT;
  1024         val ct = certify lthy fold_fun
  1024         val ct = Proof_Context.cterm_of lthy fold_fun
  1025       in
  1025       in
  1026         Goal.prove_sorry lthy [] []
  1026         Goal.prove_sorry lthy [] []
  1027           (HOLogic.mk_Trueprop (mk_mor UNIVs ctors active_UNIVs ss (map (mk_fold Ts ss) ks)))
  1027           (HOLogic.mk_Trueprop (mk_mor UNIVs ctors active_UNIVs ss (map (mk_fold Ts ss) ks)))
  1028           (fn {context = ctxt, ...} =>
  1028           (fn {context = ctxt, ...} =>
  1029             mk_mor_fold_tac ctxt cT ct fold_defs init_ex_mor_thm mor_cong)
  1029             mk_mor_fold_tac ctxt cT ct fold_defs init_ex_mor_thm mor_cong)
  1242         |> Thm.close_derivation
  1242         |> Thm.close_derivation
  1243         |> singleton (Proof_Context.export names_lthy lthy),
  1243         |> singleton (Proof_Context.export names_lthy lthy),
  1244         rev (Term.add_tfrees goal []))
  1244         rev (Term.add_tfrees goal []))
  1245       end;
  1245       end;
  1246 
  1246 
  1247     val cTs = map (SOME o certifyT lthy o TFree) induct_params;
  1247     val cTs = map (SOME o Proof_Context.ctyp_of lthy o TFree) induct_params;
  1248 
  1248 
  1249     val weak_ctor_induct_thms =
  1249     val weak_ctor_induct_thms =
  1250       let fun insts i = (replicate (i - 1) TrueI) @ (asm_rl :: replicate (n - i) TrueI);
  1250       let fun insts i = (replicate (i - 1) TrueI) @ (asm_rl :: replicate (n - i) TrueI);
  1251       in map (fn i => (ctor_induct_thm OF insts i) RS mk_conjunctN n i) ks end;
  1251       in map (fn i => (ctor_induct_thm OF insts i) RS mk_conjunctN n i) ks end;
  1252 
  1252 
  1274         fun mk_concl phi z1 z2 = phi $ z1 $ z2;
  1274         fun mk_concl phi z1 z2 = phi $ z1 $ z2;
  1275         val concl = HOLogic.mk_Trueprop (Library.foldr1 HOLogic.mk_conj
  1275         val concl = HOLogic.mk_Trueprop (Library.foldr1 HOLogic.mk_conj
  1276           (@{map 3} mk_concl phi2s Izs1 Izs2));
  1276           (@{map 3} mk_concl phi2s Izs1 Izs2));
  1277         fun mk_t phi (z1, z1') (z2, z2') =
  1277         fun mk_t phi (z1, z1') (z2, z2') =
  1278           Term.absfree z1' (HOLogic.mk_all (fst z2', snd z2', phi $ z1 $ z2));
  1278           Term.absfree z1' (HOLogic.mk_all (fst z2', snd z2', phi $ z1 $ z2));
  1279         val cts = @{map 3} (SOME o certify lthy ooo mk_t) phi2s (Izs1 ~~ Izs1') (Izs2 ~~ Izs2');
  1279         val cts = @{map 3} (SOME o Proof_Context.cterm_of lthy ooo mk_t) phi2s (Izs1 ~~ Izs1') (Izs2 ~~ Izs2');
  1280         val goal = Logic.list_implies (prems, concl);
  1280         val goal = Logic.list_implies (prems, concl);
  1281       in
  1281       in
  1282         (Goal.prove_sorry lthy [] [] goal
  1282         (Goal.prove_sorry lthy [] [] goal
  1283           (fn {context = ctxt, prems = _} => mk_ctor_induct2_tac ctxt cTs cts ctor_induct_thm
  1283           (fn {context = ctxt, prems = _} => mk_ctor_induct2_tac ctxt cTs cts ctor_induct_thm
  1284             weak_ctor_induct_thms)
  1284             weak_ctor_induct_thms)
  1550             (1 upto n);
  1550             (1 upto n);
  1551         val set_Iset_thmsss = transpose (map (map mk_set_thms) ctor_Iset_thmss);
  1551         val set_Iset_thmsss = transpose (map (map mk_set_thms) ctor_Iset_thmss);
  1552 
  1552 
  1553         val timer = time (timer "set functions for the new datatypes");
  1553         val timer = time (timer "set functions for the new datatypes");
  1554 
  1554 
  1555         val cxs = map (SOME o certify lthy) Izs;
  1555         val cxs = map (SOME o Proof_Context.cterm_of lthy) Izs;
  1556         val Isetss_by_range' =
  1556         val Isetss_by_range' =
  1557           map (map (Term.subst_atomic_types (passiveAs ~~ passiveBs))) Isetss_by_range;
  1557           map (map (Term.subst_atomic_types (passiveAs ~~ passiveBs))) Isetss_by_range;
  1558 
  1558 
  1559         val Iset_Imap0_thmss =
  1559         val Iset_Imap0_thmss =
  1560           let
  1560           let
  1561             fun mk_set_map0 f map z set set' =
  1561             fun mk_set_map0 f map z set set' =
  1562               HOLogic.mk_eq (mk_image f $ (set $ z), set' $ (map $ z));
  1562               HOLogic.mk_eq (mk_image f $ (set $ z), set' $ (map $ z));
  1563 
  1563 
  1564             fun mk_cphi f map z set set' = certify lthy
  1564             fun mk_cphi f map z set set' = Proof_Context.cterm_of lthy
  1565               (Term.absfree (dest_Free z) (mk_set_map0 f map z set set'));
  1565               (Term.absfree (dest_Free z) (mk_set_map0 f map z set set'));
  1566 
  1566 
  1567             val csetss = map (map (certify lthy)) Isetss_by_range';
  1567             val csetss = map (map (Proof_Context.cterm_of lthy)) Isetss_by_range';
  1568 
  1568 
  1569             val cphiss = @{map 3} (fn f => fn sets => fn sets' =>
  1569             val cphiss = @{map 3} (fn f => fn sets => fn sets' =>
  1570               (@{map 4} (mk_cphi f) fs_Imaps Izs sets sets')) fs Isetss_by_range Isetss_by_range';
  1570               (@{map 4} (mk_cphi f) fs_Imaps Izs sets sets')) fs Isetss_by_range Isetss_by_range';
  1571 
  1571 
  1572             val inducts = map (fn cphis =>
  1572             val inducts = map (fn cphis =>
  1592 
  1592 
  1593         val Iset_bd_thmss =
  1593         val Iset_bd_thmss =
  1594           let
  1594           let
  1595             fun mk_set_bd z bd set = mk_ordLeq (mk_card_of (set $ z)) bd;
  1595             fun mk_set_bd z bd set = mk_ordLeq (mk_card_of (set $ z)) bd;
  1596 
  1596 
  1597             fun mk_cphi z set = certify lthy (Term.absfree (dest_Free z) (mk_set_bd z sbd0 set));
  1597             fun mk_cphi z set = Proof_Context.cterm_of lthy (Term.absfree (dest_Free z) (mk_set_bd z sbd0 set));
  1598 
  1598 
  1599             val cphiss = map (map2 mk_cphi Izs) Isetss_by_range;
  1599             val cphiss = map (map2 mk_cphi Izs) Isetss_by_range;
  1600 
  1600 
  1601             val inducts = map (fn cphis =>
  1601             val inducts = map (fn cphis =>
  1602               Drule.instantiate' cTs (map SOME cphis @ cxs) ctor_induct_thm) cphiss;
  1602               Drule.instantiate' cTs (map SOME cphis @ cxs) ctor_induct_thm) cphiss;
  1628               HOLogic.mk_imp
  1628               HOLogic.mk_imp
  1629                 (Library.foldr1 HOLogic.mk_conj (@{map 5} (mk_prem z) sets fs fs_copy ys ys'),
  1629                 (Library.foldr1 HOLogic.mk_conj (@{map 5} (mk_prem z) sets fs fs_copy ys ys'),
  1630                 HOLogic.mk_eq (fmap $ z, gmap $ z));
  1630                 HOLogic.mk_eq (fmap $ z, gmap $ z));
  1631 
  1631 
  1632             fun mk_cphi sets z fmap gmap =
  1632             fun mk_cphi sets z fmap gmap =
  1633               certify lthy (Term.absfree (dest_Free z) (mk_map_cong0 sets z fmap gmap));
  1633               Proof_Context.cterm_of lthy (Term.absfree (dest_Free z) (mk_map_cong0 sets z fmap gmap));
  1634 
  1634 
  1635             val cphis = @{map 4} mk_cphi Isetss_by_bnf Izs fs_Imaps fs_copy_Imaps;
  1635             val cphis = @{map 4} mk_cphi Isetss_by_bnf Izs fs_Imaps fs_copy_Imaps;
  1636 
  1636 
  1637             val induct = Drule.instantiate' cTs (map SOME cphis @ cxs) ctor_induct_thm;
  1637             val induct = Drule.instantiate' cTs (map SOME cphis @ cxs) ctor_induct_thm;
  1638 
  1638 
  1689             fun mk_le_Irel_OO Irelpsi1 Irelpsi2 Irelpsi12 Iz1 Iz2 =
  1689             fun mk_le_Irel_OO Irelpsi1 Irelpsi2 Irelpsi12 Iz1 Iz2 =
  1690               HOLogic.mk_imp (mk_rel_compp (Irelpsi1, Irelpsi2) $ Iz1 $ Iz2,
  1690               HOLogic.mk_imp (mk_rel_compp (Irelpsi1, Irelpsi2) $ Iz1 $ Iz2,
  1691                 Irelpsi12 $ Iz1 $ Iz2);
  1691                 Irelpsi12 $ Iz1 $ Iz2);
  1692             val goals = @{map 5} mk_le_Irel_OO Irelpsi1s Irelpsi2s Irelpsi12s Izs1 Izs2;
  1692             val goals = @{map 5} mk_le_Irel_OO Irelpsi1s Irelpsi2s Irelpsi12s Izs1 Izs2;
  1693 
  1693 
  1694             val cTs = map (SOME o certifyT lthy o TFree) induct2_params;
  1694             val cTs = map (SOME o Proof_Context.ctyp_of lthy o TFree) induct2_params;
  1695             val cxs = map (SOME o certify lthy) (splice Izs1 Izs2);
  1695             val cxs = map (SOME o Proof_Context.cterm_of lthy) (splice Izs1 Izs2);
  1696             fun mk_cphi z1 z2 goal = SOME (certify lthy (Term.absfree z1 (Term.absfree z2 goal)));
  1696             fun mk_cphi z1 z2 goal = SOME (Proof_Context.cterm_of lthy (Term.absfree z1 (Term.absfree z2 goal)));
  1697             val cphis = @{map 3} mk_cphi Izs1' Izs2' goals;
  1697             val cphis = @{map 3} mk_cphi Izs1' Izs2' goals;
  1698             val induct = Drule.instantiate' cTs (cphis @ cxs) ctor_induct2_thm;
  1698             val induct = Drule.instantiate' cTs (cphis @ cxs) ctor_induct2_thm;
  1699 
  1699 
  1700             val goal = HOLogic.mk_Trueprop (Library.foldr1 HOLogic.mk_conj goals);
  1700             val goal = HOLogic.mk_Trueprop (Library.foldr1 HOLogic.mk_conj goals);
  1701           in
  1701           in