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