src/HOL/ZF/HOLZF.thy
author haftmann
Wed Sep 26 20:27:55 2007 +0200 (2007-09-26)
changeset 24728 e2b3a1065676
parent 24124 4399175e3014
child 24784 102e0e732495
permissions -rw-r--r--
moved Finite_Set before Datatype
obua@19203
     1
(*  Title:      HOL/ZF/HOLZF.thy
obua@19203
     2
    ID:         $Id$
obua@19203
     3
    Author:     Steven Obua
obua@19203
     4
obua@19203
     5
    Axiomatizes the ZFC universe as an HOL type.
obua@19203
     6
    See "Partizan Games in Isabelle/HOLZF", available from http://www4.in.tum.de/~obua/partizan
obua@19203
     7
*)
obua@19203
     8
obua@19203
     9
theory HOLZF 
obua@19203
    10
imports Helper
obua@19203
    11
begin
obua@19203
    12
obua@19203
    13
typedecl ZF
obua@19203
    14
wenzelm@22690
    15
axiomatization
wenzelm@22690
    16
  Empty :: ZF and
wenzelm@22690
    17
  Elem :: "ZF \<Rightarrow> ZF \<Rightarrow> bool" and
wenzelm@22690
    18
  Sum :: "ZF \<Rightarrow> ZF" and
wenzelm@22690
    19
  Power :: "ZF \<Rightarrow> ZF" and
wenzelm@22690
    20
  Repl :: "ZF \<Rightarrow> (ZF \<Rightarrow> ZF) \<Rightarrow> ZF" and
obua@19203
    21
  Inf :: ZF
obua@19203
    22
obua@19203
    23
constdefs
obua@19203
    24
  Upair:: "ZF \<Rightarrow> ZF \<Rightarrow> ZF"
obua@19203
    25
  "Upair a b == Repl (Power (Power Empty)) (% x. if x = Empty then a else b)"
obua@19203
    26
  Singleton:: "ZF \<Rightarrow> ZF"
obua@19203
    27
  "Singleton x == Upair x x"
obua@19203
    28
  union :: "ZF \<Rightarrow> ZF \<Rightarrow> ZF"
obua@19203
    29
  "union A B == Sum (Upair A B)"
obua@19203
    30
  SucNat:: "ZF \<Rightarrow> ZF"
obua@19203
    31
  "SucNat x == union x (Singleton x)"
obua@19203
    32
  subset :: "ZF \<Rightarrow> ZF \<Rightarrow> bool"
obua@19203
    33
  "subset A B == ! x. Elem x A \<longrightarrow> Elem x B"
obua@19203
    34
obua@19203
    35
axioms
obua@19203
    36
  Empty: "Not (Elem x Empty)"
obua@19203
    37
  Ext: "(x = y) = (! z. Elem z x = Elem z y)"
obua@19203
    38
  Sum: "Elem z (Sum x) = (? y. Elem z y & Elem y x)"
obua@19203
    39
  Power: "Elem y (Power x) = (subset y x)"
obua@19203
    40
  Repl: "Elem b (Repl A f) = (? a. Elem a A & b = f a)"
obua@19203
    41
  Regularity: "A \<noteq> Empty \<longrightarrow> (? x. Elem x A & (! y. Elem y x \<longrightarrow> Not (Elem y A)))"
obua@19203
    42
  Infinity: "Elem Empty Inf & (! x. Elem x Inf \<longrightarrow> Elem (SucNat x) Inf)"
obua@19203
    43
obua@19203
    44
constdefs
obua@19203
    45
  Sep:: "ZF \<Rightarrow> (ZF \<Rightarrow> bool) \<Rightarrow> ZF"
obua@19203
    46
  "Sep A p == (if (!x. Elem x A \<longrightarrow> Not (p x)) then Empty else 
obua@19203
    47
  (let z = (\<some> x. Elem x A & p x) in
obua@19203
    48
   let f = % x. (if p x then x else z) in Repl A f))" 
obua@19203
    49
obua@19203
    50
thm Power[unfolded subset_def]
obua@19203
    51
obua@19203
    52
theorem Sep: "Elem b (Sep A p) = (Elem b A & p b)"
obua@19203
    53
  apply (auto simp add: Sep_def Empty)
obua@19203
    54
  apply (auto simp add: Let_def Repl)
obua@19203
    55
  apply (rule someI2, auto)+
obua@19203
    56
  done
obua@19203
    57
obua@19203
    58
lemma subset_empty: "subset Empty A"
obua@19203
    59
  by (simp add: subset_def Empty)
obua@19203
    60
obua@19203
    61
theorem Upair: "Elem x (Upair a b) = (x = a | x = b)"
obua@19203
    62
  apply (auto simp add: Upair_def Repl)
obua@19203
    63
  apply (rule exI[where x=Empty])
obua@19203
    64
  apply (simp add: Power subset_empty)
obua@19203
    65
  apply (rule exI[where x="Power Empty"])
obua@19203
    66
  apply (auto)
obua@19203
    67
  apply (auto simp add: Ext Power subset_def Empty)
obua@19203
    68
  apply (drule spec[where x=Empty], simp add: Empty)+
obua@19203
    69
  done
obua@19203
    70
obua@19203
    71
lemma Singleton: "Elem x (Singleton y) = (x = y)"
obua@19203
    72
  by (simp add: Singleton_def Upair)
obua@19203
    73
obua@19203
    74
constdefs 
obua@19203
    75
  Opair:: "ZF \<Rightarrow> ZF \<Rightarrow> ZF"
obua@19203
    76
  "Opair a b == Upair (Upair a a) (Upair a b)"
obua@19203
    77
obua@19203
    78
lemma Upair_singleton: "(Upair a a = Upair c d) = (a = c & a = d)"
obua@19203
    79
  by (auto simp add: Ext[where x="Upair a a"] Upair)
obua@19203
    80
obua@19203
    81
lemma Upair_fsteq: "(Upair a b = Upair a c) = ((a = b & a = c) | (b = c))"
obua@19203
    82
  by (auto simp add: Ext[where x="Upair a b"] Upair)
obua@19203
    83
obua@19203
    84
lemma Upair_comm: "Upair a b = Upair b a"
obua@19203
    85
  by (auto simp add: Ext Upair)
obua@19203
    86
obua@19203
    87
theorem Opair: "(Opair a b = Opair c d) = (a = c & b = d)"
obua@19203
    88
  proof -
obua@19203
    89
    have fst: "(Opair a b = Opair c d) \<Longrightarrow> a = c"
obua@19203
    90
      apply (simp add: Opair_def)
obua@19203
    91
      apply (simp add: Ext[where x="Upair (Upair a a) (Upair a b)"])
obua@19203
    92
      apply (drule spec[where x="Upair a a"])
obua@19203
    93
      apply (auto simp add: Upair Upair_singleton)
obua@19203
    94
      done
obua@19203
    95
    show ?thesis
obua@19203
    96
      apply (auto)
obua@19203
    97
      apply (erule fst)
obua@19203
    98
      apply (frule fst)
obua@19203
    99
      apply (auto simp add: Opair_def Upair_fsteq)
obua@19203
   100
      done
obua@19203
   101
  qed
obua@19203
   102
obua@19203
   103
constdefs 
obua@19203
   104
  Replacement :: "ZF \<Rightarrow> (ZF \<Rightarrow> ZF option) \<Rightarrow> ZF"
obua@19203
   105
  "Replacement A f == Repl (Sep A (% a. f a \<noteq> None)) (the o f)"
obua@19203
   106
obua@19203
   107
theorem Replacement: "Elem y (Replacement A f) = (? x. Elem x A & f x = Some y)"
obua@19203
   108
  by (auto simp add: Replacement_def Repl Sep) 
obua@19203
   109
obua@19203
   110
constdefs
obua@19203
   111
  Fst :: "ZF \<Rightarrow> ZF"
obua@19203
   112
  "Fst q == SOME x. ? y. q = Opair x y"
obua@19203
   113
  Snd :: "ZF \<Rightarrow> ZF"
