1 (* Title: ZF/Tools/ind_cases.ML
3 Author: Markus Wenzel, LMU Muenchen
5 Generic inductive cases facility for (co)inductive definitions.
10 val declare: string -> (simpset -> cterm -> thm) -> theory -> theory
11 val inductive_cases: ((bstring * Attrib.src list) * string list) list -> theory -> theory
12 val setup: theory -> theory
15 structure IndCases: IND_CASES =
21 structure IndCasesData = TheoryDataFun
23 type T = (simpset -> cterm -> thm) Symtab.table;
24 val empty = Symtab.empty;
27 fun merge _ tabs : T = Symtab.merge (K true) tabs;
31 fun declare name f = IndCasesData.map (Symtab.update (name, f));
33 fun smart_cases thy ss read_prop s =
35 fun err msg = cat_error msg ("Malformed set membership statement: " ^ s);
36 val A = read_prop s handle ERROR msg => err msg;
37 val c = #1 (Term.dest_Const (Term.head_of (#2 (Ind_Syntax.dest_mem (FOLogic.dest_Trueprop
38 (Logic.strip_imp_concl A)))))) handle TERM _ => err "";
40 (case Symtab.lookup (IndCasesData.get thy) c of
41 NONE => error ("Unknown inductive cases rule for set " ^ quote c)
42 | SOME f => f ss (Thm.cterm_of thy A))
46 (* inductive_cases command *)
48 fun inductive_cases args thy =
50 val read_prop = Syntax.read_prop (ProofContext.init thy);
51 val mk_cases = smart_cases thy (Simplifier.simpset_of thy) read_prop;
52 val facts = args |> map (fn ((name, srcs), props) =>
53 ((name, map (Attrib.attribute thy) srcs),
54 map (Thm.no_attributes o single o mk_cases) props));
55 in thy |> PureThy.note_thmss_i "" facts |> snd end;
58 (* ind_cases method *)
60 fun mk_cases_meth (props, ctxt) =
62 |> map (smart_cases (ProofContext.theory_of ctxt) (local_simpset_of ctxt) (Syntax.read_prop ctxt))
65 val mk_cases_args = Method.syntax (Scan.lift (Scan.repeat1 Args.name));
72 [("ind_cases", mk_cases_meth oo mk_cases_args, "dynamic case analysis on sets")];
77 local structure P = OuterParse and K = OuterKeyword in
80 OuterSyntax.command "inductive_cases"
81 "create simplified instances of elimination rules (improper)" K.thy_script
82 (P.and_list1 (SpecParse.opt_thm_name ":" -- Scan.repeat1 P.prop)
83 >> (Toplevel.theory o inductive_cases));