src/ZF/ZF_Base.thy
author wenzelm
Sat Nov 04 19:17:19 2017 +0100 (21 months ago)
changeset 67006 b1278ed3cd46
parent 66453 cc19f7ca2ed6
child 67443 3abf6a722518
permissions -rw-r--r--
prefer main entry points of HOL;
wenzelm@65449
     1
(*  Title:      ZF/ZF_Base.thy
clasohm@0
     2
    Author:     Lawrence C Paulson and Martin D Coen, CU Computer Laboratory
clasohm@0
     3
    Copyright   1993  University of Cambridge
paulson@14076
     4
*)
clasohm@0
     5
wenzelm@65449
     6
section \<open>Base of Zermelo-Fraenkel Set Theory\<close>
clasohm@0
     7
wenzelm@65449
     8
theory ZF_Base
wenzelm@66453
     9
imports FOL
wenzelm@37781
    10
begin
clasohm@0
    11
wenzelm@62149
    12
subsection \<open>Signature\<close>
wenzelm@62149
    13
wenzelm@39128
    14
declare [[eta_contract = false]]
wenzelm@23168
    15
paulson@14076
    16
typedecl i
wenzelm@55380
    17
instance i :: "term" ..
clasohm@0
    18
wenzelm@62149
    19
axiomatization mem :: "[i, i] \<Rightarrow> o"  (infixl "\<in>" 50)  \<comment> \<open>membership relation\<close>
wenzelm@62149
    20
  and zero :: "i"  ("0")  \<comment> \<open>the empty set\<close>
wenzelm@62149
    21
  and Pow :: "i \<Rightarrow> i"  \<comment> \<open>power sets\<close>
wenzelm@62149
    22
  and Inf :: "i"  \<comment> \<open>infinite set\<close>
wenzelm@62149
    23
  and Union :: "i \<Rightarrow> i"  ("\<Union>_" [90] 90)
wenzelm@62149
    24
  and PrimReplace :: "[i, [i, i] \<Rightarrow> o] \<Rightarrow> i"
wenzelm@62149
    25
wenzelm@62149
    26
abbreviation not_mem :: "[i, i] \<Rightarrow> o"  (infixl "\<notin>" 50)  \<comment> \<open>negated membership relation\<close>
wenzelm@62149
    27
  where "x \<notin> y \<equiv> \<not> (x \<in> y)"
wenzelm@62149
    28
wenzelm@62149
    29
wenzelm@62149
    30
subsection \<open>Bounded Quantifiers\<close>
wenzelm@62149
    31
wenzelm@62149
    32
definition Ball :: "[i, i \<Rightarrow> o] \<Rightarrow> o"
wenzelm@62149
    33
  where "Ball(A, P) \<equiv> \<forall>x. x\<in>A \<longrightarrow> P(x)"
clasohm@0
    34
wenzelm@62149
    35
definition Bex :: "[i, i \<Rightarrow> o] \<Rightarrow> o"
wenzelm@62149
    36
  where "Bex(A, P) \<equiv> \<exists>x. x\<in>A \<and> P(x)"
clasohm@0
    37
wenzelm@62149
    38
syntax
wenzelm@62149
    39
  "_Ball" :: "[pttrn, i, o] \<Rightarrow> o"  ("(3\<forall>_\<in>_./ _)" 10)
wenzelm@62149
    40
  "_Bex" :: "[pttrn, i, o] \<Rightarrow> o"  ("(3\<exists>_\<in>_./ _)" 10)
wenzelm@62149
    41
translations
wenzelm@62149
    42
  "\<forall>x\<in>A. P" \<rightleftharpoons> "CONST Ball(A, \<lambda>x. P)"
wenzelm@62149
    43
  "\<exists>x\<in>A. P" \<rightleftharpoons> "CONST Bex(A, \<lambda>x. P)"
wenzelm@62149
    44
wenzelm@62149
    45
wenzelm@62149
    46
subsection \<open>Variations on Replacement\<close>
wenzelm@62149
    47
wenzelm@62149
    48
(* Derived form of replacement, restricting P to its functional part.
wenzelm@62149
    49
   The resulting set (for functional P) is the same as with
wenzelm@62149
    50
   PrimReplace, but the rules are simpler. *)
wenzelm@62149
    51
definition Replace :: "[i, [i, i] \<Rightarrow> o] \<Rightarrow> i"
wenzelm@63901
    52
  where "Replace(A,P) == PrimReplace(A, %x y. (\<exists>!z. P(x,z)) & P(x,y))"
clasohm@0
    53
wenzelm@62149
    54
syntax
wenzelm@62149
    55
  "_Replace"  :: "[pttrn, pttrn, i, o] => i"  ("(1{_ ./ _ \<in> _, _})")
wenzelm@62149
    56
translations
wenzelm@62149
    57
  "{y. x\<in>A, Q}" \<rightleftharpoons> "CONST Replace(A, \<lambda>x y. Q)"
wenzelm@62149
    58
wenzelm@62149
    59
wenzelm@62149
    60
