src/ZF/Sum.thy
author paulson
Wed Feb 19 10:53:27 2003 +0100 (2003-02-19 ago)
changeset 13823 d49ffd9f9662
parent 13356 c9cfe1638bf2
child 16417 9bc16273c2d4
permissions -rw-r--r--
fixed anomalies in the installed classical rules
clasohm@1478
     1
(*  Title:      ZF/sum.thy
clasohm@0
     2
    ID:         $Id$
clasohm@1478
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
clasohm@0
     4
    Copyright   1993  University of Cambridge
clasohm@0
     5
clasohm@0
     6
*)
clasohm@0
     7
paulson@13356
     8
header{*Disjoint Sums*}
paulson@13356
     9
paulson@13240
    10
theory Sum = Bool + equalities:
wenzelm@3923
    11
paulson@13356
    12
text{*And the "Part" primitive for simultaneous recursive type definitions*}
paulson@13356
    13
wenzelm@3923
    14
global
wenzelm@3923
    15
paulson@13240
    16
constdefs
paulson@13240
    17
  sum     :: "[i,i]=>i"                     (infixr "+" 65)
paulson@13240
    18
     "A+B == {0}*A Un {1}*B"
paulson@13240
    19
paulson@13240
    20
  Inl     :: "i=>i"
paulson@13240
    21
     "Inl(a) == <0,a>"
paulson@13240
    22
paulson@13240
    23
  Inr     :: "i=>i"
paulson@13240
    24
     "Inr(b) == <1,b>"
paulson@13240
    25
paulson@13240
    26
  "case"  :: "[i=>i, i=>i, i]=>i"
paulson@13240
    27
     "case(c,d) == (%<y,z>. cond(y, d(z), c(z)))"
paulson@13240
    28
paulson@13240
    29
  (*operator for selecting out the various summands*)
paulson@13240
    30
  Part    :: "[i,i=>i] => i"
paulson@13240
    31
     "Part(A,h) == {x: A. EX z. x = h(z)}"
clasohm@0
    32
wenzelm@3940
    33
local
wenzelm@3923
    34
paulson@13356
    35
subsection{*Rules for the @{term Part} Primitive*}
paulson@13240
    36
paulson@13240
    37
lemma Part_iff: 
paulson@13240
    38
    "a : Part(A,h) <-> a:A & (EX y. a=h(y))"
paulson@13240
    39
apply (unfold Part_def)
paulson@13240
    40
apply (rule separation)
paulson@13240
    41
done
paulson@13240
    42
paulson@13240
    43
lemma Part_eqI [intro]: 
paulson@13240
    44
    "[| a : A;  a=h(b) |] ==> a : Part(A,h)"
paulson@13255
    45
by (unfold Part_def, blast)
paulson@13240
    46
paulson@13240
    47
lemmas PartI = refl [THEN [2] Part_eqI]
paulson@13240
    48
paulson@13240
    49
lemma PartE [elim!]: 
paulson@13240
    50
    "[| a : Part(A,h);  !!z. [| a : A;  a=h(z) |] ==> P   
paulson@13240
    51
     |] ==> P"
paulson@13255
    52
apply (unfold Part_def, blast)
paulson@13240
    53
done
paulson@13240
    54
paulson@13240
    55
lemma Part_subset: "Part(A,h) <= A"
paulson@13240
    56
apply (unfold Part_def)
paulson@13240
    57
apply (rule Collect_subset)
paulson@13240
    58
done
paulson@13240
    59
paulson@13240
    60
paulson@13356
    61
subsection{*Rules for Disjoint Sums*}
paulson@13240
    62
paulson@13240
    63
lemmas sum_defs = sum_def Inl_def Inr_def case_def
paulson@13240
    64
paulson@13240
    65
lemma Sigma_bool: "Sigma(bool,C) = C(0) + C(1)"
paulson@13255
    66
by (unfold bool_def sum_def, blast)
paulson@13240
    67
paulson@13240
    68
(** Introduction rules for the injections **)
paulson@13240
    69
paulson@13240
    70
lemma InlI [intro!,simp,TC]: "a : A ==> Inl(a) : A+B"
paulson@13255
    71
by (unfold sum_defs, blast)
paulson@13240
    72
paulson@13240
    73
lemma InrI [intro!,simp,TC]: "b : B ==> Inr(b) : A+B"
paulson@13255
    74
by (unfold sum_defs, blast)
paulson@13240
    75
paulson@13240
    76
(** Elimination rules **)
paulson@13240
    77
paulson@13240
    78
lemma sumE [elim!]:
paulson@13240
    79
    "[| u: A+B;   
paulson@13240
    80
        !!x. [| x:A;  u=Inl(x) |] ==> P;  
paulson@13240
    81
        !!y. [| y:B;  u=Inr(y) |] ==> P  
paulson@13240
    82
     |] ==> P"
paulson@13255
    83
by (unfold sum_defs, blast) 
paulson@13240
    84
paulson@13240
    85
(** Injection and freeness equivalences, for rewriting **)
paulson@13240
    86
paulson@13240
    87
