src/ZF/Sum.thy
author wenzelm
Sat Oct 17 14:43:18 2009 +0200 (2009-10-17)
changeset 32960 69916a850301
parent 24893 b8ef7afe3a6b
child 35416 d8d7d1b785af
permissions -rw-r--r--
eliminated hard tabulators, guessing at each author's individual tab-width;
tuned headers;
clasohm@1478
     1
(*  Title:      ZF/sum.thy
clasohm@1478
     2
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
clasohm@0
     3
    Copyright   1993  University of Cambridge
clasohm@0
     4
*)
clasohm@0
     5
paulson@13356
     6
header{*Disjoint Sums*}
paulson@13356
     7
haftmann@16417
     8
theory Sum imports Bool equalities begin
wenzelm@3923
     9
paulson@13356
    10
text{*And the "Part" primitive for simultaneous recursive type definitions*}
paulson@13356
    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@13356
    33
subsection{*Rules for the @{term 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@13356
    59
subsection{*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@13823
    91
lemma Inl_Inr_iff [simp]: "Inl(a)=Inr(b) <-> False"
paulson@13255
    92
by (simp add: sum_defs)
paulson@13240
    93
paulson@13823
    94
lemma Inr_Inl_iff [simp]: "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@13823
   104
lemmas Inl_neq_Inr = Inl_Inr_iff [THEN iffD1, THEN FalseE, elim!]
paulson@13823
   105
lemmas Inr_neq_Inl = Inr_Inl_iff [THEN iffD1, THEN FalseE, elim!]
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@13356
   133
subsection{*The Eliminator: @{term 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 ==>    
wenzelm@32960
   162
        case(c, d, case(%x. Inl(c'(x)), %y. Inr(d'(y)), z)) =  
paulson@13240
   163
        case(%x. c(c'(x)), %y. d(d'(y)), z)"
paulson@13240
   164
by auto
paulson@13240
   165
paulson@13240
   166
paulson@13356
   167
subsection{*More Rules for @{term "Part(A,h)"}*}
paulson@13240
   168
paulson@13240
   169
lemma Part_mono: "A<=B ==> Part(A,h)<=Part(B,h)"
paulson@13255
   170
by blast
paulson@13240
   171
paulson@13240
   172
lemma Part_Collect: "Part(Collect(A,P), h) = Collect(Part(A,h), P)"
paulson@13255
   173
by blast
paulson@13240
   174
paulson@13240
   175
lemmas Part_CollectE =
paulson@13240
   176
     Part_Collect [THEN equalityD1, THEN subsetD, THEN CollectE, standard]
paulson@13240
   177
paulson@13240
   178
lemma Part_Inl: "Part(A+B,Inl) = {Inl(x). x: A}"
paulson@13255
   179
by blast
paulson@13240
   180
paulson@13240
   181
lemma Part_Inr: "Part(A+B,Inr) = {Inr(y). y: B}"
paulson@13255
   182
by blast
paulson@13240
   183
paulson@13240
   184
lemma PartD1: "a : Part(A,h) ==> a : A"
paulson@13255
   185
by (simp add: Part_def)
paulson@13240
   186
paulson@13240
   187
lemma Part_id: "Part(A,%x. x) = A"
paulson@13255
   188
by blast
paulson@13240
   189
paulson@13240
   190
lemma Part_Inr2: "Part(A+B, %x. Inr(h(x))) = {Inr(y). y: Part(B,h)}"
paulson@13255
   191
by blast
paulson@13240
   192
paulson@13240
   193
lemma Part_sum_equality: "C <= A+B ==> Part(C,Inl) Un Part(C,Inr) = C"
paulson@13255
   194
by blast
paulson@13240
   195
clasohm@0
   196
end