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