(* Functional form of replacement -- analgous to ML's map functional *)
wenzelm@62149
    61
wenzelm@62149
    62
definition RepFun :: "[i, i \<Rightarrow> i] \<Rightarrow> i"
wenzelm@62149
    63
  where "RepFun(A,f) == {y . x\<in>A, y=f(x)}"
wenzelm@62149
    64
wenzelm@62149
    65
syntax
wenzelm@62149
    66
  "_RepFun" :: "[i, pttrn, i] => i"  ("(1{_ ./ _ \<in> _})" [51,0,51])
wenzelm@62149
    67
translations
wenzelm@62149
    68
  "{b. x\<in>A}" \<rightleftharpoons> "CONST RepFun(A, \<lambda>x. b)"
wenzelm@62149
    69
clasohm@0
    70
wenzelm@62149
    71
(* Separation and Pairing can be derived from the Replacement
wenzelm@62149
    72
   and Powerset Axioms using the following definitions. *)
wenzelm@62149
    73
definition Collect :: "[i, i \<Rightarrow> o] \<Rightarrow> i"
wenzelm@62149
    74
  where "Collect(A,P) == {y . x\<in>A, x=y & P(x)}"
wenzelm@62149
    75
wenzelm@62149
    76
syntax
wenzelm@62149
    77
  "_Collect" :: "[pttrn, i, o] \<Rightarrow> i"  ("(1{_ \<in> _ ./ _})")
wenzelm@62149
    78
translations
wenzelm@62149
    79
  "{x\<in>A. P}" \<rightleftharpoons> "CONST Collect(A, \<lambda>x. P)"
wenzelm@62149
    80
paulson@6068
    81
wenzelm@62149
    82
subsection \<open>General union and intersection\<close>
wenzelm@62149
    83
wenzelm@62149
    84
definition Inter :: "i => i"  ("\<Inter>_" [90] 90)
wenzelm@62149
    85
  where "\<Inter>(A) == { x\<in>\<Union>(A) . \<forall>y\<in>A. x\<in>y}"
wenzelm@62149
    86
wenzelm@62149
    87
syntax
wenzelm@62149
    88
  "_UNION" :: "[pttrn, i, i] => i"  ("(3\<Union>_\<in>_./ _)" 10)
wenzelm@62149
    89
  "_INTER" :: "[pttrn, i, i] => i"  ("(3\<Inter>_\<in>_./ _)" 10)
wenzelm@62149
    90
translations
wenzelm@62149
    91
  "\<Union>x\<in>A. B" == "CONST Union({B. x\<in>A})"
wenzelm@62149
    92
  "\<Inter>x\<in>A. B" == "CONST Inter({B. x\<in>A})"
paulson@6068
    93
paulson@6068
    94
wenzelm@62149
    95
subsection \<open>Finite sets and binary operations\<close>
wenzelm@62149
    96
wenzelm@62149
    97
(*Unordered pairs (Upair) express binary union/intersection and cons;
wenzelm@62149
    98
  set enumerations translate as {a,...,z} = cons(a,...,cons(z,0)...)*)
wenzelm@62149
    99
wenzelm@62149
   100
definition Upair :: "[i, i] => i"
wenzelm@62149
   101
  where "Upair(a,b) == {y. x\<in>Pow(Pow(0)), (x=0 & y=a) | (x=Pow(0) & y=b)}"
clasohm@0
   102
wenzelm@62149
   103
definition Subset :: "[i, i] \<Rightarrow> o"  (infixl "\<subseteq>" 50)  \<comment> \<open>subset relation\<close>
wenzelm@62149
   104
  where subset_def: "A \<subseteq> B \<equiv> \<forall>x\<in>A. x\<in>B"
wenzelm@62149
   105
wenzelm@62149
   106
definition Diff :: "[i, i] \<Rightarrow> i"  (infixl "-" 65)  \<comment> \<open>set difference\<close>
wenzelm@62149
   107
  where "A - B == { x\<in>A . ~(x\<in>B) }"
clasohm@0
   108
wenzelm@62149
   109
definition Un :: "[i, i] \<Rightarrow> i"  (infixl "\<union>" 65)  \<comment> \<open>binary union\<close>
wenzelm@62149
   110
  where "A \<union> B == \<Union>(Upair(A,B))"
wenzelm@62149
   111
wenzelm@62149
   112
definition Int :: "[i, i] \<Rightarrow> i"  (infixl "\<inter>" 70)  \<comment> \<open>binary intersection\<close>
wenzelm@62149
   113
  where "A \<inter> B == \<Inter>(Upair(A,B))"
clasohm@0
   114
wenzelm@62149
   115
definition cons :: "[i, i] => i"
wenzelm@62149
   116
  where "cons(a,A) == Upair(a,a) \<union> A"
wenzelm@62149
   117
wenzelm@62149
   118
definition succ :: "i => i"
wenzelm@62149
   119
  where "succ(i) == cons(i, i)"
clasohm@0
   120
wenzelm@62149
   121
nonterminal "is"
wenzelm@62149
   122
syntax
wenzelm@62149
   123
  "" :: "i \<Rightarrow> is"  ("_")
wenzelm@62149
   124
  "_Enum" :: "[i, is] \<Rightarrow> is"  ("_,/ _")
wenzelm@62149
   125
  "_Finset" :: "is \<Rightarrow> i"  ("{(_)}")
wenzelm@62149
   126
translations
wenzelm@62149
   127
  "{x, xs}" == "CONST cons(x, {xs})"
wenzelm@62149
   128
  "{x}" == "CONST cons(x, 0)"
wenzelm@62149
   129
wenzelm@62149
   130
wenzelm@62149
   131
subsection \<open>Axioms\<close>
wenzelm@62149
   132
wenzelm@62149
   133
(* ZF axioms -- see Suppes p.238
wenzelm@62149
   134
   Axioms for Union, Pow and Replace state existence only,
wenzelm@62149
   135
   uniqueness is derivable using extensionality. *)
wenzelm@48733
   136
wenzelm@48733
   137
axiomatization
wenzelm@62149
   138
where
wenzelm@62149
   139
  extension:     "A = B \<longleftrightarrow> A \<subseteq> B \<and> B \<subseteq> A" and
wenzelm@62149
   140
  Union_iff:     "A \<in> \<Union>(C) \<longleftrightarrow> (\<exists>B\<in>C. A\<in>B)" and
wenzelm@62149
   141
  Pow_iff:       "A \<in> Pow(B) \<longleftrightarrow> A \<subseteq> B" and
wenzelm@24826
   142
wenzelm@62149
   143
  (*We may name this set, though it is not uniquely defined.*)
wenzelm@62149
   144
  infinity:      "0 \<in> Inf \<and> (\<forall>y\<in>Inf. succ(y) \<in> Inf)" and
wenzelm@24826
   145
wenzelm@62149
   146
  (*This formulation facilitates case analysis on A.*)
wenzelm@62149
   147
  foundation:    "A = 0 \<or> (\<exists>x\<in>A. \<forall>y\<in>x. y\<notin>A)" and
wenzelm@62149
   148
wenzelm@62149
   149
  (*Schema axiom since predicate P is a higher-order variable*)
wenzelm@62149
   150
  replacement:   "(\<forall>x\<in>A. \<forall>y z. P(x,y) \<and> P(x,z) \<longrightarrow> y = z) \<Longrightarrow>
wenzelm@62149
   151
                         b \<in> PrimReplace(A,P) \<longleftrightarrow> (\<exists>x\<in>A. P(x,b))"
clasohm@0
   152
clasohm@0
   153
wenzelm@62149
   154
subsection \<open>Definite descriptions -- via Replace over the set "1"\<close>
wenzelm@62149
   155
wenzelm@62149
   156
definition The :: "(i \<Rightarrow> o) \<Rightarrow> i"  (binder "THE " 10)
wenzelm@62149
   157
  where the_def: "The(P)    == \<Union>({y . x \<in> {0}, P(y)})"
wenzelm@615
   158
wenzelm@62149
   159
definition If :: "[o, i, i] \<Rightarrow> i"  ("(if (_)/ then (_)/ else (_))" [10] 10)
wenzelm@62149
   160
  where if_def: "if P then a else b == THE z. P & z=a | ~P & z=b"
wenzelm@62149
   161
wenzelm@62149
   162
abbreviation (input)
wenzelm@62149
   163
  old_if :: "[o, i, i] => i"  ("if '(_,_,_')")
wenzelm@62149
   164
  where "if(P,a,b) == If(P,a,b)"
wenzelm@62149
   165
wenzelm@62149
   166
wenzelm@62149
   167
subsection \<open>Ordered Pairing\<close>
wenzelm@24826
   168
wenzelm@62149
   169
(* this "symmetric" definition works better than {{a}, {a,b}} *)
wenzelm@62149
   170
definition Pair :: "[i, i] => i"
wenzelm@62149
   171
  where "Pair(a,b) == {{a,a}, {a,b}}"
wenzelm@62149
   172
wenzelm@62149
   173
definition fst :: "i \<Rightarrow> i"
wenzelm@62149
   174
  where "fst(p) == THE a. \<exists>b. p = Pair(a, b)"
lcp@1106
   175
wenzelm@62149
   176
definition snd :: "i \<Rightarrow> i"
wenzelm@62149
   177
  where "snd(p) == THE b. \<exists>a. p = Pair(a, b)"
lcp@1106
   178
wenzelm@62149
   179
definition split :: "[[i, i] \<Rightarrow> 'a, i] \<Rightarrow> 'a::{}"  \<comment> \<open>for pattern-matching\<close>
wenzelm@62149
   180
  where "split(c) == \<lambda>p. c(fst(p), snd(p))"
wenzelm@62149
   181
wenzelm@62149
   182
(* Patterns -- extends pre-defined type "pttrn" used in abstractions *)
wenzelm@62149
   183
nonterminal patterns
wenzelm@62149
   184
syntax
wenzelm@61979
   185
  "_pattern"  :: "patterns => pttrn"         ("\<langle>_\<rangle>")
paulson@13144
   186
  ""          :: "pttrn => patterns"         ("_")
wenzelm@35112
   187
  "_patterns" :: "[pttrn, patterns] => patterns"  ("_,/_")
wenzelm@62149
   188
  "_Tuple"    :: "[i, is] => i"              ("\<langle>(_,/ _)\<rangle>")
clasohm@0
   189
translations
wenzelm@61979
   190
  "\<langle>x, y, z\<rangle>"   == "\<langle>x, \<langle>y, z\<rangle>\<rangle>"
wenzelm@61979
   191
  "\<langle>x, y\<rangle>"      == "CONST Pair(x, y)"
wenzelm@61979
   192
  "\<lambda>\<langle>x,y,zs\<rangle>.b" == "CONST split(\<lambda>x \<langle>y,zs\<rangle>.b)"
wenzelm@61979
   193
  "\<lambda>\<langle>x,y\<rangle>.b"    == "CONST split(\<lambda>x y. b)"
wenzelm@2286
   194
wenzelm@62149
   195
definition Sigma :: "[i, i \<Rightarrow> i] \<Rightarrow> i"
wenzelm@62149
   196
  where "Sigma(A,B) == \<Union>x\<in>A. \<Union>y\<in>B(x). {\<langle>x,y\<rangle>}"
wenzelm@62149
   197
wenzelm@62149
   198
abbreviation cart_prod :: "[i, i] => i"  (infixr "\<times>" 80)  \<comment> \<open>Cartesian product\<close>
wenzelm@62149
   199
  where "A \<times> B \<equiv> Sigma(A, \<lambda>_. B)"
wenzelm@62149
   200
wenzelm@62149
   201
wenzelm@62149
   202
subsection \<open>Relations and Functions\<close>
wenzelm@62149
   203
wenzelm@62149
   204
(*converse of relation r, inverse of function*)
wenzelm@62149
   205
definition converse :: "i \<Rightarrow> i"
wenzelm@62149
   206
  where "converse(r) == {z. w\<in>r, \<exists>x y. w=\<langle>x,y\<rangle> \<and> z=\<langle>y,x\<rangle>}"
wenzelm@62149
   207
wenzelm@62149
   208
definition domain :: "i \<Rightarrow> i"
wenzelm@62149
   209
  where "domain(r) == {x. w\<in>r, \<exists>y. w=\<langle>x,y\<rangle>}"
wenzelm@62149
   210
wenzelm@62149
   211
definition range :: "i \<Rightarrow> i"
wenzelm@62149
   212
  where "range(r) == domain(converse(r))"
wenzelm@62149
   213
wenzelm@62149
   214
definition field :: "i \<Rightarrow> i"
wenzelm@62149
   215
  where "field(r) == domain(r) \<union> range(r)"
wenzelm@62149
   216
wenzelm@62149
   217
definition relation :: "i \<Rightarrow> o"  \<comment> \<open>recognizes sets of pairs\<close>
wenzelm@62149
   218
  where "relation(r) == \<forall>z\<in>r. \<exists>x y. z = \<langle>x,y\<rangle>"
wenzelm@62149
   219
wenzelm@65386
   220
definition "function" :: "i \<Rightarrow> o"  \<comment> \<open>recognizes functions; can have non-pairs\<close>
wenzelm@62149
   221
  where "function(r) == \<forall>x y. \<langle>x,y\<rangle> \<in> r \<longrightarrow> (\<forall>y'. \<langle>x,y'\<rangle> \<in> r \<longrightarrow> y = y')"
wenzelm@62149
   222
wenzelm@62149
   223
definition Image :: "[i, i] \<Rightarrow> i"  (infixl "``" 90)  \<comment> \<open>image\<close>
wenzelm@62149
   224
  where image_def: "r `` A  == {y \<in> range(r). \<exists>x\<in>A. \<langle>x,y\<rangle> \<in> r}"
wenzelm@62149
   225
wenzelm@62149
   226
definition vimage :: "[i, i] \<Rightarrow> i"  (infixl "-``" 90)  \<comment> \<open>inverse image\<close>
wenzelm@62149
   227
  where vimage_def: "r -`` A == converse(r)``A"
wenzelm@62149
   228
wenzelm@62149
   229
(* Restrict the relation r to the domain A *)
wenzelm@62149
   230
definition restrict :: "[i, i] \<Rightarrow> i"
wenzelm@62149
   231
  where "restrict(r,A) == {z \<in> r. \<exists>x\<in>A. \<exists>y. z = \<langle>x,y\<rangle>}"
wenzelm@62149
   232
wenzelm@62149
   233
wenzelm@62149
   234
(* Abstraction, application and Cartesian product of a family of sets *)
wenzelm@62149
   235
wenzelm@62149
   236
definition Lambda :: "[i, i \<Rightarrow> i] \<Rightarrow> i"
wenzelm@62149
   237
  where lam_def: "Lambda(A,b) == {\<langle>x,b(x)\<rangle>. x\<in>A}"
wenzelm@62149
   238
wenzelm@62149
   239
definition "apply" :: "[i, i] \<Rightarrow> i"  (infixl "`" 90)  \<comment> \<open>function application\<close>
wenzelm@62149
   240
  where "f`a == \<Union>(f``{a})"
wenzelm@62149
   241
wenzelm@62149
   242
definition Pi :: "[i, i \<Rightarrow> i] \<Rightarrow> i"
wenzelm@62149
   243
  where "Pi(A,B) == {f\<in>Pow(Sigma(A,B)). A\<subseteq>domain(f) & function(f)}"
wenzelm@62149
   244
wenzelm@62149
   245
abbreviation function_space :: "[i, i] \<Rightarrow> i"  (infixr "->" 60)  \<comment> \<open>function space\<close>
wenzelm@62149
   246
  where "A -> B \<equiv> Pi(A, \<lambda>_. B)"
wenzelm@62149
   247
wenzelm@62149
   248
wenzelm@62149
   249
(* binder syntax *)
wenzelm@62149
   250
wenzelm@62149
   251
syntax
wenzelm@62149
   252
  "_PROD"     :: "[pttrn, i, i] => i"        ("(3\<Prod>_\<in>_./ _)" 10)
wenzelm@62149
   253
  "_SUM"      :: "[pttrn, i, i] => i"        ("(3\<Sum>_\<in>_./ _)" 10)
wenzelm@62149
   254
  "_lam"      :: "[pttrn, i, i] => i"        ("(3\<lambda>_\<in>_./ _)" 10)
wenzelm@62149
   255
translations
wenzelm@62149
   256
  "\<Prod>x\<in>A. B"   == "CONST Pi(A, \<lambda>x. B)"
wenzelm@62149
   257
  "\<Sum>x\<in>A. B"   == "CONST Sigma(A, \<lambda>x. B)"
wenzelm@62149
   258
  "\<lambda>x\<in>A. f"    == "CONST Lambda(A, \<lambda>x. f)"
wenzelm@62149
   259
wenzelm@62149
   260
wenzelm@62149
   261
subsection \<open>ASCII syntax\<close>
clasohm@0
   262
wenzelm@61979
   263
notation (ASCII)
wenzelm@61979
   264
  cart_prod       (infixr "*" 80) and
wenzelm@61979
   265
  Int             (infixl "Int" 70) and
wenzelm@61979
   266
  Un              (infixl "Un" 65) and
wenzelm@24826
   267
  function_space  (infixr "\<rightarrow>" 60) and
wenzelm@61979
   268
  Subset          (infixl "<=" 50) and
wenzelm@61979
   269
  mem             (infixl ":" 50) and
wenzelm@61979
   270
  not_mem         (infixl "~:" 50)
wenzelm@24826
   271
wenzelm@61979
   272
syntax (ASCII)
wenzelm@62149
   273
  "_Ball"     :: "[pttrn, i, o] => o"        ("(3ALL _:_./ _)" 10)
wenzelm@62149
   274
  "_Bex"      :: "[pttrn, i, o] => o"        ("(3EX _:_./ _)" 10)
wenzelm@61979
   275
  "_Collect"  :: "[pttrn, i, o] => i"        ("(1{_: _ ./ _})")
wenzelm@61979
   276
  "_Replace"  :: "[pttrn, pttrn, i, o] => i" ("(1{_ ./ _: _, _})")
wenzelm@61979
   277
  "_RepFun"   :: "[i, pttrn, i] => i"        ("(1{_ ./ _: _})" [51,0,51])
wenzelm@61979
   278
  "_UNION"    :: "[pttrn, i, i] => i"        ("(3UN _:_./ _)" 10)
wenzelm@61979
   279
  "_INTER"    :: "[pttrn, i, i] => i"        ("(3INT _:_./ _)" 10)
wenzelm@61979
   280
  "_PROD"     :: "[pttrn, i, i] => i"        ("(3PROD _:_./ _)" 10)
wenzelm@61979
   281
  "_SUM"      :: "[pttrn, i, i] => i"        ("(3SUM _:_./ _)" 10)
wenzelm@61979
   282
  "_lam"      :: "[pttrn, i, i] => i"        ("(3lam _:_./ _)" 10)
wenzelm@61979
   283
  "_Tuple"    :: "[i, is] => i"              ("<(_,/ _)>")
wenzelm@61979
   284
  "_pattern"  :: "patterns => pttrn"         ("<_>")
wenzelm@2540
   285
paulson@13780
   286
wenzelm@60770
   287
subsection \<open>Substitution\<close>
paulson@13780
   288
paulson@13780
   289
(*Useful examples:  singletonI RS subst_elem,  subst_elem RSN (2,IntI) *)
paulson@14227
   290
lemma subst_elem: "[| b\<in>A;  a=b |] ==> a\<in>A"
paulson@13780
   291
by (erule ssubst, assumption)
paulson@13780
   292
paulson@13780
   293
wenzelm@60770
   294
subsection\<open>Bounded universal quantifier\<close>
paulson@13780
   295
paulson@14227
   296
lemma ballI [intro!]: "[| !!x. x\<in>A ==> P(x) |] ==> \<forall>x\<in>A. P(x)"
paulson@13780
   297
by (simp add: Ball_def)
paulson@13780
   298
paulson@15481
   299
lemmas strip = impI allI ballI
paulson@15481
   300
paulson@14227
   301
lemma bspec [dest?]: "[| \<forall>x\<in>A. P(x);  x: A |] ==> P(x)"
paulson@13780
   302
by (simp add: Ball_def)
paulson@13780
   303
paulson@13780
   304
(*Instantiates x first: better for automatic theorem proving?*)
paulson@46820
   305
lemma rev_ballE [elim]:
paulson@46820
   306
    "[| \<forall>x\<in>A. P(x);  x\<notin>A ==> Q;  P(x) ==> Q |] ==> Q"
paulson@46820
   307
by (simp add: Ball_def, blast)
paulson@13780
   308
paulson@46820
   309
lemma ballE: "[| \<forall>x\<in>A. P(x);  P(x) ==> Q;  x\<notin>A ==> Q |] ==> Q"
paulson@13780
   310
by blast
paulson@13780
   311
paulson@13780
   312
(*Used in the datatype package*)
paulson@14227
   313
lemma rev_bspec: "[| x: A;  \<forall>x\<in>A. P(x) |] ==> P(x)"
paulson@13780
   314
by (simp add: Ball_def)
paulson@13780
   315
paulson@46820
   316
(*Trival rewrite rule;   @{term"(\<forall>x\<in>A.P)<->P"} holds only if A is nonempty!*)
paulson@46820
   317
lemma ball_triv [simp]: "(\<forall>x\<in>A. P) <-> ((\<exists>x. x\<in>A) \<longrightarrow> P)"
paulson@13780
   318
by (simp add: Ball_def)
paulson@13780
   319
paulson@13780
   320
(*Congruence rule for rewriting*)
paulson@13780
   321
lemma ball_cong [cong]:
paulson@14227
   322
    "[| A=A';  !!x. x\<in>A' ==> P(x) <-> P'(x) |] ==> (\<forall>x\<in>A. P(x)) <-> (\<forall>x\<in>A'. P'(x))"
paulson@13780
   323
by (simp add: Ball_def)
paulson@13780
   324
wenzelm@18845
   325
lemma atomize_ball:
wenzelm@18845
   326
    "(!!x. x \<in> A ==> P(x)) == Trueprop (\<forall>x\<in>A. P(x))"
wenzelm@18845
   327
  by (simp only: Ball_def atomize_all atomize_imp)
wenzelm@18845
   328
wenzelm@18845
   329
lemmas [symmetric, rulify] = atomize_ball
wenzelm@18845
   330
  and [symmetric, defn] = atomize_ball
wenzelm@18845
   331
paulson@13780
   332
wenzelm@60770
   333
subsection\<open>Bounded existential quantifier\<close>
paulson@13780
   334
paulson@14227
   335
lemma bexI [intro]: "[| P(x);  x: A |] ==> \<exists>x\<in>A. P(x)"
paulson@13780
   336
by (simp add: Bex_def, blast)
paulson@13780
   337
paulson@46820
   338
(*The best argument order when there is only one @{term"x\<in>A"}*)
paulson@14227
   339
lemma rev_bexI: "[| x\<in>A;  P(x) |] ==> \<exists>x\<in>A. P(x)"
paulson@13780
   340
by blast
paulson@13780
   341
paulson@46820
   342
(*Not of the general form for such rules. The existential quanitifer becomes universal. *)
paulson@14227
   343
lemma bexCI: "[| \<forall>x\<in>A. ~P(x) ==> P(a);  a: A |] ==> \<exists>x\<in>A. P(x)"
paulson@13780
   344
by blast
paulson@13780
   345
paulson@14227
   346
lemma bexE [elim!]: "[| \<exists>x\<in>A. P(x);  !!x. [| x\<in>A; P(x) |] ==> Q |] ==> Q"
paulson@13780
   347
by (simp add: Bex_def, blast)
paulson@13780
   348
paulson@46820
   349
(*We do not even have @{term"(\<exists>x\<in>A. True) <-> True"} unless @{term"A" is nonempty!!*)
paulson@14227
   350
lemma bex_triv [simp]: "(\<exists>x\<in>A. P) <-> ((\<exists>x. x\<in>A) & P)"
paulson@13780
   351
by (simp add: Bex_def)
paulson@13780
   352
paulson@13780
   353
lemma bex_cong [cong]:
paulson@46820
   354
    "[| A=A';  !!x. x\<in>A' ==> P(x) <-> P'(x) |]
paulson@14227
   355
     ==> (\<exists>x\<in>A. P(x)) <-> (\<exists>x\<in>A'. P'(x))"
paulson@13780
   356
by (simp add: Bex_def cong: conj_cong)
paulson@13780
   357
paulson@13780
   358
paulson@13780
   359
wenzelm@60770
   360
subsection\<open>Rules for subsets\<close>
paulson@13780
   361
paulson@13780
   362
lemma subsetI [intro!]:
paulson@46820
   363
    "(!!x. x\<in>A ==> x\<in>B) ==> A \<subseteq> B"
paulson@46820
   364
by (simp add: subset_def)
paulson@13780
   365
paulson@13780
   366
(*Rule in Modus Ponens style [was called subsetE] *)
paulson@46820
   367
lemma subsetD [elim]: "[| A \<subseteq> B;  c\<in>A |] ==> c\<in>B"
paulson@13780
   368
apply (unfold subset_def)
paulson@13780
   369
apply (erule bspec, assumption)
paulson@13780
   370
done
paulson@13780
   371
paulson@13780
   372
(*Classical elimination rule*)
paulson@13780
   373
lemma subsetCE [elim]:
paulson@46820
   374
    "[| A \<subseteq> B;  c\<notin>A ==> P;  c\<in>B ==> P |] ==> P"
paulson@46820
   375
by (simp add: subset_def, blast)
paulson@13780
   376
paulson@13780
   377
(*Sometimes useful with premises in this order*)
paulson@14227
   378
lemma rev_subsetD: "[| c\<in>A; A<=B |] ==> c\<in>B"
paulson@13780
   379
by blast
paulson@13780
   380
paulson@46820
   381
lemma contra_subsetD: "[| A \<subseteq> B; c \<notin> B |] ==> c \<notin> A"
paulson@13780
   382
by blast
paulson@13780
   383
paulson@46820
   384
lemma rev_contra_subsetD: "[| c \<notin> B;  A \<subseteq> B |] ==> c \<notin> A"
paulson@13780
   385
by blast
paulson@13780
   386
paulson@46820
   387
lemma subset_refl [simp]: "A \<subseteq> A"
paulson@13780
   388
by blast
paulson@13780
   389
paulson@13780
   390
lemma subset_trans: "[| A<=B;  B<=C |] ==> A<=C"
paulson@13780
   391
by blast
paulson@13780
   392
paulson@13780
   393
(*Useful for proving A<=B by rewriting in some cases*)
paulson@46820
   394
lemma subset_iff:
paulson@46820
   395
     "A<=B <-> (\<forall>x. x\<in>A \<longrightarrow> x\<in>B)"
paulson@13780
   396
apply (unfold subset_def Ball_def)
paulson@13780
   397
apply (rule iff_refl)
paulson@13780
   398
done
paulson@13780
   399
wenzelm@60770
   400
text\<open>For calculations\<close>
paulson@46907
   401
declare subsetD [trans] rev_subsetD [trans] subset_trans [trans]
paulson@46907
   402
paulson@13780
   403
wenzelm@60770
   404
subsection\<open>Rules for equality\<close>
paulson@13780
   405
paulson@13780
   406
(*Anti-symmetry of the subset relation*)
paulson@46820
   407
lemma equalityI [intro]: "[| A \<subseteq> B;  B \<subseteq> A |] ==> A = B"
paulson@46820
   408
by (rule extension [THEN iffD2], rule conjI)
paulson@13780
   409
paulson@13780
   410
paulson@14227
   411
lemma equality_iffI: "(!!x. x\<in>A <-> x\<in>B) ==> A = B"
paulson@13780
   412
by (rule equalityI, blast+)
paulson@13780
   413
wenzelm@45602
   414
lemmas equalityD1 = extension [THEN iffD1, THEN conjunct1]
wenzelm@45602
   415
lemmas equalityD2 = extension [THEN iffD1, THEN conjunct2]
paulson@13780
   416
paulson@13780
   417
lemma equalityE: "[| A = B;  [| A<=B; B<=A |] ==> P |]  ==>  P"
paulson@46820
   418
by (blast dest: equalityD1 equalityD2)
paulson@13780
   419
paulson@13780
   420
lemma equalityCE:
paulson@46820
   421
    "[| A = B;  [| c\<in>A; c\<in>B |] ==> P;  [| c\<notin>A; c\<notin>B |] ==> P |]  ==>  P"
paulson@46820
   422
by (erule equalityE, blast)
paulson@13780
   423
ballarin@27702
   424
lemma equality_iffD:
paulson@46820
   425
  "A = B ==> (!!x. x \<in> A <-> x \<in> B)"
ballarin@27702
   426
  by auto
ballarin@27702
   427
paulson@13780
   428
wenzelm@60770
   429
subsection\<open>Rules for Replace -- the derived form of replacement\<close>
paulson@13780
   430
paulson@46820
   431
lemma Replace_iff:
paulson@46820
   432
    "b \<in> {y. x\<in>A, P(x,y)}  <->  (\<exists>x\<in>A. P(x,b) & (\<forall>y. P(x,y) \<longrightarrow> y=b))"
paulson@13780
   433
apply (unfold Replace_def)
paulson@13780
   434
apply (rule replacement [THEN iff_trans], blast+)
paulson@13780
   435
done
paulson@13780
   436
paulson@13780
   437
(*Introduction; there must be a unique y such that P(x,y), namely y=b. *)
paulson@46820
   438
lemma ReplaceI [intro]:
paulson@46820
   439
    "[| P(x,b);  x: A;  !!y. P(x,y) ==> y=b |] ==>
paulson@46820
   440
     b \<in> {y. x\<in>A, P(x,y)}"
paulson@46820
   441
by (rule Replace_iff [THEN iffD2], blast)
paulson@13780
   442
paulson@13780
   443
(*Elimination; may asssume there is a unique y such that P(x,y), namely y=b. *)
paulson@46820
   444
lemma ReplaceE:
paulson@46820
   445
    "[| b \<in> {y. x\<in>A, P(x,y)};
paulson@46820
   446
        !!x. [| x: A;  P(x,b);  \<forall>y. P(x,y)\<longrightarrow>y=b |] ==> R
paulson@13780
   447
     |] ==> R"
paulson@13780
   448
by (rule Replace_iff [THEN iffD1, THEN bexE], simp+)
paulson@13780
   449
paulson@13780
   450
(*As above but without the (generally useless) 3rd assumption*)
paulson@46820
   451
lemma ReplaceE2 [elim!]:
paulson@46820
   452
    "[| b \<in> {y. x\<in>A, P(x,y)};
paulson@46820
   453
        !!x. [| x: A;  P(x,b) |] ==> R
paulson@13780
   454
     |] ==> R"