lemma Inl_iff [iff]: "Inl(a)=Inl(b) <-> a=b"
paulson@13255
    88
by (simp add: sum_defs)
paulson@13240
    89
paulson@13240
    90
lemma Inr_iff [iff]: "Inr(a)=Inr(b) <-> a=b"
paulson@13255
    91
by (simp add: sum_defs)
paulson@13240
    92
paulson@13823
    93
lemma Inl_Inr_iff [simp]: "Inl(a)=Inr(b) <-> False"
paulson@13255
    94
by (simp add: sum_defs)
paulson@13240
    95
paulson@13823
    96
lemma Inr_Inl_iff [simp]: "Inr(b)=Inl(a) <-> False"
paulson@13255
    97
by (simp add: sum_defs)
paulson@13240
    98
paulson@13240
    99
lemma sum_empty [simp]: "0+0 = 0"
paulson@13255
   100
by (simp add: sum_defs)
paulson@13240
   101
paulson@13240
   102
(*Injection and freeness rules*)
paulson@13240
   103
paulson@13240
   104
lemmas Inl_inject = Inl_iff [THEN iffD1, standard]
paulson@13240
   105
lemmas Inr_inject = Inr_iff [THEN iffD1, standard]
paulson@13823
   106
lemmas Inl_neq_Inr = Inl_Inr_iff [THEN iffD1, THEN FalseE, elim!]
paulson@13823
   107
lemmas Inr_neq_Inl = Inr_Inl_iff [THEN iffD1, THEN FalseE, elim!]
paulson@13240
   108
paulson@13240
   109
paulson@13240
   110
lemma InlD: "Inl(a): A+B ==> a: A"
paulson@13255
   111
by blast
paulson@13240
   112
paulson@13240
   113
lemma InrD: "Inr(b): A+B ==> b: B"
paulson@13255
   114
by blast
paulson@13240
   115
paulson@13240
   116
lemma sum_iff: "u: A+B <-> (EX x. x:A & u=Inl(x)) | (EX y. y:B & u=Inr(y))"
paulson@13255
   117
by blast
paulson@13255
   118
paulson@13255
   119
lemma Inl_in_sum_iff [simp]: "(Inl(x) \<in> A+B) <-> (x \<in> A)";
paulson@13255
   120
by auto
paulson@13255
   121
paulson@13255
   122
lemma Inr_in_sum_iff [simp]: "(Inr(y) \<in> A+B) <-> (y \<in> B)";
paulson@13255
   123
by auto
paulson@13240
   124
paulson@13240
   125
lemma sum_subset_iff: "A+B <= C+D <-> A<=C & B<=D"
paulson@13255
   126
by blast
paulson@13240
   127
paulson@13240
   128
lemma sum_equal_iff: "A+B = C+D <-> A=C & B=D"
paulson@13255
   129
by (simp add: extension sum_subset_iff, blast)
paulson@13240
   130
paulson@13240
   131
lemma sum_eq_2_times: "A+A = 2*A"
paulson@13255
   132
by (simp add: sum_def, blast)
paulson@13240
   133
paulson@13240
   134
paulson@13356
   135
subsection{*The Eliminator: @{term case}*}
clasohm@0
   136
paulson@13240
   137
lemma case_Inl [simp]: "case(c, d, Inl(a)) = c(a)"
paulson@13255
   138
by (simp add: sum_defs)
paulson@13240
   139
paulson@13240
   140
lemma case_Inr [simp]: "case(c, d, Inr(b)) = d(b)"
paulson@13255
   141
by (simp add: sum_defs)
paulson@13240
   142
paulson@13240
   143
lemma case_type [TC]:
paulson@13240
   144
    "[| u: A+B;  
paulson@13240
   145
        !!x. x: A ==> c(x): C(Inl(x));    
paulson@13240
   146
        !!y. y: B ==> d(y): C(Inr(y))  
paulson@13240
   147
     |] ==> case(c,d,u) : C(u)"
paulson@13255
   148
by auto
paulson@13240
   149
paulson@13240
   150
lemma expand_case: "u: A+B ==>    
paulson@13240
   151
        R(case(c,d,u)) <->  
paulson@13240
   152
        ((ALL x:A. u = Inl(x) --> R(c(x))) &  
paulson@13240
   153
        (ALL y:B. u = Inr(y) --> R(d(y))))"
paulson@13240
   154
by auto
paulson@13240
   155
paulson@13240
   156
lemma case_cong:
paulson@13240
   157
  "[| z: A+B;    
paulson@13240
   158
      !!x. x:A ==> c(x)=c'(x);   
paulson@13240
   159
      !!y. y:B ==> d(y)=d'(y)    
paulson@13240
   160
   |] ==> case(c,d,z) = case(c',d',z)"
paulson@13255
   161
by auto 
paulson@13240
   162
paulson@13240
   163
lemma case_case: "z: A+B ==>    
paulson@13255
   164
        
paulson@13255
   165
	case(c, d, case(%x. Inl(c'(x)), %y. Inr(d'(y)), z)) =  
paulson@13240
   166
        case(%x. c(c'(x)), %y. d(d'(y)), z)"
paulson@13240
   167
