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