src/HOL/Sum.ML
author wenzelm
Thu Jun 22 23:04:34 2000 +0200 (2000-06-22)
changeset 9108 9fff97d29837
parent 7293 959e060f4a2f
child 9311 ab5b24cbaa16
permissions -rw-r--r--
bind_thm(s);
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
paulson@5316
     6
The disjoint sum of two types
clasohm@923
     7
*)
clasohm@923
     8
clasohm@923
     9
(** Inl_Rep and Inr_Rep: Representations of the constructors **)
clasohm@923
    10
clasohm@923
    11
(*This counts as a non-emptiness result for admitting 'a+'b as a type*)
wenzelm@5069
    12
Goalw [Sum_def] "Inl_Rep(a) : Sum";
clasohm@923
    13
by (EVERY1 [rtac CollectI, rtac disjI1, rtac exI, rtac refl]);
clasohm@923
    14
qed "Inl_RepI";
clasohm@923
    15
wenzelm@5069
    16
Goalw [Sum_def] "Inr_Rep(b) : Sum";
clasohm@923
    17
by (EVERY1 [rtac CollectI, rtac disjI2, rtac exI, rtac refl]);
clasohm@923
    18
qed "Inr_RepI";
clasohm@923
    19
wenzelm@5069
    20
Goal "inj_on Abs_Sum Sum";
nipkow@4830
    21
by (rtac inj_on_inverseI 1);
clasohm@923
    22
by (etac Abs_Sum_inverse 1);
nipkow@4830
    23
qed "inj_on_Abs_Sum";
clasohm@923
    24
clasohm@923
    25
(** Distinctness of Inl and Inr **)
clasohm@923
    26
wenzelm@5069
    27
Goalw [Inl_Rep_def, Inr_Rep_def] "Inl_Rep(a) ~= Inr_Rep(b)";
clasohm@923
    28
by (EVERY1 [rtac notI,
clasohm@1465
    29
            etac (fun_cong RS fun_cong RS fun_cong RS iffE), 
clasohm@1465
    30
            rtac (notE RS ccontr),  etac (mp RS conjunct2), 
clasohm@1465
    31
            REPEAT o (ares_tac [refl,conjI]) ]);
clasohm@923
    32
qed "Inl_Rep_not_Inr_Rep";
clasohm@923
    33
wenzelm@5069
    34
Goalw [Inl_def,Inr_def] "Inl(a) ~= Inr(b)";
nipkow@4830
    35
by (rtac (inj_on_Abs_Sum RS inj_on_contraD) 1);
clasohm@923
    36
by (rtac Inl_Rep_not_Inr_Rep 1);
clasohm@923
    37
by (rtac Inl_RepI 1);
clasohm@923
    38
by (rtac Inr_RepI 1);
clasohm@923
    39
qed "Inl_not_Inr";
clasohm@923
    40
paulson@1985
    41
bind_thm ("Inr_not_Inl", Inl_not_Inr RS not_sym);
paulson@1985
    42
paulson@1985
    43
AddIffs [Inl_not_Inr, Inr_not_Inl];
clasohm@923
    44
paulson@1985
    45
bind_thm ("Inl_neq_Inr", Inl_not_Inr RS notE);
wenzelm@9108
    46
bind_thm ("Inr_neq_Inl", sym RS Inl_neq_Inr);
clasohm@923
    47
clasohm@923
    48
clasohm@923
    49
(** Injectiveness of Inl and Inr **)
clasohm@923
    50
paulson@5316
    51
Goalw [Inl_Rep_def] "Inl_Rep(a) = Inl_Rep(c) ==> a=c";
paulson@5316
    52
by (etac (fun_cong RS fun_cong RS fun_cong RS iffE) 1);
paulson@2891
    53
by (Blast_tac 1);
clasohm@923
    54
qed "Inl_Rep_inject";
clasohm@923
    55
paulson@5316
    56
Goalw [Inr_Rep_def] "Inr_Rep(b) = Inr_Rep(d) ==> b=d";
paulson@5316
    57
by (etac (fun_cong RS fun_cong RS fun_cong RS iffE) 1);
paulson@2891
    58
by (Blast_tac 1);
clasohm@923
    59
qed "Inr_Rep_inject";
clasohm@923
    60
wenzelm@5069
    61
Goalw [Inl_def] "inj(Inl)";
clasohm@923
    62
by (rtac injI 1);
nipkow@4830
    63
by (etac (inj_on_Abs_Sum RS inj_onD RS Inl_Rep_inject) 1);
clasohm@923
    64
by (rtac Inl_RepI 1);
clasohm@923
    65
by (rtac Inl_RepI 1);
clasohm@923
    66
qed "inj_Inl";
wenzelm@9108
    67
bind_thm ("Inl_inject", inj_Inl RS injD);
clasohm@923
    68
wenzelm@5069
    69
Goalw [Inr_def] "inj(Inr)";
clasohm@923
    70
by (rtac injI 1);
nipkow@4830
    71
by (etac (inj_on_Abs_Sum RS inj_onD RS Inr_Rep_inject) 1);
clasohm@923
    72
by (rtac Inr_RepI 1);
clasohm@923
    73
by (rtac Inr_RepI 1);
clasohm@923
    74
qed "inj_Inr";
wenzelm@9108
    75
bind_thm ("Inr_inject", inj_Inr RS injD);
clasohm@923
    76
wenzelm@5069
    77
Goal "(Inl(x)=Inl(y)) = (x=y)";
wenzelm@4089
    78
by (blast_tac (claset() addSDs [Inl_inject]) 1);
clasohm@923
    79
qed "Inl_eq";
clasohm@923
    80
wenzelm@5069
    81
Goal "(Inr(x)=Inr(y)) = (x=y)";
wenzelm@4089
    82
