src/HOL/Tools/datatype_package.ML
changeset 18728 6790126ab5f6
parent 18708 4b3dadb4fe33
child 18751 38dc4ff2a32b
equal deleted inserted replaced
18727:caf9bc780c80 18728:6790126ab5f6
    37        case_thms : thm list list,
    37        case_thms : thm list list,
    38        split_thms : (thm * thm) list,
    38        split_thms : (thm * thm) list,
    39        induction : thm,
    39        induction : thm,
    40        size : thm list,
    40        size : thm list,
    41        simps : thm list} * theory
    41        simps : thm list} * theory
    42   val rep_datatype_i : string list option -> (thm list * theory attribute list) list list ->
    42   val rep_datatype_i : string list option -> (thm list * attribute list) list list ->
    43     (thm list * theory attribute list) list list -> (thm list * theory attribute list) ->
    43     (thm list * attribute list) list list -> (thm list * attribute list) ->
    44     theory ->
    44     theory ->
    45       {distinct : thm list list,
    45       {distinct : thm list list,
    46        inject : thm list list,
    46        inject : thm list list,
    47        exhaustion : thm list,
    47        exhaustion : thm list,
    48        rec_thms : thm list,
    48        rec_thms : thm list,
   348       
   348       
   349 fun add_rules simps case_thms size_thms rec_thms inject distinct
   349 fun add_rules simps case_thms size_thms rec_thms inject distinct
   350                   weak_case_congs cong_att =
   350                   weak_case_congs cong_att =
   351   (snd o PureThy.add_thmss [(("simps", simps), []),
   351   (snd o PureThy.add_thmss [(("simps", simps), []),
   352     (("", List.concat case_thms @ size_thms @ 
   352     (("", List.concat case_thms @ size_thms @ 
   353           List.concat distinct  @ rec_thms), [Attrib.theory Simplifier.simp_add]),
   353           List.concat distinct  @ rec_thms), [Simplifier.simp_add]),
   354     (("", size_thms @ rec_thms),             [RecfunCodegen.add NONE]),
   354     (("", size_thms @ rec_thms),             [RecfunCodegen.add NONE]),
   355     (("", List.concat inject),               [Attrib.theory iff_add]),
   355     (("", List.concat inject),               [iff_add]),
   356     (("", map name_notE (List.concat distinct)),  [Attrib.theory (Classical.safe_elim NONE)]),
   356     (("", map name_notE (List.concat distinct)),  [Classical.safe_elim NONE]),
   357     (("", weak_case_congs),                  [cong_att])]);
   357     (("", weak_case_congs),                  [cong_att])]);
   358 
   358 
   359 
   359 
   360 (* add_cases_induct *)
   360 (* add_cases_induct *)
   361 
   361 
   363   let
   363   let
   364     val n = length (HOLogic.dest_concls (Thm.concl_of induction));
   364     val n = length (HOLogic.dest_concls (Thm.concl_of induction));
   365     fun proj i = ProjectRule.project induction (i + 1);
   365     fun proj i = ProjectRule.project induction (i + 1);
   366 
   366 
   367     fun named_rules (name, {index, exhaustion, ...}: datatype_info) =
   367     fun named_rules (name, {index, exhaustion, ...}: datatype_info) =
   368       [(("", proj index), [Attrib.theory (InductAttrib.induct_type name)]),
   368       [(("", proj index), [InductAttrib.induct_type name]),
   369        (("", exhaustion), [Attrib.theory (InductAttrib.cases_type name)])];
   369        (("", exhaustion), [InductAttrib.cases_type name])];
   370     fun unnamed_rule i =
   370     fun unnamed_rule i =
   371       (("", proj i), [Drule.kind_internal, Attrib.theory (InductAttrib.induct_type "")]);
   371       (("", proj i), [Drule.kind_internal, InductAttrib.induct_type ""]);
   372   in
   372   in
   373     PureThy.add_thms
   373     PureThy.add_thms
   374       (List.concat (map named_rules infos) @
   374       (List.concat (map named_rules infos) @
   375         map unnamed_rule (length infos upto n - 1)) #> snd #>
   375         map unnamed_rule (length infos upto n - 1)) #> snd #>
   376     PureThy.add_thmss [(("inducts",
   376     PureThy.add_thmss [(("inducts",
   745     val thy12 =
   745     val thy12 =
   746       thy11
   746       thy11
   747       |> Theory.add_advanced_trfuns ([], [], make_case_tr' case_names' (hd descr), [])
   747       |> Theory.add_advanced_trfuns ([], [], make_case_tr' case_names' (hd descr), [])
   748       |> Theory.add_path (space_implode "_" new_type_names)
   748       |> Theory.add_path (space_implode "_" new_type_names)
   749       |> add_rules simps case_thms size_thms rec_thms inject distinct
   749       |> add_rules simps case_thms size_thms rec_thms inject distinct
   750            weak_case_congs (Attrib.theory Simplifier.cong_add)
   750           weak_case_congs Simplifier.cong_add
   751       |> put_datatypes (fold Symtab.update dt_infos dt_info)
   751       |> put_datatypes (fold Symtab.update dt_infos dt_info)
   752       |> add_cases_induct dt_infos induct
   752       |> add_cases_induct dt_infos induct
   753       |> Theory.parent_path
   753       |> Theory.parent_path
   754       |> store_thmss "splits" new_type_names (map (fn (x, y) => [x, y]) split_thms) |> snd
   754       |> store_thmss "splits" new_type_names (map (fn (x, y) => [x, y]) split_thms) |> snd
   755       |> DatatypeRealizer.add_dt_realizers sorts (map snd dt_infos)
   755       |> DatatypeRealizer.add_dt_realizers sorts (map snd dt_infos)
   804     val thy12 =
   804     val thy12 =
   805       thy11
   805       thy11
   806       |> Theory.add_advanced_trfuns ([], [], make_case_tr' case_names (hd descr), [])
   806       |> Theory.add_advanced_trfuns ([], [], make_case_tr' case_names (hd descr), [])
   807       |> Theory.add_path (space_implode "_" new_type_names)
   807       |> Theory.add_path (space_implode "_" new_type_names)
   808       |> add_rules simps case_thms size_thms rec_thms inject distinct
   808       |> add_rules simps case_thms size_thms rec_thms inject distinct
   809             weak_case_congs (Attrib.theory (Simplifier.attrib (op addcongs)))
   809           weak_case_congs (Simplifier.attrib (op addcongs))
   810       |> put_datatypes (fold Symtab.update dt_infos dt_info)
   810       |> put_datatypes (fold Symtab.update dt_infos dt_info)
   811       |> add_cases_induct dt_infos induct
   811       |> add_cases_induct dt_infos induct
   812       |> Theory.parent_path
   812       |> Theory.parent_path
   813       |> store_thmss "splits" new_type_names (map (fn (x, y) => [x, y]) split_thms) |> snd
   813       |> store_thmss "splits" new_type_names (map (fn (x, y) => [x, y]) split_thms) |> snd
   814       |> DatatypeRealizer.add_dt_realizers sorts (map snd dt_infos)
   814       |> DatatypeRealizer.add_dt_realizers sorts (map snd dt_infos)
   911     val simps = List.concat (distinct @ inject @ case_thms) @ size_thms @ rec_thms;
   911     val simps = List.concat (distinct @ inject @ case_thms) @ size_thms @ rec_thms;
   912 
   912 
   913     val thy11 = thy10 |>
   913     val thy11 = thy10 |>
   914       Theory.add_advanced_trfuns ([], [], make_case_tr' case_names descr, []) |>
   914       Theory.add_advanced_trfuns ([], [], make_case_tr' case_names descr, []) |>
   915       add_rules simps case_thms size_thms rec_thms inject distinct
   915       add_rules simps case_thms size_thms rec_thms inject distinct
   916                 weak_case_congs (Attrib.theory (Simplifier.attrib (op addcongs))) |> 
   916         weak_case_congs (Simplifier.attrib (op addcongs)) |> 
   917       put_datatypes (fold Symtab.update dt_infos dt_info) |>
   917       put_datatypes (fold Symtab.update dt_infos dt_info) |>
   918       add_cases_induct dt_infos induction' |>
   918       add_cases_induct dt_infos induction' |>
   919       Theory.parent_path |>
   919       Theory.parent_path |>
   920       (snd o store_thmss "splits" new_type_names (map (fn (x, y) => [x, y]) split_thms)) |>
   920       (snd o store_thmss "splits" new_type_names (map (fn (x, y) => [x, y]) split_thms)) |>
   921       DatatypeRealizer.add_dt_realizers sorts (map snd dt_infos);
   921       DatatypeRealizer.add_dt_realizers sorts (map snd dt_infos);