paulson@46820
   455
by (erule ReplaceE, blast)
paulson@13780
   456
paulson@13780
   457
lemma Replace_cong [cong]:
paulson@46820
   458
    "[| A=B;  !!x y. x\<in>B ==> P(x,y) <-> Q(x,y) |] ==>
paulson@13780
   459
     Replace(A,P) = Replace(B,Q)"
paulson@46820
   460
apply (rule equality_iffI)
paulson@46820
   461
apply (simp add: Replace_iff)
paulson@13780
   462
done
paulson@13780
   463
paulson@13780
   464
wenzelm@60770
   465
subsection\<open>Rules for RepFun\<close>
paulson@13780
   466
paulson@46820
   467
lemma RepFunI: "a \<in> A ==> f(a) \<in> {f(x). x\<in>A}"
paulson@13780
   468
by (simp add: RepFun_def Replace_iff, blast)
paulson@13780
   469
paulson@13780
   470
(*Useful for coinduction proofs*)
paulson@46820
   471
lemma RepFun_eqI [intro]: "[| b=f(a);  a \<in> A |] ==> b \<in> {f(x). x\<in>A}"
paulson@13780
   472
apply (erule ssubst)
paulson@13780
   473
apply (erule RepFunI)
paulson@13780
   474
done
paulson@13780
   475
