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