src/HOL/Tools/BNF/bnf_lfp_basic_sugar.ML
author blanchet
Wed, 17 Feb 2016 17:08:36 +0100
changeset 62335 e85c42f4f30a
parent 62321 1abe81758619
child 62684 cb20e8828196
permissions -rw-r--r--
making 'pred_inject' a first-class BNF citizen
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
58352
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
     1
(*  Title:      HOL/Tools/BNF/bnf_lfp_basic_sugar.ML
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
     2
    Author:     Jasmin Blanchette, TU Muenchen
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
     3
    Copyright   2014
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
     4
58353
c9f374b64d99 tuned fact visibility
blanchet
parents: 58352
diff changeset
     5
Registration of basic types as BNF least fixpoints (datatypes).
58352
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
     6
*)
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
     7
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
     8
structure BNF_LFP_Basic_Sugar : sig end =
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
     9
struct
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
    10
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
    11
open Ctr_Sugar
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
    12
open BNF_Util
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
    13
open BNF_Def
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
    14
open BNF_Comp
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
    15
open BNF_FP_Rec_Sugar_Util
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
    16
open BNF_FP_Util
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
    17
open BNF_FP_Def_Sugar
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
    18
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
    19
fun trivial_absT_info_of fpT =
59819
dbec7f33093d store low-level (un)fold constants
blanchet
parents: 58916
diff changeset
    20
  {absT = fpT, repT = fpT, abs = Const (@{const_name id_bnf}, fpT --> fpT),
58353
c9f374b64d99 tuned fact visibility
blanchet
parents: 58352
diff changeset
    21
   rep = Const (@{const_name id_bnf}, fpT --> fpT),
c9f374b64d99 tuned fact visibility
blanchet
parents: 58352
diff changeset
    22
   abs_inject = @{thm type_definition.Abs_inject[OF type_definition_id_bnf_UNIV UNIV_I UNIV_I]},
c9f374b64d99 tuned fact visibility
blanchet
parents: 58352
diff changeset
    23
   abs_inverse = @{thm type_definition.Abs_inverse[OF type_definition_id_bnf_UNIV UNIV_I]},
c9f374b64d99 tuned fact visibility
blanchet
parents: 58352
diff changeset
    24
   type_definition = @{thm type_definition_id_bnf_UNIV}};
58352
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
    25
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
    26
fun the_frozen_ctr_sugar_of ctxt fpT_name =
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
    27
  the (ctr_sugar_of ctxt fpT_name)
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
    28
  |> morph_ctr_sugar (Morphism.typ_morphism "BNF" Logic.unvarifyT_global
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
    29
    $> Morphism.term_morphism "BNF" (Term.map_types Logic.unvarifyT_global));
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
    30
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
    31
fun trivial_fp_result_of fp_bnf fpT C xtor_map xtor_sets xtor_rel ctor_rec_o_map xtor_rel_induct =
59819
dbec7f33093d store low-level (un)fold constants
blanchet
parents: 58916
diff changeset
    32
  let
dbec7f33093d store low-level (un)fold constants
blanchet
parents: 58916
diff changeset
    33
    val xtors = [Const (@{const_name xtor}, fpT --> fpT)];
dbec7f33093d store low-level (un)fold constants
blanchet
parents: 58916
diff changeset
    34
    val co_recs = [Const (@{const_name ctor_rec}, (fpT --> C) --> (fpT --> C))];
dbec7f33093d store low-level (un)fold constants
blanchet
parents: 58916
diff changeset
    35
    val co_rec_thms = [map_id0_of_bnf fp_bnf RS @{thm ctor_rec}];
dbec7f33093d store low-level (un)fold constants
blanchet
parents: 58916
diff changeset
    36
  in