paulson@13780
   476
lemma RepFunE [elim!]:
paulson@46820
   477
    "[| b \<in> {f(x). x\<in>A};
paulson@46820
   478
        !!x.[| x\<in>A;  b=f(x) |] ==> P |] ==>
paulson@13780
   479
     P"
paulson@46820
   480
by (simp add: RepFun_def Replace_iff, blast)
paulson@13780
   481
paulson@46820
   482
lemma RepFun_cong [cong]:
paulson@14227
   483
    "[| A=B;  !!x. x\<in>B ==> f(x)=g(x) |] ==> RepFun(A,f) = RepFun(B,g)"
paulson@13780
   484
by (simp add: RepFun_def)
paulson@13780
   485
paulson@46820
   486
lemma RepFun_iff [simp]: "b \<in> {f(x). x\<in>A} <-> (\<exists>x\<in>A. b=f(x))"
paulson@13780
   487
by (unfold Bex_def, blast)
paulson@13780
   488
paulson@14227
   489
lemma triv_RepFun [simp]: "{x. x\<in>A} = A"
paulson@13780
   490
by blast
paulson@13780
   491
paulson@13780
   492
wenzelm@60770
   493
subsection\<open>Rules for Collect -- forming a subset by separation\<close>
paulson@13780
   494
paulson@13780
   495
