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