61 split_thms : (thm * thm) list, |
61 split_thms : (thm * thm) list, |
62 induction : thm, |
62 induction : thm, |
63 size : thm list, |
63 size : thm list, |
64 simps : thm list} |
64 simps : thm list} |
65 val get_datatypes : theory -> DatatypeAux.datatype_info Symtab.table |
65 val get_datatypes : theory -> DatatypeAux.datatype_info Symtab.table |
|
66 val get_datatypes_sg : Sign.sg -> DatatypeAux.datatype_info Symtab.table |
66 val print_datatypes : theory -> unit |
67 val print_datatypes : theory -> unit |
67 val datatype_info_sg : Sign.sg -> string -> DatatypeAux.datatype_info option |
68 val datatype_info_sg : Sign.sg -> string -> DatatypeAux.datatype_info option |
68 val datatype_info : theory -> string -> DatatypeAux.datatype_info option |
69 val datatype_info : theory -> string -> DatatypeAux.datatype_info option |
69 val datatype_info_sg_err : Sign.sg -> string -> DatatypeAux.datatype_info |
70 val datatype_info_sg_err : Sign.sg -> string -> DatatypeAux.datatype_info |
70 val datatype_info_err : theory -> string -> DatatypeAux.datatype_info |
71 val datatype_info_err : theory -> string -> DatatypeAux.datatype_info |
71 val constrs_of : theory -> string -> term list option |
72 val constrs_of : theory -> string -> term list option |
72 val constrs_of_sg : Sign.sg -> string -> term list option |
73 val constrs_of_sg : Sign.sg -> string -> term list option |
73 val case_const_of : theory -> string -> term option |
74 val case_const_of : theory -> string -> term option |
|
75 val weak_case_congs_of : theory -> thm list |
|
76 val weak_case_congs_of_sg : Sign.sg -> thm list |
74 val setup: (theory -> theory) list |
77 val setup: (theory -> theory) list |
75 end; |
78 end; |
76 |
79 |
77 structure DatatypePackage : DATATYPE_PACKAGE = |
80 structure DatatypePackage : DATATYPE_PACKAGE = |
78 struct |
81 struct |
131 |
134 |
132 fun case_const_of thy tname = (case datatype_info thy tname of |
135 fun case_const_of thy tname = (case datatype_info thy tname of |
133 Some {case_name, ...} => Some (Const (case_name, the (Sign.const_type |
136 Some {case_name, ...} => Some (Const (case_name, the (Sign.const_type |
134 (Theory.sign_of thy) case_name))) |
137 (Theory.sign_of thy) case_name))) |
135 | _ => None); |
138 | _ => None); |
|
139 |
|
140 val weak_case_congs_of_sg = map (#weak_case_cong o #2) o Symtab.dest o get_datatypes_sg; |
|
141 val weak_case_congs_of = weak_case_congs_of_sg o Theory.sign_of; |
136 |
142 |
137 fun find_tname var Bi = |
143 fun find_tname var Bi = |
138 let val frees = map dest_Free (term_frees Bi) |
144 let val frees = map dest_Free (term_frees Bi) |
139 val params = Logic.strip_params Bi; |
145 val params = Logic.strip_params Bi; |
140 in case assoc (frees @ params, var) of |
146 in case assoc (frees @ params, var) of |
377 |
383 |
378 |
384 |
379 (**** make datatype info ****) |
385 (**** make datatype info ****) |
380 |
386 |
381 fun make_dt_info descr induct reccomb_names rec_thms |
387 fun make_dt_info descr induct reccomb_names rec_thms |
382 ((((((((i, (_, (tname, _, _))), case_name), case_thms), |
388 (((((((((i, (_, (tname, _, _))), case_name), case_thms), |
383 exhaustion_thm), distinct_thm), inject), nchotomy), case_cong) = (tname, |
389 exhaustion_thm), distinct_thm), inject), nchotomy), case_cong), weak_case_cong) = |
384 {index = i, |
390 (tname, |
385 descr = descr, |
391 {index = i, |
386 rec_names = reccomb_names, |
392 descr = descr, |
387 rec_rewrites = rec_thms, |
393 rec_names = reccomb_names, |
388 case_name = case_name, |
394 rec_rewrites = rec_thms, |
389 case_rewrites = case_thms, |
395 case_name = case_name, |
390 induction = induct, |
396 case_rewrites = case_thms, |
391 exhaustion = exhaustion_thm, |
397 induction = induct, |
392 distinct = distinct_thm, |
398 exhaustion = exhaustion_thm, |
393 inject = inject, |
399 distinct = distinct_thm, |
394 nchotomy = nchotomy, |
400 inject = inject, |
395 case_cong = case_cong}); |
401 nchotomy = nchotomy, |
|
402 case_cong = case_cong, |
|
403 weak_case_cong = weak_case_cong}); |
396 |
404 |
397 |
405 |
398 (********************* axiomatic introduction of datatypes ********************) |
406 (********************* axiomatic introduction of datatypes ********************) |
399 |
407 |
400 fun add_and_get_axioms_atts label tnames attss ts thy = |
408 fun add_and_get_axioms_atts label tnames attss ts thy = |
552 (DatatypeProp.make_weak_case_congs new_type_names descr sorts thy10) thy10; |
560 (DatatypeProp.make_weak_case_congs new_type_names descr sorts thy10) thy10; |
553 |
561 |
554 val dt_infos = map (make_dt_info descr' induct reccomb_names' rec_thms) |
562 val dt_infos = map (make_dt_info descr' induct reccomb_names' rec_thms) |
555 ((0 upto length (hd descr) - 1) ~~ (hd descr) ~~ case_names' ~~ case_thms ~~ |
563 ((0 upto length (hd descr) - 1) ~~ (hd descr) ~~ case_names' ~~ case_thms ~~ |
556 exhaustion ~~ replicate (length (hd descr)) QuickAndDirty ~~ inject ~~ |
564 exhaustion ~~ replicate (length (hd descr)) QuickAndDirty ~~ inject ~~ |
557 nchotomys ~~ case_congs); |
565 nchotomys ~~ case_congs ~~ weak_case_congs); |
558 |
566 |
559 val simps = flat (distinct @ inject @ case_thms) @ size_thms @ rec_thms; |
567 val simps = flat (distinct @ inject @ case_thms) @ size_thms @ rec_thms; |
560 val split_thms = split ~~ split_asm; |
568 val split_thms = split ~~ split_asm; |
561 |
569 |
562 val thy12 = thy11 |> |
570 val thy12 = thy11 |> |
611 val (thy11, size_thms) = DatatypeAbsProofs.prove_size_thms flat_names new_type_names |
619 val (thy11, size_thms) = DatatypeAbsProofs.prove_size_thms flat_names new_type_names |
612 descr sorts reccomb_names rec_thms thy10; |
620 descr sorts reccomb_names rec_thms thy10; |
613 |
621 |
614 val dt_infos = map (make_dt_info (flat descr) induct reccomb_names rec_thms) |
622 val dt_infos = map (make_dt_info (flat descr) induct reccomb_names rec_thms) |
615 ((0 upto length (hd descr) - 1) ~~ (hd descr) ~~ case_names ~~ case_thms ~~ |
623 ((0 upto length (hd descr) - 1) ~~ (hd descr) ~~ case_names ~~ case_thms ~~ |
616 casedist_thms ~~ simproc_dists ~~ inject ~~ nchotomys ~~ case_congs); |
624 casedist_thms ~~ simproc_dists ~~ inject ~~ nchotomys ~~ case_congs ~~ weak_case_congs); |
617 |
625 |
618 val simps = flat (distinct @ inject @ case_thms) @ size_thms @ rec_thms; |
626 val simps = flat (distinct @ inject @ case_thms) @ size_thms @ rec_thms; |
619 |
627 |
620 val thy12 = thy11 |> |
628 val thy12 = thy11 |> |
621 Theory.add_path (space_implode "_" new_type_names) |> |
629 Theory.add_path (space_implode "_" new_type_names) |> |
717 (#1 o store_thmss "distinct" new_type_names distinct) |> |
725 (#1 o store_thmss "distinct" new_type_names distinct) |> |
718 Theory.add_path (space_implode "_" new_type_names) |> |
726 Theory.add_path (space_implode "_" new_type_names) |> |
719 PureThy.add_thms [(("induct", induction), [case_names_induct])]; |
727 PureThy.add_thms [(("induct", induction), [case_names_induct])]; |
720 |
728 |
721 val dt_infos = map (make_dt_info descr induction' reccomb_names rec_thms) |
729 val dt_infos = map (make_dt_info descr induction' reccomb_names rec_thms) |
722 ((0 upto length descr - 1) ~~ descr ~~ case_names ~~ case_thms ~~ |
730 ((0 upto length descr - 1) ~~ descr ~~ case_names ~~ case_thms ~~ casedist_thms ~~ |
723 casedist_thms ~~ map FewConstrs distinct ~~ inject ~~ nchotomys ~~ case_congs); |
731 map FewConstrs distinct ~~ inject ~~ nchotomys ~~ case_congs ~~ weak_case_congs); |
724 |
732 |
725 val simps = flat (distinct @ inject @ case_thms) @ size_thms @ rec_thms; |
733 val simps = flat (distinct @ inject @ case_thms) @ size_thms @ rec_thms; |
726 |
734 |
727 val thy11 = thy10 |> |
735 val thy11 = thy10 |> |
728 (#1 o PureThy.add_thmss [(("simps", simps), []), |
736 (#1 o PureThy.add_thmss [(("simps", simps), []), |