by (blast_tac (claset() addSDs [Inr_inject]) 1);
clasohm@923
    83
qed "Inr_eq";
clasohm@923
    84
paulson@1985
    85
AddIffs [Inl_eq, Inr_eq];
paulson@1985
    86
clasohm@923
    87
(*** Rules for the disjoint sum of two SETS ***)
clasohm@923
    88
clasohm@923
    89
(** Introduction rules for the injections **)
clasohm@923
    90
paulson@5143
    91
Goalw [sum_def] "a : A ==> Inl(a) : A Plus B";
paulson@2891
    92
by (Blast_tac 1);
clasohm@923
    93
qed "InlI";
clasohm@923
    94
paulson@5143
    95
Goalw [sum_def] "b : B ==> Inr(b) : A Plus B";
paulson@2891
    96
by (Blast_tac 1);
clasohm@923
    97
qed "InrI";
clasohm@923
    98
clasohm@923
    99
(** Elimination rules **)
clasohm@923
   100
paulson@5316
   101
val major::prems = Goalw [sum_def]
nipkow@2212
   102
    "[| u: A Plus B;  \
clasohm@923
   103
\       !!x. [| x:A;  u=Inl(x) |] ==> P; \
clasohm@923
   104
\       !!y. [| y:B;  u=Inr(y) |] ==> P \
clasohm@923
   105
\    |] ==> P";
clasohm@923
   106
by (rtac (major RS UnE) 1);
clasohm@923
   107
by (REPEAT (rtac refl 1
clasohm@923
   108
     ORELSE eresolve_tac (prems@[imageE,ssubst]) 1));
nipkow@2212
   109
qed "PlusE";
clasohm@923
   110
clasohm@923
   111
berghofe@1760
   112
AddSIs [InlI, InrI]; 
nipkow@2212
   113
AddSEs [PlusE];
berghofe@1760
   114
clasohm@923
   115
clasohm@923
   116
(** Exhaustion rule for sums -- a degenerate form of induction **)
clasohm@923
   117
paulson@5316
   118
val prems = Goalw [Inl_def,Inr_def]
clasohm@923
   119
    "[| !!x::'a. s = Inl(x) ==> P;  !!y::'b. s = Inr(y) ==> P \
clasohm@923
   120
\    |] ==> P";
clasohm@923
   121
by (rtac (rewrite_rule [Sum_def] Rep_Sum RS CollectE) 1);
clasohm@923
   122
by (REPEAT (eresolve_tac [disjE,exE] 1
clasohm@923
   123
     ORELSE EVERY1 [resolve_tac prems, 
clasohm@1465
   124
                    etac subst,
clasohm@1465
   125
                    rtac (Rep_Sum_inverse RS sym)]));
clasohm@923
   126
qed "sumE";
clasohm@923
   127
paulson@5316
   128
val prems = Goal "[| !!x. P (Inl x); !!x. P (Inr x) |] ==> P x";
berghofe@5183
   129
by (res_inst_tac [("s","x")] sumE 1);
berghofe@5183
   130
by (ALLGOALS (hyp_subst_tac THEN' (resolve_tac prems)));
berghofe@5183
   131
qed "sum_induct";
berghofe@5183
   132
clasohm@923
   133
clasohm@923
   134
(** Rules for the Part primitive **)
clasohm@923
   135
paulson@5148
   136
Goalw [Part_def] "[| a : A;  a=h(b) |] ==> a : Part A h";
paulson@2891
   137
by (Blast_tac 1);
clasohm@923
   138
qed "Part_eqI";
clasohm@923
   139
wenzelm@9108
   140
bind_thm ("PartI", refl RSN (2,Part_eqI));
clasohm@923
   141
paulson@5316
   142
val major::prems = Goalw [Part_def]
clasohm@923
   143
    "[| a : Part A h;  !!z. [| a : A;  a=h(z) |] ==> P  \
clasohm@923
   144
\    |] ==> P";
clasohm@923
   145
by (rtac (major RS IntE) 1);
clasohm@923
   146
by (etac CollectE 1);
clasohm@923
   147
by (etac exE 1);
clasohm@923
   148
by (REPEAT (ares_tac prems 1));
clasohm@923
   149
qed "PartE";
clasohm@923
   150
paulson@2891
   151
AddIs  [Part_eqI];
paulson@2891
   152
AddSEs [PartE];
paulson@2891
   153
wenzelm@5069
   154
Goalw [Part_def] "Part A h <= A";
clasohm@923
   155
by (rtac Int_lower1 1);
clasohm@923
   156
qed "Part_subset";
clasohm@923
   157
paulson@5143
   158
Goal "A<=B ==> Part A h <= Part B h";
paulson@2922
   159
by (Blast_tac 1);
clasohm@923
   160
qed "Part_mono";
clasohm@923
   161
nipkow@1515
   162
val basic_monos = basic_monos @ [Part_mono];
nipkow@1515
   163
paulson@5143
   164
Goalw [Part_def] "a : Part A h ==> a : A";
clasohm@923
   165
by (etac IntD1 1);
clasohm@923
   166
qed "PartD1";
clasohm@923
   167
wenzelm@5069
   168
Goal "Part A (%x. x) = A";
paulson@2891
   169
by (Blast_tac 1);
clasohm@923
   170
qed "Part_id";
clasohm@923
   171
wenzelm@5069
   172
Goal "Part (A Int B) h = (Part A h) Int (Part B h)";
paulson@2922
   173
by (Blast_tac 1);
lcp@1188
   174
qed "Part_Int";
lcp@1188
   175
wenzelm@5069
   176
Goal "Part (A Int {x. P x}) h = (Part A h) Int {x. P x}";
paulson@2922
   177
by (Blast_tac 1);
lcp@1188
   178
qed "Part_Collect";