src/HOL/Sum.ML
author wenzelm
Mon Jun 22 17:26:46 1998 +0200 (1998-06-22)
changeset 5069 3ea049f7979d
parent 4988 8f4dc836a2ea
child 5143 b94cd208f073
permissions -rw-r--r--
isatool fixgoal;
clasohm@1465
     1
(*  Title:      HOL/Sum.ML
clasohm@923
     2
    ID:         $Id$
clasohm@1465
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
clasohm@923
     4
    Copyright   1991  University of Cambridge
clasohm@923
     5
clasohm@923
     6
For Sum.thy.  The disjoint sum of two types
clasohm@923
     7
*)
clasohm@923
     8
clasohm@923
     9
open Sum;
clasohm@923
    10
clasohm@923
    11
(** Inl_Rep and Inr_Rep: Representations of the constructors **)
clasohm@923
    12
clasohm@923
    13
(*This counts as a non-emptiness result for admitting 'a+'b as a type*)
wenzelm@5069
    14
Goalw [Sum_def] "Inl_Rep(a) : Sum";
clasohm@923
    15
by (EVERY1 [rtac CollectI, rtac disjI1, rtac exI, rtac refl]);
clasohm@923
    16
qed "Inl_RepI";
clasohm@923
    17
wenzelm@5069
    18
Goalw [Sum_def] "Inr_Rep(b) : Sum";
clasohm@923
    19
by (EVERY1 [rtac CollectI, rtac disjI2, rtac exI, rtac refl]);
clasohm@923
    20
qed "Inr_RepI";
clasohm@923
    21
wenzelm@5069
    22
Goal "inj_on Abs_Sum Sum";
nipkow@4830
    23
by (rtac inj_on_inverseI 1);
clasohm@923
    24
by (etac Abs_Sum_inverse 1);
nipkow@4830
    25
qed "inj_on_Abs_Sum";
clasohm@923
    26
clasohm@923
    27
(** Distinctness of Inl and Inr **)
clasohm@923
    28
wenzelm@5069
    29
Goalw [Inl_Rep_def, Inr_Rep_def] "Inl_Rep(a) ~= Inr_Rep(b)";
clasohm@923
    30
by (EVERY1 [rtac notI,
clasohm@1465
    31
            etac (fun_cong RS fun_cong RS fun_cong RS iffE), 
clasohm@1465
    32
            rtac (notE RS ccontr),  etac (mp RS conjunct2), 
clasohm@1465
    33
            REPEAT o (ares_tac [refl,conjI]) ]);
clasohm@923
    34
qed "Inl_Rep_not_Inr_Rep";
clasohm@923
    35
wenzelm@5069
    36
Goalw [Inl_def,Inr_def] "Inl(a) ~= Inr(b)";
nipkow@4830
    37
by (rtac (inj_on_Abs_Sum RS inj_on_contraD) 1);
clasohm@923
    38
by (rtac Inl_Rep_not_Inr_Rep 1);
clasohm@923
    39
by (rtac Inl_RepI 1);
clasohm@923
    40
by (rtac Inr_RepI 1);
clasohm@923
    41
qed "Inl_not_Inr";
clasohm@923
    42
paulson@1985
    43
bind_thm ("Inr_not_Inl", Inl_not_Inr RS not_sym);
paulson@1985
    44
paulson@1985
    45
AddIffs [Inl_not_Inr, Inr_not_Inl];
clasohm@923
    46
paulson@1985
    47
bind_thm ("Inl_neq_Inr", Inl_not_Inr RS notE);
clasohm@923
    48
paulson@1985
    49
val Inr_neq_Inl = sym RS Inl_neq_Inr;
clasohm@923
    50
clasohm@923
    51
clasohm@923
    52
(** Injectiveness of Inl and Inr **)
clasohm@923
    53
clasohm@923
    54
val [major] = goalw Sum.thy [Inl_Rep_def] "Inl_Rep(a) = Inl_Rep(c) ==> a=c";
clasohm@923
    55
by (rtac (major RS fun_cong RS fun_cong RS fun_cong RS iffE) 1);
paulson@2891
    56
by (Blast_tac 1);
clasohm@923
    57
qed "Inl_Rep_inject";
clasohm@923
    58
clasohm@923
    59
val [major] = goalw Sum.thy [Inr_Rep_def] "Inr_Rep(b) = Inr_Rep(d) ==> b=d";
clasohm@923
    60
by (rtac (major RS fun_cong RS fun_cong RS fun_cong RS iffE) 1);
paulson@2891
    61
by (Blast_tac 1);
clasohm@923
    62
qed "Inr_Rep_inject";
clasohm@923
    63
wenzelm@5069
    64
Goalw [Inl_def] "inj(Inl)";
clasohm@923
    65
