src/HOL/Datatype.ML
author wenzelm
Sat, 27 Oct 2001 00:00:05 +0200
changeset 11954 3d1780208bf3
parent 9108 9fff97d29837
child 12918 bca45be2d25b
permissions -rw-r--r--
made new-style theory; tuned;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7293
959e060f4a2f Moved sum_case stuff from Sum to Datatype.
berghofe
parents:
diff changeset
     1
(*  Title:      HOL/Datatype.ML
959e060f4a2f Moved sum_case stuff from Sum to Datatype.
berghofe
parents:
diff changeset
     2
    ID:         $Id$
11954
3d1780208bf3 made new-style theory;
wenzelm
parents: 9108
diff changeset
     3
    Author:     Stefan Berghofer and Markus Wenzel, TU Muenchen
3d1780208bf3 made new-style theory;
wenzelm
parents: 9108
diff changeset
     4
    License:    GPL (GNU GENERAL PUBLIC LICENSE)
7293
959e060f4a2f Moved sum_case stuff from Sum to Datatype.
berghofe
parents:
diff changeset
     5
*)
959e060f4a2f Moved sum_case stuff from Sum to Datatype.
berghofe
parents:
diff changeset
     6
11954
3d1780208bf3 made new-style theory;
wenzelm
parents: 9108
diff changeset
     7
(** legacy ML bindings **)
3d1780208bf3 made new-style theory;
wenzelm
parents: 9108
diff changeset
     8
3d1780208bf3 made new-style theory;
wenzelm
parents: 9108
diff changeset
     9
structure bool =
3d1780208bf3 made new-style theory;
wenzelm
parents: 9108
diff changeset
    10
struct
3d1780208bf3 made new-style theory;
wenzelm
parents: 9108
diff changeset
    11
  val distinct = thms "bool.distinct";
3d1780208bf3 made new-style theory;
wenzelm
parents: 9108
diff changeset
    12
  val inject = thms "bool.inject";
3d1780208bf3 made new-style theory;
wenzelm
parents: 9108
diff changeset
    13
  val exhaust = thm "bool.exhaust";
3d1780208bf3 made new-style theory;
wenzelm
parents: 9108
diff changeset
    14
  val cases = thms "bool.cases";
3d1780208bf3 made new-style theory;
wenzelm
parents: 9108
diff changeset
    15
  val split = thm "bool.split";
3d1780208bf3 made new-style theory;
wenzelm
parents: 9108
diff changeset
    16
  val split_asm = thm "bool.split_asm";
3d1780208bf3 made new-style theory;
wenzelm
parents: 9108
diff changeset
    17
  val induct = thm "bool.induct";
3d1780208bf3 made new-style theory;
wenzelm
parents: 9108
diff changeset
    18
  val recs = thms "bool.recs";
3d1780208bf3 made new-style theory;
wenzelm
parents: 9108
diff changeset
    19
  val simps = thms "bool.simps";
3d1780208bf3 made new-style theory;
wenzelm
parents: 9108
diff changeset
    20
  val size = thms "bool.size";
3d1780208bf3 made new-style theory;
wenzelm
parents: 9108
diff changeset
    21
end;
3d1780208bf3 made new-style theory;
wenzelm
parents: 9108
diff changeset
    22
3d1780208bf3 made new-style theory;
wenzelm
parents: 9108
diff changeset
    23
structure sum =
3d1780208bf3 made new-style theory;
wenzelm
parents: 9108
diff changeset
    24
struct
3d1780208bf3 made new-style theory;
wenzelm
parents: 9108
diff changeset
    25
  val distinct = thms "sum.distinct";
3d1780208bf3 made new-style theory;
wenzelm
parents: 9108
diff changeset
    26
  val inject = thms "sum.inject";
3d1780208bf3 made new-style theory;
wenzelm
parents: 9108
diff changeset
    27
  val exhaust = thm "sum.exhaust";
3d1780208bf3 made new-style theory;
wenzelm
parents: 9108
diff changeset
    28
  val cases = thms "sum.cases";
3d1780208bf3 made new-style theory;
wenzelm
parents: 9108
diff changeset
    29
  val split = thm "sum.split";
3d1780208bf3 made new-style theory;
wenzelm
parents: 9108
diff changeset
    30
  val split_asm = thm "sum.split_asm";
3d1780208bf3 made new-style theory;
wenzelm
parents: 9108
diff changeset
    31
  val induct = thm "sum.induct";
3d1780208bf3 made new-style theory;
wenzelm
parents: 9108
diff changeset
    32
  val recs = thms "sum.recs";
