src/HOL/Sum_Type.thy
author nipkow
Fri Mar 06 17:38:47 2009 +0100 (2009-03-06)
changeset 30313 b2441b0c8d38
parent 29183 f1648e009dc1
child 31080 21ffc770ebc0
permissions -rw-r--r--
added lemmas
nipkow@10213
     1
(*  Title:      HOL/Sum_Type.thy
nipkow@10213
     2
    ID:         $Id$
nipkow@10213
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
nipkow@10213
     4
    Copyright   1992  University of Cambridge
nipkow@10213
     5
*)
nipkow@10213
     6
paulson@15391
     7
header{*The Disjoint Sum of Two Types*}
nipkow@10213
     8
paulson@15391
     9
theory Sum_Type
haftmann@22424
    10
imports Typedef Fun
paulson@15391
    11
begin
paulson@15391
    12
paulson@15391
    13
text{*The representations of the two injections*}
nipkow@10213
    14
nipkow@10213
    15
constdefs
paulson@15391
    16
  Inl_Rep :: "['a, 'a, 'b, bool] => bool"
nipkow@10213
    17
  "Inl_Rep == (%a. %x y p. x=a & p)"
nipkow@10213
    18
paulson@15391
    19
  Inr_Rep :: "['b, 'a, 'b, bool] => bool"
nipkow@10213
    20
  "Inr_Rep == (%b. %x y p. y=b & ~p)"
nipkow@10213
    21
paulson@15391
    22
nipkow@10213
    23
global
nipkow@10213
    24
nipkow@10213
    25
typedef (Sum)
haftmann@22838
    26
  ('a, 'b) "+"          (infixr "+" 10)
nipkow@10213
    27
    = "{f. (? a. f = Inl_Rep(a::'a)) | (? b. f = Inr_Rep(b::'b))}"
paulson@15391
    28
  by auto
nipkow@10213
    29
nipkow@10213
    30
local
nipkow@10213
    31
paulson@15391
    32
paulson@15391
    33
text{*abstract constants and syntax*}
paulson@15391
    34
paulson@15391
    35
constdefs
paulson@15391
    36
  Inl :: "'a => 'a + 'b"
paulson@15391
    37
   "Inl == (%a. Abs_Sum(Inl_Rep(a)))"
paulson@15391
    38
paulson@15391
    39
  Inr :: "'b => 'a + 'b"
paulson@15391
    40
   "Inr == (%b. Abs_Sum(Inr_Rep(b)))"
paulson@15391
    41
paulson@15391
    42
  Plus :: "['a set, 'b set] => ('a + 'b) set"        (infixr "<+>" 65)
paulson@15391
    43
   "A <+> B == (Inl`A) Un (Inr`B)"
paulson@15391
    44
    --{*disjoint sum for sets; the operator + is overloaded with wrong type!*}
paulson@15391
    45
paulson@15391
    46
  Part :: "['a set, 'b => 'a] => 'a set"
paulson@15391
    47
   "Part A h == A Int {x. ? z. x = h(z)}"
paulson@15391
    48
    --{*for selecting out the components of a mutually recursive definition*}
paulson@15391
    49
paulson@15391
    50
paulson@15391
    51
paulson@15391
    52
(** Inl_Rep and Inr_Rep: Representations of the constructors **)
paulson@15391
    53
paulson@15391
    54
(*This counts as a non-emptiness result for admitting 'a+'b as a type*)
paulson@15391
    55
lemma Inl_RepI: "Inl_Rep(a) : Sum"
paulson@15391
    56
by (auto simp add: Sum_def)
paulson@15391
    57
paulson@15391
    58
lemma Inr_RepI: "Inr_Rep(b) : Sum"
paulson@15391
    59
by (auto simp add: Sum_def)
paulson@15391
    60
paulson@15391
    61
lemma inj_on_Abs_Sum: "inj_on Abs_Sum Sum"
paulson@15391
    62
apply (rule inj_on_inverseI)
paulson@15391
    63
apply (erule Abs_Sum_inverse)
paulson@15391
    64
done
paulson@15391
    65
paulson@15391
    66
subsection{*Freeness Properties for @{term Inl} and  @{term Inr}*}
paulson@15391
    67
paulson@15391
    68
text{*Distinctness*}
paulson@15391
    69
paulson@15391
    70
lemma Inl_Rep_not_Inr_Rep: "Inl_Rep(a) ~= Inr_Rep(b)"
paulson@15391
    71
by (auto simp add: Inl_Rep_def Inr_Rep_def expand_fun_eq)
paulson@15391
    72
paulson@15391
    73
lemma Inl_not_Inr [iff]: "Inl(a) ~= Inr(b)"
paulson@15391
    74
apply (simp add: Inl_def Inr_def)
paulson@15391
    75
