34 val unify_consts: Sign.sg -> term list -> term list -> term list * term list |
34 val unify_consts: Sign.sg -> term list -> term list -> term list * term list |
35 val get_inductive: theory -> string -> |
35 val get_inductive: theory -> string -> |
36 {names: string list, coind: bool} * {defs: thm list, elims: thm list, raw_induct: thm, |
36 {names: string list, coind: bool} * {defs: thm list, elims: thm list, raw_induct: thm, |
37 induct: thm, intrs: thm list, mk_cases: string -> thm, mono: thm, unfold: thm} |
37 induct: thm, intrs: thm list, mk_cases: string -> thm, mono: thm, unfold: thm} |
38 val print_inductives: theory -> unit |
38 val print_inductives: theory -> unit |
39 val cases_of: Sign.sg -> string -> thm |
|
40 val all_cases: Sign.sg -> thm list |
|
41 val all_inducts: Sign.sg -> thm list |
|
42 val mono_add_global: theory attribute |
39 val mono_add_global: theory attribute |
43 val mono_del_global: theory attribute |
40 val mono_del_global: theory attribute |
44 val get_monos: theory -> thm list |
41 val get_monos: theory -> thm list |
45 val add_inductive_i: bool -> bool -> bstring -> bool -> bool -> bool -> term list -> |
42 val add_inductive_i: bool -> bool -> bstring -> bool -> bool -> bool -> term list -> |
46 theory attribute list -> ((bstring * term) * theory attribute list) list -> |
43 theory attribute list -> ((bstring * term) * theory attribute list) list -> |
103 fun upd ((tab, monos), name) = (Symtab.update_new ((name, info), tab), monos); |
100 fun upd ((tab, monos), name) = (Symtab.update_new ((name, info), tab), monos); |
104 val tab_monos = foldl upd (InductiveData.get thy, names) |
101 val tab_monos = foldl upd (InductiveData.get thy, names) |
105 handle Symtab.DUP name => error ("Duplicate definition of (co)inductive set " ^ quote name); |
102 handle Symtab.DUP name => error ("Duplicate definition of (co)inductive set " ^ quote name); |
106 in InductiveData.put tab_monos thy end; |
103 in InductiveData.put tab_monos thy end; |
107 |
104 |
108 |
|
109 (* cases and induct rules *) |
|
110 |
|
111 fun cases_of sg name = |
|
112 let |
|
113 fun find (None, (_, ({names, ...}, {elims, ...}): inductive_info)) = |
|
114 assoc (names ~~ elims, name) |
|
115 | find (some, _) = some; |
|
116 val (tab, _) = InductiveData.get_sg sg; |
|
117 in |
|
118 (case Symtab.foldl find (None, tab) of |
|
119 None => error ("Unknown (co)inductive set " ^ quote name) |
|
120 | Some thm => thm) |
|
121 end; |
|
122 |
|
123 fun all_cases sg = flat (map (#elims o #2 o #2) (Symtab.dest (#1 (InductiveData.get_sg sg)))); |
|
124 fun all_inducts sg = map (#induct o #2 o #2) (Symtab.dest (#1 (InductiveData.get_sg sg))); |
|
125 |
|
126 |
105 |
127 |
106 |
128 (** monotonicity rules **) |
107 (** monotonicity rules **) |
129 |
108 |
130 val get_monos = snd o InductiveData.get; |
109 val get_monos = snd o InductiveData.get; |
763 |
742 |
764 |
743 |
765 |
744 |
766 (** introduction of (co)inductive sets **) |
745 (** introduction of (co)inductive sets **) |
767 |
746 |
|
747 fun add_cases_induct names elims induct = |
|
748 PureThy.add_thms |
|
749 (map (fn name => (("", induct), [InductMethod.induct_set_global name])) names @ |
|
750 map2 (fn (name, elim) => (("", elim), [InductMethod.cases_set_global name])) (names, elims)); |
|
751 |
|
752 |
768 fun add_inductive_i verbose declare_consts alt_name coind no_elim no_ind cs |
753 fun add_inductive_i verbose declare_consts alt_name coind no_elim no_ind cs |
769 atts intros monos con_defs thy = |
754 atts intros monos con_defs thy = |
770 let |
755 let |
771 val _ = Theory.requires thy "Inductive" (coind_prefix coind ^ "inductive definitions"); |
756 val _ = Theory.requires thy "Inductive" (coind_prefix coind ^ "inductive definitions"); |
772 val sign = Theory.sign_of thy; |
757 val sign = Theory.sign_of thy; |
787 |
772 |
788 val (thy1, result) = |
773 val (thy1, result) = |
789 (if ! quick_and_dirty then add_ind_axm else add_ind_def) |
774 (if ! quick_and_dirty then add_ind_axm else add_ind_def) |
790 verbose declare_consts alt_name coind no_elim no_ind cs atts intros monos |
775 verbose declare_consts alt_name coind no_elim no_ind cs atts intros monos |
791 con_defs thy params paramTs cTs cnames; |
776 con_defs thy params paramTs cTs cnames; |
792 val thy2 = thy1 |> put_inductives full_cnames ({names = full_cnames, coind = coind}, result); |
777 val thy2 = thy1 |
|
778 |> put_inductives full_cnames ({names = full_cnames, coind = coind}, result) |
|
779 |> add_cases_induct full_cnames (#elims result) (#induct result); |
793 in (thy2, result) end; |
780 in (thy2, result) end; |
794 |
781 |
795 |
782 |
796 |
783 |
797 (** external interface **) |
784 (** external interface **) |