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