3d1780208bf3 made new-style theory;
wenzelm
parents: 9108
diff changeset
    33
  val simps = thms "sum.simps";
3d1780208bf3 made new-style theory;
wenzelm
parents: 9108
diff changeset
    34
  val size = thms "sum.size";
3d1780208bf3 made new-style theory;
wenzelm
parents: 9108
diff changeset
    35
end;
3d1780208bf3 made new-style theory;
wenzelm
parents: 9108
diff changeset
    36
3d1780208bf3 made new-style theory;
wenzelm
parents: 9108
diff changeset
    37
structure unit =
3d1780208bf3 made new-style theory;
wenzelm
parents: 9108
diff changeset
    38
struct
3d1780208bf3 made new-style theory;
wenzelm
parents: 9108
diff changeset
    39
  val distinct = thms "unit.distinct";
3d1780208bf3 made new-style theory;
wenzelm
parents: 9108
diff changeset
    40
  val inject = thms "unit.inject";
3d1780208bf3 made new-style theory;
wenzelm
parents: 9108
diff changeset
    41
  val exhaust = thm "unit.exhaust";
3d1780208bf3 made new-style theory;
wenzelm
parents: 9108
diff changeset
    42
  val cases = thms "unit.cases";
3d1780208bf3 made new-style theory;
wenzelm
parents: 9108
diff changeset
    43
  val split = thm "unit.split";
3d1780208bf3 made new-style theory;
wenzelm
parents: 9108
diff changeset
    44
  val split_asm = thm "unit.split_asm";
3d1780208bf3 made new-style theory;
wenzelm
parents: 9108
diff changeset
    45
  val induct = thm "unit.induct";
3d1780208bf3 made new-style theory;
wenzelm
parents: 9108
diff changeset
    46
  val recs = thms "unit.recs";
3d1780208bf3 made new-style theory;
wenzelm
parents: 9108
diff changeset
    47
  val simps = thms "unit.simps";
3d1780208bf3 made new-style theory;
wenzelm
parents: 9108
diff changeset
    48
  val size = thms "unit.size";
3d1780208bf3 made new-style theory;
wenzelm
parents: 9108
diff changeset
    49
end;
3d1780208bf3 made new-style theory;
wenzelm
parents: 9108
diff changeset
    50
3d1780208bf3 made new-style theory;
wenzelm
parents: 9108
diff changeset
    51
structure prod =
3d1780208bf3 made new-style theory;
wenzelm
parents: 9108
diff changeset
    52
struct
3d1780208bf3 made new-style theory;
wenzelm
parents: 9108
diff changeset
    53
  val distinct = thms "prod.distinct";
3d1780208bf3 made new-style theory;
wenzelm
parents: 9108
diff changeset
    54
  val inject = thms "prod.inject";
3d1780208bf3 made new-style theory;
wenzelm
parents: 9108
diff changeset
    55
  val exhaust = thm "prod.exhaust";
3d1780208bf3 made new-style theory;
wenzelm
parents: 9108
diff changeset
    56
  val cases = thms "prod.cases";
3d1780208bf3 made new-style theory;
wenzelm
parents: 9108
diff changeset
    57
  val split = thm "prod.split";
3d1780208bf3 made new-style theory;
wenzelm
parents: 9108
diff changeset
    58
  val split_asm = thm "prod.split_asm";
3d1780208bf3 made new-style theory;
wenzelm
parents: 9108
diff changeset
    59
  val induct = thm "prod.induct";
3d1780208bf3 made new-style theory;
wenzelm
parents: 9108
diff changeset
    60
  val recs = thms "prod.recs";
3d1780208bf3 made new-style theory;
wenzelm
parents: 9108
diff changeset
    61
  val simps = thms "prod.simps";
3d1780208bf3 made new-style theory;
wenzelm
parents: 9108
diff changeset
    62
  val size = thms "prod.size";
3d1780208bf3 made new-style theory;
wenzelm
parents: 9108
diff changeset
    63
end;
3d1780208bf3 made new-style theory;
wenzelm
parents: 9108
diff changeset
    64
3d1780208bf3 made new-style theory;
wenzelm
parents: 9108
diff changeset
    65
7293
959e060f4a2f Moved sum_case stuff from Sum to Datatype.
berghofe
parents:
diff changeset
    66
(** sum_case -- the selection operator for sums **)
959e060f4a2f Moved sum_case stuff from Sum to Datatype.
berghofe
parents:
diff changeset
    67
