src/ZF/Sum.thy
 author wenzelm Sun Oct 07 21:19:31 2007 +0200 (2007-10-07 ago) changeset 24893 b8ef7afe3a6b parent 16417 9bc16273c2d4 child 32960 69916a850301 permissions -rw-r--r--
modernized specifications;
removed legacy ML bindings;
```     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 end
```