(*Separation is derivable from Replacement*)
paulson@46820
   496
lemma separation [simp]: "a \<in> {x\<in>A. P(x)} <-> a\<in>A & P(a)"
paulson@13780
   497
by (unfold Collect_def, blast)
paulson@13780
   498
paulson@46820
   499
lemma CollectI [intro!]: "[| a\<in>A;  P(a) |] ==> a \<in> {x\<in>A. P(x)}"
paulson@13780
   500
by simp
paulson@13780
   501
paulson@46820
   502
lemma CollectE [elim!]: "[| a \<in> {x\<in>A. P(x)};  [| a\<in>A; P(a) |] ==> R |] ==> R"
paulson@13780
   503
by simp
paulson@13780
   504
paulson@46820
   505
lemma CollectD1: "a \<in> {x\<in>A. P(x)} ==> a\<in>A"
paulson@13780
   506
by (erule CollectE, assumption)
paulson@13780
   507
paulson@46820
   508
lemma CollectD2: "a \<in> {x\<in>A. P(x)} ==> P(a)"
paulson@13780
   509
by (erule CollectE, assumption)
paulson@13780
   510
paulson@13780
   511
lemma Collect_cong [cong]:
paulson@46820
   512
    "[| A=B;  !!x. x\<in>B ==> P(x) <-> Q(x) |]