959e060f4a2f Moved sum_case stuff from Sum to Datatype.
berghofe
parents:
diff changeset
    68
(*compatibility*)
959e060f4a2f Moved sum_case stuff from Sum to Datatype.
berghofe
parents:
diff changeset
    69
val [sum_case_Inl, sum_case_Inr] = sum.cases;
9108
9fff97d29837 bind_thm(s);
wenzelm
parents: 7293
diff changeset
    70
bind_thm ("sum_case_Inl", sum_case_Inl);
9fff97d29837 bind_thm(s);
wenzelm
parents: 7293
diff changeset
    71
bind_thm ("sum_case_Inr", sum_case_Inr);
7293
959e060f4a2f Moved sum_case stuff from Sum to Datatype.
berghofe
parents:
diff changeset
    72
959e060f4a2f Moved sum_case stuff from Sum to Datatype.
berghofe
parents:
diff changeset
    73
Goal "sum_case (%x::'a. f(Inl x)) (%y::'b. f(Inr y)) s = f(s)";
11954
3d1780208bf3 made new-style theory;
wenzelm
parents: 9108
diff changeset
    74
by (EVERY1 [res_inst_tac [("s","s")] sumE,
7293
959e060f4a2f Moved sum_case stuff from Sum to Datatype.
berghofe
parents:
diff changeset
    75
            etac ssubst, rtac sum_case_Inl,
959e060f4a2f Moved sum_case stuff from Sum to Datatype.
berghofe
parents:
diff changeset
    76
            etac ssubst, rtac sum_case_Inr]);
959e060f4a2f Moved sum_case stuff from Sum to Datatype.
berghofe
parents:
diff changeset
    77
qed "surjective_sum";
959e060f4a2f Moved sum_case stuff from Sum to Datatype.
berghofe
parents:
diff changeset
    78
959e060f4a2f Moved sum_case stuff from Sum to Datatype.
berghofe
parents:
diff changeset
    79
(*Prevents simplification of f and g: much faster*)
959e060f4a2f Moved sum_case stuff from Sum to Datatype.
berghofe
parents:
diff changeset
    80
Goal "s=t ==> sum_case f g s = sum_case f g t";
959e060f4a2f Moved sum_case stuff from Sum to Datatype.
berghofe
parents:
diff changeset
    81
by (etac arg_cong 1);
959e060f4a2f Moved sum_case stuff from Sum to Datatype.
berghofe
parents:
diff changeset
    82
qed "sum_case_weak_cong";
959e060f4a2f Moved sum_case stuff from Sum to Datatype.
berghofe
parents:
diff changeset
    83
959e060f4a2f Moved sum_case stuff from Sum to Datatype.
berghofe
parents:
diff changeset
    84
val [p1,p2] = Goal
959e060f4a2f Moved sum_case stuff from Sum to Datatype.
berghofe
parents:
diff changeset
    85
  "[| sum_case f1 f2 = sum_case g1 g2;  \
959e060f4a2f Moved sum_case stuff from Sum to Datatype.
berghofe
parents:
diff changeset
    86
\     [| f1 = g1; f2 = g2 |] ==> P |] \
959e060f4a2f Moved sum_case stuff from Sum to Datatype.
berghofe
parents:
diff changeset
    87
\  ==> P";
959e060f4a2f Moved sum_case stuff from Sum to Datatype.
berghofe
parents:
diff changeset
    88
by (rtac p2 1);
959e060f4a2f Moved sum_case stuff from Sum to Datatype.
berghofe
parents:
diff changeset
    89
by (rtac ext 1);
959e060f4a2f Moved sum_case stuff from Sum to Datatype.
berghofe
parents:
diff changeset
    90
by (cut_inst_tac [("x","Inl x")] (p1 RS fun_cong) 1);
959e060f4a2f Moved sum_case stuff from Sum to Datatype.
berghofe
parents:
diff changeset
    91
by (Asm_full_simp_tac 1);
959e060f4a2f Moved sum_case stuff from Sum to Datatype.
berghofe
parents:
diff changeset
    92
by (rtac ext 1);
959e060f4a2f Moved sum_case stuff from Sum to Datatype.
berghofe
parents:
diff changeset
    93
by (cut_inst_tac [("x","Inr x")] (p1 RS fun_cong) 1);
959e060f4a2f Moved sum_case stuff from Sum to Datatype.
berghofe
parents:
diff changeset
    94
by (Asm_full_simp_tac 1);
959e060f4a2f Moved sum_case stuff from Sum to Datatype.
berghofe
parents:
diff changeset
    95
qed "sum_case_inject";