by auto
paulson@13240
   168
paulson@13240
   169
paulson@13356
   170
subsection{*More Rules for @{term "Part(A,h)"}*}
paulson@13240
   171
paulson@13240
   172
lemma Part_mono: "A<=B ==> Part(A,h)<=Part(B,h)"
paulson@13255
   173
by blast
paulson@13240
   174
paulson@13240
   175
lemma Part_Collect: "Part(Collect(A,P), h) = Collect(Part(A,h), P)"
paulson@13255
   176
by blast
paulson@13240
   177
paulson@13240
   178
lemmas Part_CollectE =
paulson@13240
   179
     Part_Collect [THEN equalityD1, THEN subsetD, THEN CollectE, standard]
paulson@13240
   180
paulson@13240
   181
lemma Part_Inl: "Part(A+B,Inl) = {Inl(x). x: A}"
paulson@13255
   182
by blast
paulson@13240
   183
paulson@13240
   184
lemma Part_Inr: "Part(A+B,Inr) = {Inr(y). y: B}"
paulson@13255
   185
by blast
paulson@13240
   186
paulson@13240
   187
lemma PartD1: "a : Part(A,h) ==> a : A"
paulson@13255
   188
by (simp add: Part_def)
paulson@13240
   189
paulson@13240
   190
lemma Part_id: "Part(A,%x. x) = A"
paulson@13255
   191
by blast
paulson@13240
   192
paulson@13240
   193
lemma Part_Inr2: "Part(A+B, %x. Inr(h(x))) = {Inr(y). y: Part(B,h)}"
paulson@13255
   194
by blast
paulson@13240
   195
paulson@13240
   196
lemma Part_sum_equality: "C <= A+B ==> Part(C,Inl) Un Part(C,Inr) = C"
paulson@13255
   197
by blast
paulson@13240
   198
paulson@13240
   199
ML
paulson@13240
   200
{*
paulson@13240
   201
val sum_def = thm "sum_def";
paulson@13240
   202
val Inl_def = thm "Inl_def";
paulson@13240
   203
val Inr_def = thm "Inr_def";
paulson@13240
   204
val sum_defs = thms "sum_defs";
paulson@13240
   205
paulson@13240
   206
val Part_iff = thm "Part_iff";
paulson@13240
   207
val Part_eqI = thm "Part_eqI";
paulson@13240
   208
val PartI = thm "PartI";
paulson@13240
   209
val PartE = thm "PartE";
paulson@13240
   210
val Part_subset = thm "Part_subset";
paulson@13240
   211
val Sigma_bool = thm "Sigma_bool";
paulson@13240
   212
val InlI = thm "InlI";
paulson@13240
   213
val InrI = thm "InrI";
paulson@13240
   214
val sumE = thm "sumE";
paulson@13240
   215
val Inl_iff = thm "Inl_iff";
paulson@13240
   216
val Inr_iff = thm "Inr_iff";
paulson@13240
   217
val Inl_Inr_iff = thm "Inl_Inr_iff";
paulson@13240
   218
val Inr_Inl_iff = thm "Inr_Inl_iff";
paulson@13240
   219
val sum_empty = thm "sum_empty";
paulson@13240
   220
val Inl_inject = thm "Inl_inject";
paulson@13240
   221
val Inr_inject = thm "Inr_inject";
paulson@13240
   222
val Inl_neq_Inr = thm "Inl_neq_Inr";
paulson@13240
   223
val Inr_neq_Inl = thm "Inr_neq_Inl";
paulson@13240
   224
val InlD = thm "InlD";
paulson@13240
   225
val InrD = thm "InrD";
paulson@13240
   226
val sum_iff = thm "sum_iff";
paulson@13240
   227
val sum_subset_iff = thm "sum_subset_iff";
paulson@13240
   228
val sum_equal_iff = thm "sum_equal_iff";
paulson@13240
   229
val sum_eq_2_times = thm "sum_eq_2_times";
paulson@13240
   230
val case_Inl = thm "case_Inl";
paulson@13240
   231
val case_Inr = thm "case_Inr";
paulson@13240
   232
val case_type = thm "case_type";
paulson@13240
   233
val expand_case = thm "expand_case";
paulson@13240
   234
val case_cong = thm "case_cong";
paulson@13240
   235
val case_case = thm "case_case";
paulson@13240
   236
val Part_mono = thm "Part_mono";
paulson@13240
   237
val Part_Collect = thm "Part_Collect";
paulson@13240
   238
val Part_CollectE = thm "Part_CollectE";
paulson@13240
   239
val Part_Inl = thm "Part_Inl";
paulson@13240
   240
val Part_Inr = thm "Part_Inr";
paulson@13240
   241
val PartD1 = thm "PartD1";
paulson@13240
   242
val Part_id = thm "Part_id";
paulson@13240
   243
val Part_Inr2 = thm "Part_Inr2";
paulson@13240
   244
val Part_sum_equality = thm "Part_sum_equality";
paulson@13240
   245
paulson@13240
   246
*}
paulson@13240
   247
paulson@13240
   248
paulson@13240
   249
clasohm@0
   250
end