src/HOL/Sum.ML
author berghofe
Thu May 23 15:15:20 1996 +0200 (1996-05-23)
changeset 1761 29e08d527ba1
parent 1760 6f41a494f3b1
child 1985 84cf16192e03
permissions -rw-r--r--
Removed equalityI from some proofs (because it is now included
in the default claset)
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*)
clasohm@923
    14
goalw Sum.thy [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
clasohm@923
    18
goalw Sum.thy [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
clasohm@923
    22
goal Sum.thy "inj_onto Abs_Sum Sum";
clasohm@923
    23
by (rtac inj_onto_inverseI 1);
clasohm@923
    24
by (etac Abs_Sum_inverse 1);
clasohm@923
    25
qed "inj_onto_Abs_Sum";
clasohm@923
    26
clasohm@923
    27
(** Distinctness of Inl and Inr **)
clasohm@923
    28
clasohm@923
    29
goalw Sum.thy [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
clasohm@923
    36
goalw Sum.thy [Inl_def,Inr_def] "Inl(a) ~= Inr(b)";
clasohm@923
    37
by (rtac (inj_onto_Abs_Sum RS inj_onto_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
clasohm@923
    43
bind_thm ("Inl_neq_Inr", (Inl_not_Inr RS notE));
clasohm@923
    44
val Inr_neq_Inl = sym RS Inl_neq_Inr;
clasohm@923
    45
clasohm@923
    46
goal Sum.thy "(Inl(a)=Inr(b)) = False";
clasohm@1264
    47
by (simp_tac (!simpset addsimps [Inl_not_Inr]) 1);
clasohm@923
    48
qed "Inl_Inr_eq";
clasohm@923
    49
clasohm@923
    50
goal Sum.thy "(Inr(b)=Inl(a))  =  False";
clasohm@1264
    51
by (simp_tac (!simpset addsimps [Inl_not_Inr RS not_sym]) 1);
clasohm@923
    52
qed "Inr_Inl_eq";
clasohm@923
    53
clasohm@923
    54
clasohm@923
    55
(** Injectiveness of Inl and Inr **)
clasohm@923
    56
clasohm@923
    57
val [major] = goalw Sum.thy [Inl_Rep_def] "Inl_Rep(a) = Inl_Rep(c) ==> a=c";
clasohm@923
    58
by (rtac (major RS fun_cong RS fun_cong RS fun_cong RS iffE) 1);
berghofe@1760
    59
by (Fast_tac 1);
clasohm@923
    60
qed "Inl_Rep_inject";
clasohm@923
    61
clasohm@923
    62
val [major] = goalw Sum.thy [Inr_Rep_def] "Inr_Rep(b) = Inr_Rep(d) ==> b=d";
clasohm@923
    63
by (rtac (major RS fun_cong RS fun_cong RS fun_cong RS iffE) 1);
berghofe@1760
    64
by (Fast_tac 1);
clasohm@923
    65
qed "Inr_Rep_inject";
clasohm@923
    66
clasohm@923
    67
goalw Sum.thy [Inl_def] "inj(Inl)";
clasohm@923
    68
by (rtac injI 1);
clasohm@923
    69
by (etac (inj_onto_Abs_Sum RS inj_ontoD RS Inl_Rep_inject) 1);
clasohm@923
    70
by (rtac Inl_RepI 1);
clasohm@923
    71
by (rtac Inl_RepI 1);
clasohm@923
    72
qed "inj_Inl";
clasohm@923
    73
val Inl_inject = inj_Inl RS injD;
clasohm@923
    74
clasohm@923
    75
goalw Sum.thy [Inr_def] "inj(Inr)";
clasohm@923
    76
by (rtac injI 1);
clasohm@923
    77
by (etac (inj_onto_Abs_Sum RS inj_ontoD RS Inr_Rep_inject) 1);
clasohm@923
    78
by (rtac Inr_RepI 1);
clasohm@923
    79
by (rtac Inr_RepI 1);
clasohm@923
    80
qed "inj_Inr";
clasohm@923
    81
val Inr_inject = inj_Inr RS injD;
clasohm@923
    82
clasohm@923
    83
goal Sum.thy "(Inl(x)=Inl(y)) = (x=y)";
berghofe@1760
    84
by (fast_tac (!claset addSEs [Inl_inject]) 1);
clasohm@923
    85
qed "Inl_eq";
clasohm@923
    86
clasohm@923
    87
goal Sum.thy "(Inr(x)=Inr(y)) = (x=y)";
berghofe@1760
    88
by (fast_tac (!claset addSEs [Inr_inject]) 1);
clasohm@923
    89
qed "Inr_eq";
clasohm@923
    90
clasohm@923
    91
(*** Rules for the disjoint sum of two SETS ***)
clasohm@923
    92
clasohm@923
    93
(** Introduction rules for the injections **)
clasohm@923
    94
clasohm@923
    95
goalw Sum.thy [sum_def] "!!a A B. a : A ==> Inl(a) : A plus B";
clasohm@923
    96
by (REPEAT (ares_tac [UnI1,imageI] 1));
clasohm@923
    97
qed "InlI";
clasohm@923
    98
clasohm@923
    99
goalw Sum.thy [sum_def] "!!b A B. b : B ==> Inr(b) : A plus B";
clasohm@923
   100
by (REPEAT (ares_tac [UnI2,imageI] 1));
clasohm@923
   101
qed "InrI";
clasohm@923
   102
clasohm@923
   103
(** Elimination rules **)
clasohm@923
   104
clasohm@923
   105
val major::prems = goalw Sum.thy [sum_def]
clasohm@923
   106
    "[| u: A plus B;  \
clasohm@923
   107
\       !!x. [| x:A;  u=Inl(x) |] ==> P; \
clasohm@923
   108
\       !!y. [| y:B;  u=Inr(y) |] ==> P \
clasohm@923
   109
\    |] ==> P";
clasohm@923
   110
by (rtac (major RS UnE) 1);
clasohm@923
   111
by (REPEAT (rtac refl 1
clasohm@923
   112
     ORELSE eresolve_tac (prems@[imageE,ssubst]) 1));
clasohm@923
   113
qed "plusE";
clasohm@923
   114
clasohm@923
   115
clasohm@923
   116
val sum_cs = set_cs addSIs [InlI, InrI] 
clasohm@923
   117
                    addSEs [plusE, Inl_neq_Inr, Inr_neq_Inl]
clasohm@923
   118
                    addSDs [Inl_inject, Inr_inject];
clasohm@923
   119
berghofe@1760
   120
AddSIs [InlI, InrI]; 
berghofe@1760
   121
AddSEs [plusE, Inl_neq_Inr, Inr_neq_Inl];
berghofe@1760
   122
AddSDs [Inl_inject, Inr_inject];
berghofe@1760
   123
clasohm@923
   124
clasohm@923
   125
(** sum_case -- the selection operator for sums **)
clasohm@923
   126
clasohm@923
   127
goalw Sum.thy [sum_case_def] "sum_case f g (Inl x) = f(x)";
berghofe@1760
   128
by (fast_tac (!claset addIs [select_equality]) 1);
clasohm@923
   129
qed "sum_case_Inl";
clasohm@923
   130
clasohm@923
   131
goalw Sum.thy [sum_case_def] "sum_case f g (Inr x) = g(x)";
berghofe@1760
   132
by (fast_tac (!claset addIs [select_equality]) 1);
clasohm@923
   133
qed "sum_case_Inr";
clasohm@923
   134
clasohm@923
   135
(** Exhaustion rule for sums -- a degenerate form of induction **)
clasohm@923
   136
clasohm@923
   137
val prems = goalw Sum.thy [Inl_def,Inr_def]
clasohm@923
   138
    "[| !!x::'a. s = Inl(x) ==> P;  !!y::'b. s = Inr(y) ==> P \
clasohm@923
   139
\    |] ==> P";
clasohm@923
   140
by (rtac (rewrite_rule [Sum_def] Rep_Sum RS CollectE) 1);
clasohm@923
   141
by (REPEAT (eresolve_tac [disjE,exE] 1
clasohm@923
   142
     ORELSE EVERY1 [resolve_tac prems, 
clasohm@1465
   143
                    etac subst,
clasohm@1465
   144
                    rtac (Rep_Sum_inverse RS sym)]));
clasohm@923
   145
qed "sumE";
clasohm@923
   146
clasohm@923
   147
goal Sum.thy "sum_case (%x::'a. f(Inl x)) (%y::'b. f(Inr y)) s = f(s)";
clasohm@923
   148
by (EVERY1 [res_inst_tac [("s","s")] sumE, 
clasohm@1465
   149
            etac ssubst, rtac sum_case_Inl,
clasohm@1465
   150
            etac ssubst, rtac sum_case_Inr]);
clasohm@923
   151
qed "surjective_sum";
clasohm@923
   152
clasohm@923
   153
goal Sum.thy "R(sum_case f g s) = \
clasohm@923
   154
\             ((! x. s = Inl(x) --> R(f(x))) & (! y. s = Inr(y) --> R(g(y))))";
clasohm@923
   155
by (rtac sumE 1);
clasohm@923
   156
by (etac ssubst 1);
clasohm@923
   157
by (stac sum_case_Inl 1);
berghofe@1760
   158
by (fast_tac (!claset addSEs [make_elim Inl_inject, Inl_neq_Inr]) 1);
clasohm@923
   159
by (etac ssubst 1);
clasohm@923
   160
by (stac sum_case_Inr 1);
berghofe@1760
   161
by (fast_tac (!claset addSEs [make_elim Inr_inject, Inr_neq_Inl]) 1);
clasohm@923
   162
qed "expand_sum_case";
clasohm@923
   163
clasohm@1264
   164
Addsimps [Inl_eq, Inr_eq, Inl_Inr_eq, Inr_Inl_eq,  sum_case_Inl, sum_case_Inr];
clasohm@923
   165
clasohm@923
   166
(*Prevents simplification of f and g: much faster*)
clasohm@923
   167
qed_goal "sum_case_weak_cong" Sum.thy
clasohm@923
   168
  "s=t ==> sum_case f g s = sum_case f g t"
clasohm@923
   169
  (fn [prem] => [rtac (prem RS arg_cong) 1]);
clasohm@923
   170
clasohm@923
   171
clasohm@923
   172
clasohm@923
   173
clasohm@923
   174
(** Rules for the Part primitive **)
clasohm@923
   175
clasohm@923
   176
goalw Sum.thy [Part_def]
clasohm@923
   177
    "!!a b A h. [| a : A;  a=h(b) |] ==> a : Part A h";
berghofe@1760
   178
by (Fast_tac 1);
clasohm@923
   179
qed "Part_eqI";
clasohm@923
   180
clasohm@923
   181
val PartI = refl RSN (2,Part_eqI);
clasohm@923
   182
clasohm@923
   183
val major::prems = goalw Sum.thy [Part_def]
clasohm@923
   184
    "[| a : Part A h;  !!z. [| a : A;  a=h(z) |] ==> P  \
clasohm@923
   185
\    |] ==> P";
clasohm@923
   186
by (rtac (major RS IntE) 1);
clasohm@923
   187
by (etac CollectE 1);
clasohm@923
   188
by (etac exE 1);
clasohm@923
   189
by (REPEAT (ares_tac prems 1));
clasohm@923
   190
qed "PartE";
clasohm@923
   191
clasohm@923
   192
goalw Sum.thy [Part_def] "Part A h <= A";
clasohm@923
   193
by (rtac Int_lower1 1);
clasohm@923
   194
qed "Part_subset";
clasohm@923
   195
clasohm@923
   196
goal Sum.thy "!!A B. A<=B ==> Part A h <= Part B h";
berghofe@1760
   197
by (fast_tac (!claset addSIs [PartI] addSEs [PartE]) 1);
clasohm@923
   198
qed "Part_mono";
clasohm@923
   199
nipkow@1515
   200
val basic_monos = basic_monos @ [Part_mono];
nipkow@1515
   201
clasohm@923
   202
goalw Sum.thy [Part_def] "!!a. a : Part A h ==> a : A";
clasohm@923
   203
by (etac IntD1 1);
clasohm@923
   204
qed "PartD1";
clasohm@923
   205
clasohm@923
   206
goal Sum.thy "Part A (%x.x) = A";
berghofe@1761
   207
by (fast_tac (!claset addIs [PartI] addSEs [PartE]) 1);
clasohm@923
   208
qed "Part_id";
clasohm@923
   209
lcp@1188
   210
goal Sum.thy "Part (A Int B) h = (Part A h) Int (Part B h)";
berghofe@1761
   211
by (fast_tac (!claset addIs [PartI] addSEs [PartE]) 1);
lcp@1188
   212
qed "Part_Int";
lcp@1188
   213
lcp@1188
   214
(*For inductive definitions*)
lcp@1188
   215
goal Sum.thy "Part (A Int {x.P x}) h = (Part A h) Int {x.P x}";
berghofe@1761
   216
by (fast_tac (!claset addIs [PartI] addSEs [PartE]) 1);
lcp@1188
   217
qed "Part_Collect";