src/ZF/Tools/ind_cases.ML
author wenzelm
Thu, 26 Mar 2009 14:14:02 +0100
changeset 30722 623d4831c8cf
parent 30515 bca05b17b618
child 32149 ef59550a55d3
permissions -rw-r--r--
simplified attribute and method setup: eliminating bottom-up styles makes it easier to keep things in one place, and also SML/NJ happy;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12174
a0aab0b9f2e9 Generic inductive cases facility for (co)inductive definitions.
wenzelm
parents:
diff changeset
     1
(*  Title:      ZF/Tools/ind_cases.ML
a0aab0b9f2e9 Generic inductive cases facility for (co)inductive definitions.
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
a0aab0b9f2e9 Generic inductive cases facility for (co)inductive definitions.
wenzelm
parents:
diff changeset
     3
    Author:     Markus Wenzel, LMU Muenchen
a0aab0b9f2e9 Generic inductive cases facility for (co)inductive definitions.
wenzelm
parents:
diff changeset
     4
a0aab0b9f2e9 Generic inductive cases facility for (co)inductive definitions.
wenzelm
parents:
diff changeset
     5
Generic inductive cases facility for (co)inductive definitions.
a0aab0b9f2e9 Generic inductive cases facility for (co)inductive definitions.
wenzelm
parents:
diff changeset
     6
*)
a0aab0b9f2e9 Generic inductive cases facility for (co)inductive definitions.
wenzelm
parents:
diff changeset
     7
a0aab0b9f2e9 Generic inductive cases facility for (co)inductive definitions.
wenzelm
parents:
diff changeset
     8
signature IND_CASES =
a0aab0b9f2e9 Generic inductive cases facility for (co)inductive definitions.
wenzelm
parents:
diff changeset
     9
sig
a0aab0b9f2e9 Generic inductive cases facility for (co)inductive definitions.
wenzelm
parents:
diff changeset
    10
  val declare: string -> (simpset -> cterm -> thm) -> theory -> theory
28084
a05ca48ef263 type Attrib.binding abbreviates Name.binding without attributes;
wenzelm
parents: 28083
diff changeset
    11
  val inductive_cases: (Attrib.binding * string list) list -> theory -> theory
18708
4b3dadb4fe33 setup: theory -> theory;
wenzelm
parents: 18678
diff changeset
    12
  val setup: theory -> theory
12174
a0aab0b9f2e9 Generic inductive cases facility for (co)inductive definitions.
wenzelm
parents:
diff changeset
    13
end;
a0aab0b9f2e9 Generic inductive cases facility for (co)inductive definitions.
wenzelm
parents:
diff changeset
    14
a0aab0b9f2e9 Generic inductive cases facility for (co)inductive definitions.
wenzelm
parents:
diff changeset
    15
structure IndCases: IND_CASES =
a0aab0b9f2e9 Generic inductive cases facility for (co)inductive definitions.
wenzelm
parents:
diff changeset
    16
struct
a0aab0b9f2e9 Generic inductive cases facility for (co)inductive definitions.
wenzelm
parents:
diff changeset
    17
a0aab0b9f2e9 Generic inductive cases facility for (co)inductive definitions.
wenzelm
parents:
diff changeset
    18
a0aab0b9f2e9 Generic inductive cases facility for (co)inductive definitions.
wenzelm
parents:
diff changeset
    19
(* theory data *)
a0aab0b9f2e9 Generic inductive cases facility for (co)inductive definitions.
wenzelm
parents:
diff changeset
    20
16424
18a07ad8fea8 accomodate change of TheoryDataFun;
wenzelm
parents: 15705
diff changeset
    21
structure IndCasesData = TheoryDataFun
22846
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22101
diff changeset
    22
(
12174
a0aab0b9f2e9 Generic inductive cases facility for (co)inductive definitions.
wenzelm
parents:
diff changeset
    23
  type T = (simpset -> cterm -> thm) Symtab.table;
a0aab0b9f2e9 Generic inductive cases facility for (co)inductive definitions.
wenzelm
parents:
diff changeset
    24
  val empty = Symtab.empty;
a0aab0b9f2e9 Generic inductive cases facility for (co)inductive definitions.
wenzelm
parents:
diff changeset
    25
  val copy = I;
16424
18a07ad8fea8 accomodate change of TheoryDataFun;
wenzelm
parents: 15705
diff changeset
    26
  val extend = I;
18a07ad8fea8 accomodate change of TheoryDataFun;
wenzelm
parents: 15705
diff changeset
    27
  fun merge _ tabs : T = Symtab.merge (K true) tabs;
22846
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22101
diff changeset
    28
);
12174
a0aab0b9f2e9 Generic inductive cases facility for (co)inductive definitions.
wenzelm
parents:
diff changeset
    29