obua@19203
   114
  "Snd q == SOME y. ? x. q = Opair x y"
obua@19203
   115
obua@19203
   116
theorem Fst: "Fst (Opair x y) = x"
obua@19203
   117
  apply (simp add: Fst_def)
obua@19203
   118
  apply (rule someI2)
obua@19203
   119
  apply (simp_all add: Opair)
obua@19203
   120
  done
obua@19203
   121
obua@19203
   122
theorem Snd: "Snd (Opair x y) = y"
obua@19203
   123
  apply (simp add: Snd_def)
obua@19203
   124
  apply (rule someI2)
obua@19203
   125
  apply (simp_all add: Opair)
obua@19203
   126
  done
obua@19203
   127
obua@19203
   128
constdefs 
obua@19203
   129
  isOpair :: "ZF \<Rightarrow> bool"
obua@19203
   130
  "isOpair q == ? x y. q = Opair x y"
obua@19203
   131
obua@19203
   132
lemma isOpair: "isOpair (Opair x y) = True"
obua@19203
   133
  by (auto simp add: isOpair_def)
obua@19203
   134
obua@19203
   135
lemma FstSnd: "isOpair x \<Longrightarrow> Opair (Fst x) (Snd x) = x"
obua@19203
   136
  by (auto simp add: isOpair_def Fst Snd)
obua@19203
   137
  
obua@19203
   138
constdefs
obua@19203
   139
  CartProd :: "ZF \<Rightarrow> ZF \<Rightarrow> ZF"
obua@19203
   140
  "CartProd A B == Sum(Repl A (% a. Repl B (% b. Opair a b)))"
obua@19203
   141
obua@19203
   142
lemma CartProd: "Elem x (CartProd A B) = (? a b. Elem a A & Elem b B & x = (Opair a b))"
obua@19203
   143
  apply (auto simp add: CartProd_def Sum Repl)
obua@19203
   144
  apply (rule_tac x="Repl B (Opair a)" in exI)
obua@19203
   145
  apply (auto simp add: Repl)
obua@19203
   146
  done
obua@19203
   147
obua@19203
   148
constdefs
obua@19203
   149
  explode :: "ZF \<Rightarrow> ZF set"
obua@19203
   150
  "explode z == { x. Elem x z }"
obua@19203
   151
obua@19203
   152
lemma explode_Empty: "(explode x = {}) = (x = Empty)"
obua@19203
   153
  by (auto simp add: explode_def Ext Empty)
obua@19203
   154
obua@19203
   155
lemma explode_Elem: "(x \<in> explode X) = (Elem x X)"
obua@19203
   156
  by (simp add: explode_def)
obua@19203
   157
obua@19203
   158
lemma Elem_explode_in: "\<lbrakk> Elem a A; explode A \<subseteq> B\<rbrakk> \<Longrightarrow> a \<in> B"
obua@19203
   159
  by (auto simp add: explode_def)
obua@19203
   160
obua@19203
   161
lemma explode_CartProd_eq: "explode (CartProd a b) = (% (x,y). Opair x y) ` ((explode a) \<times> (explode b))"
obua@19203
   162
  by (simp add: explode_def expand_set_eq CartProd image_def)
obua@19203
   163
obua@19203
   164
lemma explode_Repl_eq: "explode (Repl A f) = image f (explode A)"
obua@19203
   165
  by (simp add: explode_def Repl image_def)
obua@19203
   166
obua@19203
   167
constdefs
obua@19203
   168
  Domain :: "ZF \<Rightarrow> ZF"
obua@19203
   169
  "Domain f == Replacement f (% p. if isOpair p then Some (Fst p) else None)"
obua@19203
   170
  Range :: "ZF \<Rightarrow> ZF"
obua@19203
   171
  "Range f == Replacement f (% p. if isOpair p then Some (Snd p) else None)"
obua@19203
   172
obua@19203
   173
theorem Domain: "Elem x (Domain f) = (? y. Elem (Opair x y) f)"
obua@19203
   174
  apply (auto simp add: Domain_def Replacement)
obua@19203
   175
  apply (rule_tac x="Snd x" in exI)
obua@19203
   176
  apply (simp add: FstSnd)
obua@19203
   177
  apply (rule_tac x="Opair x y" in exI)
obua@19203
   178
  apply (simp add: isOpair Fst)
obua@19203
   179
  done
obua@19203
   180
obua@19203
   181
theorem Range: "Elem y (Range f) = (? x. Elem (Opair x y) f)"
obua@19203
   182
  apply (auto simp add: Range_def Replacement)
obua@19203
   183
  apply (rule_tac x="Fst x" in exI)
obua@19203
   184
  apply (simp add: FstSnd)
obua@19203
   185
  apply (rule_tac x="Opair x y" in exI)
obua@19203
   186
  apply (simp add: isOpair Snd)
obua@19203
   187
  done
obua@19203
   188
obua@19203
   189
theorem union: "Elem x (union A B) = (Elem x A | Elem x B)"
obua@19203
   190
  by (auto simp add: union_def Sum Upair)
obua@19203
   191
obua@19203
   192
constdefs
obua@19203
   193
  Field :: "ZF \<Rightarrow> ZF"
obua@19203
   194
  "Field A == union (Domain A) (Range A)"
obua@19203
   195
obua@19203
   196
constdefs
obua@19203
   197
  "\<acute>"         :: "ZF \<Rightarrow> ZF => ZF"    (infixl 90) --{*function application*} 
obua@19203
   198
  app_def:  "f \<acute> x == (THE y. Elem (Opair x y) f)"
obua@19203
   199
obua@19203
   200
constdefs
obua@19203
   201
  isFun :: "ZF \<Rightarrow> bool"
obua@19203
   202
  "isFun f == (! x y1 y2. Elem (Opair x y1) f & Elem (Opair x y2) f \<longrightarrow> y1 = y2)"
obua@19203
   203
obua@19203
   204
constdefs
obua@19203
   205
  Lambda :: "ZF \<Rightarrow> (ZF \<Rightarrow> ZF) \<Rightarrow> ZF"
obua@19203
   206
  "Lambda A f == Repl A (% x. Opair x (f x))"
obua@19203
   207
obua@19203
   208
lemma Lambda_app: "Elem x A \<Longrightarrow> (Lambda A f)\<acute>x = f x"
obua@19203
   209
  by (simp add: app_def Lambda_def Repl Opair)
obua@19203
   210
obua@19203
   211
lemma isFun_Lambda: "isFun (Lambda A f)"
obua@19203
   212
  by (auto simp add: isFun_def Lambda_def Repl Opair)
obua@19203
   213
obua@19203
   214
lemma domain_Lambda: "Domain (Lambda A f) = A"
obua@19203
   215
  apply (auto simp add: Domain_def)
obua@19203
   216
  apply (subst Ext)
obua@19203
   217
  apply (auto simp add: Replacement)
obua@19203
   218
  apply (simp add: Lambda_def Repl)
obua@19203
   219
  apply (auto simp add: Fst)
obua@19203
   220
  apply (simp add: Lambda_def Repl)
obua@19203
   221
  apply (rule_tac x="Opair z (f z)" in exI)
obua@19203
   222
  apply (auto simp add: Fst isOpair_def)
obua@19203
   223
  done
obua@19203
   224
obua@19203
   225
lemma Lambda_ext: "(Lambda s f = Lambda t g) = (s = t & (! x. Elem x s \<longrightarrow> f x = g x))"
obua@19203
   226
proof -
obua@19203
   227
  have "Lambda s f = Lambda t g \<Longrightarrow> s = t"
obua@19203
   228
    apply (subst domain_Lambda[where A = s and f = f, symmetric])
obua@19203
   229
    apply (subst domain_Lambda[where A = t and f = g, symmetric])
obua@19203
   230
    apply auto
obua@19203
   231
    done
obua@19203
   232
  then show ?thesis
obua@19203
   233
    apply auto
obua@19203
   234
    apply (subst Lambda_app[where f=f, symmetric], simp)
