src/HOL/ZF/HOLZF.thy
changeset 67613 ce654b0e6d69
parent 67443 3abf6a722518
equal deleted inserted replaced
67610:4939494ed791 67613:ce654b0e6d69
    30 
    30 
    31 definition SucNat:: "ZF \<Rightarrow> ZF" where
    31 definition SucNat:: "ZF \<Rightarrow> ZF" where
    32   "SucNat x == union x (Singleton x)"
    32   "SucNat x == union x (Singleton x)"
    33 
    33 
    34 definition subset :: "ZF \<Rightarrow> ZF \<Rightarrow> bool" where
    34 definition subset :: "ZF \<Rightarrow> ZF \<Rightarrow> bool" where
    35   "subset A B == ! x. Elem x A \<longrightarrow> Elem x B"
    35   "subset A B \<equiv> \<forall>x. Elem x A \<longrightarrow> Elem x B"
    36 
    36 
    37 axiomatization where
    37 axiomatization where
    38   Empty: "Not (Elem x Empty)" and
    38   Empty: "Not (Elem x Empty)" and
    39   Ext: "(x = y) = (! z. Elem z x = Elem z y)" and
    39   Ext: "(x = y) = (\<forall>z. Elem z x = Elem z y)" and
    40   Sum: "Elem z (Sum x) = (? y. Elem z y & Elem y x)" and
    40   Sum: "Elem z (Sum x) = (\<exists>y. Elem z y \<and> Elem y x)" and
    41   Power: "Elem y (Power x) = (subset y x)" and
    41   Power: "Elem y (Power x) = (subset y x)" and
    42   Repl: "Elem b (Repl A f) = (? a. Elem a A & b = f a)" and
    42   Repl: "Elem b (Repl A f) = (\<exists>a. Elem a A \<and> b = f a)" and
    43   Regularity: "A \<noteq> Empty \<longrightarrow> (? x. Elem x A & (! y. Elem y x \<longrightarrow> Not (Elem y A)))" and
    43   Regularity: "A \<noteq> Empty \<longrightarrow> (\<exists>x. Elem x A \<and> (\<forall>y. Elem y x \<longrightarrow> Not (Elem y A)))" and
    44   Infinity: "Elem Empty Inf & (! x. Elem x Inf \<longrightarrow> Elem (SucNat x) Inf)"
    44   Infinity: "Elem Empty Inf \<and> (\<forall>x. Elem x Inf \<longrightarrow> Elem (SucNat x) Inf)"
    45 
    45 
    46 definition Sep :: "ZF \<Rightarrow> (ZF \<Rightarrow> bool) \<Rightarrow> ZF" where
    46 definition Sep :: "ZF \<Rightarrow> (ZF \<Rightarrow> bool) \<Rightarrow> ZF" where
    47   "Sep A p == (if (!x. Elem x A \<longrightarrow> Not (p x)) then Empty else 
    47   "Sep A p == (if (\<forall>x. Elem x A \<longrightarrow> Not (p x)) then Empty else 
    48   (let z = (\<some> x. Elem x A & p x) in
    48   (let z = (\<some> x. Elem x A & p x) in
    49    let f = % x. (if p x then x else z) in Repl A f))" 
    49    let f = \<lambda>x. (if p x then x else z) in Repl A f))" 
    50 
    50 
    51 thm Power[unfolded subset_def]
    51 thm Power[unfolded subset_def]
    52 
    52 
    53 theorem Sep: "Elem b (Sep A p) = (Elem b A & p b)"
    53 theorem Sep: "Elem b (Sep A p) = (Elem b A \<and> p b)"
    54   apply (auto simp add: Sep_def Empty)
    54   apply (auto simp add: Sep_def Empty)
    55   apply (auto simp add: Let_def Repl)
    55   apply (auto simp add: Let_def Repl)
    56   apply (rule someI2, auto)+
    56   apply (rule someI2, auto)+
    57   done
    57   done
    58 
    58 
    59 lemma subset_empty: "subset Empty A"
    59 lemma subset_empty: "subset Empty A"
    60   by (simp add: subset_def Empty)
    60   by (simp add: subset_def Empty)
    61 
    61 
    62 theorem Upair: "Elem x (Upair a b) = (x = a | x = b)"
    62 theorem Upair: "Elem x (Upair a b) = (x = a \<or> x = b)"
    63   apply (auto simp add: Upair_def Repl)
    63   apply (auto simp add: Upair_def Repl)
    64   apply (rule exI[where x=Empty])
    64   apply (rule exI[where x=Empty])
    65   apply (simp add: Power subset_empty)
    65   apply (simp add: Power subset_empty)
    66   apply (rule exI[where x="Power Empty"])
    66   apply (rule exI[where x="Power Empty"])
    67   apply (auto)
    67   apply (auto)
   101   qed
   101   qed
   102 
   102 
   103 definition Replacement :: "ZF \<Rightarrow> (ZF \<Rightarrow> ZF option) \<Rightarrow> ZF" where
   103 definition Replacement :: "ZF \<Rightarrow> (ZF \<Rightarrow> ZF option) \<Rightarrow> ZF" where
   104   "Replacement A f == Repl (Sep A (% a. f a \<noteq> None)) (the o f)"
   104   "Replacement A f == Repl (Sep A (% a. f a \<noteq> None)) (the o f)"
   105 
   105 
   106 theorem Replacement: "Elem y (Replacement A f) = (? x. Elem x A & f x = Some y)"
   106 theorem Replacement: "Elem y (Replacement A f) = (\<exists>x. Elem x A \<and> f x = Some y)"
   107   by (auto simp add: Replacement_def Repl Sep) 
   107   by (auto simp add: Replacement_def Repl Sep) 
   108 
   108 
   109 definition Fst :: "ZF \<Rightarrow> ZF" where
   109 definition Fst :: "ZF \<Rightarrow> ZF" where
   110   "Fst q == SOME x. ? y. q = Opair x y"
   110   "Fst q == SOME x. \<exists>y. q = Opair x y"
   111 
   111 
   112 definition Snd :: "ZF \<Rightarrow> ZF" where
   112 definition Snd :: "ZF \<Rightarrow> ZF" where
   113   "Snd q == SOME y. ? x. q = Opair x y"
   113   "Snd q == SOME y. \<exists>x. q = Opair x y"
   114 
   114 
   115 theorem Fst: "Fst (Opair x y) = x"
   115 theorem Fst: "Fst (Opair x y) = x"
   116   apply (simp add: Fst_def)
   116   apply (simp add: Fst_def)
   117   apply (rule someI2)
   117   apply (rule someI2)
   118   apply (simp_all add: Opair)
   118   apply (simp_all add: Opair)
   123   apply (rule someI2)
   123   apply (rule someI2)
   124   apply (simp_all add: Opair)
   124   apply (simp_all add: Opair)
   125   done
   125   done
   126 
   126 
   127 definition isOpair :: "ZF \<Rightarrow> bool" where
   127 definition isOpair :: "ZF \<Rightarrow> bool" where
   128   "isOpair q == ? x y. q = Opair x y"
   128   "isOpair q == \<exists>x y. q = Opair x y"
   129 
   129 
   130 lemma isOpair: "isOpair (Opair x y) = True"
   130 lemma isOpair: "isOpair (Opair x y) = True"
   131   by (auto simp add: isOpair_def)
   131   by (auto simp add: isOpair_def)
   132 
   132 
   133 lemma FstSnd: "isOpair x \<Longrightarrow> Opair (Fst x) (Snd x) = x"
   133 lemma FstSnd: "isOpair x \<Longrightarrow> Opair (Fst x) (Snd x) = x"
   134   by (auto simp add: isOpair_def Fst Snd)
   134   by (auto simp add: isOpair_def Fst Snd)
   135   
   135   
   136 definition CartProd :: "ZF \<Rightarrow> ZF \<Rightarrow> ZF" where
   136 definition CartProd :: "ZF \<Rightarrow> ZF \<Rightarrow> ZF" where
   137   "CartProd A B == Sum(Repl A (% a. Repl B (% b. Opair a b)))"
   137   "CartProd A B == Sum(Repl A (% a. Repl B (% b. Opair a b)))"
   138 
   138 
   139 lemma CartProd: "Elem x (CartProd A B) = (? a b. Elem a A & Elem b B & x = (Opair a b))"
   139 lemma CartProd: "Elem x (CartProd A B) = (\<exists>a b. Elem a A \<and> Elem b B \<and> x = (Opair a b))"
   140   apply (auto simp add: CartProd_def Sum Repl)
   140   apply (auto simp add: CartProd_def Sum Repl)
   141   apply (rule_tac x="Repl B (Opair a)" in exI)
   141   apply (rule_tac x="Repl B (Opair a)" in exI)
   142   apply (auto simp add: Repl)
   142   apply (auto simp add: Repl)
   143   done
   143   done
   144 
   144 
   164   "Domain f == Replacement f (% p. if isOpair p then Some (Fst p) else None)"
   164   "Domain f == Replacement f (% p. if isOpair p then Some (Fst p) else None)"
   165 
   165 
   166 definition Range :: "ZF \<Rightarrow> ZF" where
   166 definition Range :: "ZF \<Rightarrow> ZF" where
   167   "Range f == Replacement f (% p. if isOpair p then Some (Snd p) else None)"
   167   "Range f == Replacement f (% p. if isOpair p then Some (Snd p) else None)"
   168 
   168 
   169 theorem Domain: "Elem x (Domain f) = (? y. Elem (Opair x y) f)"
   169 theorem Domain: "Elem x (Domain f) = (\<exists>y. Elem (Opair x y) f)"
   170   apply (auto simp add: Domain_def Replacement)
   170   apply (auto simp add: Domain_def Replacement)
   171   apply (rule_tac x="Snd xa" in exI)
   171   apply (rule_tac x="Snd xa" in exI)
   172   apply (simp add: FstSnd)
   172   apply (simp add: FstSnd)
   173   apply (rule_tac x="Opair x y" in exI)
   173   apply (rule_tac x="Opair x y" in exI)
   174   apply (simp add: isOpair Fst)
   174   apply (simp add: isOpair Fst)
   175   done
   175   done
   176 
   176 
   177 theorem Range: "Elem y (Range f) = (? x. Elem (Opair x y) f)"
   177 theorem Range: "Elem y (Range f) = (\<exists>x. Elem (Opair x y) f)"
   178   apply (auto simp add: Range_def Replacement)
   178   apply (auto simp add: Range_def Replacement)
   179   apply (rule_tac x="Fst x" in exI)
   179   apply (rule_tac x="Fst x" in exI)
   180   apply (simp add: FstSnd)
   180   apply (simp add: FstSnd)
   181   apply (rule_tac x="Opair x y" in exI)
   181   apply (rule_tac x="Opair x y" in exI)
   182   apply (simp add: isOpair Snd)
   182   apply (simp add: isOpair Snd)
   190 
   190 
   191 definition app :: "ZF \<Rightarrow> ZF => ZF" (infixl "\<acute>" 90) \<comment> \<open>function application\<close> where
   191 definition app :: "ZF \<Rightarrow> ZF => ZF" (infixl "\<acute>" 90) \<comment> \<open>function application\<close> where
   192   "f \<acute> x == (THE y. Elem (Opair x y) f)"
   192   "f \<acute> x == (THE y. Elem (Opair x y) f)"
   193 
   193 
   194 definition isFun :: "ZF \<Rightarrow> bool" where
   194 definition isFun :: "ZF \<Rightarrow> bool" where
   195   "isFun f == (! x y1 y2. Elem (Opair x y1) f & Elem (Opair x y2) f \<longrightarrow> y1 = y2)"
   195   "isFun f == (\<forall>x y1 y2. Elem (Opair x y1) f & Elem (Opair x y2) f \<longrightarrow> y1 = y2)"
   196 
   196 
   197 definition Lambda :: "ZF \<Rightarrow> (ZF \<Rightarrow> ZF) \<Rightarrow> ZF" where
   197 definition Lambda :: "ZF \<Rightarrow> (ZF \<Rightarrow> ZF) \<Rightarrow> ZF" where
   198   "Lambda A f == Repl A (% x. Opair x (f x))"
   198   "Lambda A f == Repl A (% x. Opair x (f x))"
   199 
   199 
   200 lemma Lambda_app: "Elem x A \<Longrightarrow> (Lambda A f)\<acute>x = f x"
   200 lemma Lambda_app: "Elem x A \<Longrightarrow> (Lambda A f)\<acute>x = f x"
   212   apply (simp add: Lambda_def Repl)
   212   apply (simp add: Lambda_def Repl)
   213   apply (rule_tac x="Opair z (f z)" in exI)
   213   apply (rule_tac x="Opair z (f z)" in exI)
   214   apply (auto simp add: Fst isOpair_def)
   214   apply (auto simp add: Fst isOpair_def)
   215   done
   215   done
   216 
   216 
   217 lemma Lambda_ext: "(Lambda s f = Lambda t g) = (s = t & (! x. Elem x s \<longrightarrow> f x = g x))"
   217 lemma Lambda_ext: "(Lambda s f = Lambda t g) = (s = t \<and> (\<forall>x. Elem x s \<longrightarrow> f x = g x))"
   218 proof -
   218 proof -
   219   have "Lambda s f = Lambda t g \<Longrightarrow> s = t"
   219   have "Lambda s f = Lambda t g \<Longrightarrow> s = t"
   220     apply (subst domain_Lambda[where A = s and f = f, symmetric])
   220     apply (subst domain_Lambda[where A = s and f = f, symmetric])
   221     apply (subst domain_Lambda[where A = t and f = g, symmetric])
   221     apply (subst domain_Lambda[where A = t and f = g, symmetric])
   222     apply auto
   222     apply auto
   280   apply (simp add: app_def)
   280   apply (simp add: app_def)
   281   apply (rule exI[where x=x])
   281   apply (rule exI[where x=x])
   282   apply (auto simp add: the_equality)
   282   apply (auto simp add: the_equality)
   283   done
   283   done
   284 
   284 
   285 lemma fun_range_witness: "\<lbrakk>isFun f; Elem y (Range f)\<rbrakk> \<Longrightarrow> ? x. Elem x (Domain f) & f\<acute>x = y"
   285 lemma fun_range_witness: "\<lbrakk>isFun f; Elem y (Range f)\<rbrakk> \<Longrightarrow> \<exists>x. Elem x (Domain f) & f\<acute>x = y"
   286   apply (auto simp add: Range)
   286   apply (auto simp add: Range)
   287   apply (rule_tac x="x" in exI)
   287   apply (rule_tac x="x" in exI)
   288   apply (auto simp add: app_def the_equality isFun_def Domain)
   288   apply (auto simp add: app_def the_equality isFun_def Domain)
   289   done
   289   done
   290 
   290 
   291 lemma Elem_Fun_Lambda: "Elem F (Fun U V) \<Longrightarrow> ? f. F = Lambda U f"
   291 lemma Elem_Fun_Lambda: "Elem F (Fun U V) \<Longrightarrow> \<exists>f. F = Lambda U f"
   292   apply (rule exI[where x= "% x. (THE y. Elem (Opair x y) F)"])
   292   apply (rule exI[where x= "% x. (THE y. Elem (Opair x y) F)"])
   293   apply (simp add: Ext Lambda_def Repl Domain)
   293   apply (simp add: Ext Lambda_def Repl Domain)
   294   apply (simp add: Ext[symmetric])
   294   apply (simp add: Ext[symmetric])
   295   apply auto
   295   apply auto
   296   apply (frule Elem_Elem_Fun)
   296   apply (frule Elem_Elem_Fun)
   311   apply (drule Fun_implies_PFun)
   311   apply (drule Fun_implies_PFun)
   312   apply (drule_tac x="Opair a x" and y="Opair a y" in PFun_inj)
   312   apply (drule_tac x="Opair a x" and y="Opair a y" in PFun_inj)
   313   apply (auto simp add: Fst Snd)
   313   apply (auto simp add: Fst Snd)
   314   done
   314   done
   315  
   315  
   316 lemma Elem_Lambda_Fun: "Elem (Lambda A f) (Fun U V) = (A = U & (! x. Elem x A \<longrightarrow> Elem (f x) V))"
   316 lemma Elem_Lambda_Fun: "Elem (Lambda A f) (Fun U V) = (A = U \<and> (\<forall>x. Elem x A \<longrightarrow> Elem (f x) V))"
   317 proof -
   317 proof -
   318   have "Elem (Lambda A f) (Fun U V) \<Longrightarrow> A = U"
   318   have "Elem (Lambda A f) (Fun U V) \<Longrightarrow> A = U"
   319     by (simp add: Fun_def Sep domain_Lambda)
   319     by (simp add: Fun_def Sep domain_Lambda)
   320   then show ?thesis
   320   then show ?thesis
   321     apply auto
   321     apply auto
   357         have "?Z = Empty \<longrightarrow> P a" by (simp add: Ext Sep Empty a_in_U)     
   357         have "?Z = Empty \<longrightarrow> P a" by (simp add: Ext Sep Empty a_in_U)     
   358         moreover have "?Z \<noteq> Empty \<longrightarrow> False"
   358         moreover have "?Z \<noteq> Empty \<longrightarrow> False"
   359           proof 
   359           proof 
   360             assume not_empty: "?Z \<noteq> Empty" 
   360             assume not_empty: "?Z \<noteq> Empty" 
   361             note thereis_x = Regularity[where A="?Z", simplified not_empty, simplified]
   361             note thereis_x = Regularity[where A="?Z", simplified not_empty, simplified]
   362             then obtain x where x_def: "Elem x ?Z & (! y. Elem y x \<longrightarrow> Not (Elem y ?Z))" ..
   362             then obtain x where x_def: "Elem x ?Z \<and> (\<forall>y. Elem y x \<longrightarrow> Not (Elem y ?Z))" ..
   363             then have x_induct:"! y. Elem y x \<longrightarrow> Elem y U \<longrightarrow> P y" by (simp add: Sep)
   363             then have x_induct:"\<forall>y. Elem y x \<longrightarrow> Elem y U \<longrightarrow> P y" by (simp add: Sep)
   364             have "Elem x U \<longrightarrow> P x" 
   364             have "Elem x U \<longrightarrow> P x" 
   365               by (rule impE[OF spec[OF P_induct, where x=x], OF x_induct], assumption)
   365               by (rule impE[OF spec[OF P_induct, where x=x], OF x_induct], assumption)
   366             moreover have "Elem x U & Not(P x)"
   366             moreover have "Elem x U & Not(P x)"
   367               apply (insert x_def)
   367               apply (insert x_def)
   368               apply (simp add: Sep)
   368               apply (simp add: Sep)
   375   with hyps show ?thesis by blast
   375   with hyps show ?thesis by blast
   376 qed    
   376 qed    
   377 
   377 
   378 lemma cond2_wf_Elem:
   378 lemma cond2_wf_Elem:
   379   assumes 
   379   assumes 
   380      special_P: "? U. ! x. Not(Elem x U) \<longrightarrow> (P x)"
   380      special_P: "\<exists>U. \<forall>x. Not(Elem x U) \<longrightarrow> (P x)"
   381      and P_induct: "\<forall>x. (\<forall>y. Elem y x \<longrightarrow> P y) \<longrightarrow> P x"
   381      and P_induct: "\<forall>x. (\<forall>y. Elem y x \<longrightarrow> P y) \<longrightarrow> P x"
   382   shows
   382   shows
   383      "P a"
   383      "P a"
   384 proof -
   384 proof -
   385   have "? U Q. P = (\<lambda> x. (Elem x U \<longrightarrow> Q x))"
   385   have "\<exists>U Q. P = (\<lambda> x. (Elem x U \<longrightarrow> Q x))"
   386   proof -
   386   proof -
   387     from special_P obtain U where U:"! x. Not(Elem x U) \<longrightarrow> (P x)" ..
   387     from special_P obtain U where U: "\<forall>x. Not(Elem x U) \<longrightarrow> (P x)" ..
   388     show ?thesis
   388     show ?thesis
   389       apply (rule_tac exI[where x=U])
   389       apply (rule_tac exI[where x=U])
   390       apply (rule exI[where x="P"])
   390       apply (rule exI[where x="P"])
   391       apply (rule ext)
   391       apply (rule ext)
   392       apply (auto simp add: U)
   392       apply (auto simp add: U)
   393       done
   393       done
   394   qed    
   394   qed    
   395   then obtain U where "? Q. P = (\<lambda> x. (Elem x U \<longrightarrow> Q x))" ..
   395   then obtain U where "\<exists>Q. P = (\<lambda> x. (Elem x U \<longrightarrow> Q x))" ..
   396   then obtain Q where UQ: "P = (\<lambda> x. (Elem x U \<longrightarrow> Q x))" ..
   396   then obtain Q where UQ: "P = (\<lambda> x. (Elem x U \<longrightarrow> Q x))" ..
   397   show ?thesis
   397   show ?thesis
   398     apply (auto simp add: UQ)
   398     apply (auto simp add: UQ)
   399     apply (rule cond_wf_Elem)
   399     apply (rule cond_wf_Elem)
   400     apply (rule P_induct[simplified UQ])
   400     apply (rule P_induct[simplified UQ])
   413   apply (induct n)
   413   apply (induct n)
   414   apply (simp_all add: Infinity)
   414   apply (simp_all add: Infinity)
   415   done
   415   done
   416 
   416 
   417 definition Nat :: ZF
   417 definition Nat :: ZF
   418  where  "Nat == Sep Inf (\<lambda> N. ? n. nat2Nat n = N)"
   418  where  "Nat == Sep Inf (\<lambda>N. \<exists>n. nat2Nat n = N)"
   419 
   419 
   420 lemma Elem_nat2Nat_Nat[intro]: "Elem (nat2Nat n) Nat"
   420 lemma Elem_nat2Nat_Nat[intro]: "Elem (nat2Nat n) Nat"
   421   by (auto simp add: Nat_def Sep)
   421   by (auto simp add: Nat_def Sep)
   422 
   422 
   423 lemma Elem_Empty_Nat: "Elem Empty Nat"
   423 lemma Elem_Empty_Nat: "Elem Empty Nat"
   425 
   425 
   426 lemma Elem_SucNat_Nat: "Elem N Nat \<Longrightarrow> Elem (SucNat N) Nat"
   426 lemma Elem_SucNat_Nat: "Elem N Nat \<Longrightarrow> Elem (SucNat N) Nat"
   427   by (auto simp add: Nat_def Sep Infinity)
   427   by (auto simp add: Nat_def Sep Infinity)
   428   
   428   
   429 lemma no_infinite_Elem_down_chain:
   429 lemma no_infinite_Elem_down_chain:
   430   "Not (? f. isFun f & Domain f = Nat & (! N. Elem N Nat \<longrightarrow> Elem (f\<acute>(SucNat N)) (f\<acute>N)))"
   430   "Not (\<exists>f. isFun f \<and> Domain f = Nat \<and> (\<forall>N. Elem N Nat \<longrightarrow> Elem (f\<acute>(SucNat N)) (f\<acute>N)))"
   431 proof -
   431 proof -
   432   {
   432   {
   433     fix f
   433     fix f
   434     assume f:"isFun f & Domain f = Nat & (! N. Elem N Nat \<longrightarrow> Elem (f\<acute>(SucNat N)) (f\<acute>N))"
   434     assume f: "isFun f \<and> Domain f = Nat \<and> (\<forall>N. Elem N Nat \<longrightarrow> Elem (f\<acute>(SucNat N)) (f\<acute>N))"
   435     let ?r = "Range f"
   435     let ?r = "Range f"
   436     have "?r \<noteq> Empty"
   436     have "?r \<noteq> Empty"
   437       apply (auto simp add: Ext Empty)
   437       apply (auto simp add: Ext Empty)
   438       apply (rule exI[where x="f\<acute>Empty"])
   438       apply (rule exI[where x="f\<acute>Empty"])
   439       apply (rule fun_value_in_range)
   439       apply (rule fun_value_in_range)
   440       apply (auto simp add: f Elem_Empty_Nat)
   440       apply (auto simp add: f Elem_Empty_Nat)
   441       done
   441       done
   442     then have "? x. Elem x ?r & (! y. Elem y x \<longrightarrow> Not(Elem y ?r))"
   442     then have "\<exists>x. Elem x ?r \<and> (\<forall>y. Elem y x \<longrightarrow> Not(Elem y ?r))"
   443       by (simp add: Regularity)
   443       by (simp add: Regularity)
   444     then obtain x where x: "Elem x ?r & (! y. Elem y x \<longrightarrow> Not(Elem y ?r))" ..
   444     then obtain x where x: "Elem x ?r \<and> (\<forall>y. Elem y x \<longrightarrow> Not(Elem y ?r))" ..
   445     then have "? N. Elem N (Domain f) & f\<acute>N = x" 
   445     then have "\<exists>N. Elem N (Domain f) & f\<acute>N = x" 
   446       apply (rule_tac fun_range_witness)
   446       apply (rule_tac fun_range_witness)
   447       apply (simp_all add: f)
   447       apply (simp_all add: f)
   448       done
   448       done
   449     then have "? N. Elem N Nat & f\<acute>N = x" 
   449     then have "\<exists>N. Elem N Nat & f\<acute>N = x" 
   450       by (simp add: f)
   450       by (simp add: f)
   451     then obtain N where N: "Elem N Nat & f\<acute>N = x" ..
   451     then obtain N where N: "Elem N Nat & f\<acute>N = x" ..
   452     from N have N': "Elem N Nat" by auto
   452     from N have N': "Elem N Nat" by auto
   453     let ?y = "f\<acute>(SucNat N)"
   453     let ?y = "f\<acute>(SucNat N)"
   454     have Elem_y_r: "Elem ?y ?r"
   454     have Elem_y_r: "Elem ?y ?r"
   473     fix a b
   473     fix a b
   474     assume ab: "Elem a b"
   474     assume ab: "Elem a b"
   475     assume ba: "Elem b a"
   475     assume ba: "Elem b a"
   476     let ?Z = "Upair a b"
   476     let ?Z = "Upair a b"
   477     have "?Z \<noteq> Empty" by (simp add: Upair_nonEmpty)
   477     have "?Z \<noteq> Empty" by (simp add: Upair_nonEmpty)
   478     then have "? x. Elem x ?Z & (! y. Elem y x \<longrightarrow> Not(Elem y ?Z))"
   478     then have "\<exists>x. Elem x ?Z \<and> (\<forall>y. Elem y x \<longrightarrow> Not(Elem y ?Z))"
   479       by (simp add: Regularity)
   479       by (simp add: Regularity)
   480     then obtain x where x:"Elem x ?Z & (! y. Elem y x \<longrightarrow> Not(Elem y ?Z))" ..
   480     then obtain x where x:"Elem x ?Z \<and> (\<forall>y. Elem y x \<longrightarrow> Not(Elem y ?Z))" ..
   481     then have "x = a \<or> x = b" by (simp add: Upair)
   481     then have "x = a \<or> x = b" by (simp add: Upair)
   482     moreover have "x = a \<longrightarrow> Not (Elem b ?Z)"
   482     moreover have "x = a \<longrightarrow> Not (Elem b ?Z)"
   483       by (auto simp add: x ba)
   483       by (auto simp add: x ba)
   484     moreover have "x = b \<longrightarrow> Not (Elem a ?Z)"
   484     moreover have "x = b \<longrightarrow> Not (Elem a ?Z)"
   485       by (auto simp add: x ab)
   485       by (auto simp add: x ab)
   499 
   499 
   500 primrec NatInterval :: "nat \<Rightarrow> nat \<Rightarrow> ZF" where
   500 primrec NatInterval :: "nat \<Rightarrow> nat \<Rightarrow> ZF" where
   501   "NatInterval n 0 = Singleton (nat2Nat n)"
   501   "NatInterval n 0 = Singleton (nat2Nat n)"
   502 | "NatInterval n (Suc m) = union (NatInterval n m) (Singleton (nat2Nat (n+m+1)))"
   502 | "NatInterval n (Suc m) = union (NatInterval n m) (Singleton (nat2Nat (n+m+1)))"
   503 
   503 
   504 lemma n_Elem_NatInterval[rule_format]: "! q. q <= m \<longrightarrow> Elem (nat2Nat (n+q)) (NatInterval n m)"
   504 lemma n_Elem_NatInterval[rule_format]: "\<forall>q. q \<le> m \<longrightarrow> Elem (nat2Nat (n+q)) (NatInterval n m)"
   505   apply (induct m)
   505   apply (induct m)
   506   apply (auto simp add: Singleton union)
   506   apply (auto simp add: Singleton union)
   507   apply (case_tac "q <= m")
   507   apply (case_tac "q <= m")
   508   apply auto
   508   apply auto
   509   apply (subgoal_tac "q = Suc m")
   509   apply (subgoal_tac "q = Suc m")
   512 
   512 
   513 lemma NatInterval_not_Empty: "NatInterval n m \<noteq> Empty"
   513 lemma NatInterval_not_Empty: "NatInterval n m \<noteq> Empty"
   514   by (auto intro:   n_Elem_NatInterval[where q = 0, simplified] simp add: Empty Ext)
   514   by (auto intro:   n_Elem_NatInterval[where q = 0, simplified] simp add: Empty Ext)
   515 
   515 
   516 lemma increasing_nat2Nat[rule_format]: "0 < n \<longrightarrow> Elem (nat2Nat (n - 1)) (nat2Nat n)"
   516 lemma increasing_nat2Nat[rule_format]: "0 < n \<longrightarrow> Elem (nat2Nat (n - 1)) (nat2Nat n)"
   517   apply (case_tac "? m. n = Suc m")
   517   apply (case_tac "\<exists>m. n = Suc m")
   518   apply (auto simp add: SucNat_def union Singleton)
   518   apply (auto simp add: SucNat_def union Singleton)
   519   apply (drule spec[where x="n - 1"])
   519   apply (drule spec[where x="n - 1"])
   520   apply arith
   520   apply arith
   521   done
   521   done
   522 
   522 
   523 lemma represent_NatInterval[rule_format]: "Elem x (NatInterval n m) \<longrightarrow> (? u. n \<le> u & u \<le> n+m & nat2Nat u = x)"
   523 lemma represent_NatInterval[rule_format]: "Elem x (NatInterval n m) \<longrightarrow> (\<exists>u. n \<le> u \<and> u \<le> n+m \<and> nat2Nat u = x)"
   524   apply (induct m)
   524   apply (induct m)
   525   apply (auto simp add: Singleton union)
   525   apply (auto simp add: Singleton union)
   526   apply (rule_tac x="Suc (n+m)" in exI)
   526   apply (rule_tac x="Suc (n+m)" in exI)
   527   apply auto
   527   apply auto
   528   done
   528   done
   533     fix n m :: nat
   533     fix n m :: nat
   534     assume nm: "nat2Nat n = nat2Nat (n+m)"
   534     assume nm: "nat2Nat n = nat2Nat (n+m)"
   535     assume mg0: "0 < m"
   535     assume mg0: "0 < m"
   536     let ?Z = "NatInterval n m"
   536     let ?Z = "NatInterval n m"
   537     have "?Z \<noteq> Empty" by (simp add: NatInterval_not_Empty)
   537     have "?Z \<noteq> Empty" by (simp add: NatInterval_not_Empty)
   538     then have "? x. (Elem x ?Z) & (! y. Elem y x \<longrightarrow> Not (Elem y ?Z))" 
   538     then have "\<exists>x. (Elem x ?Z) \<and> (\<forall>y. Elem y x \<longrightarrow> Not (Elem y ?Z))" 
   539       by (auto simp add: Regularity)
   539       by (auto simp add: Regularity)
   540     then obtain x where x:"Elem x ?Z & (! y. Elem y x \<longrightarrow> Not (Elem y ?Z))" ..
   540     then obtain x where x:"Elem x ?Z \<and> (\<forall>y. Elem y x \<longrightarrow> Not (Elem y ?Z))" ..
   541     then have "? u. n \<le> u & u \<le> n+m & nat2Nat u = x" 
   541     then have "\<exists>u. n \<le> u & u \<le> n+m & nat2Nat u = x" 
   542       by (simp add: represent_NatInterval)
   542       by (simp add: represent_NatInterval)
   543     then obtain u where u: "n \<le> u & u \<le> n+m & nat2Nat u = x" ..
   543     then obtain u where u: "n \<le> u & u \<le> n+m \<and> nat2Nat u = x" ..
   544     have "n < u \<longrightarrow> False"
   544     have "n < u \<longrightarrow> False"
   545     proof 
   545     proof 
   546       assume n_less_u: "n < u"
   546       assume n_less_u: "n < u"
   547       let ?y = "nat2Nat (u - 1)"
   547       let ?y = "nat2Nat (u - 1)"
   548       have "Elem ?y (nat2Nat u)"
   548       have "Elem ?y (nat2Nat u)"
   588   show ?thesis
   588   show ?thesis
   589     apply (auto simp add: inj_on_def)
   589     apply (auto simp add: inj_on_def)
   590     apply (case_tac "x = y")
   590     apply (case_tac "x = y")
   591     apply auto
   591     apply auto
   592     apply (case_tac "x < y")
   592     apply (case_tac "x < y")
   593     apply (case_tac "? m. y = x + m & 0 < m")
   593     apply (case_tac "\<exists>m. y = x + m & 0 < m")
   594     apply (auto intro: lemma_nat2Nat)
   594     apply (auto intro: lemma_nat2Nat)
   595     apply (case_tac "y < x")
   595     apply (case_tac "y < x")
   596     apply (case_tac "? m. x = y + m & 0 < m")
   596     apply (case_tac "\<exists>m. x = y + m & 0 < m")
   597     apply simp
   597     apply simp
   598     apply simp
   598     apply simp
   599     using th apply blast
   599     using th apply blast
   600     apply (case_tac "? m. x = y + m")
   600     apply (case_tac "\<exists>m. x = y + m")
   601     apply (auto intro: lemma_nat2Nat)
   601     apply (auto intro: lemma_nat2Nat)
   602     apply (drule sym)
   602     apply (drule sym)
   603     using lemma_nat2Nat apply blast
   603     using lemma_nat2Nat apply blast
   604     using th' apply blast    
   604     using th' apply blast    
   605     done
   605     done
   623   
   623   
   624 
   624 
   625 (*lemma Elem_induct: "(\<And>x. \<forall>y. Elem y x \<longrightarrow> P y \<Longrightarrow> P x) \<Longrightarrow> P a"
   625 (*lemma Elem_induct: "(\<And>x. \<forall>y. Elem y x \<longrightarrow> P y \<Longrightarrow> P x) \<Longrightarrow> P a"
   626   by (erule wf_induct[OF wf_is_Elem_of, simplified is_Elem_of_def, simplified])*)
   626   by (erule wf_induct[OF wf_is_Elem_of, simplified is_Elem_of_def, simplified])*)
   627 
   627 
   628 lemma Elem_Opair_exists: "? z. Elem x z & Elem y z & Elem z (Opair x y)"
   628 lemma Elem_Opair_exists: "\<exists>z. Elem x z & Elem y z & Elem z (Opair x y)"
   629   apply (rule exI[where x="Upair x y"])
   629   apply (rule exI[where x="Upair x y"])
   630   by (simp add: Upair Opair_def)
   630   by (simp add: Upair Opair_def)
   631 
   631 
   632 lemma UNIV_is_not_in_ZF: "UNIV \<noteq> explode R"
   632 lemma UNIV_is_not_in_ZF: "UNIV \<noteq> explode R"
   633 proof
   633 proof
   680 
   680 
   681 lemma implode_explode[simp]: "implode (explode x) = x"
   681 lemma implode_explode[simp]: "implode (explode x) = x"
   682   by (simp add: implode_def inj_explode)
   682   by (simp add: implode_def inj_explode)
   683 
   683 
   684 definition regular :: "(ZF * ZF) set \<Rightarrow> bool" where
   684 definition regular :: "(ZF * ZF) set \<Rightarrow> bool" where
   685   "regular R == ! A. A \<noteq> Empty \<longrightarrow> (? x. Elem x A & (! y. (y, x) \<in> R \<longrightarrow> Not (Elem y A)))"
   685   "regular R == \<forall>A. A \<noteq> Empty \<longrightarrow> (\<exists>x. Elem x A \<and> (\<forall>y. (y, x) \<in> R \<longrightarrow> Not (Elem y A)))"
   686 
   686 
   687 definition set_like :: "(ZF * ZF) set \<Rightarrow> bool" where
   687 definition set_like :: "(ZF * ZF) set \<Rightarrow> bool" where
   688   "set_like R == ! y. Ext R y \<in> range explode"
   688   "set_like R == \<forall>y. Ext R y \<in> range explode"
   689 
   689 
   690 definition wfzf :: "(ZF * ZF) set \<Rightarrow> bool" where
   690 definition wfzf :: "(ZF * ZF) set \<Rightarrow> bool" where
   691   "wfzf R == regular R & set_like R"
   691   "wfzf R == regular R \<and> set_like R"
   692 
   692 
   693 lemma regular_Elem: "regular is_Elem_of"
   693 lemma regular_Elem: "regular is_Elem_of"
   694   by (simp add: regular_def is_Elem_of_def Regularity)
   694   by (simp add: regular_def is_Elem_of_def Regularity)
   695 
   695 
   696 lemma set_like_Elem: "set_like is_Elem_of"
   696 lemma set_like_Elem: "set_like is_Elem_of"
   700   by (auto simp add: wfzf_def regular_Elem set_like_Elem)
   700   by (auto simp add: wfzf_def regular_Elem set_like_Elem)
   701 
   701 
   702 definition SeqSum :: "(nat \<Rightarrow> ZF) \<Rightarrow> ZF" where
   702 definition SeqSum :: "(nat \<Rightarrow> ZF) \<Rightarrow> ZF" where
   703   "SeqSum f == Sum (Repl Nat (f o Nat2nat))"
   703   "SeqSum f == Sum (Repl Nat (f o Nat2nat))"
   704 
   704 
   705 lemma SeqSum: "Elem x (SeqSum f) = (? n. Elem x (f n))"
   705 lemma SeqSum: "Elem x (SeqSum f) = (\<exists>n. Elem x (f n))"
   706   apply (auto simp add: SeqSum_def Sum Repl)
   706   apply (auto simp add: SeqSum_def Sum Repl)
   707   apply (rule_tac x = "f n" in exI)
   707   apply (rule_tac x = "f n" in exI)
   708   apply auto
   708   apply auto
   709   done
   709   done
   710 
   710 
   730 definition Ext_ZF_hull :: "(ZF * ZF) set \<Rightarrow> ZF \<Rightarrow> ZF" where
   730 definition Ext_ZF_hull :: "(ZF * ZF) set \<Rightarrow> ZF \<Rightarrow> ZF" where
   731   "Ext_ZF_hull R s == SeqSum (Ext_ZF_n R s)"
   731   "Ext_ZF_hull R s == SeqSum (Ext_ZF_n R s)"
   732 
   732 
   733 lemma Elem_Ext_ZF_hull:
   733 lemma Elem_Ext_ZF_hull:
   734   assumes set_like_R: "set_like R" 
   734   assumes set_like_R: "set_like R" 
   735   shows "Elem x (Ext_ZF_hull R S) = (? n. Elem x (Ext_ZF_n R S n))"
   735   shows "Elem x (Ext_ZF_hull R S) = (\<exists>n. Elem x (Ext_ZF_n R S n))"
   736   by (simp add: Ext_ZF_hull_def SeqSum)
   736   by (simp add: Ext_ZF_hull_def SeqSum)
   737   
   737   
   738 lemma Elem_Elem_Ext_ZF_hull:
   738 lemma Elem_Elem_Ext_ZF_hull:
   739   assumes set_like_R: "set_like R" 
   739   assumes set_like_R: "set_like R" 
   740           and x_hull: "Elem x (Ext_ZF_hull R S)"
   740           and x_hull: "Elem x (Ext_ZF_hull R S)"
   741           and y_R_x: "(y, x) \<in> R"
   741           and y_R_x: "(y, x) \<in> R"
   742   shows "Elem y (Ext_ZF_hull R S)"
   742   shows "Elem y (Ext_ZF_hull R S)"
   743 proof -
   743 proof -
   744   from Elem_Ext_ZF_hull[OF set_like_R] x_hull 
   744   from Elem_Ext_ZF_hull[OF set_like_R] x_hull 
   745   have "? n. Elem x (Ext_ZF_n R S n)" by auto
   745   have "\<exists>n. Elem x (Ext_ZF_n R S n)" by auto
   746   then obtain n where n:"Elem x (Ext_ZF_n R S n)" ..
   746   then obtain n where n:"Elem x (Ext_ZF_n R S n)" ..
   747   with y_R_x have "Elem y (Ext_ZF_n R S (Suc n))"
   747   with y_R_x have "Elem y (Ext_ZF_n R S (Suc n))"
   748     apply (auto simp add: Repl Sum)
   748     apply (auto simp add: Repl Sum)
   749     apply (rule_tac x="Ext_ZF R x" in exI) 
   749     apply (rule_tac x="Ext_ZF R x" in exI) 
   750     apply (auto simp add: Elem_Ext_ZF[OF set_like_R])
   750     apply (auto simp add: Elem_Ext_ZF[OF set_like_R])
   803         apply (rule_tac induct[rule_format])
   803         apply (rule_tac induct[rule_format])
   804         apply auto
   804         apply auto
   805         done
   805         done
   806       with x show "False" by auto
   806       with x show "False" by auto
   807     qed
   807     qed
   808     then have "! x. P x" by auto
   808     then have "\<forall>x. P x" by auto
   809   }
   809   }
   810   then show "(\<forall>x. (\<forall>y. (y, x) \<in> R \<longrightarrow> P y) \<longrightarrow> P x) \<longrightarrow> (! x. P x)" by blast
   810   then show "(\<forall>x. (\<forall>y. (y, x) \<in> R \<longrightarrow> P y) \<longrightarrow> P x) \<longrightarrow> (\<forall>x. P x)" by blast
   811 qed
   811 qed
   812 
   812 
   813 lemma wf_is_Elem_of: "wf is_Elem_of"
   813 lemma wf_is_Elem_of: "wf is_Elem_of"
   814   by (auto simp add: wfzf_is_Elem_of wfzf_implies_wf)
   814   by (auto simp add: wfzf_is_Elem_of wfzf_implies_wf)
   815 
   815 
   816 lemma in_Ext_RTrans_implies_Elem_Ext_ZF_hull:  
   816 lemma in_Ext_RTrans_implies_Elem_Ext_ZF_hull:  
   817   "set_like R \<Longrightarrow> x \<in> (Ext (R^+) s) \<Longrightarrow> Elem x (Ext_ZF_hull R s)"
   817   "set_like R \<Longrightarrow> x \<in> (Ext (R\<^sup>+) s) \<Longrightarrow> Elem x (Ext_ZF_hull R s)"
   818   apply (simp add: Ext_def Elem_Ext_ZF_hull)
   818   apply (simp add: Ext_def Elem_Ext_ZF_hull)
   819   apply (erule converse_trancl_induct[where r="R"])
   819   apply (erule converse_trancl_induct[where r="R"])
   820   apply (rule exI[where x=0])
   820   apply (rule exI[where x=0])
   821   apply (simp add: Elem_Ext_ZF)
   821   apply (simp add: Elem_Ext_ZF)
   822   apply auto
   822   apply auto
   824   apply (simp add: Sum Repl)
   824   apply (simp add: Sum Repl)
   825   apply (rule_tac x="Ext_ZF R z" in exI)
   825   apply (rule_tac x="Ext_ZF R z" in exI)
   826   apply (auto simp add: Elem_Ext_ZF)
   826   apply (auto simp add: Elem_Ext_ZF)
   827   done
   827   done
   828 
   828 
   829 lemma implodeable_Ext_trancl: "set_like R \<Longrightarrow> set_like (R^+)"
   829 lemma implodeable_Ext_trancl: "set_like R \<Longrightarrow> set_like (R\<^sup>+)"
   830   apply (subst set_like_def)
   830   apply (subst set_like_def)
   831   apply (auto simp add: image_def)
   831   apply (auto simp add: image_def)
   832   apply (rule_tac x="Sep (Ext_ZF_hull R y) (\<lambda> z. z \<in> (Ext (R^+) y))" in exI)
   832   apply (rule_tac x="Sep (Ext_ZF_hull R y) (\<lambda> z. z \<in> (Ext (R\<^sup>+) y))" in exI)
   833   apply (auto simp add: explode_def Sep set_eqI 
   833   apply (auto simp add: explode_def Sep set_eqI 
   834     in_Ext_RTrans_implies_Elem_Ext_ZF_hull)
   834     in_Ext_RTrans_implies_Elem_Ext_ZF_hull)
   835   done
   835   done
   836  
   836  
   837 lemma Elem_Ext_ZF_hull_implies_in_Ext_RTrans[rule_format]:
   837 lemma Elem_Ext_ZF_hull_implies_in_Ext_RTrans[rule_format]:
   838   "set_like R \<Longrightarrow> ! x. Elem x (Ext_ZF_n R s n) \<longrightarrow> x \<in> (Ext (R^+) s)"
   838   "set_like R \<Longrightarrow> \<forall>x. Elem x (Ext_ZF_n R s n) \<longrightarrow> x \<in> (Ext (R\<^sup>+) s)"
   839   apply (induct_tac n)
   839   apply (induct_tac n)
   840   apply (auto simp add: Elem_Ext_ZF Ext_def Sum Repl)
   840   apply (auto simp add: Elem_Ext_ZF Ext_def Sum Repl)
   841   done
   841   done
   842 
   842 
   843 lemma "set_like R \<Longrightarrow> Ext_ZF (R^+) s = Ext_ZF_hull R s"
   843 lemma "set_like R \<Longrightarrow> Ext_ZF (R\<^sup>+) s = Ext_ZF_hull R s"
   844   apply (frule implodeable_Ext_trancl)
   844   apply (frule implodeable_Ext_trancl)
   845   apply (auto simp add: Ext)
   845   apply (auto simp add: Ext)
   846   apply (erule in_Ext_RTrans_implies_Elem_Ext_ZF_hull)
   846   apply (erule in_Ext_RTrans_implies_Elem_Ext_ZF_hull)
   847   apply (simp add: Elem_Ext_ZF Ext_def)
   847   apply (simp add: Elem_Ext_ZF Ext_def)
   848   apply (auto simp add: Elem_Ext_ZF Elem_Ext_ZF_hull)
   848   apply (auto simp add: Elem_Ext_ZF Elem_Ext_ZF_hull)
   854   assume wf: "wf R"
   854   assume wf: "wf R"
   855   fix A
   855   fix A
   856   show "A \<noteq> Empty \<longrightarrow> (\<exists>x. Elem x A \<and> (\<forall>y. (y, x) \<in> R \<longrightarrow> \<not> Elem y A))"
   856   show "A \<noteq> Empty \<longrightarrow> (\<exists>x. Elem x A \<and> (\<forall>y. (y, x) \<in> R \<longrightarrow> \<not> Elem y A))"
   857   proof
   857   proof
   858     assume A: "A \<noteq> Empty"
   858     assume A: "A \<noteq> Empty"
   859     then have "? x. x \<in> explode A" 
   859     then have "\<exists>x. x \<in> explode A" 
   860       by (auto simp add: explode_def Ext Empty)
   860       by (auto simp add: explode_def Ext Empty)
   861     then obtain x where x:"x \<in> explode A" ..   
   861     then obtain x where x:"x \<in> explode A" ..   
   862     from iffD1[OF wf_eq_minimal wf, rule_format, where Q="explode A", OF x]
   862     from iffD1[OF wf_eq_minimal wf, rule_format, where Q="explode A", OF x]
   863     obtain z where "z \<in> explode A \<and> (\<forall>y. (y, z) \<in> R \<longrightarrow> y \<notin> explode A)" by auto    
   863     obtain z where "z \<in> explode A \<and> (\<forall>y. (y, z) \<in> R \<longrightarrow> y \<notin> explode A)" by auto    
   864     then show "\<exists>x. Elem x A \<and> (\<forall>y. (y, x) \<in> R \<longrightarrow> \<not> Elem y A)"      
   864     then show "\<exists>x. Elem x A \<and> (\<forall>y. (y, x) \<in> R \<longrightarrow> \<not> Elem y A)"      
   871 lemma wf_eq_wfzf: "(wf R \<and> set_like R) = wfzf R"
   871 lemma wf_eq_wfzf: "(wf R \<and> set_like R) = wfzf R"
   872   apply (auto simp add: wfzf_implies_wf)
   872   apply (auto simp add: wfzf_implies_wf)
   873   apply (auto simp add: wfzf_def wf_implies_regular)
   873   apply (auto simp add: wfzf_def wf_implies_regular)
   874   done
   874   done
   875 
   875 
   876 lemma wfzf_trancl: "wfzf R \<Longrightarrow> wfzf (R^+)"
   876 lemma wfzf_trancl: "wfzf R \<Longrightarrow> wfzf (R\<^sup>+)"
   877   by (auto simp add: wf_eq_wfzf[symmetric] implodeable_Ext_trancl wf_trancl)
   877   by (auto simp add: wf_eq_wfzf[symmetric] implodeable_Ext_trancl wf_trancl)
   878 
   878 
   879 lemma Ext_subset_mono: "R \<subseteq> S \<Longrightarrow> Ext R y \<subseteq> Ext S y"
   879 lemma Ext_subset_mono: "R \<subseteq> S \<Longrightarrow> Ext R y \<subseteq> Ext S y"
   880   by (auto simp add: Ext_def)
   880   by (auto simp add: Ext_def)
   881 
   881