apply (rule inj_on_Abs_Sum [THEN inj_on_contraD])
paulson@15391
    76
apply (rule Inl_Rep_not_Inr_Rep)
paulson@15391
    77
apply (rule Inl_RepI)
paulson@15391
    78
apply (rule Inr_RepI)
paulson@15391
    79
done
paulson@15391
    80
paulson@17084
    81
lemmas Inr_not_Inl = Inl_not_Inr [THEN not_sym, standard]
paulson@17084
    82
declare Inr_not_Inl [iff]
paulson@15391
    83
paulson@15391
    84
lemmas Inl_neq_Inr = Inl_not_Inr [THEN notE, standard]
paulson@15391
    85
lemmas Inr_neq_Inl = sym [THEN Inl_neq_Inr, standard]
paulson@15391
    86
paulson@15391
    87
paulson@15391
    88
text{*Injectiveness*}
paulson@15391
    89
paulson@15391
    90
lemma Inl_Rep_inject: "Inl_Rep(a) = Inl_Rep(c) ==> a=c"
paulson@15391
    91
by (auto simp add: Inl_Rep_def expand_fun_eq)
paulson@15391
    92
paulson@15391
    93
lemma Inr_Rep_inject: "Inr_Rep(b) = Inr_Rep(d) ==> b=d"
paulson@15391
    94
by (auto simp add: Inr_Rep_def expand_fun_eq)
paulson@15391
    95
huffman@29025
    96
lemma inj_Inl [simp]: "inj_on Inl A"
paulson@15391
    97
apply (simp add: Inl_def)
paulson@15391
    98
apply (rule inj_onI)
paulson@15391
    99
apply (erule inj_on_Abs_Sum [THEN inj_onD, THEN Inl_Rep_inject])
paulson@15391
   100
apply (rule Inl_RepI)
paulson@15391
   101
apply (rule Inl_RepI)
paulson@15391
   102
done
huffman@29025
   103
paulson@15391
   104
lemmas Inl_inject = inj_Inl [THEN injD, standard]
paulson@15391
   105
huffman@29025
   106
lemma inj_Inr [simp]: "inj_on Inr A"
paulson@15391
   107
apply (simp add: Inr_def)
paulson@15391
   108
apply (rule inj_onI)
paulson@15391
   109
apply (erule inj_on_Abs_Sum [THEN inj_onD, THEN Inr_Rep_inject])
paulson@15391
   110
apply (rule Inr_RepI)
paulson@15391
   111
apply (rule Inr_RepI)
paulson@15391
   112
done
paulson@15391
   113
paulson@15391
   114
lemmas Inr_inject = inj_Inr [THEN injD, standard]
paulson@15391
   115
paulson@15391
   116
lemma Inl_eq [iff]: "(Inl(x)=Inl(y)) = (x=y)"
paulson@15391
   117
by (blast dest!: Inl_inject)
paulson@15391
   118
paulson@15391
   119
lemma Inr_eq [iff]: "(Inr(x)=Inr(y)) = (x=y)"
paulson@15391
   120
by (blast dest!: Inr_inject)
paulson@15391
   121
paulson@15391
   122
paulson@15391
   123
subsection{*The Disjoint Sum of Sets*}
paulson@15391
   124
paulson@15391
   125
(** Introduction rules for the injections **)
nipkow@10213
   126
paulson@15391
   127
lemma InlI [intro!]: "a : A ==> Inl(a) : A <+> B"
paulson@15391
   128
by (simp add: Plus_def)
paulson@15391
   129
paulson@15391
   130
lemma InrI [intro!]: "b : B ==> Inr(b) : A <+> B"
paulson@15391
   131
by (simp add: Plus_def)
paulson@15391
   132
paulson@15391
   133
(** Elimination rules **)
paulson@15391
   134
paulson@15391
   135
lemma PlusE [elim!]: 
paulson@15391
   136
    "[| u: A <+> B;   
paulson@15391
   137
        !!x. [| x:A;  u=Inl(x) |] ==> P;  
paulson@15391
   138
        !!y. [| y:B;  u=Inr(y) |] ==> P  
paulson@15391
   139
     |] ==> P"
paulson@15391
   140
by (auto simp add: Plus_def)
paulson@15391
   141
paulson@15391
   142
paulson@15391
   143
paulson@15391
   144
text{*Exhaustion rule for sums, a degenerate form of induction*}
paulson@15391
   145
lemma sumE: 
paulson@15391
   146
    "[| !!x::'a. s = Inl(x) ==> P;  !!y::'b. s = Inr(y) ==> P  
paulson@15391
   147
     |] ==> P"
paulson@15391
   148
apply (rule Abs_Sum_cases [of s]) 
paulson@15391
   149
apply (auto simp add: Sum_def Inl_def Inr_def)
paulson@15391
   150