paulson@13780
   513
     ==> Collect(A, %x. P(x)) = Collect(B, %x. Q(x))"
paulson@13780
   514
by (simp add: Collect_def)
paulson@13780
   515
paulson@13780
   516
wenzelm@60770
   517
subsection\<open>Rules for Unions\<close>
paulson@13780
   518
paulson@13780
   519
declare Union_iff [simp]
paulson@13780
   520
paulson@13780
   521
(*The order of the premises presupposes that C is rigid; A may be flexible*)
paulson@46820
   522
lemma UnionI [intro]: "[| B: C;  A: B |] ==> A: \<Union>(C)"
paulson@13780
   523
by (simp, blast)
paulson@13780
   524
paulson@46820
   525
lemma UnionE [elim!]: "[| A \<in> \<Union>(C);  !!B.[| A: B;  B: C |] ==> R |] ==> R"
paulson@13780
   526
by (simp, blast)
paulson@13780
   527
paulson@13780
   528
wenzelm@60770
   529
subsection\<open>Rules for Unions of families\<close>
paulson@46820
   530
(* @{term"\<Union>x\<in>A. B(x)"} abbreviates @{term"\<Union>({B(x). x\<in>A})"} *)
paulson@13780
   531
paulson@46820
   532
lemma UN_iff [simp]: "b \<in> (\<Union>x\<in>A. B(x)) <-> (\<exists>x\<in>A. b \<in> B(x))"
paulson@13780
   533
