src/ZF/Sum.thy
author paulson
Sun Jun 23 10:14:13 2002 +0200 (2002-06-23)
changeset 13240 bb5f4faea1f3
parent 13220 62c899c77151
child 13255 407ad9c3036d
permissions -rw-r--r--
conversion of Sum, pair to Isar script
     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 apply (unfold Part_def)
    44 apply blast
    45 done
    46 
    47 lemmas PartI = refl [THEN [2] Part_eqI]
    48 
    49 lemma PartE [elim!]: 
    50     "[| a : Part(A,h);  !!z. [| a : A;  a=h(z) |] ==> P   
    51      |] ==> P"
    52 apply (unfold Part_def)
    53 apply blast
    54 done
    55 
    56 lemma Part_subset: "Part(A,h) <= A"
    57 apply (unfold Part_def)
    58 apply (rule Collect_subset)
    59 done
    60 
    61 
    62 (*** Rules for Disjoint Sums ***)
    63 
    64 lemmas sum_defs = sum_def Inl_def Inr_def case_def
    65 
    66 lemma Sigma_bool: "Sigma(bool,C) = C(0) + C(1)"
    67 apply (unfold bool_def sum_def)
    68 apply blast
    69 done
    70 
    71 (** Introduction rules for the injections **)
    72 
    73 lemma InlI [intro!,simp,TC]: "a : A ==> Inl(a) : A+B"
    74 apply (unfold sum_defs)
    75 apply blast
    76 done
    77 
    78 lemma InrI [intro!,simp,TC]: "b : B ==> Inr(b) : A+B"
    79 apply (unfold sum_defs)
    80 apply blast
    81 done
    82 
    83 (** Elimination rules **)
    84 
    85 lemma sumE [elim!]:
    86     "[| u: A+B;   
    87         !!x. [| x:A;  u=Inl(x) |] ==> P;  
    88         !!y. [| y:B;  u=Inr(y) |] ==> P  
    89      |] ==> P"
    90 apply (unfold sum_defs)
    91 apply (blast intro: elim:); 
    92 done
    93 
    94 (** Injection and freeness equivalences, for rewriting **)
    95 
    96 lemma Inl_iff [iff]: "Inl(a)=Inl(b) <-> a=b"
    97 apply (simp add: sum_defs)
    98 done
    99 
   100 lemma Inr_iff [iff]: "Inr(a)=Inr(b) <-> a=b"
   101 apply (simp add: sum_defs)
   102 done
   103 
   104 lemma Inl_Inr_iff [iff]: "Inl(a)=Inr(b) <-> False"
   105 apply (simp add: sum_defs)
   106 done
   107 
   108 lemma Inr_Inl_iff [iff]: "Inr(b)=Inl(a) <-> False"
   109 apply (simp add: sum_defs)
   110 done
   111 
   112 lemma sum_empty [simp]: "0+0 = 0"
   113 apply (simp add: sum_defs)
   114 done
   115 
   116 (*Injection and freeness rules*)
   117 
   118 lemmas Inl_inject = Inl_iff [THEN iffD1, standard]
   119 lemmas Inr_inject = Inr_iff [THEN iffD1, standard]
   120 lemmas Inl_neq_Inr = Inl_Inr_iff [THEN iffD1, THEN FalseE]
   121 lemmas Inr_neq_Inl = Inr_Inl_iff [THEN iffD1, THEN FalseE]
   122 
   123 
   124 lemma InlD: "Inl(a): A+B ==> a: A"
   125 apply blast
   126 done
   127 
   128 lemma InrD: "Inr(b): A+B ==> b: B"
   129 apply blast
   130 done
   131 
   132 lemma sum_iff: "u: A+B <-> (EX x. x:A & u=Inl(x)) | (EX y. y:B & u=Inr(y))"
   133 apply blast
   134 done
   135 
   136 lemma sum_subset_iff: "A+B <= C+D <-> A<=C & B<=D"
   137 apply blast
   138 done
   139 
   140 lemma sum_equal_iff: "A+B = C+D <-> A=C & B=D"
   141 apply (simp add: extension sum_subset_iff)
   142 apply blast
   143 done
   144 
   145 lemma sum_eq_2_times: "A+A = 2*A"
   146 apply (simp add: sum_def)
   147 apply blast
   148 done
   149 
   150 
   151 (*** Eliminator -- case ***)
   152 
   153 lemma case_Inl [simp]: "case(c, d, Inl(a)) = c(a)"
   154 apply (simp add: sum_defs)
   155 done
   156 
   157 lemma case_Inr [simp]: "case(c, d, Inr(b)) = d(b)"
   158 apply (simp add: sum_defs)
   159 done
   160 
   161 lemma case_type [TC]:
   162     "[| u: A+B;  
   163         !!x. x: A ==> c(x): C(Inl(x));    
   164         !!y. y: B ==> d(y): C(Inr(y))  
   165      |] ==> case(c,d,u) : C(u)"
   166 apply (auto );  
   167 done
   168 
   169 lemma expand_case: "u: A+B ==>    
   170         R(case(c,d,u)) <->  
   171         ((ALL x:A. u = Inl(x) --> R(c(x))) &  
   172         (ALL y:B. u = Inr(y) --> R(d(y))))"
   173 by auto
   174 
   175 lemma case_cong:
   176   "[| z: A+B;    
   177       !!x. x:A ==> c(x)=c'(x);   
   178       !!y. y:B ==> d(y)=d'(y)    
   179    |] ==> case(c,d,z) = case(c',d',z)"
   180 by (auto ); 
   181 
   182 lemma case_case: "z: A+B ==>    
   183         case(c, d, case(%x. Inl(c'(x)), %y. Inr(d'(y)), z)) =  
   184         case(%x. c(c'(x)), %y. d(d'(y)), z)"
   185 by auto
   186 
   187 
   188 (*** More rules for Part(A,h) ***)
   189 
   190 lemma Part_mono: "A<=B ==> Part(A,h)<=Part(B,h)"
   191 apply blast
   192 done
   193 
   194 lemma Part_Collect: "Part(Collect(A,P), h) = Collect(Part(A,h), P)"
   195 apply blast
   196 done
   197 
   198 lemmas Part_CollectE =
   199      Part_Collect [THEN equalityD1, THEN subsetD, THEN CollectE, standard]
   200 
   201 lemma Part_Inl: "Part(A+B,Inl) = {Inl(x). x: A}"
   202 apply blast
   203 done
   204 
   205 lemma Part_Inr: "Part(A+B,Inr) = {Inr(y). y: B}"
   206 apply blast
   207 done
   208 
   209 lemma PartD1: "a : Part(A,h) ==> a : A"
   210 apply (simp add: Part_def)
   211 done
   212 
   213 lemma Part_id: "Part(A,%x. x) = A"
   214 apply blast
   215 done
   216 
   217 lemma Part_Inr2: "Part(A+B, %x. Inr(h(x))) = {Inr(y). y: Part(B,h)}"
   218 apply blast
   219 done
   220 
   221 lemma Part_sum_equality: "C <= A+B ==> Part(C,Inl) Un Part(C,Inr) = C"
   222 apply blast
   223 done
   224 
   225 ML
   226 {*
   227 val sum_def = thm "sum_def";
   228 val Inl_def = thm "Inl_def";
   229 val Inr_def = thm "Inr_def";
   230 val sum_defs = thms "sum_defs";
   231 
   232 val Part_iff = thm "Part_iff";
   233 val Part_eqI = thm "Part_eqI";
   234 val PartI = thm "PartI";
   235 val PartE = thm "PartE";
   236 val Part_subset = thm "Part_subset";
   237 val Sigma_bool = thm "Sigma_bool";
   238 val InlI = thm "InlI";
   239 val InrI = thm "InrI";
   240 val sumE = thm "sumE";
   241 val Inl_iff = thm "Inl_iff";
   242 val Inr_iff = thm "Inr_iff";
   243 val Inl_Inr_iff = thm "Inl_Inr_iff";
   244 val Inr_Inl_iff = thm "Inr_Inl_iff";
   245 val sum_empty = thm "sum_empty";
   246 val Inl_inject = thm "Inl_inject";
   247 val Inr_inject = thm "Inr_inject";
   248 val Inl_neq_Inr = thm "Inl_neq_Inr";
   249 val Inr_neq_Inl = thm "Inr_neq_Inl";
   250 val InlD = thm "InlD";
   251 val InrD = thm "InrD";
   252 val sum_iff = thm "sum_iff";
   253 val sum_subset_iff = thm "sum_subset_iff";
   254 val sum_equal_iff = thm "sum_equal_iff";
   255 val sum_eq_2_times = thm "sum_eq_2_times";
   256 val case_Inl = thm "case_Inl";
   257 val case_Inr = thm "case_Inr";
   258 val case_type = thm "case_type";
   259 val expand_case = thm "expand_case";
   260 val case_cong = thm "case_cong";
   261 val case_case = thm "case_case";
   262 val Part_mono = thm "Part_mono";
   263 val Part_Collect = thm "Part_Collect";
   264 val Part_CollectE = thm "Part_CollectE";
   265 val Part_Inl = thm "Part_Inl";
   266 val Part_Inr = thm "Part_Inr";
   267 val PartD1 = thm "PartD1";
   268 val Part_id = thm "Part_id";
   269 val Part_Inr2 = thm "Part_Inr2";
   270 val Part_sum_equality = thm "Part_sum_equality";
   271 
   272 *}
   273 
   274 
   275 
   276 end