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