by (simp add: Bex_def, blast)
paulson@13780
   534
paulson@13780
   535
(*The order of the premises presupposes that A is rigid; b may be flexible*)
paulson@14227
   536
lemma UN_I: "[| a: A;  b: B(a) |] ==> b: (\<Union>x\<in>A. B(x))"
paulson@13780
   537
by (simp, blast)
paulson@13780
   538
paulson@13780
   539
paulson@46820
   540
lemma UN_E [elim!]:
paulson@46820
   541
    "[| b \<in> (\<Union>x\<in>A. B(x));  !!x.[| x: A;  b: B(x) |] ==> R |] ==> R"
paulson@46820
   542
by blast
paulson@13780
   543
paulson@46820
   544
lemma UN_cong:
paulson@14227
   545
    "[| A=B;  !!x. x\<in>B ==> C(x)=D(x) |] ==> (\<Union>x\<in>A. C(x)) = (\<Union>x\<in>B. D(x))"
paulson@46820
   546
by simp
paulson@13780
   547
paulson@13780
   548
paulson@46820
   549
(*No "Addcongs [UN_cong]" because @{term\<Union>} is a combination of constants*)
paulson@13780
   550
paulson@13780
   551
(* UN_E appears before UnionE so that it is tried first, to avoid expensive
paulson@13780
   552
  calls to hyp_subst_tac.  Cannot include UN_I as it is unsafe: would enlarge
paulson@13780
   553
  the search space.*)
paulson@13780
   554
paulson@13780
   555
wenzelm@60770
   556
subsection\<open>Rules for the empty set\<close>
paulson@13780
   557
paulson@46820
   558
(*The set @{term"{x\<in>0. False}"} is empty; by foundation it equals 0
paulson@13780
   559
  See Suppes, page 21.*)
paulson@46820
   560
lemma not_mem_empty [simp]: "a \<notin> 0"
paulson@13780
   561