dbec7f33093d store low-level (un)fold constants
blanchet
parents: 58916
diff changeset
    37
    {Ts = [fpT], bnfs = [fp_bnf], ctors = xtors, dtors = xtors, xtor_un_folds = co_recs,
dbec7f33093d store low-level (un)fold constants
blanchet
parents: 58916
diff changeset
    38
     xtor_co_recs = co_recs, xtor_co_induct = @{thm xtor_induct}, dtor_ctors = @{thms xtor_xtor},
dbec7f33093d store low-level (un)fold constants
blanchet
parents: 58916
diff changeset
    39
     ctor_dtors = @{thms xtor_xtor}, ctor_injects = @{thms xtor_inject},
59856
ed0ca9029021 export more low-level theorems in data structure (partly for 'corec')
blanchet
parents: 59819
diff changeset
    40
     dtor_injects = @{thms xtor_inject}, xtor_maps = [xtor_map], xtor_map_uniques = [],
ed0ca9029021 export more low-level theorems in data structure (partly for 'corec')
blanchet
parents: 59819
diff changeset
    41
     xtor_setss = [xtor_sets], xtor_rels = [xtor_rel], xtor_un_fold_thms = co_rec_thms,
ed0ca9029021 export more low-level theorems in data structure (partly for 'corec')
blanchet
parents: 59819
diff changeset
    42
     xtor_co_rec_thms = co_rec_thms, xtor_un_fold_uniques = [], xtor_co_rec_uniques = [],
ed0ca9029021 export more low-level theorems in data structure (partly for 'corec')
blanchet
parents: 59819
diff changeset
    43
     xtor_un_fold_o_maps = [ctor_rec_o_map], xtor_co_rec_o_maps = [ctor_rec_o_map],
ed0ca9029021 export more low-level theorems in data structure (partly for 'corec')
blanchet
parents: 59819
diff changeset
    44
     xtor_un_fold_transfers = [], xtor_co_rec_transfers = [], xtor_rel_co_induct = xtor_rel_induct,
ed0ca9029021 export more low-level theorems in data structure (partly for 'corec')
blanchet
parents: 59819
diff changeset
    45
     dtor_set_inducts = []}
59819
dbec7f33093d store low-level (un)fold constants
blanchet
parents: 58916
diff changeset
    46
  end;
58352
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
    47
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
    48