by (rtac injI 1);
nipkow@4830
    66
by (etac (inj_on_Abs_Sum RS inj_onD RS Inl_Rep_inject) 1);
clasohm@923
    67
by (rtac Inl_RepI 1);
clasohm@923
    68
by (rtac Inl_RepI 1);
clasohm@923
    69
qed "inj_Inl";
clasohm@923
    70
val Inl_inject = inj_Inl RS injD;
clasohm@923
    71
wenzelm@5069
    72
Goalw [Inr_def] "inj(Inr)";
clasohm@923
    73
by (rtac injI 1);
nipkow@4830
    74
by (etac (inj_on_Abs_Sum RS inj_onD RS Inr_Rep_inject) 1);
clasohm@923
    75
by (rtac Inr_RepI 1);
clasohm@923
    76
by (rtac Inr_RepI 1);
clasohm@923
    77
qed "inj_Inr";
clasohm@923
    78
val Inr_inject = inj_Inr RS injD;
clasohm@923
    79
wenzelm@5069
    80
Goal "(Inl(x)=Inl(y)) = (x=y)";
wenzelm@4089
    81
by (blast_tac (claset() addSDs [Inl_inject]) 1);
clasohm@923
    82
qed "Inl_eq";
clasohm@923
    83
wenzelm@5069
    84
Goal "(Inr(x)=Inr(y)) = (x=y)";
wenzelm@4089
    85
by (blast_tac (claset() addSDs [Inr_inject]) 1);
clasohm@923
    86
qed "Inr_eq";
clasohm@923
    87
paulson@1985
    88
AddIffs [Inl_eq, Inr_eq];
paulson@1985
    89
clasohm@923
    90
(*** Rules for the disjoint sum of two SETS ***)
clasohm@923
    91
clasohm@923
    92
(** Introduction rules for the injections **)
clasohm@923
    93
wenzelm@5069
    94
Goalw [sum_def] "!!a A B. a : A ==> Inl(a) : A Plus B";
paulson@2891
    95
by (Blast_tac 1);
clasohm@923
    96
qed "InlI";
clasohm@923
    97
wenzelm@5069
    98
Goalw [sum_def] "!!b A B. b : B ==> Inr(b) : A Plus B";
paulson@2891
    99
by (Blast_tac 1);
clasohm@923
   100
qed "InrI";
clasohm@923
   101
clasohm@923
   102
(** Elimination rules **)
clasohm@923
   103
clasohm@923
   104
val major::prems = goalw Sum.thy [sum_def]
nipkow@2212
   105
    "[| u: A Plus B;  \
clasohm@923
   106
\       !!x. [| x:A;  u=Inl(x) |] ==> P; \
clasohm@923
   107
\       !!y. [| y:B;  u=Inr(y) |] ==> P \
clasohm@923
   108
\    |] ==> P";
clasohm@923
   109
by (rtac (major RS UnE) 1);
clasohm@923
   110
by (REPEAT (rtac refl 1
clasohm@923
   111
     ORELSE eresolve_tac (prems@[imageE,ssubst]) 1));
nipkow@2212
   112
qed "PlusE";
clasohm@923
   113
clasohm@923
   114
berghofe@1760
   115
AddSIs [InlI, InrI]; 
nipkow@2212
   116
AddSEs [PlusE];
berghofe@1760
   117
clasohm@923
   118
clasohm@923
   119
(** sum_case -- the selection operator for sums **)
clasohm@923
   120
wenzelm@5069
   121
Goalw [sum_case_def] "sum_case f g (Inl x) = f(x)";
oheimb@4535
   122
by (Blast_tac 1);
clasohm@923
   123
qed "sum_case_Inl";
clasohm@923
   124
wenzelm@5069
   125
Goalw [sum_case_def] "sum_case f g (Inr x) = g(x)";
oheimb@4535
   126
by (Blast_tac 1);
clasohm@923
   127
qed "sum_case_Inr";
clasohm@923
   128
paulson@1985
   129
Addsimps [sum_case_Inl, sum_case_Inr];
paulson@1985
   130
clasohm@923
   131
(** Exhaustion rule for sums -- a degenerate form of induction **)
clasohm@923
   132
clasohm@923
   133
val prems = goalw Sum.thy [Inl_def,Inr_def]
clasohm@923
   134
    "[| !!x::'a. s = Inl(x) ==> P;  !!y::'b. s = Inr(y) ==> P \
clasohm@923
   135
\    |] ==> P";
clasohm@923
   136
by (rtac (rewrite_rule [Sum_def] Rep_Sum RS CollectE) 1);
clasohm@923
   137