obua@19203
   235
    apply (subst Lambda_app[where f=g, symmetric], simp)
obua@19203
   236
    apply auto
obua@19203
   237
    apply (auto simp add: Lambda_def Repl Ext)
obua@19203
   238
    apply (auto simp add: Ext[symmetric])
obua@19203
   239
    done
obua@19203
   240
qed
obua@19203
   241
obua@19203
   242
constdefs 
obua@19203
   243
  PFun :: "ZF \<Rightarrow> ZF \<Rightarrow> ZF"
obua@19203
   244
  "PFun A B == Sep (Power (CartProd A B)) isFun"
obua@19203
   245
  Fun :: "ZF \<Rightarrow> ZF \<Rightarrow> ZF"
obua@19203
   246
  "Fun A B == Sep (PFun A B) (\<lambda> f. Domain f = A)"
obua@19203
   247
obua@19203
   248
lemma Fun_Range: "Elem f (Fun U V) \<Longrightarrow> subset (Range f) V"
obua@19203
   249
  apply (simp add: Fun_def Sep PFun_def Power subset_def CartProd)
obua@19203
   250
  apply (auto simp add: Domain Range)
obua@19203
   251
  apply (erule_tac x="Opair xa x" in allE)
obua@19203
   252
  apply (auto simp add: Opair)
obua@19203
   253
  done
obua@19203
   254
obua@19203
   255
lemma Elem_Elem_PFun: "Elem F (PFun U V) \<Longrightarrow> Elem p F \<Longrightarrow> isOpair p & Elem (Fst p) U & Elem (Snd p) V"
obua@19203
   256
  apply (simp add: PFun_def Sep Power subset_def, clarify)
obua@19203
   257
  apply (erule_tac x=p in allE)
obua@19203
   258
  apply (auto simp add: CartProd isOpair Fst Snd)
obua@19203
   259
  done
obua@19203
   260
obua@19203
   261
lemma Fun_implies_PFun[simp]: "Elem f (Fun U V) \<Longrightarrow> Elem f (PFun U V)"
obua@19203
   262
  by (simp add: Fun_def Sep)
obua@19203
   263
obua@19203
   264
lemma Elem_Elem_Fun: "Elem F (Fun U V) \<Longrightarrow> Elem p F \<Longrightarrow> isOpair p & Elem (Fst p) U & Elem (Snd p) V" 
obua@19203
   265
  by (auto simp add: Elem_Elem_PFun dest: Fun_implies_PFun)
obua@19203
   266
obua@19203
   267
lemma PFun_inj: "Elem F (PFun U V) \<Longrightarrow> Elem x F \<Longrightarrow> Elem y F \<Longrightarrow> Fst x = Fst y \<Longrightarrow> Snd x = Snd y"
obua@19203
   268
  apply (frule Elem_Elem_PFun[where p=x], simp)
obua@19203
   269
  apply (frule Elem_Elem_PFun[where p=y], simp)
obua@19203
   270
  apply (subgoal_tac "isFun F")
obua@19203
   271
  apply (simp add: isFun_def isOpair_def)  
obua@19203
   272
  apply (auto simp add: Fst Snd, blast)
obua@19203
   273
  apply (auto simp add: PFun_def Sep)
obua@19203
   274
  done
obua@19203
   275
obua@19203
   276
lemma Fun_total: "\<lbrakk>Elem F (Fun U V); Elem a U\<rbrakk> \<Longrightarrow> \<exists>x. Elem (Opair a x) F"
wenzelm@24124
   277
  using [[simp_depth_limit = 2]]
obua@19203
   278
  by (auto simp add: Fun_def Sep Domain)
obua@19203
   279
obua@19203
   280
obua@19203
   281
lemma unique_fun_value: "\<lbrakk>isFun f; Elem x (Domain f)\<rbrakk> \<Longrightarrow> ?! y. Elem (Opair x y) f"
obua@19203
   282
  by (auto simp add: Domain isFun_def)
obua@19203
   283
obua@19203
   284
lemma fun_value_in_range: "\<lbrakk>isFun f; Elem x (Domain f)\<rbrakk> \<Longrightarrow> Elem (f\<acute>x) (Range f)"
obua@19203
   285
  apply (auto simp add: Range)
obua@19203
   286
  apply (drule unique_fun_value)
obua@19203
   287
  apply simp
obua@19203
   288
  apply (simp add: app_def)
obua@19203
   289
  apply (rule exI[where x=x])
obua@19203
   290
  apply (auto simp add: the_equality)
obua@19203
   291
  done
obua@19203
   292
obua@19203
   293
lemma fun_range_witness: "\<lbrakk>isFun f; Elem y (Range f)\<rbrakk> \<Longrightarrow> ? x. Elem x (Domain f) & f\<acute>x = y"
obua@19203
   294
  apply (auto simp add: Range)
obua@19203
   295
  apply (rule_tac x="x" in exI)
obua@19203
   296
  apply (auto simp add: app_def the_equality isFun_def Domain)
obua@19203
   297
  done
obua@19203
   298
obua@19203
   299
lemma Elem_Fun_Lambda: "Elem F (Fun U V) \<Longrightarrow> ? f. F = Lambda U f"
obua@19203
   300
  apply (rule exI[where x= "% x. (THE y. Elem (Opair x y) F)"])
obua@19203
   301
  apply (simp add: Ext Lambda_def Repl Domain)
obua@19203
   302
  apply (simp add: Ext[symmetric])
obua@19203
   303
  apply auto
obua@19203
   304
  apply (frule Elem_Elem_Fun)
obua@19203
   305
  apply auto
obua@19203
   306
  apply (rule_tac x="Fst z" in exI)
obua@19203
   307
  apply (simp add: isOpair_def)
obua@19203
   308
  apply (auto simp add: Fst Snd Opair)