a0aab0b9f2e9 Generic inductive cases facility for (co)inductive definitions.
wenzelm
parents:
diff changeset
    30
17412
e26cb20ef0cc TableFun/Symtab: curried lookup and update;
wenzelm
parents: 17224
diff changeset
    31
fun declare name f = IndCasesData.map (Symtab.update (name, f));
12174
a0aab0b9f2e9 Generic inductive cases facility for (co)inductive definitions.
wenzelm
parents:
diff changeset
    32
a0aab0b9f2e9 Generic inductive cases facility for (co)inductive definitions.
wenzelm
parents:
diff changeset
    33
fun smart_cases thy ss read_prop s =
a0aab0b9f2e9 Generic inductive cases facility for (co)inductive definitions.
wenzelm
parents:
diff changeset
    34
  let
18678
dd0c569fa43d sane ERROR handling;
wenzelm
parents: 18418
diff changeset
    35
    fun err msg = cat_error msg ("Malformed set membership statement: " ^ s);
dd0c569fa43d sane ERROR handling;
wenzelm
parents: 18418
diff changeset
    36
    val A = read_prop s handle ERROR msg => err msg;
12174
a0aab0b9f2e9 Generic inductive cases facility for (co)inductive definitions.
wenzelm
parents:
diff changeset
    37
    val c = #1 (Term.dest_Const (Term.head_of (#2 (Ind_Syntax.dest_mem (FOLogic.dest_Trueprop
18678
dd0c569fa43d sane ERROR handling;
wenzelm
parents: 18418
diff changeset
    38
      (Logic.strip_imp_concl A)))))) handle TERM _ => err "";
12174
a0aab0b9f2e9 Generic inductive cases facility for (co)inductive definitions.
wenzelm
parents:
diff changeset
    39
  in
17412
e26cb20ef0cc TableFun/Symtab: curried lookup and update;
wenzelm
parents: 17224
diff changeset
    40
    (case Symtab.lookup (IndCasesData.get thy) c of
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15032
diff changeset
    41
      NONE => error ("Unknown inductive cases rule for set " ^ quote c)
20342
wenzelm
parents: 18799
diff changeset
    42
    | SOME f => f ss (Thm.cterm_of thy A))
12174
a0aab0b9f2e9 Generic inductive cases facility for (co)inductive definitions.
wenzelm
parents:
diff changeset
    43
  end;
a0aab0b9f2e9 Generic inductive cases facility for (co)inductive definitions.
wenzelm
parents:
diff changeset
    44
a0aab0b9f2e9 Generic inductive cases facility for (co)inductive definitions.
wenzelm
parents:
diff changeset
    45
a0aab0b9f2e9 Generic inductive cases facility for (co)inductive definitions.
wenzelm
parents:
diff changeset
    46
(* inductive_cases command *)
a0aab0b9f2e9 Generic inductive cases facility for (co)inductive definitions.
wenzelm
parents:
diff changeset
    47
12609
fb073a34b537 'inductive_cases': support 'and' form;
wenzelm
parents: 12311
diff changeset
    48
fun inductive_cases args thy =
12174
a0aab0b9f2e9 Generic inductive cases facility for (co)inductive definitions.
wenzelm
parents:
diff changeset
    49
  let
24508
c8b82fec6447 replaced ProofContext.read_term/prop by general Syntax.read_term/prop;
wenzelm
parents: 22846
diff changeset
    50
    val read_prop = Syntax.read_prop (ProofContext.init thy);
12609
fb073a34b537 'inductive_cases': support 'and' form;
wenzelm
parents: 12311
diff changeset
    51
    val mk_cases = smart_cases thy (Simplifier.simpset_of thy) read_prop;
fb073a34b537 'inductive_cases': support 'and' form;
wenzelm
parents: 12311
diff changeset
    52
    val facts = args |> map (fn ((name, srcs), props) =>
18728
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
    53
      ((name, map (Attrib.attribute thy) srcs),
12876
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12716
diff changeset
    54
        map (Thm.no_attributes o single o mk_cases) props));
27691
ce171cbd4b93 PureThy: dropped note_thmss_qualified, dropped _i suffix
haftmann
parents: 24867
diff changeset
    55
  in thy |> PureThy.note_thmss "" facts |> snd end;
12174
a0aab0b9f2e9 Generic inductive cases facility for (co)inductive definitions.
wenzelm
parents:
diff changeset
    56
a0aab0b9f2e9 Generic inductive cases facility for (co)inductive definitions.
wenzelm
parents:
diff changeset
    57