by (REPEAT (eresolve_tac [disjE,exE] 1
clasohm@923
   138
     ORELSE EVERY1 [resolve_tac prems, 
clasohm@1465
   139
                    etac subst,
clasohm@1465
   140
                    rtac (Rep_Sum_inverse RS sym)]));
clasohm@923
   141
qed "sumE";
clasohm@923
   142
wenzelm@5069
   143
Goal "sum_case (%x::'a. f(Inl x)) (%y::'b. f(Inr y)) s = f(s)";
clasohm@923
   144
by (EVERY1 [res_inst_tac [("s","s")] sumE, 
clasohm@1465
   145
            etac ssubst, rtac sum_case_Inl,
clasohm@1465
   146
            etac ssubst, rtac sum_case_Inr]);
clasohm@923
   147
qed "surjective_sum";
clasohm@923
   148
wenzelm@5069
   149
Goal "R(sum_case f g s) = \
clasohm@923
   150
\             ((! x. s = Inl(x) --> R(f(x))) & (! y. s = Inr(y) --> R(g(y))))";
paulson@1985
   151
by (res_inst_tac [("s","s")] sumE 1);
paulson@4477
   152
by Auto_tac;
nipkow@4830
   153
qed "split_sum_case";
clasohm@923
   154
oheimb@4988
   155
qed_goal "split_sum_case_asm" Sum.thy "P (sum_case f g s) = \
oheimb@4988
   156
\ (~((? x. s = Inl x & ~P (f x)) | (? y. s = Inr y & ~P (g y))))"
oheimb@4988
   157
    (K [stac split_sum_case 1,
oheimb@4988
   158
	Blast_tac 1]);
oheimb@4988
   159
clasohm@923
   160
(*Prevents simplification of f and g: much faster*)
clasohm@923
   161
qed_goal "sum_case_weak_cong" Sum.thy
clasohm@923
   162
  "s=t ==> sum_case f g s = sum_case f g t"
clasohm@923
   163
  (fn [prem] => [rtac (prem RS arg_cong) 1]);
clasohm@923
   164
clasohm@923
   165
clasohm@923
   166
clasohm@923
   167
(** Rules for the Part primitive **)
clasohm@923
   168
wenzelm@5069
   169
Goalw [Part_def]
clasohm@923
   170
    "!!a b A h. [| a : A;  a=h(b) |] ==> a : Part A h";
paulson@2891
   171
by (Blast_tac 1);
clasohm@923
   172
qed "Part_eqI";
clasohm@923
   173
clasohm@923
   174
val PartI = refl RSN (2,Part_eqI);
clasohm@923
   175
clasohm@923
   176
val major::prems = goalw Sum.thy [Part_def]
clasohm@923
   177
    "[| a : Part A h;  !!z. [| a : A;  a=h(z) |] ==> P  \
clasohm@923
   178
\    |] ==> P";
clasohm@923
   179
by (rtac (major RS IntE) 1);
clasohm@923
   180
by (etac CollectE 1);
clasohm@923
   181
by (etac exE 1);
clasohm@923
   182
by (REPEAT (ares_tac prems 1));
clasohm@923
   183
qed "PartE";
clasohm@923
   184
paulson@2891
   185
AddIs  [Part_eqI];
paulson@2891
   186
AddSEs [PartE];
paulson@2891
   187
wenzelm@5069
   188
Goalw [Part_def] "Part A h <= A";
clasohm@923
   189
by (rtac Int_lower1 1);
clasohm@923
   190
qed "Part_subset";
clasohm@923
   191
wenzelm@5069
   192
Goal "!!A B. A<=B ==> Part A h <= Part B h";
paulson@2922
   193
by (Blast_tac 1);
clasohm@923
   194
qed "Part_mono";
clasohm@923
   195
nipkow@1515
   196
val basic_monos = basic_monos @ [Part_mono];
nipkow@1515
   197
wenzelm@5069
   198
Goalw [Part_def] "!!a. a : Part A h ==> a : A";
clasohm@923
   199
by (etac IntD1 1);
clasohm@923
   200
qed "PartD1";
clasohm@923
   201
wenzelm@5069
   202
Goal "Part A (%x. x) = A";
paulson@2891
   203
by (Blast_tac 1);
clasohm@923
   204
qed "Part_id";
clasohm@923
   205
wenzelm@5069
   206
Goal "Part (A Int B) h = (Part A h) Int (Part B h)";
paulson@2922
   207
by (Blast_tac 1);
lcp@1188
   208
qed "Part_Int";
lcp@1188
   209
lcp@1188
   210
(*For inductive definitions*)
wenzelm@5069
   211
Goal "Part (A Int {x. P x}) h = (Part A h) Int {x. P x}";
paulson@2922
   212
by (Blast_tac 1);
lcp@1188
   213
qed "Part_Collect";