src/HOL/BNF/Tools/bnf_fp_def_sugar.ML
changeset 52338 8bf544733e0e
parent 52337 9691b0e9bb66
child 52339 844b1c8e3d9e
equal deleted inserted replaced
52337:9691b0e9bb66 52338:8bf544733e0e
   134 
   134 
   135 fun register_fp_sugar key fp_sugar =
   135 fun register_fp_sugar key fp_sugar =
   136   Local_Theory.declaration {syntax = false, pervasive = true}
   136   Local_Theory.declaration {syntax = false, pervasive = true}
   137     (fn phi => Data.map (Symtab.update_new (key, morph_fp_sugar phi fp_sugar)));
   137     (fn phi => Data.map (Symtab.update_new (key, morph_fp_sugar phi fp_sugar)));
   138 
   138 
   139 fun register_fp_sugars fp pre_bnfs (fp_res as {Ts, ...}) ctr_defss ctr_sugars co_iterss'
   139 fun register_fp_sugars fp pre_bnfs (fp_res as {Ts, ...}) ctr_defss ctr_sugars co_iterss co_induct
   140     co_induct strong_co_induct co_iter_thmsss lthy =
   140     strong_co_induct co_iter_thmsss lthy =
   141   (0, lthy)
   141   (0, lthy)
   142   |> fold (fn T as Type (s, _) => fn (kk, lthy) => (kk + 1,
   142   |> fold (fn T as Type (s, _) => fn (kk, lthy) => (kk + 1,
   143     register_fp_sugar s {T = T, fp = fp, index = kk, pre_bnfs = pre_bnfs, fp_res = fp_res,
   143     register_fp_sugar s {T = T, fp = fp, index = kk, pre_bnfs = pre_bnfs, fp_res = fp_res,
   144         ctr_defss = ctr_defss, ctr_sugars = ctr_sugars, co_iterss = transpose co_iterss',
   144         ctr_defss = ctr_defss, ctr_sugars = ctr_sugars, co_iterss = co_iterss,
   145         co_induct = co_induct, strong_co_induct = strong_co_induct, co_iter_thmsss = co_iter_thmsss}
   145         co_induct = co_induct, strong_co_induct = strong_co_induct, co_iter_thmsss = co_iter_thmsss}
   146       lthy)) Ts
   146       lthy)) Ts
   147   |> snd;
   147   |> snd;
   148 
   148 
   149 (* This function could produce clashes in contrived examples (e.g., "x.A", "x.x_A", "y.A"). *)
   149 (* This function could produce clashes in contrived examples (e.g., "x.A", "x.x_A", "y.A"). *)
   673      (fold_thmss, code_simp_attrs), (rec_thmss, code_simp_attrs))
   673      (fold_thmss, code_simp_attrs), (rec_thmss, code_simp_attrs))
   674   end;
   674   end;
   675 
   675 
   676 fun derive_coinduct_coiters_thms_for_types pre_bnfs (dtor_coiters1 :: _) dtor_coinduct
   676 fun derive_coinduct_coiters_thms_for_types pre_bnfs (dtor_coiters1 :: _) dtor_coinduct
   677     dtor_strong_induct dtor_ctors [dtor_unfold_thms, dtor_corec_thms] nesting_bnfs nested_bnfs fpTs
   677     dtor_strong_induct dtor_ctors [dtor_unfold_thms, dtor_corec_thms] nesting_bnfs nested_bnfs fpTs
   678     Cs As kss mss ns ctr_defss ctr_sugars [unfolds, corecs] [unfold_defs, corec_defs] lthy =
   678     Cs As kss mss ns ctr_defss ctr_sugars iterss iter_defss lthy =
   679   let
   679   let
       
   680     val [unfolds, corecs] = transpose iterss;
       
   681     val [unfold_defs, corec_defs] = transpose iter_defss;
       
   682 
   680     val nn = length pre_bnfs;
   683     val nn = length pre_bnfs;
   681 
   684 
   682     val pre_map_defs = map map_def_of_bnf pre_bnfs;
   685     val pre_map_defs = map map_def_of_bnf pre_bnfs;
   683     val pre_rel_defs = map rel_def_of_bnf pre_bnfs;
   686     val pre_rel_defs = map rel_def_of_bnf pre_bnfs;
   684     val nesting_map_ids'' = map (unfold_thms lthy @{thms id_def} o map_id_of_bnf) nesting_bnfs;
   687     val nesting_map_ids'' = map (unfold_thms lthy @{thms id_def} o map_id_of_bnf) nesting_bnfs;
  1333            (simpsN, simp_thmss, K [])]
  1336            (simpsN, simp_thmss, K [])]
  1334           |> massage_multi_notes;
  1337           |> massage_multi_notes;
  1335       in
  1338       in
  1336         lthy
  1339         lthy
  1337         |> Local_Theory.notes (common_notes @ notes) |> snd
  1340         |> Local_Theory.notes (common_notes @ notes) |> snd
  1338         |> register_fp_sugars Least_FP pre_bnfs fp_res ctr_defss ctr_sugars iterss' induct_thm
  1341         |> register_fp_sugars Least_FP pre_bnfs fp_res ctr_defss ctr_sugars (transpose iterss')
  1339           induct_thm (transpose [fold_thmss, rec_thmss])
  1342           induct_thm induct_thm (transpose [fold_thmss, rec_thmss])
  1340       end;
  1343       end;
  1341 
  1344 
  1342     fun derive_and_note_coinduct_coiters_thms_for_types
  1345     fun derive_and_note_coinduct_coiters_thms_for_types
  1343         ((((mapsx, rel_injects, rel_distincts, setss), (_, _, ctr_defss, ctr_sugars)),
  1346         ((((mapsx, rel_injects, rel_distincts, setss), (_, _, ctr_defss, ctr_sugars)),
  1344           (coiterss', coiter_defss')), lthy) =
  1347           (coiterss', coiter_defss')), lthy) =
  1350              (disc_unfold_thmss, disc_corec_thmss, disc_coiter_attrs),
  1353              (disc_unfold_thmss, disc_corec_thmss, disc_coiter_attrs),
  1351              (disc_unfold_iff_thmss, disc_corec_iff_thmss, disc_coiter_iff_attrs),
  1354              (disc_unfold_iff_thmss, disc_corec_iff_thmss, disc_coiter_iff_attrs),
  1352              (sel_unfold_thmss, sel_corec_thmss, sel_coiter_attrs)) =
  1355              (sel_unfold_thmss, sel_corec_thmss, sel_coiter_attrs)) =
  1353           derive_coinduct_coiters_thms_for_types pre_bnfs xtor_co_iterss xtor_co_induct
  1356           derive_coinduct_coiters_thms_for_types pre_bnfs xtor_co_iterss xtor_co_induct
  1354             xtor_strong_co_induct dtor_ctors (transpose xtor_co_iter_thmss) nesting_bnfs nested_bnfs
  1357             xtor_strong_co_induct dtor_ctors (transpose xtor_co_iter_thmss) nesting_bnfs nested_bnfs
  1355             fpTs Cs As kss mss ns ctr_defss ctr_sugars coiterss' coiter_defss' lthy;
  1358             fpTs Cs As kss mss ns ctr_defss ctr_sugars (transpose coiterss')
       
  1359             (transpose coiter_defss') lthy;
  1356 
  1360 
  1357         val coinduct_type_attr = Attrib.internal o K o Induct.coinduct_type;
  1361         val coinduct_type_attr = Attrib.internal o K o Induct.coinduct_type;
  1358 
  1362 
  1359         fun flat_coiter_thms coiters disc_coiters sel_coiters =
  1363         fun flat_coiter_thms coiters disc_coiters sel_coiters =
  1360           coiters @ disc_coiters @ sel_coiters;
  1364           coiters @ disc_coiters @ sel_coiters;
  1392            (unfoldN, unfold_thmss, K coiter_attrs)]
  1396            (unfoldN, unfold_thmss, K coiter_attrs)]
  1393           |> massage_multi_notes;
  1397           |> massage_multi_notes;
  1394       in
  1398       in
  1395         lthy
  1399         lthy
  1396         |> Local_Theory.notes (anonymous_notes @ common_notes @ notes) |> snd
  1400         |> Local_Theory.notes (anonymous_notes @ common_notes @ notes) |> snd
  1397         |> register_fp_sugars Greatest_FP pre_bnfs fp_res ctr_defss ctr_sugars coiterss'
  1401         |> register_fp_sugars Greatest_FP pre_bnfs fp_res ctr_defss ctr_sugars (transpose coiterss')
  1398           coinduct_thm strong_coinduct_thm (transpose [unfold_thmss, corec_thmss])
  1402           coinduct_thm strong_coinduct_thm (transpose [unfold_thmss, corec_thmss])
  1399       end;
  1403       end;
  1400 
  1404 
  1401     val lthy' = lthy
  1405     val lthy' = lthy
  1402       |> fold_map define_ctrs_case_for_type (fp_bnfs ~~ fp_bs ~~ fpTs ~~ Cs ~~ ctors ~~ dtors ~~
  1406       |> fold_map define_ctrs_case_for_type (fp_bnfs ~~ fp_bs ~~ fpTs ~~ Cs ~~ ctors ~~ dtors ~~