src/HOL/Tools/BNF/bnf_gfp.ML
changeset 67710 cc2db3239932
parent 67405 e9ab4ad7bd15
child 69593 3dda49e08b9d
equal deleted inserted replaced
67709:3c9e0b4709e7 67710:cc2db3239932
   280       |> Local_Theory.define ((coalg_bind, NoSyn), (coalg_def_bind, coalg_spec))
   280       |> Local_Theory.define ((coalg_bind, NoSyn), (coalg_def_bind, coalg_spec))
   281       ||> `Local_Theory.close_target;
   281       ||> `Local_Theory.close_target;
   282 
   282 
   283     val phi = Proof_Context.export_morphism lthy_old lthy;
   283     val phi = Proof_Context.export_morphism lthy_old lthy;
   284     val coalg = fst (Term.dest_Const (Morphism.term phi coalg_free));
   284     val coalg = fst (Term.dest_Const (Morphism.term phi coalg_free));
   285     val coalg_def = mk_unabs_def (2 * n) (Morphism.thm phi coalg_def_free RS meta_eq_to_obj_eq);
   285     val coalg_def = mk_unabs_def (2 * n) (HOLogic.mk_obj_eq (Morphism.thm phi coalg_def_free));
   286 
   286 
   287     fun mk_coalg Bs ss =
   287     fun mk_coalg Bs ss =
   288       let
   288       let
   289         val args = Bs @ ss;
   289         val args = Bs @ ss;
   290         val Ts = map fastype_of args;
   290         val Ts = map fastype_of args;
   369       |> Local_Theory.define ((mor_bind, NoSyn), (mor_def_bind, mor_spec))
   369       |> Local_Theory.define ((mor_bind, NoSyn), (mor_def_bind, mor_spec))
   370       ||> `Local_Theory.close_target;
   370       ||> `Local_Theory.close_target;
   371 
   371 
   372     val phi = Proof_Context.export_morphism lthy_old lthy;
   372     val phi = Proof_Context.export_morphism lthy_old lthy;
   373     val mor = fst (Term.dest_Const (Morphism.term phi mor_free));
   373     val mor = fst (Term.dest_Const (Morphism.term phi mor_free));
   374     val mor_def = mk_unabs_def (5 * n) (Morphism.thm phi mor_def_free RS meta_eq_to_obj_eq);
   374     val mor_def = mk_unabs_def (5 * n) (HOLogic.mk_obj_eq (Morphism.thm phi mor_def_free));
   375 
   375 
   376     fun mk_mor Bs1 ss1 Bs2 ss2 fs =
   376     fun mk_mor Bs1 ss1 Bs2 ss2 fs =
   377       let
   377       let
   378         val args = Bs1 @ ss1 @ Bs2 @ ss2 @ fs;
   378         val args = Bs1 @ ss1 @ Bs2 @ ss2 @ fs;
   379         val Ts = map fastype_of (Bs1 @ ss1 @ Bs2 @ ss2 @ fs);
   379         val Ts = map fastype_of (Bs1 @ ss1 @ Bs2 @ ss2 @ fs);
   524       |> Local_Theory.define ((bis_bind, NoSyn), (bis_def_bind, bis_spec))
   524       |> Local_Theory.define ((bis_bind, NoSyn), (bis_def_bind, bis_spec))
   525       ||> `Local_Theory.close_target;
   525       ||> `Local_Theory.close_target;
   526 
   526 
   527     val phi = Proof_Context.export_morphism lthy_old lthy;
   527     val phi = Proof_Context.export_morphism lthy_old lthy;
   528     val bis = fst (Term.dest_Const (Morphism.term phi bis_free));
   528     val bis = fst (Term.dest_Const (Morphism.term phi bis_free));
   529     val bis_def = mk_unabs_def (5 * n) (Morphism.thm phi bis_def_free RS meta_eq_to_obj_eq);
   529     val bis_def = mk_unabs_def (5 * n) (HOLogic.mk_obj_eq (Morphism.thm phi bis_def_free));
   530 
   530 
   531     fun mk_bis Bs1 ss1 Bs2 ss2 Rs =
   531     fun mk_bis Bs1 ss1 Bs2 ss2 Rs =
   532       let
   532       let
   533         val args = Bs1 @ ss1 @ Bs2 @ ss2 @ Rs;
   533         val args = Bs1 @ ss1 @ Bs2 @ ss2 @ Rs;
   534         val Ts = map fastype_of args;
   534         val Ts = map fastype_of args;
   673       ||> `Local_Theory.close_target;
   673       ||> `Local_Theory.close_target;
   674 
   674 
   675     val phi = Proof_Context.export_morphism lthy_old lthy;
   675     val phi = Proof_Context.export_morphism lthy_old lthy;
   676 
   676 
   677     val lsbis_defs = map (fn def =>
   677     val lsbis_defs = map (fn def =>
   678       mk_unabs_def (2 * n) (Morphism.thm phi def RS meta_eq_to_obj_eq)) lsbis_def_frees;
   678       mk_unabs_def (2 * n) (HOLogic.mk_obj_eq (Morphism.thm phi def))) lsbis_def_frees;
   679     val lsbiss = map (fst o Term.dest_Const o Morphism.term phi) lsbis_frees;
   679     val lsbiss = map (fst o Term.dest_Const o Morphism.term phi) lsbis_frees;
   680 
   680 
   681     fun mk_lsbis Bs ss i =
   681     fun mk_lsbis Bs ss i =
   682       let
   682       let
   683         val args = Bs @ ss;
   683         val args = Bs @ ss;
   772             |> Local_Theory.define ((sbd_bind, NoSyn), (sbd_def_bind, sbd_spec))
   772             |> Local_Theory.define ((sbd_bind, NoSyn), (sbd_def_bind, sbd_spec))
   773             ||> `Local_Theory.close_target;
   773             ||> `Local_Theory.close_target;
   774 
   774 
   775           val phi = Proof_Context.export_morphism lthy_old lthy;
   775           val phi = Proof_Context.export_morphism lthy_old lthy;
   776 
   776 
   777           val sbd_def = Morphism.thm phi sbd_def_free RS meta_eq_to_obj_eq;
   777           val sbd_def = HOLogic.mk_obj_eq (Morphism.thm phi sbd_def_free);
   778           val sbd = Const (fst (Term.dest_Const (Morphism.term phi sbd_free)), mk_relT (`I sbdT));
   778           val sbd = Const (fst (Term.dest_Const (Morphism.term phi sbd_free)), mk_relT (`I sbdT));
   779 
   779 
   780           val Abs_sbdT_inj = mk_Abs_inj_thm (#Abs_inject sbdT_loc_info);
   780           val Abs_sbdT_inj = mk_Abs_inj_thm (#Abs_inject sbdT_loc_info);
   781           val Abs_sbdT_bij = mk_Abs_bij_thm lthy Abs_sbdT_inj (#Abs_cases sbdT_loc_info);
   781           val Abs_sbdT_bij = mk_Abs_bij_thm lthy Abs_sbdT_inj (#Abs_cases sbdT_loc_info);
   782 
   782 
   880       ||> `Local_Theory.close_target;
   880       ||> `Local_Theory.close_target;
   881 
   881 
   882     val phi = Proof_Context.export_morphism lthy_old lthy;
   882     val phi = Proof_Context.export_morphism lthy_old lthy;
   883 
   883 
   884     val isNode_defs = map (fn def =>
   884     val isNode_defs = map (fn def =>
   885       mk_unabs_def 3 (Morphism.thm phi def RS meta_eq_to_obj_eq)) isNode_def_frees;
   885       mk_unabs_def 3 (HOLogic.mk_obj_eq (Morphism.thm phi def))) isNode_def_frees;
   886     val isNodes = map (fst o Term.dest_Const o Morphism.term phi) isNode_frees;
   886     val isNodes = map (fst o Term.dest_Const o Morphism.term phi) isNode_frees;
   887 
   887 
   888     fun mk_isNode kl i =
   888     fun mk_isNode kl i =
   889       Term.list_comb (Const (nth isNodes (i - 1), isNodeT), [Kl, lab, kl]);
   889       Term.list_comb (Const (nth isNodes (i - 1), isNodeT), [Kl, lab, kl]);
   890 
   890 
   918       |>> apsnd split_list o split_list
   918       |>> apsnd split_list o split_list
   919       ||> `Local_Theory.close_target;
   919       ||> `Local_Theory.close_target;
   920 
   920 
   921     val phi = Proof_Context.export_morphism lthy_old lthy;
   921     val phi = Proof_Context.export_morphism lthy_old lthy;
   922 
   922 
   923     val carT_defs = map (fn def => Morphism.thm phi def RS meta_eq_to_obj_eq) carT_def_frees;
   923     val carT_defs = map (fn def => HOLogic.mk_obj_eq (Morphism.thm phi def)) carT_def_frees;
   924     val carTs = map (fst o Term.dest_Const o Morphism.term phi) carT_frees;
   924     val carTs = map (fst o Term.dest_Const o Morphism.term phi) carT_frees;
   925 
   925 
   926     fun mk_carT i = Const (nth carTs (i - 1), HOLogic.mk_setT treeT);
   926     fun mk_carT i = Const (nth carTs (i - 1), HOLogic.mk_setT treeT);
   927 
   927 
   928     val strT_binds = mk_internal_bs strTN;
   928     val strT_binds = mk_internal_bs strTN;
   953       ||> `Local_Theory.close_target;
   953       ||> `Local_Theory.close_target;
   954 
   954 
   955     val phi = Proof_Context.export_morphism lthy_old lthy;
   955     val phi = Proof_Context.export_morphism lthy_old lthy;
   956 
   956 
   957     val strT_defs = map (fn def =>
   957     val strT_defs = map (fn def =>
   958         trans OF [Morphism.thm phi def RS meta_eq_to_obj_eq RS fun_cong, @{thm prod.case}])
   958         trans OF [HOLogic.mk_obj_eq (Morphism.thm phi def) RS fun_cong, @{thm prod.case}])
   959       strT_def_frees;
   959       strT_def_frees;
   960     val strTs = map (fst o Term.dest_Const o Morphism.term phi) strT_frees;
   960     val strTs = map (fst o Term.dest_Const o Morphism.term phi) strT_frees;
   961 
   961 
   962     fun mk_strT FT i = Const (nth strTs (i - 1), treeT --> FT);
   962     fun mk_strT FT i = Const (nth strTs (i - 1), treeT --> FT);
   963 
   963 
  1019       |> Local_Theory.define ((Lev_bind, NoSyn), (Lev_def_bind, Lev_spec))
  1019       |> Local_Theory.define ((Lev_bind, NoSyn), (Lev_def_bind, Lev_spec))
  1020       ||> `Local_Theory.close_target;
  1020       ||> `Local_Theory.close_target;
  1021 
  1021 
  1022     val phi = Proof_Context.export_morphism lthy_old lthy;
  1022     val phi = Proof_Context.export_morphism lthy_old lthy;
  1023 
  1023 
  1024     val Lev_def = mk_unabs_def n (Morphism.thm phi Lev_def_free RS meta_eq_to_obj_eq);
  1024     val Lev_def = mk_unabs_def n (HOLogic.mk_obj_eq (Morphism.thm phi Lev_def_free));
  1025     val Lev = fst (Term.dest_Const (Morphism.term phi Lev_free));
  1025     val Lev = fst (Term.dest_Const (Morphism.term phi Lev_free));
  1026 
  1026 
  1027     fun mk_Lev ss nat i =
  1027     fun mk_Lev ss nat i =
  1028       let
  1028       let
  1029         val Ts = map fastype_of ss;
  1029         val Ts = map fastype_of ss;
  1063       |> Local_Theory.define ((rv_bind, NoSyn), (rv_def_bind, rv_spec))
  1063       |> Local_Theory.define ((rv_bind, NoSyn), (rv_def_bind, rv_spec))
  1064       ||> `Local_Theory.close_target;
  1064       ||> `Local_Theory.close_target;
  1065 
  1065 
  1066     val phi = Proof_Context.export_morphism lthy_old lthy;
  1066     val phi = Proof_Context.export_morphism lthy_old lthy;
  1067 
  1067 
  1068     val rv_def = mk_unabs_def n (Morphism.thm phi rv_def_free RS meta_eq_to_obj_eq);
  1068     val rv_def = mk_unabs_def n (HOLogic.mk_obj_eq (Morphism.thm phi rv_def_free));
  1069     val rv = fst (Term.dest_Const (Morphism.term phi rv_free));
  1069     val rv = fst (Term.dest_Const (Morphism.term phi rv_free));
  1070 
  1070 
  1071     fun mk_rv ss kl i =
  1071     fun mk_rv ss kl i =
  1072       let
  1072       let
  1073         val Ts = map fastype_of ss;
  1073         val Ts = map fastype_of ss;
  1109       ||> `Local_Theory.close_target;
  1109       ||> `Local_Theory.close_target;
  1110 
  1110 
  1111     val phi = Proof_Context.export_morphism lthy_old lthy;
  1111     val phi = Proof_Context.export_morphism lthy_old lthy;
  1112 
  1112 
  1113     val beh_defs = map (fn def =>
  1113     val beh_defs = map (fn def =>
  1114       mk_unabs_def (n + 1) (Morphism.thm phi def RS meta_eq_to_obj_eq)) beh_def_frees;
  1114       mk_unabs_def (n + 1) (HOLogic.mk_obj_eq (Morphism.thm phi def))) beh_def_frees;
  1115     val behs = map (fst o Term.dest_Const o Morphism.term phi) beh_frees;
  1115     val behs = map (fst o Term.dest_Const o Morphism.term phi) beh_frees;
  1116 
  1116 
  1117     fun mk_beh ss i =
  1117     fun mk_beh ss i =
  1118       let
  1118       let
  1119         val Ts = map fastype_of ss;
  1119         val Ts = map fastype_of ss;
  1391     fun mk_dtors passive =
  1391     fun mk_dtors passive =
  1392       map (Term.subst_atomic_types (map (Morphism.typ phi) params' ~~ (mk_params passive)) o
  1392       map (Term.subst_atomic_types (map (Morphism.typ phi) params' ~~ (mk_params passive)) o
  1393         Morphism.term phi) dtor_frees;
  1393         Morphism.term phi) dtor_frees;
  1394     val dtors = mk_dtors passiveAs;
  1394     val dtors = mk_dtors passiveAs;
  1395     val dtor's = mk_dtors passiveBs;
  1395     val dtor's = mk_dtors passiveBs;
  1396     val dtor_defs = map (fn def =>
  1396     val dtor_defs =
  1397       Morphism.thm phi def RS meta_eq_to_obj_eq RS fun_cong) dtor_def_frees;
  1397       map (fn def => HOLogic.mk_obj_eq (Morphism.thm phi def) RS fun_cong) dtor_def_frees;
  1398 
  1398 
  1399     val coalg_final_set_thmss = map (map (fn thm => coalg_final_thm RS thm)) coalg_set_thmss;
  1399     val coalg_final_set_thmss = map (map (fn thm => coalg_final_thm RS thm)) coalg_set_thmss;
  1400     val (mor_Rep_thm, mor_Abs_thm) =
  1400     val (mor_Rep_thm, mor_Abs_thm) =
  1401       let
  1401       let
  1402         val mor_Rep =
  1402         val mor_Rep =
  1442           (map2 (curry op -->) actives (mk_FTs (passives @ actives)), active --> T)))
  1442           (map2 (curry op -->) actives (mk_FTs (passives @ actives)), active --> T)))
  1443       unfold_names (mk_Ts passives) actives;
  1443       unfold_names (mk_Ts passives) actives;
  1444     fun mk_unfold Ts ss i = Term.list_comb (Const (nth unfold_names (i - 1), Library.foldr (op -->)
  1444     fun mk_unfold Ts ss i = Term.list_comb (Const (nth unfold_names (i - 1), Library.foldr (op -->)
  1445       (map fastype_of ss, domain_type (fastype_of (nth ss (i - 1))) --> nth Ts (i - 1))), ss);
  1445       (map fastype_of ss, domain_type (fastype_of (nth ss (i - 1))) --> nth Ts (i - 1))), ss);
  1446     val unfold_defs = map (fn def =>
  1446     val unfold_defs = map (fn def =>
  1447       mk_unabs_def (n + 1) (Morphism.thm phi def RS meta_eq_to_obj_eq)) unfold_def_frees;
  1447       mk_unabs_def (n + 1) (HOLogic.mk_obj_eq (Morphism.thm phi def))) unfold_def_frees;
  1448 
  1448 
  1449     val (((ss, TRs), unfold_fs), _) =
  1449     val (((ss, TRs), unfold_fs), _) =
  1450       lthy
  1450       lthy
  1451       |> mk_Frees "s" sTs
  1451       |> mk_Frees "s" sTs
  1452       ||>> mk_Frees "r" (map (mk_relT o `I) Ts)
  1452       ||>> mk_Frees "r" (map (mk_relT o `I) Ts)
  1534     val phi = Proof_Context.export_morphism lthy_old lthy;
  1534     val phi = Proof_Context.export_morphism lthy_old lthy;
  1535     fun mk_ctors params =
  1535     fun mk_ctors params =
  1536       map (Term.subst_atomic_types (map (Morphism.typ phi) params' ~~ params) o Morphism.term phi)
  1536       map (Term.subst_atomic_types (map (Morphism.typ phi) params' ~~ params) o Morphism.term phi)
  1537         ctor_frees;
  1537         ctor_frees;
  1538     val ctors = mk_ctors params';
  1538     val ctors = mk_ctors params';
  1539     val ctor_defs = map (fn def => Morphism.thm phi def RS meta_eq_to_obj_eq) ctor_def_frees;
  1539     val ctor_defs = map (fn def => HOLogic.mk_obj_eq (Morphism.thm phi def)) ctor_def_frees;
  1540 
  1540 
  1541     val ctor_o_dtor_thms = map2 (Local_Defs.fold lthy o single) ctor_defs unfold_o_dtor_thms;
  1541     val ctor_o_dtor_thms = map2 (Local_Defs.fold lthy o single) ctor_defs unfold_o_dtor_thms;
  1542 
  1542 
  1543     val dtor_o_ctor_thms =
  1543     val dtor_o_ctor_thms =
  1544       let
  1544       let
  1738           |>> apsnd split_list o split_list
  1738           |>> apsnd split_list o split_list
  1739           ||> `Local_Theory.close_target;
  1739           ||> `Local_Theory.close_target;
  1740 
  1740 
  1741         val phi = Proof_Context.export_morphism lthy_old lthy;
  1741         val phi = Proof_Context.export_morphism lthy_old lthy;
  1742 
  1742 
  1743         val col_defs = map (fn def => Morphism.thm phi def RS meta_eq_to_obj_eq) col_def_frees;
  1743         val col_defs = map (fn def => HOLogic.mk_obj_eq (Morphism.thm phi def)) col_def_frees;
  1744         val cols = map (fst o Term.dest_Const o Morphism.term phi) col_frees;
  1744         val cols = map (fst o Term.dest_Const o Morphism.term phi) col_frees;
  1745 
  1745 
  1746         fun mk_col Ts nat i j T =
  1746         fun mk_col Ts nat i j T =
  1747           let
  1747           let
  1748             val hrecT = HOLogic.mk_tupleT (map (fn U => U --> HOLogic.mk_setT T) Ts)
  1748             val hrecT = HOLogic.mk_tupleT (map (fn U => U --> HOLogic.mk_setT T) Ts)
  1776         val (Jmap_defs, Jset_defss, Jbd_defs, _, Jrel_defs, Jpred_defs) =
  1776         val (Jmap_defs, Jset_defss, Jbd_defs, _, Jrel_defs, Jpred_defs) =
  1777           @{split_list 6} Jconst_defs;
  1777           @{split_list 6} Jconst_defs;
  1778         val (mk_Jmaps_Ds, mk_Jt_Ds, _, mk_Jrels_Ds, mk_Jpreds_Ds, _, _) =
  1778         val (mk_Jmaps_Ds, mk_Jt_Ds, _, mk_Jrels_Ds, mk_Jpreds_Ds, _, _) =
  1779           @{split_list 7} mk_Jconsts;
  1779           @{split_list 7} mk_Jconsts;
  1780 
  1780 
  1781         val Jrel_unabs_defs = map (fn def => mk_unabs_def m (def RS meta_eq_to_obj_eq)) Jrel_defs;
  1781         val Jrel_unabs_defs = map (fn def => mk_unabs_def m (HOLogic.mk_obj_eq def)) Jrel_defs;
  1782         val Jpred_unabs_defs = map (fn def => mk_unabs_def m (def RS meta_eq_to_obj_eq)) Jpred_defs;
  1782         val Jpred_unabs_defs = map (fn def => mk_unabs_def m (HOLogic.mk_obj_eq def)) Jpred_defs;
  1783         val Jset_defs = flat Jset_defss;
  1783         val Jset_defs = flat Jset_defss;
  1784 
  1784 
  1785         fun mk_Jmaps As Bs = map (fn mk => mk deads As Bs) mk_Jmaps_Ds;
  1785         fun mk_Jmaps As Bs = map (fn mk => mk deads As Bs) mk_Jmaps_Ds;
  1786         fun mk_Jsetss As = map2 (fn mk => fn Jsets => map (mk deads As) Jsets) mk_Jt_Ds Jsetss;
  1786         fun mk_Jsetss As = map2 (fn mk => fn Jsets => map (mk deads As) Jsets) mk_Jt_Ds Jsetss;
  1787         val Jbds = map2 (fn mk => mk deads passiveAs) mk_Jt_Ds Jbds_Ds;
  1787         val Jbds = map2 (fn mk => mk deads passiveAs) mk_Jt_Ds Jbds_Ds;