apply (cut_tac foundation)
paulson@13780
   562
apply (best dest: equalityD2)
paulson@13780
   563
done
paulson@13780
   564
wenzelm@45602
   565
lemmas emptyE [elim!] = not_mem_empty [THEN notE]
paulson@13780
   566
paulson@13780
   567
paulson@46820
   568
lemma empty_subsetI [simp]: "0 \<subseteq> A"
paulson@46820
   569
by blast
paulson@13780
   570
paulson@14227
   571
lemma equals0I: "[| !!y. y\<in>A ==> False |] ==> A=0"
paulson@13780
   572
by blast
paulson@13780
   573
paulson@46820
   574
lemma equals0D [dest]: "A=0 ==> a \<notin> A"
paulson@13780
   575
by blast
paulson@13780
   576
paulson@13780
   577
declare sym [THEN equals0D, dest]
paulson@13780
   578
paulson@46820
   579
lemma not_emptyI: "a\<in>A ==> A \<noteq> 0"
paulson@13780
   580
by blast
paulson@13780
   581
paulson@46820
   582
lemma not_emptyE:  "[| A \<noteq> 0;  !!x. x\<in>A ==> R |] ==> R"
paulson@13780
   583
by blast
paulson@13780
   584
paulson@13780
   585
wenzelm@60770
   586
subsection\<open>Rules for Inter\<close>
paulson@14095
   587
paulson@14095
   588
(*Not obviously useful for proving InterI, InterD, InterE*)
paulson@46820
   589
lemma Inter_iff: "A \<in> \<Inter>(C) <-> (\<forall>x\<in>C. A: x) & C\<noteq>0"
paulson@14095
   590
by (simp add: Inter_def Ball_def, blast)
paulson@14095
   591
paulson@14095
   592
(* Intersection is well-behaved only if the family is non-empty! *)
paulson@46820
   593
lemma InterI [intro!]:
paulson@46820
   594
    "[| !!x. x: C ==> A: x;  C\<noteq>0 |] ==> A \<in> \<Inter>(C)"
paulson@14095
   595
by (simp add: Inter_iff)
paulson@14095
   596
paulson@14095
   597
(*A "destruct" rule -- every B in C contains A as an element, but
paulson@14227
   598
  A\<in>B can hold when B\<in>C does not!  This rule is analogous to "spec". *)
paulson@46820
   599
lemma InterD [elim, Pure.elim]: "[| A \<in> \<Inter>(C);  B \<in> C |] ==> A \<in> B"
paulson@14095
   600
by (unfold Inter_def, blast)
paulson@14095
   601
paulson@46820
   602
(*"Classical" elimination rule -- does not require exhibiting @{term"B\<in>C"} *)
paulson@46820
   603
lemma InterE [elim]:
paulson@46820
   604
    "[| A \<in> \<Inter>(C);  B\<notin>C ==> R;  A\<in>B ==> R |] ==> R"
paulson@46820
   605
by (simp add: Inter_def, blast)
paulson@46820
   606
paulson@14095
   607
wenzelm@60770
   608
subsection\<open>Rules for Intersections of families\<close>
paulson@14095
   609
paulson@46820
   610
(* @{term"\<Inter>x\<in>A. B(x)"} abbreviates @{term"\<Inter>({B(x). x\<in>A})"} *)
paulson@14095
   611
paulson@46820
   612
lemma INT_iff: "b \<in> (\<Inter>x\<in>A. B(x)) <-> (\<forall>x\<in>A. b \<in> B(x)) & A\<noteq>0"
paulson@14095
   613
by (force simp add: Inter_def)
paulson@14095
   614
paulson@14227
   615
lemma INT_I: "[| !!x. x: A ==> b: B(x);  A\<noteq>0 |] ==> b: (\<Inter>x\<in>A. B(x))"
paulson@14095
   616
by blast
paulson@14095
   617
paulson@46820
   618
lemma INT_E: "[| b \<in> (\<Inter>x\<in>A. B(x));  a: A |] ==> b \<in> B(a)"
paulson@14095
   619
by blast
paulson@14095
   620
paulson@14095
   621
lemma INT_cong:
paulson@14227
   622
    "[| A=B;  !!x. x\<in>B ==> C(x)=D(x) |] ==> (\<Inter>x\<in>A. C(x)) = (\<Inter>x\<in>B. D(x))"
paulson@14095
   623
by simp
paulson@14095
   624
paulson@46820
   625
(*No "Addcongs [INT_cong]" because @{term\<Inter>} is a combination of constants*)
paulson@14095
   626
paulson@14095
   627
wenzelm@60770
   628
subsection\<open>Rules for Powersets\<close>
paulson@13780
   629
paulson@46820
   630
lemma PowI: "A \<subseteq> B ==> A \<in> Pow(B)"
paulson@13780
   631
by (erule Pow_iff [THEN iffD2])
paulson@13780
   632
paulson@14227
   633
lemma PowD: "A \<in> Pow(B)  ==>  A<=B"
paulson@13780
   634
by (erule Pow_iff [THEN iffD1])
paulson@13780
   635
paulson@13780
   636
declare Pow_iff [iff]
paulson@13780
   637
wenzelm@61798
   638
lemmas Pow_bottom = empty_subsetI [THEN PowI]    \<comment>\<open>@{term"0 \<in> Pow(B)"}\<close>
wenzelm@61798
   639
lemmas Pow_top = subset_refl [THEN PowI]         \<comment>\<open>@{term"A \<in> Pow(A)"}\<close>
paulson@13780
   640
paulson@13780
   641
wenzelm@60770
   642
subsection\<open>Cantor's Theorem: There is no surjection from a set to its powerset.\<close>
paulson@13780
   643
paulson@46820
   644
(*The search is undirected.  Allowing redundant introduction rules may
paulson@13780
   645
  make it diverge.  Variable b represents ANY map, such as
paulson@14227
   646
  (lam x\<in>A.b(x)): A->Pow(A). *)
paulson@46820
   647
lemma cantor: "\<exists>S \<in> Pow(A). \<forall>x\<in>A. b(x) \<noteq> S"
paulson@13780
   648
by (best elim!: equalityCE del: ReplaceI RepFun_eqI)
paulson@13780
   649
clasohm@0
   650
end