a0aab0b9f2e9 Generic inductive cases facility for (co)inductive definitions.
wenzelm
parents:
diff changeset
    58
(* ind_cases method *)
a0aab0b9f2e9 Generic inductive cases facility for (co)inductive definitions.
wenzelm
parents:
diff changeset
    59
a0aab0b9f2e9 Generic inductive cases facility for (co)inductive definitions.
wenzelm
parents:
diff changeset
    60
val setup =
30722
623d4831c8cf simplified attribute and method setup: eliminating bottom-up styles makes it easier to keep things in one place, and also SML/NJ happy;
wenzelm
parents: 30515
diff changeset
    61
  Method.setup @{binding "ind_cases"}
623d4831c8cf simplified attribute and method setup: eliminating bottom-up styles makes it easier to keep things in one place, and also SML/NJ happy;
wenzelm
parents: 30515
diff changeset
    62
    (Scan.lift (Scan.repeat1 Args.name_source) >>
623d4831c8cf simplified attribute and method setup: eliminating bottom-up styles makes it easier to keep things in one place, and also SML/NJ happy;
wenzelm
parents: 30515
diff changeset
    63
      (fn props => fn ctxt =>
623d4831c8cf simplified attribute and method setup: eliminating bottom-up styles makes it easier to keep things in one place, and also SML/NJ happy;
wenzelm
parents: 30515
diff changeset
    64
        props
623d4831c8cf simplified attribute and method setup: eliminating bottom-up styles makes it easier to keep things in one place, and also SML/NJ happy;
wenzelm
parents: 30515
diff changeset
    65
        |> map (smart_cases (ProofContext.theory_of ctxt) (local_simpset_of ctxt) (Syntax.read_prop ctxt))
623d4831c8cf simplified attribute and method setup: eliminating bottom-up styles makes it easier to keep things in one place, and also SML/NJ happy;
wenzelm
parents: 30515
diff changeset
    66
        |> Method.erule 0))
623d4831c8cf simplified attribute and method setup: eliminating bottom-up styles makes it easier to keep things in one place, and also SML/NJ happy;
wenzelm
parents: 30515
diff changeset
    67
    "dynamic case analysis on sets";
12174
a0aab0b9f2e9 Generic inductive cases facility for (co)inductive definitions.
wenzelm
parents:
diff changeset
    68
a0aab0b9f2e9 Generic inductive cases facility for (co)inductive definitions.
wenzelm
parents:
diff changeset
    69
a0aab0b9f2e9 Generic inductive cases facility for (co)inductive definitions.
wenzelm
parents:
diff changeset
    70
(* outer syntax *)
a0aab0b9f2e9 Generic inductive cases facility for (co)inductive definitions.
wenzelm
parents:
diff changeset
    71
17057
0934ac31985f OuterKeyword;
wenzelm
parents: 16424
diff changeset
    72
local structure P = OuterParse and K = OuterKeyword in
12174
a0aab0b9f2e9 Generic inductive cases facility for (co)inductive definitions.
wenzelm
parents:
diff changeset
    73
24867
e5b55d7be9bb simplified interfaces for outer syntax;
wenzelm
parents: 24508
diff changeset
    74
val _ =
12174
a0aab0b9f2e9 Generic inductive cases facility for (co)inductive definitions.
wenzelm
parents:
diff changeset
    75
  OuterSyntax.command "inductive_cases"
24867
e5b55d7be9bb simplified interfaces for outer syntax;
wenzelm
parents: 24508
diff changeset
    76
    "create simplified instances of elimination rules (improper)" K.thy_script
e5b55d7be9bb simplified interfaces for outer syntax;
wenzelm
parents: 24508
diff changeset
    77
    (P.and_list1 (SpecParse.opt_thm_name ":" -- Scan.repeat1 P.prop)
e5b55d7be9bb simplified interfaces for outer syntax;
wenzelm
parents: 24508
diff changeset
    78
      >> (Toplevel.theory o inductive_cases));
12174
a0aab0b9f2e9 Generic inductive cases facility for (co)inductive definitions.
wenzelm
parents:
diff changeset
    79
a0aab0b9f2e9 Generic inductive cases facility for (co)inductive definitions.
wenzelm
parents:
diff changeset
    80
end;
a0aab0b9f2e9 Generic inductive cases facility for (co)inductive definitions.
wenzelm
parents:
diff changeset
    81
a0aab0b9f2e9 Generic inductive cases facility for (co)inductive definitions.
wenzelm
parents:
diff changeset
    82
end;
15705
b5edb9dcec9a *** MESSAGE REFERS TO PREVIOUS VERSION ***
wenzelm
parents: 15703
diff changeset
    83