src/ZF/upair.thy
changeset 46820 c656222c4dc1
parent 45620 f2a587696afb
child 46821 ff6b0c1087f2
equal deleted inserted replaced
46819:9b38f8527510 46820:c656222c4dc1
     2     Author:     Lawrence C Paulson and Martin D Coen, CU Computer Laboratory
     2     Author:     Lawrence C Paulson and Martin D Coen, CU Computer Laboratory
     3     Copyright   1993  University of Cambridge
     3     Copyright   1993  University of Cambridge
     4 
     4 
     5 Observe the order of dependence:
     5 Observe the order of dependence:
     6     Upair is defined in terms of Replace
     6     Upair is defined in terms of Replace
     7     Un is defined in terms of Upair and Union (similarly for Int)
     7     \<union> is defined in terms of Upair and \<Union>(similarly for Int)
     8     cons is defined in terms of Upair and Un
     8     cons is defined in terms of Upair and Un
     9     Ordered pairs and descriptions are defined using cons ("set notation")
     9     Ordered pairs and descriptions are defined using cons ("set notation")
    10 *)
    10 *)
    11 
    11 
    12 header{*Unordered Pairs*}
    12 header{*Unordered Pairs*}
    15 uses "Tools/typechk.ML" begin
    15 uses "Tools/typechk.ML" begin
    16 
    16 
    17 setup TypeCheck.setup
    17 setup TypeCheck.setup
    18 
    18 
    19 lemma atomize_ball [symmetric, rulify]:
    19 lemma atomize_ball [symmetric, rulify]:
    20      "(!!x. x:A ==> P(x)) == Trueprop (ALL x:A. P(x))"
    20      "(!!x. x:A ==> P(x)) == Trueprop (\<forall>x\<in>A. P(x))"
    21 by (simp add: Ball_def atomize_all atomize_imp)
    21 by (simp add: Ball_def atomize_all atomize_imp)
    22 
    22 
    23 
    23 
    24 subsection{*Unordered Pairs: constant @{term Upair}*}
    24 subsection{*Unordered Pairs: constant @{term Upair}*}
    25 
    25 
    26 lemma Upair_iff [simp]: "c : Upair(a,b) <-> (c=a | c=b)"
    26 lemma Upair_iff [simp]: "c \<in> Upair(a,b) <-> (c=a | c=b)"
    27 by (unfold Upair_def, blast)
    27 by (unfold Upair_def, blast)
    28 
    28 
    29 lemma UpairI1: "a : Upair(a,b)"
    29 lemma UpairI1: "a \<in> Upair(a,b)"
    30 by simp
    30 by simp
    31 
    31 
    32 lemma UpairI2: "b : Upair(a,b)"
    32 lemma UpairI2: "b \<in> Upair(a,b)"
    33 by simp
    33 by simp
    34 
    34 
    35 lemma UpairE: "[| a : Upair(b,c);  a=b ==> P;  a=c ==> P |] ==> P"
    35 lemma UpairE: "[| a \<in> Upair(b,c);  a=b ==> P;  a=c ==> P |] ==> P"
    36 by (simp, blast)
    36 by (simp, blast)
    37 
    37 
    38 subsection{*Rules for Binary Union, Defined via @{term Upair}*}
    38 subsection{*Rules for Binary Union, Defined via @{term Upair}*}
    39 
    39 
    40 lemma Un_iff [simp]: "c : A Un B <-> (c:A | c:B)"
    40 lemma Un_iff [simp]: "c \<in> A \<union> B <-> (c:A | c:B)"
    41 apply (simp add: Un_def)
    41 apply (simp add: Un_def)
    42 apply (blast intro: UpairI1 UpairI2 elim: UpairE)
    42 apply (blast intro: UpairI1 UpairI2 elim: UpairE)
    43 done
    43 done
    44 
    44 
    45 lemma UnI1: "c : A ==> c : A Un B"
    45 lemma UnI1: "c \<in> A ==> c \<in> A \<union> B"
    46 by simp
    46 by simp
    47 
    47 
    48 lemma UnI2: "c : B ==> c : A Un B"
    48 lemma UnI2: "c \<in> B ==> c \<in> A \<union> B"
    49 by simp
    49 by simp
    50 
    50 
    51 declare UnI1 [elim?]  UnI2 [elim?]
    51 declare UnI1 [elim?]  UnI2 [elim?]
    52 
    52 
    53 lemma UnE [elim!]: "[| c : A Un B;  c:A ==> P;  c:B ==> P |] ==> P"
    53 lemma UnE [elim!]: "[| c \<in> A \<union> B;  c:A ==> P;  c:B ==> P |] ==> P"
    54 by (simp, blast)
    54 by (simp, blast)
    55 
    55 
    56 (*Stronger version of the rule above*)
    56 (*Stronger version of the rule above*)
    57 lemma UnE': "[| c : A Un B;  c:A ==> P;  [| c:B;  c~:A |] ==> P |] ==> P"
    57 lemma UnE': "[| c \<in> A \<union> B;  c:A ==> P;  [| c:B;  c\<notin>A |] ==> P |] ==> P"
    58 by (simp, blast)
    58 by (simp, blast)
    59 
    59 
    60 (*Classical introduction rule: no commitment to A vs B*)
    60 (*Classical introduction rule: no commitment to A vs B*)
    61 lemma UnCI [intro!]: "(c ~: B ==> c : A) ==> c : A Un B"
    61 lemma UnCI [intro!]: "(c \<notin> B ==> c \<in> A) ==> c \<in> A \<union> B"
    62 by (simp, blast)
    62 by (simp, blast)
    63 
    63 
    64 subsection{*Rules for Binary Intersection, Defined via @{term Upair}*}
    64 subsection{*Rules for Binary Intersection, Defined via @{term Upair}*}
    65 
    65 
    66 lemma Int_iff [simp]: "c : A Int B <-> (c:A & c:B)"
    66 lemma Int_iff [simp]: "c \<in> A \<inter> B <-> (c:A & c:B)"
    67 apply (unfold Int_def)
    67 apply (unfold Int_def)
    68 apply (blast intro: UpairI1 UpairI2 elim: UpairE)
    68 apply (blast intro: UpairI1 UpairI2 elim: UpairE)
    69 done
    69 done
    70 
    70 
    71 lemma IntI [intro!]: "[| c : A;  c : B |] ==> c : A Int B"
    71 lemma IntI [intro!]: "[| c \<in> A;  c \<in> B |] ==> c \<in> A \<inter> B"
    72 by simp
    72 by simp
    73 
    73 
    74 lemma IntD1: "c : A Int B ==> c : A"
    74 lemma IntD1: "c \<in> A \<inter> B ==> c \<in> A"
    75 by simp
    75 by simp
    76 
    76 
    77 lemma IntD2: "c : A Int B ==> c : B"
    77 lemma IntD2: "c \<in> A \<inter> B ==> c \<in> B"
    78 by simp
    78 by simp
    79 
    79 
    80 lemma IntE [elim!]: "[| c : A Int B;  [| c:A; c:B |] ==> P |] ==> P"
    80 lemma IntE [elim!]: "[| c \<in> A \<inter> B;  [| c:A; c:B |] ==> P |] ==> P"
    81 by simp
    81 by simp
    82 
    82 
    83 
    83 
    84 subsection{*Rules for Set Difference, Defined via @{term Upair}*}
    84 subsection{*Rules for Set Difference, Defined via @{term Upair}*}
    85 
    85 
    86 lemma Diff_iff [simp]: "c : A-B <-> (c:A & c~:B)"
    86 lemma Diff_iff [simp]: "c \<in> A-B <-> (c:A & c\<notin>B)"
    87 by (unfold Diff_def, blast)
    87 by (unfold Diff_def, blast)
    88 
    88 
    89 lemma DiffI [intro!]: "[| c : A;  c ~: B |] ==> c : A - B"
    89 lemma DiffI [intro!]: "[| c \<in> A;  c \<notin> B |] ==> c \<in> A - B"
    90 by simp
    90 by simp
    91 
    91 
    92 lemma DiffD1: "c : A - B ==> c : A"
    92 lemma DiffD1: "c \<in> A - B ==> c \<in> A"
    93 by simp
    93 by simp
    94 
    94 
    95 lemma DiffD2: "c : A - B ==> c ~: B"
    95 lemma DiffD2: "c \<in> A - B ==> c \<notin> B"
    96 by simp
    96 by simp
    97 
    97 
    98 lemma DiffE [elim!]: "[| c : A - B;  [| c:A; c~:B |] ==> P |] ==> P"
    98 lemma DiffE [elim!]: "[| c \<in> A - B;  [| c:A; c\<notin>B |] ==> P |] ==> P"
    99 by simp
    99 by simp
   100 
   100 
   101 
   101 
   102 subsection{*Rules for @{term cons}*}
   102 subsection{*Rules for @{term cons}*}
   103 
   103 
   104 lemma cons_iff [simp]: "a : cons(b,A) <-> (a=b | a:A)"
   104 lemma cons_iff [simp]: "a \<in> cons(b,A) <-> (a=b | a:A)"
   105 apply (unfold cons_def)
   105 apply (unfold cons_def)
   106 apply (blast intro: UpairI1 UpairI2 elim: UpairE)
   106 apply (blast intro: UpairI1 UpairI2 elim: UpairE)
   107 done
   107 done
   108 
   108 
   109 (*risky as a typechecking rule, but solves otherwise unconstrained goals of
   109 (*risky as a typechecking rule, but solves otherwise unconstrained goals of
   110 the form x : ?A*)
   110 the form x \<in> ?A*)
   111 lemma consI1 [simp,TC]: "a : cons(a,B)"
   111 lemma consI1 [simp,TC]: "a \<in> cons(a,B)"
   112 by simp
   112 by simp
   113 
   113 
   114 
   114 
   115 lemma consI2: "a : B ==> a : cons(b,B)"
   115 lemma consI2: "a \<in> B ==> a \<in> cons(b,B)"
   116 by simp
   116 by simp
   117 
   117 
   118 lemma consE [elim!]: "[| a : cons(b,A);  a=b ==> P;  a:A ==> P |] ==> P"
   118 lemma consE [elim!]: "[| a \<in> cons(b,A);  a=b ==> P;  a:A ==> P |] ==> P"
   119 by (simp, blast)
   119 by (simp, blast)
   120 
   120 
   121 (*Stronger version of the rule above*)
   121 (*Stronger version of the rule above*)
   122 lemma consE':
   122 lemma consE':
   123     "[| a : cons(b,A);  a=b ==> P;  [| a:A;  a~=b |] ==> P |] ==> P"
   123     "[| a \<in> cons(b,A);  a=b ==> P;  [| a:A;  a\<noteq>b |] ==> P |] ==> P"
   124 by (simp, blast)
   124 by (simp, blast)
   125 
   125 
   126 (*Classical introduction rule*)
   126 (*Classical introduction rule*)
   127 lemma consCI [intro!]: "(a~:B ==> a=b) ==> a: cons(b,B)"
   127 lemma consCI [intro!]: "(a\<notin>B ==> a=b) ==> a: cons(b,B)"
   128 by (simp, blast)
   128 by (simp, blast)
   129 
   129 
   130 lemma cons_not_0 [simp]: "cons(a,B) ~= 0"
   130 lemma cons_not_0 [simp]: "cons(a,B) \<noteq> 0"
   131 by (blast elim: equalityE)
   131 by (blast elim: equalityE)
   132 
   132 
   133 lemmas cons_neq_0 = cons_not_0 [THEN notE]
   133 lemmas cons_neq_0 = cons_not_0 [THEN notE]
   134 
   134 
   135 declare cons_not_0 [THEN not_sym, simp]
   135 declare cons_not_0 [THEN not_sym, simp]
   136 
   136 
   137 
   137 
   138 subsection{*Singletons*}
   138 subsection{*Singletons*}
   139 
   139 
   140 lemma singleton_iff: "a : {b} <-> a=b"
   140 lemma singleton_iff: "a \<in> {b} <-> a=b"
   141 by simp
   141 by simp
   142 
   142 
   143 lemma singletonI [intro!]: "a : {a}"
   143 lemma singletonI [intro!]: "a \<in> {a}"
   144 by (rule consI1)
   144 by (rule consI1)
   145 
   145 
   146 lemmas singletonE = singleton_iff [THEN iffD1, elim_format, elim!]
   146 lemmas singletonE = singleton_iff [THEN iffD1, elim_format, elim!]
   147 
   147 
   148 
   148 
   149 subsection{*Descriptions*}
   149 subsection{*Descriptions*}
   150 
   150 
   151 lemma the_equality [intro]:
   151 lemma the_equality [intro]:
   152     "[| P(a);  !!x. P(x) ==> x=a |] ==> (THE x. P(x)) = a"
   152     "[| P(a);  !!x. P(x) ==> x=a |] ==> (THE x. P(x)) = a"
   153 apply (unfold the_def) 
   153 apply (unfold the_def)
   154 apply (fast dest: subst)
   154 apply (fast dest: subst)
   155 done
   155 done
   156 
   156 
   157 (* Only use this if you already know EX!x. P(x) *)
   157 (* Only use this if you already know EX!x. P(x) *)
   158 lemma the_equality2: "[| EX! x. P(x);  P(a) |] ==> (THE x. P(x)) = a"
   158 lemma the_equality2: "[| EX! x. P(x);  P(a) |] ==> (THE x. P(x)) = a"
   162 apply (erule ex1E)
   162 apply (erule ex1E)
   163 apply (subst the_equality)
   163 apply (subst the_equality)
   164 apply (blast+)
   164 apply (blast+)
   165 done
   165 done
   166 
   166 
   167 (*the_cong is no longer necessary: if (ALL y.P(y)<->Q(y)) then 
   167 (*No congruence rule is necessary: if @{term"\<forall>y.P(y)<->Q(y)"} then
   168   (THE x.P(x))  rewrites to  (THE x. Q(x))  *)
   168   @{term "THE x.P(x)"}  rewrites to @{term "THE x.Q(x)"} *)
   169 
   169 
   170 (*If it's "undefined", it's zero!*)
   170 (*If it's "undefined", it's zero!*)
   171 lemma the_0: "~ (EX! x. P(x)) ==> (THE x. P(x))=0"
   171 lemma the_0: "~ (EX! x. P(x)) ==> (THE x. P(x))=0"
   172 apply (unfold the_def)
   172 apply (unfold the_def)
   173 apply (blast elim!: ReplaceE)
   173 apply (blast elim!: ReplaceE)
   201 lemma if_false [simp]: "(if False then a else b) = b"
   201 lemma if_false [simp]: "(if False then a else b) = b"
   202 by (unfold if_def, blast)
   202 by (unfold if_def, blast)
   203 
   203 
   204 (*Never use with case splitting, or if P is known to be true or false*)
   204 (*Never use with case splitting, or if P is known to be true or false*)
   205 lemma if_cong:
   205 lemma if_cong:
   206     "[| P<->Q;  Q ==> a=c;  ~Q ==> b=d |]  
   206     "[| P<->Q;  Q ==> a=c;  ~Q ==> b=d |]
   207      ==> (if P then a else b) = (if Q then c else d)"
   207      ==> (if P then a else b) = (if Q then c else d)"
   208 by (simp add: if_def cong add: conj_cong)
   208 by (simp add: if_def cong add: conj_cong)
   209 
   209 
   210 (*Prevents simplification of x and y: faster and allows the execution
   210 (*Prevents simplification of x and y: faster and allows the execution
   211   of functional programs. NOW THE DEFAULT.*)
   211   of functional programs. NOW THE DEFAULT.*)
   219 (*Not needed for rewriting, since P would rewrite to False anyway*)
   219 (*Not needed for rewriting, since P would rewrite to False anyway*)
   220 lemma if_not_P: "~P ==> (if P then a else b) = b"
   220 lemma if_not_P: "~P ==> (if P then a else b) = b"
   221 by (unfold if_def, blast)
   221 by (unfold if_def, blast)
   222 
   222 
   223 lemma split_if [split]:
   223 lemma split_if [split]:
   224      "P(if Q then x else y) <-> ((Q --> P(x)) & (~Q --> P(y)))"
   224      "P(if Q then x else y) <-> ((Q \<longrightarrow> P(x)) & (~Q \<longrightarrow> P(y)))"
   225 by (case_tac Q, simp_all)
   225 by (case_tac Q, simp_all)
   226 
   226 
   227 (** Rewrite rules for boolean case-splitting: faster than split_if [split]
   227 (** Rewrite rules for boolean case-splitting: faster than split_if [split]
   228 **)
   228 **)
   229 
   229 
   230 lemmas split_if_eq1 = split_if [of "%x. x = b"] for b
   230 lemmas split_if_eq1 = split_if [of "%x. x = b"] for b
   231 lemmas split_if_eq2 = split_if [of "%x. a = x"] for x
   231 lemmas split_if_eq2 = split_if [of "%x. a = x"] for x
   232 
   232 
   233 lemmas split_if_mem1 = split_if [of "%x. x : b"] for b
   233 lemmas split_if_mem1 = split_if [of "%x. x \<in> b"] for b
   234 lemmas split_if_mem2 = split_if [of "%x. a : x"] for x
   234 lemmas split_if_mem2 = split_if [of "%x. a \<in> x"] for x
   235 
   235 
   236 lemmas split_ifs = split_if_eq1 split_if_eq2 split_if_mem1 split_if_mem2
   236 lemmas split_ifs = split_if_eq1 split_if_eq2 split_if_mem1 split_if_mem2
   237 
   237 
   238 (*Logically equivalent to split_if_mem2*)
   238 (*Logically equivalent to split_if_mem2*)
   239 lemma if_iff: "a: (if P then x else y) <-> P & a:x | ~P & a:y"
   239 lemma if_iff: "a: (if P then x else y) <-> P & a:x | ~P & a:y"
   265 by (blast intro: mem_asym)
   265 by (blast intro: mem_asym)
   266 
   266 
   267 (*mem_irrefl should NOT be added to default databases:
   267 (*mem_irrefl should NOT be added to default databases:
   268       it would be tried on most goals, making proofs slower!*)
   268       it would be tried on most goals, making proofs slower!*)
   269 
   269 
   270 lemma mem_not_refl: "a ~: a"
   270 lemma mem_not_refl: "a \<notin> a"
   271 apply (rule notI)
   271 apply (rule notI)
   272 apply (erule mem_irrefl)
   272 apply (erule mem_irrefl)
   273 done
   273 done
   274 
   274 
   275 (*Good for proving inequalities by rewriting*)
   275 (*Good for proving inequalities by rewriting*)
   276 lemma mem_imp_not_eq: "a:A ==> a ~= A"
   276 lemma mem_imp_not_eq: "a:A ==> a \<noteq> A"
   277 by (blast elim!: mem_irrefl)
   277 by (blast elim!: mem_irrefl)
   278 
   278 
   279 lemma eq_imp_not_mem: "a=A ==> a ~: A"
   279 lemma eq_imp_not_mem: "a=A ==> a \<notin> A"
   280 by (blast intro: elim: mem_irrefl)
   280 by (blast intro: elim: mem_irrefl)
   281 
   281 
   282 subsection{*Rules for Successor*}
   282 subsection{*Rules for Successor*}
   283 
   283 
   284 lemma succ_iff: "i : succ(j) <-> i=j | i:j"
   284 lemma succ_iff: "i \<in> succ(j) <-> i=j | i:j"
   285 by (unfold succ_def, blast)
   285 by (unfold succ_def, blast)
   286 
   286 
   287 lemma succI1 [simp]: "i : succ(i)"
   287 lemma succI1 [simp]: "i \<in> succ(i)"
   288 by (simp add: succ_iff)
   288 by (simp add: succ_iff)
   289 
   289 
   290 lemma succI2: "i : j ==> i : succ(j)"
   290 lemma succI2: "i \<in> j ==> i \<in> succ(j)"
   291 by (simp add: succ_iff)
   291 by (simp add: succ_iff)
   292 
   292 
   293 lemma succE [elim!]: 
   293 lemma succE [elim!]:
   294     "[| i : succ(j);  i=j ==> P;  i:j ==> P |] ==> P"
   294     "[| i \<in> succ(j);  i=j ==> P;  i:j ==> P |] ==> P"
   295 apply (simp add: succ_iff, blast) 
   295 apply (simp add: succ_iff, blast)
   296 done
   296 done
   297 
   297 
   298 (*Classical introduction rule*)
   298 (*Classical introduction rule*)
   299 lemma succCI [intro!]: "(i~:j ==> i=j) ==> i: succ(j)"
   299 lemma succCI [intro!]: "(i\<notin>j ==> i=j) ==> i: succ(j)"
   300 by (simp add: succ_iff, blast)
   300 by (simp add: succ_iff, blast)
   301 
   301 
   302 lemma succ_not_0 [simp]: "succ(n) ~= 0"
   302 lemma succ_not_0 [simp]: "succ(n) \<noteq> 0"
   303 by (blast elim!: equalityE)
   303 by (blast elim!: equalityE)
   304 
   304 
   305 lemmas succ_neq_0 = succ_not_0 [THEN notE, elim!]
   305 lemmas succ_neq_0 = succ_not_0 [THEN notE, elim!]
   306 
   306 
   307 declare succ_not_0 [THEN not_sym, simp]
   307 declare succ_not_0 [THEN not_sym, simp]
   308 declare sym [THEN succ_neq_0, elim!]
   308 declare sym [THEN succ_neq_0, elim!]
   309 
   309 
   310 (* succ(c) <= B ==> c : B *)
   310 (* @{term"succ(c) \<subseteq> B ==> c \<in> B"} *)
   311 lemmas succ_subsetD = succI1 [THEN [2] subsetD]
   311 lemmas succ_subsetD = succI1 [THEN [2] subsetD]
   312 
   312 
   313 (* succ(b) ~= b *)
   313 (* @{term"succ(b) \<noteq> b"} *)
   314 lemmas succ_neq_self = succI1 [THEN mem_imp_not_eq, THEN not_sym]
   314 lemmas succ_neq_self = succI1 [THEN mem_imp_not_eq, THEN not_sym]
   315 
   315 
   316 lemma succ_inject_iff [simp]: "succ(m) = succ(n) <-> m=n"
   316 lemma succ_inject_iff [simp]: "succ(m) = succ(n) <-> m=n"
   317 by (blast elim: mem_asym elim!: equalityE)
   317 by (blast elim: mem_asym elim!: equalityE)
   318 
   318 
   320 
   320 
   321 
   321 
   322 subsection{*Miniscoping of the Bounded Universal Quantifier*}
   322 subsection{*Miniscoping of the Bounded Universal Quantifier*}
   323 
   323 
   324 lemma ball_simps1:
   324 lemma ball_simps1:
   325      "(ALL x:A. P(x) & Q)   <-> (ALL x:A. P(x)) & (A=0 | Q)"
   325      "(\<forall>x\<in>A. P(x) & Q)   <-> (\<forall>x\<in>A. P(x)) & (A=0 | Q)"
   326      "(ALL x:A. P(x) | Q)   <-> ((ALL x:A. P(x)) | Q)"
   326      "(\<forall>x\<in>A. P(x) | Q)   <-> ((\<forall>x\<in>A. P(x)) | Q)"
   327      "(ALL x:A. P(x) --> Q) <-> ((EX x:A. P(x)) --> Q)"
   327      "(\<forall>x\<in>A. P(x) \<longrightarrow> Q) <-> ((\<exists>x\<in>A. P(x)) \<longrightarrow> Q)"
   328      "(~(ALL x:A. P(x))) <-> (EX x:A. ~P(x))"
   328      "(~(\<forall>x\<in>A. P(x))) <-> (\<exists>x\<in>A. ~P(x))"
   329      "(ALL x:0.P(x)) <-> True"
   329      "(\<forall>x\<in>0.P(x)) <-> True"
   330      "(ALL x:succ(i).P(x)) <-> P(i) & (ALL x:i. P(x))"
   330      "(\<forall>x\<in>succ(i).P(x)) <-> P(i) & (\<forall>x\<in>i. P(x))"
   331      "(ALL x:cons(a,B).P(x)) <-> P(a) & (ALL x:B. P(x))"
   331      "(\<forall>x\<in>cons(a,B).P(x)) <-> P(a) & (\<forall>x\<in>B. P(x))"
   332      "(ALL x:RepFun(A,f). P(x)) <-> (ALL y:A. P(f(y)))"
   332      "(\<forall>x\<in>RepFun(A,f). P(x)) <-> (\<forall>y\<in>A. P(f(y)))"
   333      "(ALL x:Union(A).P(x)) <-> (ALL y:A. ALL x:y. P(x))" 
   333      "(\<forall>x\<in>\<Union>(A).P(x)) <-> (\<forall>y\<in>A. \<forall>x\<in>y. P(x))"
   334 by blast+
   334 by blast+
   335 
   335 
   336 lemma ball_simps2:
   336 lemma ball_simps2:
   337      "(ALL x:A. P & Q(x))   <-> (A=0 | P) & (ALL x:A. Q(x))"
   337      "(\<forall>x\<in>A. P & Q(x))   <-> (A=0 | P) & (\<forall>x\<in>A. Q(x))"
   338      "(ALL x:A. P | Q(x))   <-> (P | (ALL x:A. Q(x)))"
   338      "(\<forall>x\<in>A. P | Q(x))   <-> (P | (\<forall>x\<in>A. Q(x)))"
   339      "(ALL x:A. P --> Q(x)) <-> (P --> (ALL x:A. Q(x)))"
   339      "(\<forall>x\<in>A. P \<longrightarrow> Q(x)) <-> (P \<longrightarrow> (\<forall>x\<in>A. Q(x)))"
   340 by blast+
   340 by blast+
   341 
   341 
   342 lemma ball_simps3:
   342 lemma ball_simps3:
   343      "(ALL x:Collect(A,Q).P(x)) <-> (ALL x:A. Q(x) --> P(x))"
   343      "(\<forall>x\<in>Collect(A,Q).P(x)) <-> (\<forall>x\<in>A. Q(x) \<longrightarrow> P(x))"
   344 by blast+
   344 by blast+
   345 
   345 
   346 lemmas ball_simps [simp] = ball_simps1 ball_simps2 ball_simps3
   346 lemmas ball_simps [simp] = ball_simps1 ball_simps2 ball_simps3
   347 
   347 
   348 lemma ball_conj_distrib:
   348 lemma ball_conj_distrib:
   349     "(ALL x:A. P(x) & Q(x)) <-> ((ALL x:A. P(x)) & (ALL x:A. Q(x)))"
   349     "(\<forall>x\<in>A. P(x) & Q(x)) <-> ((\<forall>x\<in>A. P(x)) & (\<forall>x\<in>A. Q(x)))"
   350 by blast
   350 by blast
   351 
   351 
   352 
   352 
   353 subsection{*Miniscoping of the Bounded Existential Quantifier*}
   353 subsection{*Miniscoping of the Bounded Existential Quantifier*}
   354 
   354 
   355 lemma bex_simps1:
   355 lemma bex_simps1:
   356      "(EX x:A. P(x) & Q) <-> ((EX x:A. P(x)) & Q)"
   356      "(\<exists>x\<in>A. P(x) & Q) <-> ((\<exists>x\<in>A. P(x)) & Q)"
   357      "(EX x:A. P(x) | Q) <-> (EX x:A. P(x)) | (A~=0 & Q)"
   357      "(\<exists>x\<in>A. P(x) | Q) <-> (\<exists>x\<in>A. P(x)) | (A\<noteq>0 & Q)"
   358      "(EX x:A. P(x) --> Q) <-> ((ALL x:A. P(x)) --> (A~=0 & Q))"
   358      "(\<exists>x\<in>A. P(x) \<longrightarrow> Q) <-> ((\<forall>x\<in>A. P(x)) \<longrightarrow> (A\<noteq>0 & Q))"
   359      "(EX x:0.P(x)) <-> False"
   359      "(\<exists>x\<in>0.P(x)) <-> False"
   360      "(EX x:succ(i).P(x)) <-> P(i) | (EX x:i. P(x))"
   360      "(\<exists>x\<in>succ(i).P(x)) <-> P(i) | (\<exists>x\<in>i. P(x))"
   361      "(EX x:cons(a,B).P(x)) <-> P(a) | (EX x:B. P(x))"
   361      "(\<exists>x\<in>cons(a,B).P(x)) <-> P(a) | (\<exists>x\<in>B. P(x))"
   362      "(EX x:RepFun(A,f). P(x)) <-> (EX y:A. P(f(y)))"
   362      "(\<exists>x\<in>RepFun(A,f). P(x)) <-> (\<exists>y\<in>A. P(f(y)))"
   363      "(EX x:Union(A).P(x)) <-> (EX y:A. EX x:y.  P(x))"
   363      "(\<exists>x\<in>\<Union>(A).P(x)) <-> (\<exists>y\<in>A. \<exists>x\<in>y.  P(x))"
   364      "(~(EX x:A. P(x))) <-> (ALL x:A. ~P(x))"
   364      "(~(\<exists>x\<in>A. P(x))) <-> (\<forall>x\<in>A. ~P(x))"
   365 by blast+
   365 by blast+
   366 
   366 
   367 lemma bex_simps2:
   367 lemma bex_simps2:
   368      "(EX x:A. P & Q(x)) <-> (P & (EX x:A. Q(x)))"
   368      "(\<exists>x\<in>A. P & Q(x)) <-> (P & (\<exists>x\<in>A. Q(x)))"
   369      "(EX x:A. P | Q(x)) <-> (A~=0 & P) | (EX x:A. Q(x))"
   369      "(\<exists>x\<in>A. P | Q(x)) <-> (A\<noteq>0 & P) | (\<exists>x\<in>A. Q(x))"
   370      "(EX x:A. P --> Q(x)) <-> ((A=0 | P) --> (EX x:A. Q(x)))"
   370      "(\<exists>x\<in>A. P \<longrightarrow> Q(x)) <-> ((A=0 | P) \<longrightarrow> (\<exists>x\<in>A. Q(x)))"
   371 by blast+
   371 by blast+
   372 
   372 
   373 lemma bex_simps3:
   373 lemma bex_simps3:
   374      "(EX x:Collect(A,Q).P(x)) <-> (EX x:A. Q(x) & P(x))"
   374      "(\<exists>x\<in>Collect(A,Q).P(x)) <-> (\<exists>x\<in>A. Q(x) & P(x))"
   375 by blast
   375 by blast
   376 
   376 
   377 lemmas bex_simps [simp] = bex_simps1 bex_simps2 bex_simps3
   377 lemmas bex_simps [simp] = bex_simps1 bex_simps2 bex_simps3
   378 
   378 
   379 lemma bex_disj_distrib:
   379 lemma bex_disj_distrib:
   380     "(EX x:A. P(x) | Q(x)) <-> ((EX x:A. P(x)) | (EX x:A. Q(x)))"
   380     "(\<exists>x\<in>A. P(x) | Q(x)) <-> ((\<exists>x\<in>A. P(x)) | (\<exists>x\<in>A. Q(x)))"
   381 by blast
   381 by blast
   382 
   382 
   383 
   383 
   384 (** One-point rule for bounded quantifiers: see HOL/Set.ML **)
   384 (** One-point rule for bounded quantifiers: see HOL/Set.ML **)
   385 
   385 
   386 lemma bex_triv_one_point1 [simp]: "(EX x:A. x=a) <-> (a:A)"
   386 lemma bex_triv_one_point1 [simp]: "(\<exists>x\<in>A. x=a) <-> (a:A)"
   387 by blast
   387 by blast
   388 
   388 
   389 lemma bex_triv_one_point2 [simp]: "(EX x:A. a=x) <-> (a:A)"
   389 lemma bex_triv_one_point2 [simp]: "(\<exists>x\<in>A. a=x) <-> (a:A)"
   390 by blast
   390 by blast
   391 
   391 
   392 lemma bex_one_point1 [simp]: "(EX x:A. x=a & P(x)) <-> (a:A & P(a))"
   392 lemma bex_one_point1 [simp]: "(\<exists>x\<in>A. x=a & P(x)) <-> (a:A & P(a))"
   393 by blast
   393 by blast
   394 
   394 
   395 lemma bex_one_point2 [simp]: "(EX x:A. a=x & P(x)) <-> (a:A & P(a))"
   395 lemma bex_one_point2 [simp]: "(\<exists>x\<in>A. a=x & P(x)) <-> (a:A & P(a))"
   396 by blast
   396 by blast
   397 
   397 
   398 lemma ball_one_point1 [simp]: "(ALL x:A. x=a --> P(x)) <-> (a:A --> P(a))"
   398 lemma ball_one_point1 [simp]: "(\<forall>x\<in>A. x=a \<longrightarrow> P(x)) <-> (a:A \<longrightarrow> P(a))"
   399 by blast
   399 by blast
   400 
   400 
   401 lemma ball_one_point2 [simp]: "(ALL x:A. a=x --> P(x)) <-> (a:A --> P(a))"
   401 lemma ball_one_point2 [simp]: "(\<forall>x\<in>A. a=x \<longrightarrow> P(x)) <-> (a:A \<longrightarrow> P(a))"
   402 by blast
   402 by blast
   403 
   403 
   404 
   404 
   405 subsection{*Miniscoping of the Replacement Operator*}
   405 subsection{*Miniscoping of the Replacement Operator*}
   406 
   406 
   416 
   416 
   417 
   417 
   418 subsection{*Miniscoping of Unions*}
   418 subsection{*Miniscoping of Unions*}
   419 
   419 
   420 lemma UN_simps1:
   420 lemma UN_simps1:
   421      "(UN x:C. cons(a, B(x))) = (if C=0 then 0 else cons(a, UN x:C. B(x)))"
   421      "(\<Union>x\<in>C. cons(a, B(x))) = (if C=0 then 0 else cons(a, \<Union>x\<in>C. B(x)))"
   422      "(UN x:C. A(x) Un B')   = (if C=0 then 0 else (UN x:C. A(x)) Un B')"
   422      "(\<Union>x\<in>C. A(x) \<union> B')   = (if C=0 then 0 else (\<Union>x\<in>C. A(x)) \<union> B')"
   423      "(UN x:C. A' Un B(x))   = (if C=0 then 0 else A' Un (UN x:C. B(x)))"
   423      "(\<Union>x\<in>C. A' \<union> B(x))   = (if C=0 then 0 else A' \<union> (\<Union>x\<in>C. B(x)))"
   424      "(UN x:C. A(x) Int B')  = ((UN x:C. A(x)) Int B')"
   424      "(\<Union>x\<in>C. A(x) \<inter> B')  = ((\<Union>x\<in>C. A(x)) \<inter> B')"
   425      "(UN x:C. A' Int B(x))  = (A' Int (UN x:C. B(x)))"
   425      "(\<Union>x\<in>C. A' \<inter> B(x))  = (A' \<inter> (\<Union>x\<in>C. B(x)))"
   426      "(UN x:C. A(x) - B')    = ((UN x:C. A(x)) - B')"
   426      "(\<Union>x\<in>C. A(x) - B')    = ((\<Union>x\<in>C. A(x)) - B')"
   427      "(UN x:C. A' - B(x))    = (if C=0 then 0 else A' - (INT x:C. B(x)))"
   427      "(\<Union>x\<in>C. A' - B(x))    = (if C=0 then 0 else A' - (\<Inter>x\<in>C. B(x)))"
   428 apply (simp_all add: Inter_def) 
   428 apply (simp_all add: Inter_def)
   429 apply (blast intro!: equalityI )+
   429 apply (blast intro!: equalityI )+
   430 done
   430 done
   431 
   431 
   432 lemma UN_simps2:
   432 lemma UN_simps2:
   433       "(UN x: Union(A). B(x)) = (UN y:A. UN x:y. B(x))"
   433       "(\<Union>x\<in>\<Union>(A). B(x)) = (\<Union>y\<in>A. \<Union>x\<in>y. B(x))"
   434       "(UN z: (UN x:A. B(x)). C(z)) = (UN  x:A. UN z: B(x). C(z))"
   434       "(\<Union>z\<in>(\<Union>x\<in>A. B(x)). C(z)) = (\<Union>x\<in>A. \<Union>z\<in>B(x). C(z))"
   435       "(UN x: RepFun(A,f). B(x))     = (UN a:A. B(f(a)))"
   435       "(\<Union>x\<in>RepFun(A,f). B(x))     = (\<Union>a\<in>A. B(f(a)))"
   436 by blast+
   436 by blast+
   437 
   437 
   438 lemmas UN_simps [simp] = UN_simps1 UN_simps2
   438 lemmas UN_simps [simp] = UN_simps1 UN_simps2
   439 
   439 
   440 text{*Opposite of miniscoping: pull the operator out*}
   440 text{*Opposite of miniscoping: pull the operator out*}
   441 
   441 
   442 lemma UN_extend_simps1:
   442 lemma UN_extend_simps1:
   443      "(UN x:C. A(x)) Un B   = (if C=0 then B else (UN x:C. A(x) Un B))"
   443      "(\<Union>x\<in>C. A(x)) \<union> B   = (if C=0 then B else (\<Union>x\<in>C. A(x) \<union> B))"
   444      "((UN x:C. A(x)) Int B) = (UN x:C. A(x) Int B)"
   444      "((\<Union>x\<in>C. A(x)) \<inter> B) = (\<Union>x\<in>C. A(x) \<inter> B)"
   445      "((UN x:C. A(x)) - B) = (UN x:C. A(x) - B)"
   445      "((\<Union>x\<in>C. A(x)) - B) = (\<Union>x\<in>C. A(x) - B)"
   446 apply simp_all 
   446 apply simp_all
   447 apply blast+
   447 apply blast+
   448 done
   448 done
   449 
   449 
   450 lemma UN_extend_simps2:
   450 lemma UN_extend_simps2:
   451      "cons(a, UN x:C. B(x)) = (if C=0 then {a} else (UN x:C. cons(a, B(x))))"
   451      "cons(a, \<Union>x\<in>C. B(x)) = (if C=0 then {a} else (\<Union>x\<in>C. cons(a, B(x))))"
   452      "A Un (UN x:C. B(x))   = (if C=0 then A else (UN x:C. A Un B(x)))"
   452      "A \<union> (\<Union>x\<in>C. B(x))   = (if C=0 then A else (\<Union>x\<in>C. A \<union> B(x)))"
   453      "(A Int (UN x:C. B(x))) = (UN x:C. A Int B(x))"
   453      "(A \<inter> (\<Union>x\<in>C. B(x))) = (\<Union>x\<in>C. A \<inter> B(x))"
   454      "A - (INT x:C. B(x))    = (if C=0 then A else (UN x:C. A - B(x)))"
   454      "A - (\<Inter>x\<in>C. B(x))    = (if C=0 then A else (\<Union>x\<in>C. A - B(x)))"
   455      "(UN y:A. UN x:y. B(x)) = (UN x: Union(A). B(x))"
   455      "(\<Union>y\<in>A. \<Union>x\<in>y. B(x)) = (\<Union>x\<in>\<Union>(A). B(x))"
   456      "(UN a:A. B(f(a))) = (UN x: RepFun(A,f). B(x))"
   456      "(\<Union>a\<in>A. B(f(a))) = (\<Union>x\<in>RepFun(A,f). B(x))"
   457 apply (simp_all add: Inter_def) 
   457 apply (simp_all add: Inter_def)
   458 apply (blast intro!: equalityI)+
   458 apply (blast intro!: equalityI)+
   459 done
   459 done
   460 
   460 
   461 lemma UN_UN_extend:
   461 lemma UN_UN_extend:
   462      "(UN  x:A. UN z: B(x). C(z)) = (UN z: (UN x:A. B(x)). C(z))"
   462      "(\<Union>x\<in>A. \<Union>z\<in>B(x). C(z)) = (\<Union>z\<in>(\<Union>x\<in>A. B(x)). C(z))"
   463 by blast
   463 by blast
   464 
   464 
   465 lemmas UN_extend_simps = UN_extend_simps1 UN_extend_simps2 UN_UN_extend
   465 lemmas UN_extend_simps = UN_extend_simps1 UN_extend_simps2 UN_UN_extend
   466 
   466 
   467 
   467 
   468 subsection{*Miniscoping of Intersections*}
   468 subsection{*Miniscoping of Intersections*}
   469 
   469 
   470 lemma INT_simps1:
   470 lemma INT_simps1:
   471      "(INT x:C. A(x) Int B) = (INT x:C. A(x)) Int B"
   471      "(\<Inter>x\<in>C. A(x) \<inter> B) = (\<Inter>x\<in>C. A(x)) \<inter> B"
   472      "(INT x:C. A(x) - B)   = (INT x:C. A(x)) - B"
   472      "(\<Inter>x\<in>C. A(x) - B)   = (\<Inter>x\<in>C. A(x)) - B"
   473      "(INT x:C. A(x) Un B)  = (if C=0 then 0 else (INT x:C. A(x)) Un B)"
   473      "(\<Inter>x\<in>C. A(x) \<union> B)  = (if C=0 then 0 else (\<Inter>x\<in>C. A(x)) \<union> B)"
   474 by (simp_all add: Inter_def, blast+)
   474 by (simp_all add: Inter_def, blast+)
   475 
   475 
   476 lemma INT_simps2:
   476 lemma INT_simps2:
   477      "(INT x:C. A Int B(x)) = A Int (INT x:C. B(x))"
   477      "(\<Inter>x\<in>C. A \<inter> B(x)) = A \<inter> (\<Inter>x\<in>C. B(x))"
   478      "(INT x:C. A - B(x))   = (if C=0 then 0 else A - (UN x:C. B(x)))"
   478      "(\<Inter>x\<in>C. A - B(x))   = (if C=0 then 0 else A - (\<Union>x\<in>C. B(x)))"
   479      "(INT x:C. cons(a, B(x))) = (if C=0 then 0 else cons(a, INT x:C. B(x)))"
   479      "(\<Inter>x\<in>C. cons(a, B(x))) = (if C=0 then 0 else cons(a, \<Inter>x\<in>C. B(x)))"
   480      "(INT x:C. A Un B(x))  = (if C=0 then 0 else A Un (INT x:C. B(x)))"
   480      "(\<Inter>x\<in>C. A \<union> B(x))  = (if C=0 then 0 else A \<union> (\<Inter>x\<in>C. B(x)))"
   481 apply (simp_all add: Inter_def) 
   481 apply (simp_all add: Inter_def)
   482 apply (blast intro!: equalityI)+
   482 apply (blast intro!: equalityI)+
   483 done
   483 done
   484 
   484 
   485 lemmas INT_simps [simp] = INT_simps1 INT_simps2
   485 lemmas INT_simps [simp] = INT_simps1 INT_simps2
   486 
   486 
   487 text{*Opposite of miniscoping: pull the operator out*}
   487 text{*Opposite of miniscoping: pull the operator out*}
   488 
   488 
   489 
   489 
   490 lemma INT_extend_simps1:
   490 lemma INT_extend_simps1:
   491      "(INT x:C. A(x)) Int B = (INT x:C. A(x) Int B)"
   491      "(\<Inter>x\<in>C. A(x)) \<inter> B = (\<Inter>x\<in>C. A(x) \<inter> B)"
   492      "(INT x:C. A(x)) - B = (INT x:C. A(x) - B)"
   492      "(\<Inter>x\<in>C. A(x)) - B = (\<Inter>x\<in>C. A(x) - B)"
   493      "(INT x:C. A(x)) Un B  = (if C=0 then B else (INT x:C. A(x) Un B))"
   493      "(\<Inter>x\<in>C. A(x)) \<union> B  = (if C=0 then B else (\<Inter>x\<in>C. A(x) \<union> B))"
   494 apply (simp_all add: Inter_def, blast+)
   494 apply (simp_all add: Inter_def, blast+)
   495 done
   495 done
   496 
   496 
   497 lemma INT_extend_simps2:
   497 lemma INT_extend_simps2:
   498      "A Int (INT x:C. B(x)) = (INT x:C. A Int B(x))"
   498      "A \<inter> (\<Inter>x\<in>C. B(x)) = (\<Inter>x\<in>C. A \<inter> B(x))"
   499      "A - (UN x:C. B(x))   = (if C=0 then A else (INT x:C. A - B(x)))"
   499      "A - (\<Union>x\<in>C. B(x))   = (if C=0 then A else (\<Inter>x\<in>C. A - B(x)))"
   500      "cons(a, INT x:C. B(x)) = (if C=0 then {a} else (INT x:C. cons(a, B(x))))"
   500      "cons(a, \<Inter>x\<in>C. B(x)) = (if C=0 then {a} else (\<Inter>x\<in>C. cons(a, B(x))))"
   501      "A Un (INT x:C. B(x))  = (if C=0 then A else (INT x:C. A Un B(x)))"
   501      "A \<union> (\<Inter>x\<in>C. B(x))  = (if C=0 then A else (\<Inter>x\<in>C. A \<union> B(x)))"
   502 apply (simp_all add: Inter_def) 
   502 apply (simp_all add: Inter_def)
   503 apply (blast intro!: equalityI)+
   503 apply (blast intro!: equalityI)+
   504 done
   504 done
   505 
   505 
   506 lemmas INT_extend_simps = INT_extend_simps1 INT_extend_simps2
   506 lemmas INT_extend_simps = INT_extend_simps1 INT_extend_simps2
   507 
   507 
   510 
   510 
   511 
   511 
   512 (*** Miniscoping: pushing in big Unions, Intersections, quantifiers, etc. ***)
   512 (*** Miniscoping: pushing in big Unions, Intersections, quantifiers, etc. ***)
   513 
   513 
   514 lemma misc_simps [simp]:
   514 lemma misc_simps [simp]:
   515      "0 Un A = A"
   515      "0 \<union> A = A"
   516      "A Un 0 = A"
   516      "A \<union> 0 = A"
   517      "0 Int A = 0"
   517      "0 \<inter> A = 0"
   518      "A Int 0 = 0"
   518      "A \<inter> 0 = 0"
   519      "0 - A = 0"
   519      "0 - A = 0"
   520      "A - 0 = A"
   520      "A - 0 = A"
   521      "Union(0) = 0"
   521      "\<Union>(0) = 0"
   522      "Union(cons(b,A)) = b Un Union(A)"
   522      "\<Union>(cons(b,A)) = b \<union> \<Union>(A)"
   523      "Inter({b}) = b"
   523      "\<Inter>({b}) = b"
   524 by blast+
   524 by blast+
   525 
   525 
   526 end
   526 end