obua@19203
   309
  apply (rule theI2')
obua@19203
   310
  apply auto
obua@19203
   311
  apply (drule Fun_implies_PFun)
obua@19203
   312
  apply (drule_tac x="Opair x ya" and y="Opair x yb" in PFun_inj)
obua@19203
   313
  apply (auto simp add: Fst Snd)
obua@19203
   314
  apply (drule Fun_implies_PFun)
obua@19203
   315
  apply (drule_tac x="Opair x y" and y="Opair x ya" in PFun_inj)
obua@19203
   316
  apply (auto simp add: Fst Snd)
obua@19203
   317
  apply (rule theI2')
obua@19203
   318
  apply (auto simp add: Fun_total)
obua@19203
   319
  apply (drule Fun_implies_PFun)
obua@19203
   320
  apply (drule_tac x="Opair a x" and y="Opair a y" in PFun_inj)
obua@19203
   321
  apply (auto simp add: Fst Snd)
obua@19203
   322
  done
obua@19203
   323
 
obua@19203
   324
lemma Elem_Lambda_Fun: "Elem (Lambda A f) (Fun U V) = (A = U & (! x. Elem x A \<longrightarrow> Elem (f x) V))"
obua@19203
   325
proof -
obua@19203
   326
  have "Elem (Lambda A f) (Fun U V) \<Longrightarrow> A = U"
obua@19203
   327
    by (simp add: Fun_def Sep domain_Lambda)
obua@19203
   328
  then show ?thesis
obua@19203
   329
    apply auto
obua@19203
   330
    apply (drule Fun_Range)
obua@19203
   331
    apply (subgoal_tac "f x = ((Lambda U f) \<acute> x)")
obua@19203
   332
    prefer 2
obua@19203
   333
    apply (simp add: Lambda_app)
obua@19203
   334
    apply simp
obua@19203
   335
    apply (subgoal_tac "Elem (Lambda U f \<acute> x) (Range (Lambda U f))")
obua@19203
   336
    apply (simp add: subset_def)
obua@19203
   337
    apply (rule fun_value_in_range)
obua@19203
   338
    apply (simp_all add: isFun_Lambda domain_Lambda)
obua@19203
   339
    apply (simp add: Fun_def Sep PFun_def Power domain_Lambda isFun_Lambda)
obua@19203
   340
    apply (auto simp add: subset_def CartProd)
obua@19203
   341
    apply (rule_tac x="Fst x" in exI)
obua@19203
   342
    apply (auto simp add: Lambda_def Repl Fst)
obua@19203
   343
    done
obua@19203
   344
qed    
obua@19203
   345
obua@19203
   346
obua@19203
   347
constdefs
obua@19203
   348
  is_Elem_of :: "(ZF * ZF) set"
obua@19203
   349
  "is_Elem_of == { (a,b) | a b. Elem a b }"
obua@19203
   350
obua@19203
   351
lemma cond_wf_Elem:
obua@19203
   352
  assumes hyps:"\<forall>x. (\<forall>y. Elem y x \<longrightarrow> Elem y U \<longrightarrow> P y) \<longrightarrow> Elem x U \<longrightarrow> P x" "Elem a U"
obua@19203
   353
  shows "P a"
obua@19203
   354
proof -
obua@19203
   355
  {
obua@19203
   356
    fix P
obua@19203
   357
    fix U
obua@19203
   358
    fix a
obua@19203
   359
    assume P_induct: "(\<forall>x. (\<forall>y. Elem y x \<longrightarrow> Elem y U \<longrightarrow> P y) \<longrightarrow> (Elem x U \<longrightarrow> P x))"
obua@19203
   360
    assume a_in_U: "Elem a U"
obua@19203
   361
    have "P a"
obua@19203
   362
      proof -
obua@19203
   363
	term "P"
obua@19203
   364
	term Sep
obua@19203
   365
	let ?Z = "Sep U (Not o P)"
obua@19203
   366
	have "?Z = Empty \<longrightarrow> P a" by (simp add: Ext Sep Empty a_in_U)	
obua@19203
   367
	moreover have "?Z \<noteq> Empty \<longrightarrow> False"
obua@19203
   368
	  proof 
obua@19203
   369
	    assume not_empty: "?Z \<noteq> Empty" 
obua@19203
   370
	    note thereis_x = Regularity[where A="?Z", simplified not_empty, simplified]
obua@19203
   371
	    then obtain x where x_def: "Elem x ?Z & (! y. Elem y x \<longrightarrow> Not (Elem y ?Z))" ..
obua@19203
   372
            then have x_induct:"! y. Elem y x \<longrightarrow> Elem y U \<longrightarrow> P y" by (simp add: Sep)
obua@19203
   373
	    have "Elem x U \<longrightarrow> P x" 
obua@19203
   374
	      by (rule impE[OF spec[OF P_induct, where x=x], OF x_induct], assumption)
obua@19203
   375
	    moreover have "Elem x U & Not(P x)"
obua@19203
   376
	      apply (insert x_def)
obua@19203
   377
	      apply (simp add: Sep)
obua@19203
   378
	      done
obua@19203
   379
	    ultimately show "False" by auto
obua@19203
   380
	  qed
obua@19203
   381
	ultimately show "P a" by auto
obua@19203
   382
      qed
obua@19203
   383
  }
obua@19203
   384
  with hyps show ?thesis by blast
obua@19203
   385
qed    
obua@19203
   386
obua@19203
   387
lemma cond2_wf_Elem:
obua@19203
   388
  assumes 
obua@19203
   389
     special_P: "? U. ! x. Not(Elem x U) \<longrightarrow> (P x)"
obua@19203
   390
     and P_induct: "\<forall>x. (\<forall>y. Elem y x \<longrightarrow> P y) \<longrightarrow> P x"
obua@19203
   391
  shows
obua@19203
   392
     "P a"
obua@19203
   393
proof -
obua@19203
   394
  have "? U Q. P = (\<lambda> x. (Elem x U \<longrightarrow> Q x))"
obua@19203
   395
  proof -
obua@19203
   396
    from special_P obtain U where U:"! x. Not(Elem x U) \<longrightarrow> (P x)" ..
obua@19203
   397
    show ?thesis
obua@19203
   398
      apply (rule_tac exI[where x=U])
obua@19203
   399
      apply (rule exI[where x="P"])
obua@19203
   400
      apply (rule ext)
obua@19203
   401
      apply (auto simp add: U)
obua@19203
   402
      done
obua@19203
   403
  qed    
obua@19203
   404
  then obtain U where "? Q. P = (\<lambda> x. (Elem x U \<longrightarrow> Q x))" ..
obua@19203
   405
  then obtain Q where UQ: "P = (\<lambda> x. (Elem x U \<longrightarrow> Q x))" ..
obua@19203
   406
  show ?thesis
obua@19203
   407
    apply (auto simp add: UQ)
obua@19203
   408
    apply (rule cond_wf_Elem)
obua@19203
   409
    apply (rule P_induct[simplified UQ])
obua@19203
   410
    apply simp
obua@19203
   411
    done
obua@19203
   412
qed
obua@19203
   413
obua@19203
   414
consts
obua@19203
   415
  nat2Nat :: "nat \<Rightarrow> ZF"
obua@19203
   416
obua@19203
   417
primrec
obua@19203
   418
nat2Nat_0[intro]:  "nat2Nat 0 = Empty"
obua@19203
   419
nat2Nat_Suc[intro]:  "nat2Nat (Suc n) = SucNat (nat2Nat n)"
obua@19203
   420
obua@19203
   421
constdefs
obua@19203
   422
  Nat2nat :: "ZF \<Rightarrow> nat"
obua@19203
   423
  "Nat2nat == inv nat2Nat"
obua@19203
   424
obua@19203
   425
lemma Elem_nat2Nat_inf[intro]: "Elem (nat2Nat n) Inf"
obua@19203
   426
  apply (induct n)
obua@19203
   427
  apply (simp_all add: Infinity)
obua@19203
   428
  done
obua@19203
   429
obua@19203
   430
constdefs
obua@19203
   431
  Nat :: ZF
obua@19203
   432
  "Nat == Sep Inf (\<lambda> N. ? n. nat2Nat n = N)"
obua@19203
   433
obua@19203
   434
lemma Elem_nat2Nat_Nat[intro]: "Elem (nat2Nat n) Nat"
obua@19203
   435
  by (auto simp add: Nat_def Sep)
obua@19203
   436
obua@19203
   437
lemma Elem_Empty_Nat: "Elem Empty Nat"
obua@19203
   438
  by (auto simp add: Nat_def Sep Infinity)
obua@19203
   439
obua@19203
   440
lemma Elem_SucNat_Nat: "Elem N Nat \<Longrightarrow> Elem (SucNat N) Nat"
obua@19203
   441
  by (auto simp add: Nat_def Sep Infinity)
obua@19203
   442
  
obua@19203
   443
lemma no_infinite_Elem_down_chain:
obua@19203
   444
  "Not (? f. isFun f & Domain f = Nat & (! N. Elem N Nat \<longrightarrow> Elem (f\<acute>(SucNat N)) (f\<acute>N)))"
obua@19203
   445
proof -
obua@19203
   446
  {
obua@19203
   447
    fix f
obua@19203
   448
    assume f:"isFun f & Domain f = Nat & (! N. Elem N Nat \<longrightarrow> Elem (f\<acute>(SucNat N)) (f\<acute>N))"
obua@19203
   449
    let ?r = "Range f"
obua@19203
   450
    have "?r \<noteq> Empty"
obua@19203
   451
      apply (auto simp add: Ext Empty)
obua@19203
   452
      apply (rule exI[where x="f\<acute>Empty"])
obua@19203
   453
      apply (rule fun_value_in_range)
obua@19203
   454
      apply (auto simp add: f Elem_Empty_Nat)
obua@19203
   455
      done
obua@19203
   456
    then have "? x. Elem x ?r & (! y. Elem y x \<longrightarrow> Not(Elem y ?r))"
obua@19203
   457
      by (simp add: Regularity)
obua@19203
   458
    then obtain x where x: "Elem x ?r & (! y. Elem y x \<longrightarrow> Not(Elem y ?r))" ..
obua@19203
   459
    then have "? N. Elem N (Domain f) & f\<acute>N = x" 
obua@19203
   460
      apply (rule_tac fun_range_witness)
obua@19203
   461
      apply (simp_all add: f)
obua@19203
   462
      done
obua@19203
   463
    then have "? N. Elem N Nat & f\<acute>N = x" 
obua@19203
   464
      by (simp add: f)
obua@19203
   465
    then obtain N where N: "Elem N Nat & f\<acute>N = x" ..
obua@19203
   466
    from N have N': "Elem N Nat" by auto
obua@19203
   467
    let ?y = "f\<acute>(SucNat N)"
obua@19203
   468
    have Elem_y_r: "Elem ?y ?r"
obua@19203
   469
      by (simp_all add: f Elem_SucNat_Nat N fun_value_in_range)
obua@19203
   470
    have "Elem ?y (f\<acute>N)" by (auto simp add: f N')
obua@19203
   471
    then have "Elem ?y x" by (simp add: N)
obua@19203
   472
    with x have "Not (Elem ?y ?r)" by auto
obua@19203
   473
    with Elem_y_r have "False" by auto
obua@19203
   474
  }
obua@19203
   475
  then show ?thesis by auto
obua@19203
   476
qed
obua@19203
   477
obua@19203
   478
lemma Upair_nonEmpty: "Upair a b \<noteq> Empty"
obua@19203
   479
  by (auto simp add: Ext Empty Upair)  
obua@19203
   480
obua@19203
   481
lemma Singleton_nonEmpty: "Singleton x \<noteq> Empty"
obua@19203
   482
  by (auto simp add: Singleton_def Upair_nonEmpty)
obua@19203
   483
obua@19203
   484
lemma antisym_Elem: "Not(Elem a b & Elem b a)"
obua@19203
   485
proof -
obua@19203
   486
  {
obua@19203
   487
    fix a b
obua@19203
   488
    assume ab: "Elem a b"
obua@19203
   489
    assume ba: "Elem b a"
obua@19203
   490
    let ?Z = "Upair a b"
obua@19203
   491
    have "?Z \<noteq> Empty" by (simp add: Upair_nonEmpty)
obua@19203
   492
    then have "? x. Elem x ?Z & (! y. Elem y x \<longrightarrow> Not(Elem y ?Z))"
obua@19203
   493
      by (simp add: Regularity)
obua@19203
   494
    then obtain x where x:"Elem x ?Z & (! y. Elem y x \<longrightarrow> Not(Elem y ?Z))" ..
obua@19203
   495
    then have "x = a \<or> x = b" by (simp add: Upair)
obua@19203
   496
    moreover have "x = a \<longrightarrow> Not (Elem b ?Z)"
obua@19203
   497
      by (auto simp add: x ba)
obua@19203
   498
    moreover have "x = b \<longrightarrow> Not (Elem a ?Z)"
obua@19203
   499
      by (auto simp add: x ab)
obua@19203
   500
    ultimately have "False"
obua@19203
   501
      by (auto simp add: Upair)
obua@19203
   502
  }    
obua@19203
   503
  then show ?thesis by auto
obua@19203
   504
qed
obua@19203
   505
obua@19203
   506
lemma irreflexiv_Elem: "Not(Elem a a)"
obua@19203
   507
  by (simp add: antisym_Elem[of a a, simplified])
obua@19203
   508
obua@19203
   509
lemma antisym_Elem: "Elem a b \<Longrightarrow> Not (Elem b a)"
obua@19203
   510
  apply (insert antisym_Elem[of a b])
obua@19203
   511
  apply auto
obua@19203
   512
  done
obua@19203
   513
obua@19203
   514
consts
obua@19203
   515
  NatInterval :: "nat \<Rightarrow> nat \<Rightarrow> ZF"
obua@19203
   516
obua@19203
   517
primrec
obua@19203
   518
  "NatInterval n 0 = Singleton (nat2Nat n)"
obua@19203
   519
  "NatInterval n (Suc m) = union (NatInterval n m) (Singleton (nat2Nat (n+m+1)))"
obua@19203
   520
obua@19203
   521
lemma n_Elem_NatInterval[rule_format]: "! q. q <= m \<longrightarrow> Elem (nat2Nat (n+q)) (NatInterval n m)"
obua@19203
   522
  apply (induct m)
obua@19203
   523
  apply (auto simp add: Singleton union)
obua@19203
   524
  apply (case_tac "q <= m")
obua@19203
   525
  apply auto
obua@19203
   526
  apply (subgoal_tac "q = Suc m")
obua@19203
   527
  apply auto
obua@19203
   528
  done
obua@19203
   529
obua@19203
   530
lemma NatInterval_not_Empty: "NatInterval n m \<noteq> Empty"
obua@19203
   531
  by (auto intro:   n_Elem_NatInterval[where q = 0, simplified] simp add: Empty Ext)
obua@19203
   532
obua@19203
   533
lemma increasing_nat2Nat[rule_format]: "0 < n \<longrightarrow> Elem (nat2Nat (n - 1)) (nat2Nat n)"
obua@19203
   534
  apply (case_tac "? m. n = Suc m")
obua@19203
   535
  apply (auto simp add: SucNat_def union Singleton)
obua@19203
   536
  apply (drule spec[where x="n - 1"])
obua@19203
   537
  apply arith
obua@19203
   538
  done
obua@19203
   539
obua@19203
   540
lemma represent_NatInterval[rule_format]: "Elem x (NatInterval n m) \<longrightarrow> (? u. n \<le> u & u \<le> n+m & nat2Nat u = x)"
obua@19203
   541
  apply (induct m)
obua@19203
   542
  apply (auto simp add: Singleton union)
obua@19203
   543
  apply (rule_tac x="Suc (n+m)" in exI)
obua@19203
   544
  apply auto
obua@19203
   545
  done
obua@19203
   546
obua@19203
   547
lemma inj_nat2Nat: "inj nat2Nat"
obua@19203
   548
proof -
obua@19203
   549
  {
obua@19203
   550
    fix n m :: nat
obua@19203
   551
    assume nm: "nat2Nat n = nat2Nat (n+m)"
obua@19203
   552
    assume mg0: "0 < m"
obua@19203
   553
    let ?Z = "NatInterval n m"
obua@19203
   554
    have "?Z \<noteq> Empty" by (simp add: NatInterval_not_Empty)
obua@19203
   555
    then have "? x. (Elem x ?Z) & (! y. Elem y x \<longrightarrow> Not (Elem y ?Z))" 
obua@19203
   556
      by (auto simp add: Regularity)
obua@19203
   557
    then obtain x where x:"Elem x ?Z & (! y. Elem y x \<longrightarrow> Not (Elem y ?Z))" ..
obua@19203
   558
    then have "? u. n \<le> u & u \<le> n+m & nat2Nat u = x" 
obua@19203
   559
      by (simp add: represent_NatInterval)
obua@19203
   560
    then obtain u where u: "n \<le> u & u \<le> n+m & nat2Nat u = x" ..
obua@19203
   561
    have "n < u \<longrightarrow> False"
obua@19203
   562
    proof 
obua@19203
   563
      assume n_less_u: "n < u"
obua@19203
   564
      let ?y = "nat2Nat (u - 1)"
obua@19203
   565
      have "Elem ?y (nat2Nat u)"
obua@19203
   566
	apply (rule increasing_nat2Nat)
obua@19203
   567
	apply (insert n_less_u)
obua@19203
   568
	apply arith
obua@19203
   569
	done
obua@19203
   570
      with u have "Elem ?y x" by auto
obua@19203
   571
      with x have "Not (Elem ?y ?Z)" by auto
obua@19203
   572
      moreover have "Elem ?y ?Z" 
obua@19203
   573
	apply (insert n_Elem_NatInterval[where q = "u - n - 1" and n=n and m=m])
obua@19203
   574
	apply (insert n_less_u)
obua@19203
   575
	apply (insert u)
obua@19203
   576
	apply auto
obua@19203
   577
	done
obua@19203
   578
      ultimately show False by auto
obua@19203
   579
    qed
obua@19203
   580
    moreover have "u = n \<longrightarrow> False"
obua@19203
   581
    proof 
obua@19203
   582
      assume "u = n"
obua@19203
   583
      with u have "nat2Nat n = x" by auto
obua@19203
   584
      then have nm_eq_x: "nat2Nat (n+m) = x" by (simp add: nm)
obua@19203
   585
      let ?y = "nat2Nat (n+m - 1)"
obua@19203
   586
      have "Elem ?y (nat2Nat (n+m))"
obua@19203
   587
	apply (rule increasing_nat2Nat)
obua@19203
   588
	apply (insert mg0)
obua@19203
   589
	apply arith
obua@19203
   590
	done
obua@19203
   591
      with nm_eq_x have "Elem ?y x" by auto
obua@19203
   592
      with x have "Not (Elem ?y ?Z)" by auto
obua@19203
   593
      moreover have "Elem ?y ?Z" 
obua@19203
   594
	apply (insert n_Elem_NatInterval[where q = "m - 1" and n=n and m=m])
obua@19203
   595
	apply (insert mg0)
obua@19203
   596
	apply auto
obua@19203
   597
	done
obua@19203
   598
      ultimately show False by auto      
obua@19203
   599
    qed
obua@19203
   600
    ultimately have "False" using u by arith
obua@19203
   601
  }
obua@19203
   602
  note lemma_nat2Nat = this
chaieb@23315
   603
  have th:"\<And>x y. \<not> (x < y \<and> (\<forall>(m\<Colon>nat). y \<noteq> x + m))" by presburger
chaieb@23315
   604
  have th': "\<And>x y. \<not> (x \<noteq> y \<and> (\<not> x < y) \<and> (\<forall>(m\<Colon>nat). x \<noteq> y + m))" by presburger
obua@19203
   605
  show ?thesis
obua@19203
   606
    apply (auto simp add: inj_on_def)
obua@19203
   607
    apply (case_tac "x = y")
obua@19203
   608
    apply auto
obua@19203
   609
    apply (case_tac "x < y")
obua@19203
   610
    apply (case_tac "? m. y = x + m & 0 < m")
chaieb@23315
   611
    apply (auto intro: lemma_nat2Nat)
obua@19203
   612
    apply (case_tac "y < x")
obua@19203
   613
    apply (case_tac "? m. x = y + m & 0 < m")
chaieb@23315
   614
    apply simp
chaieb@23315
   615
    apply simp
chaieb@23315
   616
    using th apply blast
chaieb@23315
   617
    apply (case_tac "? m. x = y + m")
chaieb@23315
   618
    apply (auto intro: lemma_nat2Nat)
obua@19203
   619
    apply (drule sym)
chaieb@23315
   620
    using lemma_nat2Nat apply blast
chaieb@23315
   621
    using th' apply blast    
obua@19203
   622
    done
obua@19203
   623
qed
obua@19203
   624
obua@19203
   625
lemma Nat2nat_nat2Nat[simp]: "Nat2nat (nat2Nat n) = n"
obua@19203
   626
  by (simp add: Nat2nat_def inv_f_f[OF inj_nat2Nat])
obua@19203
   627
obua@19203
   628
lemma nat2Nat_Nat2nat[simp]: "Elem n Nat \<Longrightarrow> nat2Nat (Nat2nat n) = n"
obua@19203
   629
  apply (simp add: Nat2nat_def)
obua@19203
   630
  apply (rule_tac f_inv_f)
obua@19203
   631
  apply (auto simp add: image_def Nat_def Sep)
obua@19203
   632
  done
obua@19203
   633
obua@19203
   634
lemma Nat2nat_SucNat: "Elem N Nat \<Longrightarrow> Nat2nat (SucNat N) = Suc (Nat2nat N)"
obua@19203
   635
  apply (auto simp add: Nat_def Sep Nat2nat_def)
obua@19203
   636
  apply (auto simp add: inv_f_f[OF inj_nat2Nat])
obua@19203
   637
  apply (simp only: nat2Nat.simps[symmetric])
obua@19203
   638
  apply (simp only: inv_f_f[OF inj_nat2Nat])
obua@19203
   639
  done
obua@19203
   640
  
obua@19203
   641
obua@19203
   642
(*lemma Elem_induct: "(\<And>x. \<forall>y. Elem y x \<longrightarrow> P y \<Longrightarrow> P x) \<Longrightarrow> P a"
obua@19203
   643
  by (erule wf_induct[OF wf_is_Elem_of, simplified is_Elem_of_def, simplified])*)
obua@19203
   644
obua@19203
   645
lemma Elem_Opair_exists: "? z. Elem x z & Elem y z & Elem z (Opair x y)"
obua@19203
   646
  apply (rule exI[where x="Upair x y"])
obua@19203
   647
  by (simp add: Upair Opair_def)
obua@19203
   648
obua@19203
   649
lemma UNIV_is_not_in_ZF: "UNIV \<noteq> explode R"
obua@19203
   650
proof
obua@19203
   651
  let ?Russell = "{ x. Not(Elem x x) }"
obua@19203
   652
  have "?Russell = UNIV" by (simp add: irreflexiv_Elem)
obua@19203
   653
  moreover assume "UNIV = explode R"
obua@19203
   654
  ultimately have russell: "?Russell = explode R" by simp
obua@19203
   655
  then show "False"
obua@19203
   656
  proof(cases "Elem R R")
obua@19203
   657
    case True     
obua@19203
   658
    then show ?thesis 
obua@19203
   659
      by (insert irreflexiv_Elem, auto)
obua@19203
   660
  next
obua@19203
   661
    case False
obua@19203
   662
    then have "R \<in> ?Russell" by auto
obua@19203
   663
    then have "Elem R R" by (simp add: russell explode_def)
obua@19203
   664
    with False show ?thesis by auto
obua@19203
   665
  qed
obua@19203
   666
qed
obua@19203
   667
obua@19203
   668
constdefs 
obua@19203
   669
  SpecialR :: "(ZF * ZF) set"
obua@19203
   670
  "SpecialR \<equiv> { (x, y) . x \<noteq> Empty \<and> y = Empty}"
obua@19203
   671
obua@19203
   672
lemma "wf SpecialR"
obua@19203
   673
  apply (subst wf_def)
obua@19203
   674
  apply (auto simp add: SpecialR_def)
obua@19203
   675
  done
obua@19203
   676
obua@19203
   677
constdefs
obua@19203
   678
  Ext :: "('a * 'b) set \<Rightarrow> 'b \<Rightarrow> 'a set"
obua@19203
   679
  "Ext R y \<equiv> { x . (x, y) \<in> R }" 
obua@19203
   680
obua@19203
   681
lemma Ext_Elem: "Ext is_Elem_of = explode"
obua@19203
   682
  by (auto intro: ext simp add: Ext_def is_Elem_of_def explode_def)
obua@19203
   683
obua@19203
   684
lemma "Ext SpecialR Empty \<noteq> explode z"
obua@19203
   685
proof 
obua@19203
   686
  have "Ext SpecialR Empty = UNIV - {Empty}"
obua@19203
   687
    by (auto simp add: Ext_def SpecialR_def)
obua@19203
   688
  moreover assume "Ext SpecialR Empty = explode z"
obua@19203
   689
  ultimately have "UNIV = explode(union z (Singleton Empty)) "
obua@19203
   690
    by (auto simp add: explode_def union Singleton)
obua@19203
   691
  then show "False" by (simp add: UNIV_is_not_in_ZF)
obua@19203
   692
qed
obua@19203
   693
obua@19203
   694
constdefs 
obua@19203
   695
  implode :: "ZF set \<Rightarrow> ZF"
obua@19203
   696
  "implode == inv explode"
obua@19203
   697
obua@19203
   698
lemma inj_explode: "inj explode"
obua@19203
   699
  by (auto simp add: inj_on_def explode_def Ext)
obua@19203
   700
obua@19203
   701
lemma implode_explode[simp]: "implode (explode x) = x"
obua@19203
   702
  by (simp add: implode_def inj_explode)
obua@19203
   703
obua@19203
   704
constdefs
obua@19203
   705
  regular :: "(ZF * ZF) set \<Rightarrow> bool"
obua@19203
   706
  "regular R == ! A. A \<noteq> Empty \<longrightarrow> (? x. Elem x A & (! y. (y, x) \<in> R \<longrightarrow> Not (Elem y A)))"
obua@20565
   707
  set_like :: "(ZF * ZF) set \<Rightarrow> bool"
obua@20565
   708
  "set_like R == ! y. Ext R y \<in> range explode"
obua@19203
   709
  wfzf :: "(ZF * ZF) set \<Rightarrow> bool"
obua@20565
   710
  "wfzf R == regular R & set_like R"
obua@19203
   711
obua@19203
   712
lemma regular_Elem: "regular is_Elem_of"
obua@19203
   713
  by (simp add: regular_def is_Elem_of_def Regularity)
obua@19203
   714
obua@20565
   715
lemma set_like_Elem: "set_like is_Elem_of"
obua@20565
   716
  by (auto simp add: set_like_def image_def Ext_Elem)
obua@19203
   717
obua@19203
   718
lemma wfzf_is_Elem_of: "wfzf is_Elem_of"
obua@20565
   719
  by (auto simp add: wfzf_def regular_Elem set_like_Elem)
obua@19203
   720
obua@19203
   721
constdefs
obua@19203
   722
  SeqSum :: "(nat \<Rightarrow> ZF) \<Rightarrow> ZF"
obua@19203
   723
  "SeqSum f == Sum (Repl Nat (f o Nat2nat))"
obua@19203
   724
obua@19203
   725
lemma SeqSum: "Elem x (SeqSum f) = (? n. Elem x (f n))"
obua@19203
   726
  apply (auto simp add: SeqSum_def Sum Repl)
obua@19203
   727
  apply (rule_tac x = "f n" in exI)
obua@19203
   728
  apply auto
obua@19203
   729
  done
obua@19203
   730
obua@19203
   731
constdefs
obua@19203
   732
  Ext_ZF :: "(ZF * ZF) set \<Rightarrow> ZF \<Rightarrow> ZF"
obua@19203
   733
  "Ext_ZF R s == implode (Ext R s)"
obua@19203
   734
obua@19203
   735
lemma Elem_implode: "A \<in> range explode \<Longrightarrow> Elem x (implode A) = (x \<in> A)"
obua@19203
   736
  apply (auto)
obua@19203
   737
  apply (simp_all add: explode_def)
obua@19203
   738
  done
obua@19203
   739
obua@20565
   740
lemma Elem_Ext_ZF: "set_like R \<Longrightarrow> Elem x (Ext_ZF R s) = ((x,s) \<in> R)"
obua@19203
   741
  apply (simp add: Ext_ZF_def)
obua@19203
   742
  apply (subst Elem_implode)
obua@20565
   743
  apply (simp add: set_like_def)
obua@19203
   744
  apply (simp add: Ext_def)
obua@19203
   745
  done
obua@19203
   746
obua@19203
   747
consts
obua@19203
   748
  Ext_ZF_n :: "(ZF * ZF) set \<Rightarrow> ZF \<Rightarrow> nat \<Rightarrow> ZF"
obua@19203
   749
obua@19203
   750
primrec
obua@19203
   751
  "Ext_ZF_n R s 0 = Ext_ZF R s"
obua@19203
   752
  "Ext_ZF_n R s (Suc n) = Sum (Repl (Ext_ZF_n R s n) (Ext_ZF R))"
obua@19203
   753
obua@19203
   754
constdefs
obua@19203
   755
  Ext_ZF_hull :: "(ZF * ZF) set \<Rightarrow> ZF \<Rightarrow> ZF"
obua@19203
   756
  "Ext_ZF_hull R s == SeqSum (Ext_ZF_n R s)"
obua@19203
   757
obua@19203
   758
lemma Elem_Ext_ZF_hull:
obua@20565
   759
  assumes set_like_R: "set_like R" 
obua@19203
   760
  shows "Elem x (Ext_ZF_hull R S) = (? n. Elem x (Ext_ZF_n R S n))"
obua@19203
   761
  by (simp add: Ext_ZF_hull_def SeqSum)
obua@19203
   762
  
obua@19203
   763
lemma Elem_Elem_Ext_ZF_hull:
obua@20565
   764
  assumes set_like_R: "set_like R" 
obua@19203
   765
          and x_hull: "Elem x (Ext_ZF_hull R S)"
obua@19203
   766
          and y_R_x: "(y, x) \<in> R"
obua@19203
   767
  shows "Elem y (Ext_ZF_hull R S)"
obua@19203
   768
proof -
obua@20565
   769
  from Elem_Ext_ZF_hull[OF set_like_R] x_hull 
obua@19203
   770
  have "? n. Elem x (Ext_ZF_n R S n)" by auto
obua@19203
   771
  then obtain n where n:"Elem x (Ext_ZF_n R S n)" ..
obua@19203
   772
  with y_R_x have "Elem y (Ext_ZF_n R S (Suc n))"
obua@19203
   773
    apply (auto simp add: Repl Sum)
obua@19203
   774
    apply (rule_tac x="Ext_ZF R x" in exI) 
obua@20565
   775
    apply (auto simp add: Elem_Ext_ZF[OF set_like_R])
obua@19203
   776
    done
obua@20565
   777
  with Elem_Ext_ZF_hull[OF set_like_R, where x=y] show ?thesis
obua@19203
   778
    by (auto simp del: Ext_ZF_n.simps)
obua@19203
   779
qed
obua@19203
   780
obua@19203
   781
lemma wfzf_minimal:
obua@19203
   782
  assumes hyps: "wfzf R" "C \<noteq> {}"
obua@19203
   783
  shows "\<exists>x. x \<in> C \<and> (\<forall>y. (y, x) \<in> R \<longrightarrow> y \<notin> C)"
obua@19203
   784
proof -
obua@19203
   785
  from hyps have "\<exists>S. S \<in> C" by auto
obua@19203
   786
  then obtain S where S:"S \<in> C" by auto  
obua@19203
   787
  let ?T = "Sep (Ext_ZF_hull R S) (\<lambda> s. s \<in> C)"
obua@20565
   788
  from hyps have set_like_R: "set_like R" by (simp add: wfzf_def)
obua@19203
   789
  show ?thesis
obua@19203
   790
  proof (cases "?T = Empty")
obua@19203
   791
    case True
obua@19203
   792
    then have "\<forall> z. \<not> (Elem z (Sep (Ext_ZF R S) (\<lambda> s. s \<in> C)))"      
obua@19203
   793
      apply (auto simp add: Ext Empty Sep Ext_ZF_hull_def SeqSum)
obua@19203
   794
      apply (erule_tac x="z" in allE, auto)
obua@19203
   795
      apply (erule_tac x=0 in allE, auto)
obua@19203
   796
      done
obua@19203
   797
    then show ?thesis 
obua@19203
   798
      apply (rule_tac exI[where x=S])
obua@19203
   799
      apply (auto simp add: Sep Empty S)
obua@19203
   800
      apply (erule_tac x=y in allE)
obua@20565
   801
      apply (simp add: set_like_R Elem_Ext_ZF)
obua@19203
   802
      done
obua@19203
   803
  next
obua@19203
   804
    case False
obua@19203
   805
    from hyps have regular_R: "regular R" by (simp add: wfzf_def)
obua@19203
   806
    from 
obua@19203
   807
      regular_R[simplified regular_def, rule_format, OF False, simplified Sep] 
obua@20565
   808
      Elem_Elem_Ext_ZF_hull[OF set_like_R]
obua@19203
   809
    show ?thesis by blast
obua@19203
   810
  qed
obua@19203
   811
qed
obua@19203
   812
obua@19203
   813
lemma wfzf_implies_wf: "wfzf R \<Longrightarrow> wf R"
obua@19203
   814
proof (subst wf_def, rule allI)
obua@19203
   815
  assume wfzf: "wfzf R"
obua@19203
   816
  fix P :: "ZF \<Rightarrow> bool"
obua@19203
   817
  let ?C = "{x. P x}"
obua@19203
   818
  {
obua@19203
   819
    assume induct: "(\<forall>x. (\<forall>y. (y, x) \<in> R \<longrightarrow> P y) \<longrightarrow> P x)"
obua@19203
   820
    let ?C = "{x. \<not> (P x)}"
obua@19203
   821
    have "?C = {}"
obua@19203
   822
    proof (rule ccontr)
obua@19203
   823
      assume C: "?C \<noteq> {}"
obua@19203
   824
      from
obua@19203
   825
	wfzf_minimal[OF wfzf C]
obua@19203
   826
      obtain x where x: "x \<in> ?C \<and> (\<forall>y. (y, x) \<in> R \<longrightarrow> y \<notin> ?C)" ..
obua@19203
   827
      then have "P x"
obua@19203
   828
	apply (rule_tac induct[rule_format])
obua@19203
   829
	apply auto
obua@19203
   830
	done
obua@19203
   831
      with x show "False" by auto
obua@19203
   832
    qed
obua@19203
   833
    then have "! x. P x" by auto
obua@19203
   834
  }
obua@19203
   835
  then show "(\<forall>x. (\<forall>y. (y, x) \<in> R \<longrightarrow> P y) \<longrightarrow> P x) \<longrightarrow> (! x. P x)" by blast
obua@19203
   836
qed
obua@19203
   837
obua@19203
   838
lemma wf_is_Elem_of: "wf is_Elem_of"
obua@19203
   839
  by (auto simp add: wfzf_is_Elem_of wfzf_implies_wf)
obua@19203
   840
obua@19203
   841
lemma in_Ext_RTrans_implies_Elem_Ext_ZF_hull:  
obua@20565
   842
  "set_like R \<Longrightarrow> x \<in> (Ext (R^+) s) \<Longrightarrow> Elem x (Ext_ZF_hull R s)"
obua@19203
   843
  apply (simp add: Ext_def Elem_Ext_ZF_hull)
obua@19203
   844
  apply (erule converse_trancl_induct[where r="R"])
obua@19203
   845
  apply (rule exI[where x=0])
obua@19203
   846
  apply (simp add: Elem_Ext_ZF)
obua@19203
   847
  apply auto
obua@19203
   848
  apply (rule_tac x="Suc n" in exI)
obua@19203
   849
  apply (simp add: Sum Repl)
obua@19203
   850
  apply (rule_tac x="Ext_ZF R z" in exI)
obua@19203
   851
  apply (auto simp add: Elem_Ext_ZF)
obua@19203
   852
  done
obua@19203
   853
obua@20565
   854
lemma implodeable_Ext_trancl: "set_like R \<Longrightarrow> set_like (R^+)"
obua@20565
   855
  apply (subst set_like_def)
obua@19203
   856
  apply (auto simp add: image_def)
obua@19203
   857
  apply (rule_tac x="Sep (Ext_ZF_hull R y) (\<lambda> z. z \<in> (Ext (R^+) y))" in exI)
obua@19203
   858
  apply (auto simp add: explode_def Sep set_ext 
obua@19203
   859
    in_Ext_RTrans_implies_Elem_Ext_ZF_hull)
obua@19203
   860
  done
obua@19203
   861
 
obua@19203
   862
lemma Elem_Ext_ZF_hull_implies_in_Ext_RTrans[rule_format]:
obua@20565
   863
  "set_like R \<Longrightarrow> ! x. Elem x (Ext_ZF_n R s n) \<longrightarrow> x \<in> (Ext (R^+) s)"
obua@19203
   864
  apply (induct_tac n)
obua@19203
   865
  apply (auto simp add: Elem_Ext_ZF Ext_def Sum Repl)
obua@19203
   866
  done
obua@19203
   867
obua@20565
   868
lemma "set_like R \<Longrightarrow> Ext_ZF (R^+) s = Ext_ZF_hull R s"
obua@19203
   869
  apply (frule implodeable_Ext_trancl)
obua@19203
   870
  apply (auto simp add: Ext)
obua@19203
   871
  apply (erule in_Ext_RTrans_implies_Elem_Ext_ZF_hull)
obua@19203
   872
  apply (simp add: Elem_Ext_ZF Ext_def)
obua@19203
   873
  apply (auto simp add: Elem_Ext_ZF Elem_Ext_ZF_hull)
obua@19203
   874
  apply (erule Elem_Ext_ZF_hull_implies_in_Ext_RTrans[simplified Ext_def, simplified], assumption)
obua@19203
   875
  done
obua@19203
   876
obua@19203
   877
lemma wf_implies_regular: "wf R \<Longrightarrow> regular R"
obua@19203
   878
proof (simp add: regular_def, rule allI)
obua@19203
   879
  assume wf: "wf R"
obua@19203
   880
  fix A
obua@19203
   881
  show "A \<noteq> Empty \<longrightarrow> (\<exists>x. Elem x A \<and> (\<forall>y. (y, x) \<in> R \<longrightarrow> \<not> Elem y A))"
obua@19203
   882
  proof
obua@19203
   883
    assume A: "A \<noteq> Empty"
obua@19203
   884
    then have "? x. x \<in> explode A" 
obua@19203
   885
      by (auto simp add: explode_def Ext Empty)
obua@19203
   886
    then obtain x where x:"x \<in> explode A" ..   
obua@19203
   887
    from iffD1[OF wf_eq_minimal wf, rule_format, where Q="explode A", OF x]
obua@19203
   888
    obtain z where "z \<in> explode A \<and> (\<forall>y. (y, z) \<in> R \<longrightarrow> y \<notin> explode A)" by auto    
obua@19203
   889
    then show "\<exists>x. Elem x A \<and> (\<forall>y. (y, x) \<in> R \<longrightarrow> \<not> Elem y A)"      
obua@19203
   890
      apply (rule_tac exI[where x = z])
obua@19203
   891
      apply (simp add: explode_def)
obua@19203
   892
      done
obua@19203
   893
  qed
obua@19203
   894
qed
obua@19203
   895
obua@20565
   896
lemma wf_eq_wfzf: "(wf R \<and> set_like R) = wfzf R"
obua@19203
   897
  apply (auto simp add: wfzf_implies_wf)
obua@19203
   898
  apply (auto simp add: wfzf_def wf_implies_regular)
obua@19203
   899
  done
obua@19203
   900
obua@19203
   901
lemma wfzf_trancl: "wfzf R \<Longrightarrow> wfzf (R^+)"
obua@19203
   902
  by (auto simp add: wf_eq_wfzf[symmetric] implodeable_Ext_trancl wf_trancl)
obua@19203
   903
obua@19203
   904
lemma Ext_subset_mono: "R \<subseteq> S \<Longrightarrow> Ext R y \<subseteq> Ext S y"
obua@19203
   905
  by (auto simp add: Ext_def)
obua@19203
   906
obua@20565
   907
lemma set_like_subset: "set_like R \<Longrightarrow> S \<subseteq> R \<Longrightarrow> set_like S"
obua@20565
   908
  apply (auto simp add: set_like_def)
obua@19203
   909
  apply (erule_tac x=y in allE)
obua@19203
   910
  apply (drule_tac y=y in Ext_subset_mono)
obua@19203
   911
  apply (auto simp add: image_def)
obua@19203
   912
  apply (rule_tac x="Sep x (% z. z \<in> (Ext S y))" in exI) 
obua@19203
   913
  apply (auto simp add: explode_def Sep)
obua@19203
   914
  done
obua@19203
   915
obua@19203
   916
lemma wfzf_subset: "wfzf S \<Longrightarrow> R \<subseteq> S \<Longrightarrow> wfzf R"
obua@20565
   917
  by (auto intro: set_like_subset wf_subset simp add: wf_eq_wfzf[symmetric])  
obua@19203
   918
obua@19203
   919
end