done
paulson@15391
   151
paulson@15391
   152
nipkow@17026
   153
lemma UNIV_Plus_UNIV [simp]: "UNIV <+> UNIV = UNIV"
nipkow@17026
   154
apply (rule set_ext)
nipkow@17026
   155
apply(rename_tac s)
nipkow@17026
   156
apply(rule_tac s=s in sumE)
nipkow@17026
   157
apply auto
nipkow@17026
   158
done
nipkow@17026
   159
nipkow@17026
   160
paulson@15391
   161
subsection{*The @{term Part} Primitive*}
paulson@15391
   162
paulson@15391
   163
lemma Part_eqI [intro]: "[| a : A;  a=h(b) |] ==> a : Part A h"
paulson@15391
   164
by (auto simp add: Part_def)
paulson@15391
   165
paulson@15391
   166
lemmas PartI = Part_eqI [OF _ refl, standard]
paulson@15391
   167
paulson@15391
   168
lemma PartE [elim!]: "[| a : Part A h;  !!z. [| a : A;  a=h(z) |] ==> P |] ==> P"
paulson@15391
   169
by (auto simp add: Part_def)
paulson@15391
   170
paulson@15391
   171
paulson@15391
   172
lemma Part_subset: "Part A h <= A"
paulson@15391
   173
by (auto simp add: Part_def)
paulson@15391
   174
paulson@15391
   175
lemma Part_mono: "A<=B ==> Part A h <= Part B h"
paulson@15391
   176
by blast
paulson@15391
   177
paulson@15391
   178
lemmas basic_monos = basic_monos Part_mono
nipkow@10213
   179
paulson@15391
   180
lemma PartD1: "a : Part A h ==> a : A"
paulson@15391
   181
by (simp add: Part_def)
paulson@15391
   182
paulson@15391
   183
lemma Part_id: "Part A (%x. x) = A"
paulson@15391
   184
by blast
paulson@15391
   185
paulson@15391
   186
lemma Part_Int: "Part (A Int B) h = (Part A h) Int (Part B h)"
paulson@15391
   187
by blast
paulson@15391
   188
paulson@15391
   189
lemma Part_Collect: "Part (A Int {x. P x}) h = (Part A h) Int {x. P x}"
paulson@15391
   190
by blast
paulson@15391
   191
haftmann@20588
   192
paulson@15391
   193
ML
paulson@15391
   194
{*
paulson@15391
   195
val Inl_RepI = thm "Inl_RepI";
paulson@15391
   196
val Inr_RepI = thm "Inr_RepI";
paulson@15391
   197
val inj_on_Abs_Sum = thm "inj_on_Abs_Sum";
paulson@15391
   198
val Inl_Rep_not_Inr_Rep = thm "Inl_Rep_not_Inr_Rep";
paulson@15391
   199
val Inl_not_Inr = thm "Inl_not_Inr";
paulson@15391
   200
val Inr_not_Inl = thm "Inr_not_Inl";
paulson@15391
   201
val Inl_neq_Inr = thm "Inl_neq_Inr";
paulson@15391
   202
val Inr_neq_Inl = thm "Inr_neq_Inl";
paulson@15391
   203
val Inl_Rep_inject = thm "Inl_Rep_inject";
paulson@15391
   204
val Inr_Rep_inject = thm "Inr_Rep_inject";
paulson@15391
   205
val inj_Inl = thm "inj_Inl";
paulson@15391
   206
val Inl_inject = thm "Inl_inject";
paulson@15391
   207
val inj_Inr = thm "inj_Inr";
paulson@15391
   208
val Inr_inject = thm "Inr_inject";
paulson@15391
   209
val Inl_eq = thm "Inl_eq";
paulson@15391
   210
val Inr_eq = thm "Inr_eq";
paulson@15391
   211
val InlI = thm "InlI";
paulson@15391
   212
val InrI = thm "InrI";
paulson@15391
   213
val PlusE = thm "PlusE";
paulson@15391
   214
val sumE = thm "sumE";
paulson@15391
   215
val Part_eqI = thm "Part_eqI";
paulson@15391
   216
val PartI = thm "PartI";
paulson@15391
   217
val PartE = thm "PartE";
paulson@15391
   218
val Part_subset = thm "Part_subset";
paulson@15391
   219
val Part_mono = thm "Part_mono";
paulson@15391
   220
val PartD1 = thm "PartD1";
paulson@15391
   221
val Part_id = thm "Part_id";
paulson@15391
   222
val Part_Int = thm "Part_Int";
paulson@15391
   223
val Part_Collect = thm "Part_Collect";
paulson@15391
   224
paulson@15391
   225
val basic_monos = thms "basic_monos";
paulson@15391
   226
*}
paulson@15391
   227
nipkow@10213
   228
end