fun fp_sugar_of_sum ctxt =
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
    49
  let
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
    50
    val fpT as Type (fpT_name, As) = @{typ "'a + 'b"};
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
    51
    val fpBT = @{typ "'c + 'd"};
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
    52
    val C = @{typ 'e};
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
    53
    val X = @{typ 'sum};
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
    54
    val ctr_Tss = map single As;
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
    55
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
    56
    val fp_bnf = the (bnf_of ctxt fpT_name);
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
    57
    val xtor_map = @{thm xtor_map[of "map_sum f1 f2" for f1 f2]};
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
    58
    val xtor_sets = @{thms xtor_set[of setl] xtor_set[of setr]};
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
    59
    val xtor_rel = @{thm xtor_rel[of "rel_sum R1 R2" for R1 R2]};
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
    60
    val ctor_rec_o_map = @{thm ctor_rec_o_map[of _ "map_sum g1 g2" for g1 g2]};
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
    61
    val xtor_rel_induct = @{thm xtor_rel_induct[of "rel_sum R1 R2" for R1 R2]};
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
    62
  in
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
    63
    {T = fpT,
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
    64
     BT = fpBT,
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
    65
     X = X,
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
    66
     fp = Least_FP,
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
    67
     fp_res_index = 0,
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
    68
     fp_res =
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
    69
       trivial_fp_result_of fp_bnf fpT C xtor_map xtor_sets xtor_rel ctor_rec_o_map xtor_rel_induct,
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
    70
     pre_bnf = ID_bnf (*wrong*),
58674
eb98d1971d2a add 'fp_bnf' to 'bnf_sugar'
desharna
parents: 58673
diff changeset
    71
     fp_bnf = fp_bnf,
58352
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
    72
     absT_info = trivial_absT_info_of fpT,
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
    73
     fp_nesting_bnfs = [],
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
    74
     live_nesting_bnfs = [],
58460
a88eb33058f7 refactor fp_sugar move theorems
desharna
parents: 58459
diff changeset
    75
     fp_ctr_sugar =
a88eb33058f7 refactor fp_sugar move theorems
desharna
parents: 58459
diff changeset
    76
       {ctrXs_Tss = ctr_Tss,
62321
1abe81758619 keep 'ctor_iff_dtor' theorem around in BNF FP database
blanchet
parents: 61424
diff changeset
    77
        ctor_iff_dtor = @{thm xtor_iff_xtor},
58460
a88eb33058f7 refactor fp_sugar move theorems
desharna
parents: 58459
diff changeset
    78
        ctr_defs = @{thms Inl_def_alt Inr_def_alt},
58569
3f61adcc1fc9 add 'ctr_transfers' to 'fp_sugar'
desharna
parents: 58568
diff changeset
    79
        ctr_sugar = the_frozen_ctr_sugar_of ctxt fpT_name,
58916
229765cc3414 more complete fp_sugars for sum and prod;
traytel
parents: 58734
diff changeset
    80
        ctr_transfers = @{thms Inl_transfer Inr_transfer},
229765cc3414 more complete fp_sugars for sum and prod;
traytel
parents: 58734
diff changeset
    81
        case_transfers = @{thms case_sum_transfer},
229765cc3414 more complete fp_sugars for sum and prod;
traytel
parents: 58734
diff changeset
    82
        disc_transfers = @{thms isl_transfer},
58676
cdf84b6e1297 generate 'sel_transfer' for (co)datatypes
desharna
parents: 58674
diff changeset
    83
        sel_transfers = []},
58459
f70bffabd7cf refactor fp_sugar move theorems
desharna
parents: 58458
diff changeset
    84
     fp_bnf_sugar =
58462
b46874f2090f refactor fp_sugar move theorems
desharna
parents: 58461
diff changeset
    85
       {map_thms = @{thms map_sum.simps},
58916
229765cc3414 more complete fp_sugars for sum and prod;
traytel
parents: 58734
diff changeset
    86
        map_disc_iffs = @{thms isl_map_sum},
229765cc3414 more complete fp_sugars for sum and prod;
traytel
parents: 58734
diff changeset
    87
        map_selss = map single @{thms map_sum_sel},
58462
b46874f2090f refactor fp_sugar move theorems
desharna
parents: 58461
diff changeset
    88
        rel_injects = @{thms rel_sum_simps(1,4)},
58562
e94cd4f71d0c add 'rel_sels' to 'fp_sugar'
desharna
parents: 58561
diff changeset
    89
        rel_distincts = @{thms rel_sum_simps(2,3)[THEN eq_False[THEN iffD1]]},
58916
229765cc3414 more complete fp_sugars for sum and prod;
traytel
parents: 58734
diff changeset
    90
        rel_sels = @{thms rel_sum_sel},
229765cc3414 more complete fp_sugars for sum and prod;
traytel
parents: 58734
diff changeset
    91
        rel_intros = @{thms rel_sum.intros},
229765cc3414 more complete fp_sugars for sum and prod;
traytel
parents: 58734
diff changeset
    92
        rel_cases = @{thms rel_sum.cases},
62335
e85c42f4f30a making 'pred_inject' a first-class BNF citizen
blanchet
parents: 62321
diff changeset
    93
        pred_injects = @{thms pred_sum_inject},
58916
229765cc3414 more complete fp_sugars for sum and prod;
traytel
parents: 58734
diff changeset
    94
        set_thms = @{thms sum_set_simps},
229765cc3414 more complete fp_sugars for sum and prod;
traytel
parents: 58734
diff changeset
    95
        set_selssss = [[[@{thms set_sum_sel(1)}], [[]]], [[[]], [@{thms set_sum_sel(2)}]]],
229765cc3414 more complete fp_sugars for sum and prod;
traytel
parents: 58734
diff changeset
    96
        set_introssss = [[[@{thms setl.intros[OF refl]}], [[]]],
229765cc3414 more complete fp_sugars for sum and prod;
traytel
parents: 58734
diff changeset
    97
          [[[]], [@{thms setr.intros[OF refl]}]]],
229765cc3414 more complete fp_sugars for sum and prod;
traytel
parents: 58734
diff changeset
    98
        set_cases = @{thms setl.cases[unfolded hypsubst_in_prems]
229765cc3414 more complete fp_sugars for sum and prod;
traytel
parents: 58734
diff changeset
    99
          setr.cases[unfolded hypsubst_in_prems]}},
58459
f70bffabd7cf refactor fp_sugar move theorems
desharna
parents: 58458
diff changeset
   100
     fp_co_induct_sugar =
58461
75ee8d49c724 refactor fp_sugar move theorems
desharna
parents: 58460
diff changeset
   101
       {co_rec = Const (@{const_name case_sum}, map (fn Ts => (Ts ---> C)) ctr_Tss ---> fpT --> C),
75ee8d49c724 refactor fp_sugar move theorems
desharna
parents: 58460
diff changeset
   102
        common_co_inducts = @{thms sum.induct},
75ee8d49c724 refactor fp_sugar move theorems
desharna
parents: 58460
diff changeset
   103
        co_inducts = @{thms sum.induct},
75ee8d49c724 refactor fp_sugar move theorems
desharna
parents: 58460
diff changeset
   104
        co_rec_def = @{thm ctor_rec_def_alt[of "case_sum f1 f2" for f1 f2]},
58459
f70bffabd7cf refactor fp_sugar move theorems
desharna
parents: 58458
diff changeset
   105
        co_rec_thms = @{thms sum.case},
f70bffabd7cf refactor fp_sugar move theorems
desharna
parents: 58458
diff changeset
   106
        co_rec_discs = [],
58572
2e0cf67fa89f add 'co_rec_disc_iffs' to 'fp_sugar'
desharna
parents: 58571
diff changeset
   107
        co_rec_disc_iffs = [],
58573
04f5d23cd9e5 add 'co_rec_transfers' to 'fp_sugar'
desharna
parents: 58572
diff changeset
   108
        co_rec_selss = [],
04f5d23cd9e5 add 'co_rec_transfers' to 'fp_sugar'
desharna
parents: 58572
diff changeset
   109
        co_rec_codes = [],
58916
229765cc3414 more complete fp_sugars for sum and prod;
traytel
parents: 58734
diff changeset
   110
        co_rec_transfers = @{thms case_sum_transfer},
58734
20235f0512e2 generate 'map_o_corec' for (co)datatypes
desharna
parents: 58732
diff changeset
   111
        co_rec_o_maps = @{thms case_sum_o_map_sum},
58916
229765cc3414 more complete fp_sugars for sum and prod;
traytel
parents: 58734
diff changeset
   112
        common_rel_co_inducts = @{thms rel_sum.inducts},
229765cc3414 more complete fp_sugars for sum and prod;
traytel
parents: 58734
diff changeset
   113
        rel_co_inducts = @{thms rel_sum.induct},
58577
15337ad05370 add 'set_inducts' to 'fp_sugar'
desharna
parents: 58576
diff changeset
   114
        common_set_inducts = [],
15337ad05370 add 'set_inducts' to 'fp_sugar'
desharna
parents: 58576
diff changeset
   115
        set_inducts = []}}
58352
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
   116
  end;
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
   117
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
   118
fun fp_sugar_of_prod ctxt =
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
   119
  let
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
   120
    val fpT as Type (fpT_name, As) = @{typ "'a * 'b"};
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
   121
    val fpBT = @{typ "'c * 'd"};
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
   122
    val C = @{typ 'e};
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
   123
    val X = @{typ 'prod};
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
   124
    val ctr_Ts = As;
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
   125
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
   126
    val fp_bnf = the (bnf_of ctxt fpT_name);
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
   127
    val xtor_map = @{thm xtor_map[of "map_prod f1 f2" for f1 f2]};
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
   128
    val xtor_sets = @{thms xtor_set[of fsts] xtor_set[of snds]};
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
   129
    val xtor_rel = @{thm xtor_rel[of "rel_prod R1 R2" for R1 R2]};
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
   130
    val ctor_rec_o_map = @{thm ctor_rec_o_map[of _ "map_prod g1 g2" for g1 g2]};
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
   131
    val xtor_rel_induct = @{thm xtor_rel_induct[of "rel_prod R1 R2" for R1 R2]};
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
   132
  in
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
   133
    {T = fpT,
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
   134
     BT = fpBT,
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
   135
     X = X,
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
   136
     fp = Least_FP,
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
   137
     fp_res_index = 0,
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
   138
     fp_res =
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
   139
       trivial_fp_result_of fp_bnf fpT C xtor_map xtor_sets xtor_rel ctor_rec_o_map xtor_rel_induct,
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
   140
     pre_bnf = ID_bnf (*wrong*),
58674
eb98d1971d2a add 'fp_bnf' to 'bnf_sugar'
desharna
parents: 58673
diff changeset
   141
     fp_bnf = fp_bnf,
58352
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
   142
     absT_info = trivial_absT_info_of fpT,
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
   143
     fp_nesting_bnfs = [],
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
   144
     live_nesting_bnfs = [],
58460
a88eb33058f7 refactor fp_sugar move theorems
desharna
parents: 58459
diff changeset
   145
     fp_ctr_sugar =
a88eb33058f7 refactor fp_sugar move theorems
desharna
parents: 58459
diff changeset
   146
       {ctrXs_Tss = [ctr_Ts],
62321
1abe81758619 keep 'ctor_iff_dtor' theorem around in BNF FP database
blanchet
parents: 61424
diff changeset
   147
        ctor_iff_dtor = @{thm xtor_iff_xtor},
58460
a88eb33058f7 refactor fp_sugar move theorems
desharna
parents: 58459
diff changeset
   148
        ctr_defs = @{thms Pair_def_alt},
58569
3f61adcc1fc9 add 'ctr_transfers' to 'fp_sugar'
desharna
parents: 58568
diff changeset
   149
        ctr_sugar = the_frozen_ctr_sugar_of ctxt fpT_name,
58916
229765cc3414 more complete fp_sugars for sum and prod;
traytel
parents: 58734
diff changeset
   150
        ctr_transfers = @{thms Pair_transfer},
229765cc3414 more complete fp_sugars for sum and prod;
traytel
parents: 58734
diff changeset
   151
        case_transfers = @{thms case_prod_transfer},
58676
cdf84b6e1297 generate 'sel_transfer' for (co)datatypes
desharna
parents: 58674
diff changeset
   152
        disc_transfers = [],
58916
229765cc3414 more complete fp_sugars for sum and prod;
traytel
parents: 58734
diff changeset
   153
        sel_transfers = @{thms fst_transfer snd_transfer}},
58459
f70bffabd7cf refactor fp_sugar move theorems
desharna
parents: 58458
diff changeset
   154
     fp_bnf_sugar =
58462
b46874f2090f refactor fp_sugar move theorems
desharna
parents: 58461
diff changeset
   155
       {map_thms = @{thms map_prod_simp},
58560
ee502a9b38aa add 'map_disc_iffs' to 'fp_sugar'
desharna
parents: 58462
diff changeset
   156
        map_disc_iffs = [],
58916
229765cc3414 more complete fp_sugars for sum and prod;
traytel
parents: 58734
diff changeset
   157
        map_selss = [@{thms fst_map_prod snd_map_prod}],
62335
e85c42f4f30a making 'pred_inject' a first-class BNF citizen
blanchet
parents: 62321
diff changeset
   158
        rel_injects = @{thms rel_prod_inject},
58562
e94cd4f71d0c add 'rel_sels' to 'fp_sugar'
desharna
parents: 58561
diff changeset
   159
        rel_distincts = [],
58916
229765cc3414 more complete fp_sugars for sum and prod;
traytel
parents: 58734
diff changeset
   160
        rel_sels = @{thms rel_prod_sel},
229765cc3414 more complete fp_sugars for sum and prod;
traytel
parents: 58734
diff changeset
   161
        rel_intros = @{thms rel_prod.intros},
229765cc3414 more complete fp_sugars for sum and prod;
traytel
parents: 58734
diff changeset
   162
        rel_cases = @{thms rel_prod.cases},
62335
e85c42f4f30a making 'pred_inject' a first-class BNF citizen
blanchet
parents: 62321
diff changeset
   163
        pred_injects = @{thms pred_prod_inject},
58916
229765cc3414 more complete fp_sugars for sum and prod;
traytel
parents: 58734
diff changeset
   164
        set_thms = @{thms prod_set_simps},
229765cc3414 more complete fp_sugars for sum and prod;
traytel
parents: 58734
diff changeset
   165
        set_selssss = [[[@{thms fsts.intros}, []]], [[[], @{thms snds.intros}]]],
229765cc3414 more complete fp_sugars for sum and prod;
traytel
parents: 58734
diff changeset
   166
        set_introssss = [[[@{thms fsts.intros[of "(a, b)" for a b, unfolded fst_conv]}, []]],
229765cc3414 more complete fp_sugars for sum and prod;
traytel
parents: 58734
diff changeset
   167
          [[[], @{thms snds.intros[of "(a, b)" for a b, unfolded snd_conv]}]]],
229765cc3414 more complete fp_sugars for sum and prod;
traytel
parents: 58734
diff changeset
   168
        set_cases = @{thms fsts.cases[unfolded eq_fst_iff ex_neg_all_pos]
229765cc3414 more complete fp_sugars for sum and prod;
traytel
parents: 58734
diff changeset
   169
          snds.cases[unfolded eq_snd_iff ex_neg_all_pos]}},
58459
f70bffabd7cf refactor fp_sugar move theorems
desharna
parents: 58458
diff changeset
   170
     fp_co_induct_sugar =
61424
c3658c18b7bc prod_case as canonical name for product type eliminator
haftmann
parents: 61125
diff changeset
   171
       {co_rec = Const (@{const_name case_prod}, (ctr_Ts ---> C) --> fpT --> C),
58461
75ee8d49c724 refactor fp_sugar move theorems
desharna
parents: 58460
diff changeset
   172
        common_co_inducts = @{thms prod.induct},
75ee8d49c724 refactor fp_sugar move theorems
desharna
parents: 58460
diff changeset
   173
        co_inducts = @{thms prod.induct},
75ee8d49c724 refactor fp_sugar move theorems
desharna
parents: 58460
diff changeset
   174
        co_rec_def = @{thm ctor_rec_def_alt[of "case_prod f" for f]},
58459
f70bffabd7cf refactor fp_sugar move theorems
desharna
parents: 58458
diff changeset
   175
        co_rec_thms = @{thms prod.case},
f70bffabd7cf refactor fp_sugar move theorems
desharna
parents: 58458
diff changeset
   176
        co_rec_discs = [],
58572
2e0cf67fa89f add 'co_rec_disc_iffs' to 'fp_sugar'
desharna
parents: 58571
diff changeset
   177
        co_rec_disc_iffs = [],
58573
04f5d23cd9e5 add 'co_rec_transfers' to 'fp_sugar'
desharna
parents: 58572
diff changeset
   178
        co_rec_selss = [],
04f5d23cd9e5 add 'co_rec_transfers' to 'fp_sugar'
desharna
parents: 58572
diff changeset
   179
        co_rec_codes = [],
58916
229765cc3414 more complete fp_sugars for sum and prod;
traytel
parents: 58734
diff changeset
   180
        co_rec_transfers = @{thms case_prod_transfer},
58734
20235f0512e2 generate 'map_o_corec' for (co)datatypes
desharna
parents: 58732
diff changeset
   181
        co_rec_o_maps = @{thms case_prod_o_map_prod},
58916
229765cc3414 more complete fp_sugars for sum and prod;
traytel
parents: 58734
diff changeset
   182
        common_rel_co_inducts = @{thms rel_prod.inducts},
229765cc3414 more complete fp_sugars for sum and prod;
traytel
parents: 58734
diff changeset
   183
        rel_co_inducts = @{thms rel_prod.induct},
58577
15337ad05370 add 'set_inducts' to 'fp_sugar'
desharna
parents: 58576
diff changeset
   184
        common_set_inducts = [],
15337ad05370 add 'set_inducts' to 'fp_sugar'
desharna
parents: 58576
diff changeset
   185
        set_inducts = []}}
58352
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
   186
  end;
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
   187
58665
50b229a5a097 tuned signature;
wenzelm
parents: 58585
diff changeset
   188
val _ = Theory.setup (Named_Target.theory_map (fn lthy =>
58377
c6f93b8d2d8e moved old 'size' generator together with 'old_datatype'
blanchet
parents: 58353
diff changeset
   189
  fold (BNF_FP_Def_Sugar.register_fp_sugars (K true) o single o (fn f => f lthy))
58352
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
   190
    [fp_sugar_of_sum, fp_sugar_of_prod] lthy));
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
   191
37745650a3f4 register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
diff changeset
   192
end;