src/ZF/Constructible/WF_absolute.thy
changeset 13268 240509babf00
parent 13254 5146ccaedf42
child 13269 3ba9be497c33
equal deleted inserted replaced
13267:502f69ea6627 13268:240509babf00
     1 theory WF_absolute = WFrec:
     1 theory WF_absolute = WFrec:
       
     2 
       
     3 (*????move to Wellorderings.thy*)
       
     4 lemma (in M_axioms) wellfounded_on_field_imp_wellfounded:
       
     5      "wellfounded_on(M, field(r), r) ==> wellfounded(M,r)"
       
     6 by (simp add: wellfounded_def wellfounded_on_iff_wellfounded, fast)
       
     7 
       
     8 lemma (in M_axioms) wellfounded_iff_wellfounded_on_field:
       
     9      "M(r) ==> wellfounded(M,r) <-> wellfounded_on(M, field(r), r)"
       
    10 by (blast intro: wellfounded_imp_wellfounded_on
       
    11                  wellfounded_on_field_imp_wellfounded)
       
    12 
       
    13 lemma (in M_axioms) wellfounded_on_subset_A:
       
    14      "[| wellfounded_on(M,A,r);  B<=A |] ==> wellfounded_on(M,B,r)"
       
    15 by (simp add: wellfounded_on_def, blast)
       
    16 
     2 
    17 
     3 subsection{*Every well-founded relation is a subset of some inverse image of
    18 subsection{*Every well-founded relation is a subset of some inverse image of
     4       an ordinal*}
    19       an ordinal*}
     5 
    20 
     6 lemma wf_rvimage_Ord: "Ord(i) \<Longrightarrow> wf(rvimage(A, f, Memrel(i)))"
    21 lemma wf_rvimage_Ord: "Ord(i) \<Longrightarrow> wf(rvimage(A, f, Memrel(i)))"
   125                   (\<forall>fi'. M(fi') --> fun_apply(M,f,i',fi') -->
   140                   (\<forall>fi'. M(fi') --> fun_apply(M,f,i',fi') -->
   126                    (\<forall>q. M(q) --> pair(M,fi,fi',q) --> q \<in> r))))))))))"
   141                    (\<forall>q. M(q) --> pair(M,fi,fi',q) --> q \<in> r))))))))))"
   127 
   142 
   128   tran_closure :: "[i=>o,i,i] => o"
   143   tran_closure :: "[i=>o,i,i] => o"
   129     "tran_closure(M,r,t) ==
   144     "tran_closure(M,r,t) ==
   130          \<exists>s. M(s) & rtran_closure(M,r,s) & composition(M,r,s,t)"
   145          \<exists>s[M]. rtran_closure(M,r,s) & composition(M,r,s,t)"
   131 
   146 
   132 
   147 
   133 locale M_trancl = M_axioms +
   148 locale M_trancl = M_axioms +
   134 (*THEY NEED RELATIVIZATION*)
   149 (*THEY NEED RELATIVIZATION*)
   135   assumes rtrancl_separation:
   150   assumes rtrancl_separation:
   136      "[| M(r); M(A) |] ==>
   151      "[| M(r); M(A) |] ==>
   137 	separation
   152 	separation
   138 	   (M, \<lambda>p. \<exists>n\<in>nat. \<exists>f \<in> succ(n) -> A.
   153 	   (M, \<lambda>p. \<exists>n[M]. n\<in>nat & 
   139                     (\<exists>x y. p = <x,y> &  f`0 = x & f`n = y) &
   154                     (\<exists>f[M]. 
   140                           (\<forall>i\<in>n. <f`i, f`succ(i)> \<in> r))"
   155                      f \<in> succ(n) -> A &
       
   156                      (\<exists>x[M]. \<exists>y[M]. pair(M,x,y,p) &  
       
   157                            f`0 = x & f`n = y) &
       
   158                            (\<forall>i\<in>n. <f`i, f`succ(i)> \<in> r)))"
   141       and wellfounded_trancl_separation:
   159       and wellfounded_trancl_separation:
   142      "[| M(r); M(Z) |] ==> separation (M, \<lambda>x. \<exists>w. M(w) & \<langle>w,x\<rangle> \<in> r^+ & w \<in> Z)"
   160      "[| M(r); M(Z) |] ==> separation (M, \<lambda>x. \<exists>w[M]. w \<in> Z & \<langle>w,x\<rangle> \<in> r^+)"
   143 
   161 
   144 
   162 
   145 lemma (in M_trancl) rtran_closure_rtrancl:
   163 lemma (in M_trancl) rtran_closure_rtrancl:
   146      "M(r) ==> rtran_closure(M,r,rtrancl(r))"
   164      "M(r) ==> rtran_closure(M,r,rtrancl(r))"
   147 apply (simp add: rtran_closure_def rtrancl_alt_eq_rtrancl [symmetric]
   165 apply (simp add: rtran_closure_def rtrancl_alt_eq_rtrancl [symmetric]
   163 lemma (in M_trancl) rtrancl_closed [intro,simp]:
   181 lemma (in M_trancl) rtrancl_closed [intro,simp]:
   164      "M(r) ==> M(rtrancl(r))"
   182      "M(r) ==> M(rtrancl(r))"
   165 apply (insert rtrancl_separation [of r "field(r)"])
   183 apply (insert rtrancl_separation [of r "field(r)"])
   166 apply (simp add: rtrancl_alt_eq_rtrancl [symmetric]
   184 apply (simp add: rtrancl_alt_eq_rtrancl [symmetric]
   167                  rtrancl_alt_def field_closed typed_apply_abs apply_closed
   185                  rtrancl_alt_def field_closed typed_apply_abs apply_closed
   168                  Ord_succ_mem_iff M_nat
   186                  Ord_succ_mem_iff M_nat nat_into_M
   169                  nat_0_le [THEN ltD] leI [THEN ltD] ltI apply_funtype)
   187                  nat_0_le [THEN ltD] leI [THEN ltD] ltI apply_funtype)
   170 done
   188 done
   171 
   189 
   172 lemma (in M_trancl) rtrancl_abs [simp]:
   190 lemma (in M_trancl) rtrancl_abs [simp]:
   173      "[| M(r); M(z) |] ==> rtran_closure(M,r,z) <-> z = rtrancl(r)"
   191      "[| M(r); M(z) |] ==> rtran_closure(M,r,z) <-> z = rtrancl(r)"
   213      "[| wellfounded_on(M,A,r);  r-``A <= A; M(r); M(A) |]
   231      "[| wellfounded_on(M,A,r);  r-``A <= A; M(r); M(A) |]
   214       ==> wellfounded_on(M,A,r^+)"
   232       ==> wellfounded_on(M,A,r^+)"
   215 apply (simp add: wellfounded_on_def)
   233 apply (simp add: wellfounded_on_def)
   216 apply (safe intro!: equalityI)
   234 apply (safe intro!: equalityI)
   217 apply (rename_tac Z x)
   235 apply (rename_tac Z x)
   218 apply (subgoal_tac "M({x\<in>A. \<exists>w. M(w) & \<langle>w,x\<rangle> \<in> r^+ & w \<in> Z})")
   236 apply (subgoal_tac "M({x\<in>A. \<exists>w[M]. w \<in> Z & \<langle>w,x\<rangle> \<in> r^+})")
   219  prefer 2
   237  prefer 2
   220  apply (simp add: wellfounded_trancl_separation)
   238  apply (blast intro: wellfounded_trancl_separation) 
   221 apply (drule_tac x = "{x\<in>A. \<exists>w. M(w) & \<langle>w,x\<rangle> \<in> r^+ & w \<in> Z}" in spec)
   239 apply (drule_tac x = "{x\<in>A. \<exists>w[M]. w \<in> Z & \<langle>w,x\<rangle> \<in> r^+}" in spec, safe)
   222 apply safe
       
   223 apply (blast dest: transM, simp)
   240 apply (blast dest: transM, simp)
   224 apply (rename_tac y w)
   241 apply (rename_tac y w)
   225 apply (drule_tac x=w in bspec, assumption, clarify)
   242 apply (drule_tac x=w in bspec, assumption, clarify)
   226 apply (erule tranclE)
   243 apply (erule tranclE)
   227   apply (blast dest: transM)   (*transM is needed to prove M(xa)*)
   244   apply (blast dest: transM)   (*transM is needed to prove M(xa)*)
   228  apply blast
   245  apply blast
   229 done
   246 done
   230 
       
   231 (*????move to Wellorderings.thy*)
       
   232 lemma (in M_axioms) wellfounded_on_field_imp_wellfounded:
       
   233      "wellfounded_on(M, field(r), r) ==> wellfounded(M,r)"
       
   234 by (simp add: wellfounded_def wellfounded_on_iff_wellfounded, fast)
       
   235 
       
   236 lemma (in M_axioms) wellfounded_iff_wellfounded_on_field:
       
   237      "M(r) ==> wellfounded(M,r) <-> wellfounded_on(M, field(r), r)"
       
   238 by (blast intro: wellfounded_imp_wellfounded_on
       
   239                  wellfounded_on_field_imp_wellfounded)
       
   240 
       
   241 lemma (in M_axioms) wellfounded_on_subset_A:
       
   242      "[| wellfounded_on(M,A,r);  B<=A |] ==> wellfounded_on(M,B,r)"
       
   243 by (simp add: wellfounded_on_def, blast)
       
   244 
       
   245 
       
   246 
   247 
   247 lemma (in M_trancl) wellfounded_trancl:
   248 lemma (in M_trancl) wellfounded_trancl:
   248      "[|wellfounded(M,r); M(r)|] ==> wellfounded(M,r^+)"
   249      "[|wellfounded(M,r); M(r)|] ==> wellfounded(M,r^+)"
   249 apply (rotate_tac -1)
   250 apply (rotate_tac -1)
   250 apply (simp add: wellfounded_iff_wellfounded_on_field)
   251 apply (simp add: wellfounded_iff_wellfounded_on_field)
   257 inverse image of an ordinal.  Key step is the construction (in M) of a
   258 inverse image of an ordinal.  Key step is the construction (in M) of a
   258 rank function.*}
   259 rank function.*}
   259 
   260 
   260 
   261 
   261 (*NEEDS RELATIVIZATION*)
   262 (*NEEDS RELATIVIZATION*)
   262 locale M_recursion = M_trancl +
   263 locale M_wfrank = M_trancl +
   263   assumes wfrank_separation':
   264   assumes wfrank_separation':
   264      "M(r) ==>
   265      "M(r) ==>
   265 	separation
   266 	separation
   266 	   (M, \<lambda>x. ~ (\<exists>f. M(f) & is_recfun(r^+, x, %x f. range(f), f)))"
   267 	   (M, \<lambda>x. ~ (\<exists>f[M]. is_recfun(r^+, x, %x f. range(f), f)))"
   267  and wfrank_strong_replacement':
   268  and wfrank_strong_replacement':
   268      "M(r) ==>
   269      "M(r) ==>
   269       strong_replacement(M, \<lambda>x z. \<exists>y f. M(y) & M(f) &
   270       strong_replacement(M, \<lambda>x z. \<exists>y[M]. \<exists>f[M]. 
   270 		  pair(M,x,y,z) & is_recfun(r^+, x, %x f. range(f), f) &
   271 		  pair(M,x,y,z) & is_recfun(r^+, x, %x f. range(f), f) &
   271 		  y = range(f))"
   272 		  y = range(f))"
   272  and Ord_wfrank_separation:
   273  and Ord_wfrank_separation:
   273      "M(r) ==>
   274      "M(r) ==>
   274       separation (M, \<lambda>x. ~ (\<forall>f. M(f) \<longrightarrow>
   275       separation (M, \<lambda>x. ~ (\<forall>f. M(f) \<longrightarrow>
   277 text{*This function, defined using replacement, is a rank function for
   278 text{*This function, defined using replacement, is a rank function for
   278 well-founded relations within the class M.*}
   279 well-founded relations within the class M.*}
   279 constdefs
   280 constdefs
   280  wellfoundedrank :: "[i=>o,i,i] => i"
   281  wellfoundedrank :: "[i=>o,i,i] => i"
   281     "wellfoundedrank(M,r,A) ==
   282     "wellfoundedrank(M,r,A) ==
   282         {p. x\<in>A, \<exists>y f. M(y) & M(f) &
   283         {p. x\<in>A, \<exists>y[M]. \<exists>f[M]. 
   283                        p = <x,y> & is_recfun(r^+, x, %x f. range(f), f) &
   284                        p = <x,y> & is_recfun(r^+, x, %x f. range(f), f) &
   284                        y = range(f)}"
   285                        y = range(f)}"
   285 
   286 
   286 lemma (in M_recursion) exists_wfrank:
   287 lemma (in M_wfrank) exists_wfrank:
   287     "[| wellfounded(M,r); M(a); M(r) |]
   288     "[| wellfounded(M,r); M(a); M(r) |]
   288      ==> \<exists>f. M(f) & is_recfun(r^+, a, %x f. range(f), f)"
   289      ==> \<exists>f[M]. is_recfun(r^+, a, %x f. range(f), f)"
   289 apply (rule wellfounded_exists_is_recfun)
   290 apply (rule wellfounded_exists_is_recfun)
   290       apply (blast intro: wellfounded_trancl)
   291       apply (blast intro: wellfounded_trancl)
   291      apply (rule trans_trancl)
   292      apply (rule trans_trancl)
   292     apply (erule wfrank_separation')
   293     apply (erule wfrank_separation')
   293    apply (erule wfrank_strong_replacement')
   294    apply (erule wfrank_strong_replacement')
   294 apply (simp_all add: trancl_subset_times)
   295 apply (simp_all add: trancl_subset_times)
   295 done
   296 done
   296 
   297 
   297 lemma (in M_recursion) M_wellfoundedrank:
   298 lemma (in M_wfrank) M_wellfoundedrank:
   298     "[| wellfounded(M,r); M(r); M(A) |] ==> M(wellfoundedrank(M,r,A))"
   299     "[| wellfounded(M,r); M(r); M(A) |] ==> M(wellfoundedrank(M,r,A))"
   299 apply (insert wfrank_strong_replacement' [of r])
   300 apply (insert wfrank_strong_replacement' [of r])
   300 apply (simp add: wellfoundedrank_def)
   301 apply (simp add: wellfoundedrank_def)
   301 apply (rule strong_replacement_closed)
   302 apply (rule strong_replacement_closed)
   302    apply assumption+
   303    apply assumption+
   304    apply (blast intro: wellfounded_trancl)
   305    apply (blast intro: wellfounded_trancl)
   305   apply (rule trans_trancl)
   306   apply (rule trans_trancl)
   306  apply (simp add: trancl_subset_times, blast)
   307  apply (simp add: trancl_subset_times, blast)
   307 done
   308 done
   308 
   309 
   309 lemma (in M_recursion) Ord_wfrank_range [rule_format]:
   310 lemma (in M_wfrank) Ord_wfrank_range [rule_format]:
   310     "[| wellfounded(M,r); a\<in>A; M(r); M(A) |]
   311     "[| wellfounded(M,r); a\<in>A; M(r); M(A) |]
   311      ==> \<forall>f. M(f) --> is_recfun(r^+, a, %x f. range(f), f) --> Ord(range(f))"
   312      ==> \<forall>f. M(f) --> is_recfun(r^+, a, %x f. range(f), f) --> Ord(range(f))"
   312 apply (drule wellfounded_trancl, assumption)
   313 apply (drule wellfounded_trancl, assumption)
   313 apply (rule wellfounded_induct, assumption+)
   314 apply (rule wellfounded_induct, assumption+)
   314   apply simp
   315   apply simp
   335  apply (drule_tac x="restrict(f, r^+ -`` {y})" in spec)
   336  apply (drule_tac x="restrict(f, r^+ -`` {y})" in spec)
   336  apply (simp add: function_apply_equality [OF _ is_recfun_imp_function])
   337  apply (simp add: function_apply_equality [OF _ is_recfun_imp_function])
   337 apply (blast dest: pair_components_in_M)
   338 apply (blast dest: pair_components_in_M)
   338 done
   339 done
   339 
   340 
   340 lemma (in M_recursion) Ord_range_wellfoundedrank:
   341 lemma (in M_wfrank) Ord_range_wellfoundedrank:
   341     "[| wellfounded(M,r); r \<subseteq> A*A;  M(r); M(A) |]
   342     "[| wellfounded(M,r); r \<subseteq> A*A;  M(r); M(A) |]
   342      ==> Ord (range(wellfoundedrank(M,r,A)))"
   343      ==> Ord (range(wellfoundedrank(M,r,A)))"
   343 apply (frule wellfounded_trancl, assumption)
   344 apply (frule wellfounded_trancl, assumption)
   344 apply (frule trancl_subset_times)
   345 apply (frule trancl_subset_times)
   345 apply (simp add: wellfoundedrank_def)
   346 apply (simp add: wellfoundedrank_def)
   347  prefer 2
   348  prefer 2
   348  txt{*by our previous result the range consists of ordinals.*}
   349  txt{*by our previous result the range consists of ordinals.*}
   349  apply (blast intro: Ord_wfrank_range)
   350  apply (blast intro: Ord_wfrank_range)
   350 txt{*We still must show that the range is a transitive set.*}
   351 txt{*We still must show that the range is a transitive set.*}
   351 apply (simp add: Transset_def, clarify, simp)
   352 apply (simp add: Transset_def, clarify, simp)
   352 apply (rename_tac x i f u)
   353 apply (rename_tac x f i u)
   353 apply (frule is_recfun_imp_in_r, assumption)
   354 apply (frule is_recfun_imp_in_r, assumption)
   354 apply (subgoal_tac "M(u) & M(i) & M(x)")
   355 apply (subgoal_tac "M(u) & M(i) & M(x)")
   355  prefer 2 apply (blast dest: transM, clarify)
   356  prefer 2 apply (blast dest: transM, clarify)
   356 apply (rule_tac a=u in rangeI)
   357 apply (rule_tac a=u in rangeI)
   357 apply (rule ReplaceI)
   358 apply (rule ReplaceI)
   358   apply (rule_tac x=i in exI, simp)
   359   apply (rule_tac x=i in rexI, simp)
   359   apply (rule_tac x="restrict(f, r^+ -`` {u})" in exI)
   360    apply (rule_tac x="restrict(f, r^+ -`` {u})" in rexI)
   360   apply (blast intro: is_recfun_restrict trans_trancl dest: apply_recfun2)
   361     apply (blast intro: is_recfun_restrict trans_trancl dest: apply_recfun2)
   361  apply blast
   362    apply (simp, simp, blast) 
   362 txt{*Unicity requirement of Replacement*}
   363 txt{*Unicity requirement of Replacement*}
   363 apply clarify
   364 apply clarify
   364 apply (frule apply_recfun2, assumption)
   365 apply (frule apply_recfun2, assumption)
   365 apply (simp add: trans_trancl is_recfun_cut)+
   366 apply (simp add: trans_trancl is_recfun_cut)+
   366 done
   367 done
   367 
   368 
   368 lemma (in M_recursion) function_wellfoundedrank:
   369 lemma (in M_wfrank) function_wellfoundedrank:
   369     "[| wellfounded(M,r); M(r); M(A)|]
   370     "[| wellfounded(M,r); M(r); M(A)|]
   370      ==> function(wellfoundedrank(M,r,A))"
   371      ==> function(wellfoundedrank(M,r,A))"
   371 apply (simp add: wellfoundedrank_def function_def, clarify)
   372 apply (simp add: wellfoundedrank_def function_def, clarify)
   372 txt{*Uniqueness: repeated below!*}
   373 txt{*Uniqueness: repeated below!*}
   373 apply (drule is_recfun_functional, assumption)
   374 apply (drule is_recfun_functional, assumption)
   374      apply (blast intro: wellfounded_trancl)
   375      apply (blast intro: wellfounded_trancl)
   375     apply (simp_all add: trancl_subset_times trans_trancl)
   376     apply (simp_all add: trancl_subset_times trans_trancl)
   376 done
   377 done
   377 
   378 
   378 lemma (in M_recursion) domain_wellfoundedrank:
   379 lemma (in M_wfrank) domain_wellfoundedrank:
   379     "[| wellfounded(M,r); M(r); M(A)|]
   380     "[| wellfounded(M,r); M(r); M(A)|]
   380      ==> domain(wellfoundedrank(M,r,A)) = A"
   381      ==> domain(wellfoundedrank(M,r,A)) = A"
   381 apply (simp add: wellfoundedrank_def function_def)
   382 apply (simp add: wellfoundedrank_def function_def)
   382 apply (rule equalityI, auto)
   383 apply (rule equalityI, auto)
   383 apply (frule transM, assumption)
   384 apply (frule transM, assumption)
   384 apply (frule_tac a=x in exists_wfrank, assumption+, clarify)
   385 apply (frule_tac a=x in exists_wfrank, assumption+, clarify)
   385 apply (rule domainI)
   386 apply (rule domainI)
   386 apply (rule ReplaceI)
   387 apply (rule ReplaceI)
   387   apply (rule_tac x="range(f)" in exI)
   388   apply (rule_tac x="range(f)" in rexI)
   388   apply simp
   389   apply simp
   389   apply (rule_tac x=f in exI, blast, assumption)
   390   apply (rule_tac x=f in rexI, blast, simp_all)
   390 txt{*Uniqueness (for Replacement): repeated above!*}
   391 txt{*Uniqueness (for Replacement): repeated above!*}
   391 apply clarify
   392 apply clarify
   392 apply (drule is_recfun_functional, assumption)
   393 apply (drule is_recfun_functional, assumption)
   393     apply (blast intro: wellfounded_trancl)
   394     apply (blast intro: wellfounded_trancl)
   394     apply (simp_all add: trancl_subset_times trans_trancl)
   395     apply (simp_all add: trancl_subset_times trans_trancl)
   395 done
   396 done
   396 
   397 
   397 lemma (in M_recursion) wellfoundedrank_type:
   398 lemma (in M_wfrank) wellfoundedrank_type:
   398     "[| wellfounded(M,r);  M(r); M(A)|]
   399     "[| wellfounded(M,r);  M(r); M(A)|]
   399      ==> wellfoundedrank(M,r,A) \<in> A -> range(wellfoundedrank(M,r,A))"
   400      ==> wellfoundedrank(M,r,A) \<in> A -> range(wellfoundedrank(M,r,A))"
   400 apply (frule function_wellfoundedrank [of r A], assumption+)
   401 apply (frule function_wellfoundedrank [of r A], assumption+)
   401 apply (frule function_imp_Pi)
   402 apply (frule function_imp_Pi)
   402  apply (simp add: wellfoundedrank_def relation_def)
   403  apply (simp add: wellfoundedrank_def relation_def)
   403  apply blast
   404  apply blast
   404 apply (simp add: domain_wellfoundedrank)
   405 apply (simp add: domain_wellfoundedrank)
   405 done
   406 done
   406 
   407 
   407 lemma (in M_recursion) Ord_wellfoundedrank:
   408 lemma (in M_wfrank) Ord_wellfoundedrank:
   408     "[| wellfounded(M,r); a \<in> A; r \<subseteq> A*A;  M(r); M(A) |]
   409     "[| wellfounded(M,r); a \<in> A; r \<subseteq> A*A;  M(r); M(A) |]
   409      ==> Ord(wellfoundedrank(M,r,A) ` a)"
   410      ==> Ord(wellfoundedrank(M,r,A) ` a)"
   410 by (blast intro: apply_funtype [OF wellfoundedrank_type]
   411 by (blast intro: apply_funtype [OF wellfoundedrank_type]
   411                  Ord_in_Ord [OF Ord_range_wellfoundedrank])
   412                  Ord_in_Ord [OF Ord_range_wellfoundedrank])
   412 
   413 
   413 lemma (in M_recursion) wellfoundedrank_eq:
   414 lemma (in M_wfrank) wellfoundedrank_eq:
   414      "[| is_recfun(r^+, a, %x. range, f);
   415      "[| is_recfun(r^+, a, %x. range, f);
   415          wellfounded(M,r);  a \<in> A; M(f); M(r); M(A)|]
   416          wellfounded(M,r);  a \<in> A; M(f); M(r); M(A)|]
   416       ==> wellfoundedrank(M,r,A) ` a = range(f)"
   417       ==> wellfoundedrank(M,r,A) ` a = range(f)"
   417 apply (rule apply_equality)
   418 apply (rule apply_equality)
   418  prefer 2 apply (blast intro: wellfoundedrank_type)
   419  prefer 2 apply (blast intro: wellfoundedrank_type)
   419 apply (simp add: wellfoundedrank_def)
   420 apply (simp add: wellfoundedrank_def)
   420 apply (rule ReplaceI)
   421 apply (rule ReplaceI)
   421   apply (rule_tac x="range(f)" in exI)
   422   apply (rule_tac x="range(f)" in rexI) 
   422   apply blast
   423   apply blast
   423  apply assumption
   424  apply simp_all
   424 txt{*Unicity requirement of Replacement*}
   425 txt{*Unicity requirement of Replacement*}
   425 apply clarify
   426 apply clarify
   426 apply (drule is_recfun_functional, assumption)
   427 apply (drule is_recfun_functional, assumption)
   427     apply (blast intro: wellfounded_trancl)
   428     apply (blast intro: wellfounded_trancl)
   428     apply (simp_all add: trancl_subset_times trans_trancl)
   429     apply (simp_all add: trancl_subset_times trans_trancl)
   429 done
   430 done
   430 
   431 
   431 
   432 
   432 lemma (in M_recursion) wellfoundedrank_lt:
   433 lemma (in M_wfrank) wellfoundedrank_lt:
   433      "[| <a,b> \<in> r;
   434      "[| <a,b> \<in> r;
   434          wellfounded(M,r); r \<subseteq> A*A;  M(r); M(A)|]
   435          wellfounded(M,r); r \<subseteq> A*A;  M(r); M(A)|]
   435       ==> wellfoundedrank(M,r,A) ` a < wellfoundedrank(M,r,A) ` b"
   436       ==> wellfoundedrank(M,r,A) ` a < wellfoundedrank(M,r,A) ` b"
   436 apply (frule wellfounded_trancl, assumption)
   437 apply (frule wellfounded_trancl, assumption)
   437 apply (subgoal_tac "a\<in>A & b\<in>A")
   438 apply (subgoal_tac "a\<in>A & b\<in>A")
   452 apply (simp add: is_recfun_type [THEN apply_iff] vimage_singleton_iff
   453 apply (simp add: is_recfun_type [THEN apply_iff] vimage_singleton_iff
   453                  r_into_trancl apply_recfun r_into_trancl)
   454                  r_into_trancl apply_recfun r_into_trancl)
   454 done
   455 done
   455 
   456 
   456 
   457 
   457 lemma (in M_recursion) wellfounded_imp_subset_rvimage:
   458 lemma (in M_wfrank) wellfounded_imp_subset_rvimage:
   458      "[|wellfounded(M,r); r \<subseteq> A*A; M(r); M(A)|]
   459      "[|wellfounded(M,r); r \<subseteq> A*A; M(r); M(A)|]
   459       ==> \<exists>i f. Ord(i) & r <= rvimage(A, f, Memrel(i))"
   460       ==> \<exists>i f. Ord(i) & r <= rvimage(A, f, Memrel(i))"
   460 apply (rule_tac x="range(wellfoundedrank(M,r,A))" in exI)
   461 apply (rule_tac x="range(wellfoundedrank(M,r,A))" in exI)
   461 apply (rule_tac x="wellfoundedrank(M,r,A)" in exI)
   462 apply (rule_tac x="wellfoundedrank(M,r,A)" in exI)
   462 apply (simp add: Ord_range_wellfoundedrank, clarify)
   463 apply (simp add: Ord_range_wellfoundedrank, clarify)
   463 apply (frule subsetD, assumption, clarify)
   464 apply (frule subsetD, assumption, clarify)
   464 apply (simp add: rvimage_iff wellfoundedrank_lt [THEN ltD])
   465 apply (simp add: rvimage_iff wellfoundedrank_lt [THEN ltD])
   465 apply (blast intro: apply_rangeI wellfoundedrank_type)
   466 apply (blast intro: apply_rangeI wellfoundedrank_type)
   466 done
   467 done
   467 
   468 
   468 lemma (in M_recursion) wellfounded_imp_wf:
   469 lemma (in M_wfrank) wellfounded_imp_wf:
   469      "[|wellfounded(M,r); relation(r); M(r)|] ==> wf(r)"
   470      "[|wellfounded(M,r); relation(r); M(r)|] ==> wf(r)"
   470 by (blast dest!: relation_field_times_field wellfounded_imp_subset_rvimage
   471 by (blast dest!: relation_field_times_field wellfounded_imp_subset_rvimage
   471           intro: wf_rvimage_Ord [THEN wf_subset])
   472           intro: wf_rvimage_Ord [THEN wf_subset])
   472 
   473 
   473 lemma (in M_recursion) wellfounded_on_imp_wf_on:
   474 lemma (in M_wfrank) wellfounded_on_imp_wf_on:
   474      "[|wellfounded_on(M,A,r); relation(r); M(r); M(A)|] ==> wf[A](r)"
   475      "[|wellfounded_on(M,A,r); relation(r); M(r); M(A)|] ==> wf[A](r)"
   475 apply (simp add: wellfounded_on_iff_wellfounded wf_on_def)
   476 apply (simp add: wellfounded_on_iff_wellfounded wf_on_def)
   476 apply (rule wellfounded_imp_wf)
   477 apply (rule wellfounded_imp_wf)
   477 apply (simp_all add: relation_def)
   478 apply (simp_all add: relation_def)
   478 done
   479 done
   479 
   480 
   480 
   481 
   481 theorem (in M_recursion) wf_abs [simp]:
   482 theorem (in M_wfrank) wf_abs [simp]:
   482      "[|relation(r); M(r)|] ==> wellfounded(M,r) <-> wf(r)"
   483      "[|relation(r); M(r)|] ==> wellfounded(M,r) <-> wf(r)"
   483 by (blast intro: wellfounded_imp_wf wf_imp_relativized)
   484 by (blast intro: wellfounded_imp_wf wf_imp_relativized)
   484 
   485 
   485 theorem (in M_recursion) wf_on_abs [simp]:
   486 theorem (in M_wfrank) wf_on_abs [simp]:
   486      "[|relation(r); M(r); M(A)|] ==> wellfounded_on(M,A,r) <-> wf[A](r)"
   487      "[|relation(r); M(r); M(A)|] ==> wellfounded_on(M,A,r) <-> wf[A](r)"
   487 by (blast intro: wellfounded_on_imp_wf_on wf_on_imp_relativized)
   488 by (blast intro: wellfounded_on_imp_wf_on wf_on_imp_relativized)
   488 
   489 
   489 
   490 
   490 text{*absoluteness for wfrec-defined functions.*}
   491 text{*absoluteness for wfrec-defined functions.*}
   491 
   492 
   492 (*first use is_recfun, then M_is_recfun*)
   493 (*first use is_recfun, then M_is_recfun*)
   493 
   494 
   494 lemma (in M_trancl) wfrec_relativize:
   495 lemma (in M_trancl) wfrec_relativize:
   495   "[|wf(r); M(a); M(r);  
   496   "[|wf(r); M(a); M(r);  
   496      strong_replacement(M, \<lambda>x z. \<exists>y g. M(y) & M(g) &
   497      strong_replacement(M, \<lambda>x z. \<exists>y[M]. \<exists>g[M].
   497           pair(M,x,y,z) & 
   498           pair(M,x,y,z) & 
   498           is_recfun(r^+, x, \<lambda>x f. H(x, restrict(f, r -`` {x})), g) & 
   499           is_recfun(r^+, x, \<lambda>x f. H(x, restrict(f, r -`` {x})), g) & 
   499           y = H(x, restrict(g, r -`` {x}))); 
   500           y = H(x, restrict(g, r -`` {x}))); 
   500      \<forall>x[M]. \<forall>g[M]. function(g) --> M(H(x,g))|] 
   501      \<forall>x[M]. \<forall>g[M]. function(g) --> M(H(x,g))|] 
   501    ==> wfrec(r,a,H) = z <-> 
   502    ==> wfrec(r,a,H) = z <-> 
   502        (\<exists>f. M(f) & is_recfun(r^+, a, \<lambda>x f. H(x, restrict(f, r -`` {x})), f) & 
   503        (\<exists>f[M]. is_recfun(r^+, a, \<lambda>x f. H(x, restrict(f, r -`` {x})), f) & 
   503             z = H(a,restrict(f,r-``{a})))"
   504             z = H(a,restrict(f,r-``{a})))"
   504 apply (frule wf_trancl) 
   505 apply (frule wf_trancl) 
   505 apply (simp add: wftrec_def wfrec_def, safe)
   506 apply (simp add: wftrec_def wfrec_def, safe)
   506  apply (frule wf_exists_is_recfun 
   507  apply (frule wf_exists_is_recfun 
   507               [of concl: "r^+" a "\<lambda>x f. H(x, restrict(f, r -`` {x}))"]) 
   508               [of concl: "r^+" a "\<lambda>x f. H(x, restrict(f, r -`` {x}))"]) 
   508       apply (simp_all add: trans_trancl function_restrictI trancl_subset_times)
   509       apply (simp_all add: trans_trancl function_restrictI trancl_subset_times)
   509  apply (clarify, rule_tac x=f in exI) 
   510  apply (clarify, rule_tac x=x in rexI) 
   510  apply (simp_all add: the_recfun_eq trans_trancl trancl_subset_times)
   511  apply (simp_all add: the_recfun_eq trans_trancl trancl_subset_times)
   511 done
   512 done
   512 
   513 
   513 
   514 
   514 text{*Assuming @{term r} is transitive simplifies the occurrences of @{text H}.
   515 text{*Assuming @{term r} is transitive simplifies the occurrences of @{text H}.
   515       The premise @{term "relation(r)"} is necessary 
   516       The premise @{term "relation(r)"} is necessary 
   516       before we can replace @{term "r^+"} by @{term r}. *}
   517       before we can replace @{term "r^+"} by @{term r}. *}
   517 theorem (in M_trancl) trans_wfrec_relativize:
   518 theorem (in M_trancl) trans_wfrec_relativize:
   518   "[|wf(r);  trans(r);  relation(r);  M(r);  M(a);
   519   "[|wf(r);  trans(r);  relation(r);  M(r);  M(a);
   519      strong_replacement(M, \<lambda>x z. \<exists>y g. M(y) & M(g) &
   520      strong_replacement(M, \<lambda>x z. \<exists>y[M]. \<exists>g[M].
   520                 pair(M,x,y,z) & is_recfun(r,x,H,g) & y = H(x,g)); 
   521                 pair(M,x,y,z) & is_recfun(r,x,H,g) & y = H(x,g)); 
   521      \<forall>x[M]. \<forall>g[M]. function(g) --> M(H(x,g))|] 
   522      \<forall>x[M]. \<forall>g[M]. function(g) --> M(H(x,g))|] 
   522    ==> wfrec(r,a,H) = z <-> (\<exists>f. M(f) & is_recfun(r,a,H,f) & z = H(a,f))" 
   523    ==> wfrec(r,a,H) = z <-> (\<exists>f[M]. is_recfun(r,a,H,f) & z = H(a,f))" 
   523 by (simp cong: is_recfun_cong
   524 by (simp cong: is_recfun_cong
   524          add: wfrec_relativize trancl_eq_r
   525          add: wfrec_relativize trancl_eq_r
   525                is_recfun_restrict_idem domain_restrict_idem)
   526                is_recfun_restrict_idem domain_restrict_idem)
   526 
   527 
   527 
   528 
   528 lemma (in M_trancl) trans_eq_pair_wfrec_iff:
   529 lemma (in M_trancl) trans_eq_pair_wfrec_iff:
   529   "[|wf(r);  trans(r); relation(r); M(r);  M(y); 
   530   "[|wf(r);  trans(r); relation(r); M(r);  M(y); 
   530      strong_replacement(M, \<lambda>x z. \<exists>y g. M(y) & M(g) &
   531      strong_replacement(M, \<lambda>x z. \<exists>y[M]. \<exists>g[M].
   531                 pair(M,x,y,z) & is_recfun(r,x,H,g) & y = H(x,g)); 
   532                 pair(M,x,y,z) & is_recfun(r,x,H,g) & y = H(x,g)); 
   532      \<forall>x[M]. \<forall>g[M]. function(g) --> M(H(x,g))|] 
   533      \<forall>x[M]. \<forall>g[M]. function(g) --> M(H(x,g))|] 
   533    ==> y = <x, wfrec(r, x, H)> <-> 
   534    ==> y = <x, wfrec(r, x, H)> <-> 
   534        (\<exists>f. M(f) & is_recfun(r,x,H,f) & y = <x, H(x,f)>)"
   535        (\<exists>f[M]. is_recfun(r,x,H,f) & y = <x, H(x,f)>)"
   535 apply safe  
   536 apply safe  
   536  apply (simp add: trans_wfrec_relativize [THEN iff_sym]) 
   537  apply (simp add: trans_wfrec_relativize [THEN iff_sym]) 
   537 txt{*converse direction*}
   538 txt{*converse direction*}
   538 apply (rule sym)
   539 apply (rule sym)
   539 apply (simp add: trans_wfrec_relativize, blast) 
   540 apply (simp add: trans_wfrec_relativize, blast) 
   541 
   542 
   542 
   543 
   543 subsection{*M is closed under well-founded recursion*}
   544 subsection{*M is closed under well-founded recursion*}
   544 
   545 
   545 text{*Lemma with the awkward premise mentioning @{text wfrec}.*}
   546 text{*Lemma with the awkward premise mentioning @{text wfrec}.*}
   546 lemma (in M_recursion) wfrec_closed_lemma [rule_format]:
   547 lemma (in M_wfrank) wfrec_closed_lemma [rule_format]:
   547      "[|wf(r); M(r); 
   548      "[|wf(r); M(r); 
   548         strong_replacement(M, \<lambda>x y. y = \<langle>x, wfrec(r, x, H)\<rangle>);
   549         strong_replacement(M, \<lambda>x y. y = \<langle>x, wfrec(r, x, H)\<rangle>);
   549         \<forall>x[M]. \<forall>g[M]. function(g) --> M(H(x,g)) |] 
   550         \<forall>x[M]. \<forall>g[M]. function(g) --> M(H(x,g)) |] 
   550       ==> M(a) --> M(wfrec(r,a,H))"
   551       ==> M(a) --> M(wfrec(r,a,H))"
   551 apply (rule_tac a=a in wf_induct, assumption+)
   552 apply (rule_tac a=a in wf_induct, assumption+)
   555 apply (simp_all add: function_lam) 
   556 apply (simp_all add: function_lam) 
   556 apply (blast intro: dest: pair_components_in_M ) 
   557 apply (blast intro: dest: pair_components_in_M ) 
   557 done
   558 done
   558 
   559 
   559 text{*Eliminates one instance of replacement.*}
   560 text{*Eliminates one instance of replacement.*}
   560 lemma (in M_recursion) wfrec_replacement_iff:
   561 lemma (in M_wfrank) wfrec_replacement_iff:
   561      "strong_replacement(M, \<lambda>x z. \<exists>y g. M(y) & M(g) &
   562      "strong_replacement(M, \<lambda>x z. \<exists>y[M]. \<exists>g[M]. 
   562                 pair(M,x,y,z) & is_recfun(r,x,H,g) & y = H(x,g)) <->
   563                 pair(M,x,y,z) & is_recfun(r,x,H,g) & y = H(x,g)) <->
   563       strong_replacement(M, 
   564       strong_replacement(M, 
   564            \<lambda>x y. \<exists>f. M(f) & is_recfun(r,x,H,f) & y = <x, H(x,f)>)"
   565            \<lambda>x y. \<exists>f[M]. is_recfun(r,x,H,f) & y = <x, H(x,f)>)"
   565 apply simp 
   566 apply simp 
   566 apply (rule strong_replacement_cong, blast) 
   567 apply (rule strong_replacement_cong, blast) 
   567 done
   568 done
   568 
   569 
   569 text{*Useful version for transitive relations*}
   570 text{*Useful version for transitive relations*}
   570 theorem (in M_recursion) trans_wfrec_closed:
   571 theorem (in M_wfrank) trans_wfrec_closed:
   571      "[|wf(r); trans(r); relation(r); M(r); M(a);
   572      "[|wf(r); trans(r); relation(r); M(r); M(a);
   572         strong_replacement(M, 
   573         strong_replacement(M, 
   573              \<lambda>x z. \<exists>y g. M(y) & M(g) &
   574              \<lambda>x z. \<exists>y[M]. \<exists>g[M].
   574                     pair(M,x,y,z) & is_recfun(r,x,H,g) & y = H(x,g)); 
   575                     pair(M,x,y,z) & is_recfun(r,x,H,g) & y = H(x,g)); 
   575         \<forall>x[M]. \<forall>g[M]. function(g) --> M(H(x,g)) |] 
   576         \<forall>x[M]. \<forall>g[M]. function(g) --> M(H(x,g)) |] 
   576       ==> M(wfrec(r,a,H))"
   577       ==> M(wfrec(r,a,H))"
   577 apply (frule wfrec_replacement_iff [THEN iffD1]) 
   578 apply (frule wfrec_replacement_iff [THEN iffD1]) 
   578 apply (rule wfrec_closed_lemma, assumption+) 
   579 apply (rule wfrec_closed_lemma, assumption+) 
   580 done
   581 done
   581 
   582 
   582 section{*Absoluteness without assuming transitivity*}
   583 section{*Absoluteness without assuming transitivity*}
   583 lemma (in M_trancl) eq_pair_wfrec_iff:
   584 lemma (in M_trancl) eq_pair_wfrec_iff:
   584   "[|wf(r);  M(r);  M(y); 
   585   "[|wf(r);  M(r);  M(y); 
   585      strong_replacement(M, \<lambda>x z. \<exists>y g. M(y) & M(g) &
   586      strong_replacement(M, \<lambda>x z. \<exists>y[M]. \<exists>g[M].
   586           pair(M,x,y,z) & 
   587           pair(M,x,y,z) & 
   587           is_recfun(r^+, x, \<lambda>x f. H(x, restrict(f, r -`` {x})), g) & 
   588           is_recfun(r^+, x, \<lambda>x f. H(x, restrict(f, r -`` {x})), g) & 
   588           y = H(x, restrict(g, r -`` {x}))); 
   589           y = H(x, restrict(g, r -`` {x}))); 
   589      \<forall>x[M]. \<forall>g[M]. function(g) --> M(H(x,g))|] 
   590      \<forall>x[M]. \<forall>g[M]. function(g) --> M(H(x,g))|] 
   590    ==> y = <x, wfrec(r, x, H)> <-> 
   591    ==> y = <x, wfrec(r, x, H)> <-> 
   591        (\<exists>f. M(f) & is_recfun(r^+, x, \<lambda>x f. H(x, restrict(f, r -`` {x})), f) & 
   592        (\<exists>f[M]. is_recfun(r^+, x, \<lambda>x f. H(x, restrict(f, r -`` {x})), f) & 
   592             y = <x, H(x,restrict(f,r-``{x}))>)"
   593             y = <x, H(x,restrict(f,r-``{x}))>)"
   593 apply safe  
   594 apply safe  
   594  apply (simp add: wfrec_relativize [THEN iff_sym]) 
   595  apply (simp add: wfrec_relativize [THEN iff_sym]) 
   595 txt{*converse direction*}
   596 txt{*converse direction*}
   596 apply (rule sym)
   597 apply (rule sym)
   597 apply (simp add: wfrec_relativize, blast) 
   598 apply (simp add: wfrec_relativize, blast) 
   598 done
   599 done
   599 
   600 
   600 lemma (in M_recursion) wfrec_closed_lemma [rule_format]:
   601 lemma (in M_wfrank) wfrec_closed_lemma [rule_format]:
   601      "[|wf(r); M(r); 
   602      "[|wf(r); M(r); 
   602         strong_replacement(M, \<lambda>x y. y = \<langle>x, wfrec(r, x, H)\<rangle>);
   603         strong_replacement(M, \<lambda>x y. y = \<langle>x, wfrec(r, x, H)\<rangle>);
   603         \<forall>x[M]. \<forall>g[M]. function(g) --> M(H(x,g)) |] 
   604         \<forall>x[M]. \<forall>g[M]. function(g) --> M(H(x,g)) |] 
   604       ==> M(a) --> M(wfrec(r,a,H))"
   605       ==> M(a) --> M(wfrec(r,a,H))"
   605 apply (rule_tac a=a in wf_induct, assumption+)
   606 apply (rule_tac a=a in wf_induct, assumption+)
   609 apply (simp_all add: function_lam) 
   610 apply (simp_all add: function_lam) 
   610 apply (blast intro: dest: pair_components_in_M ) 
   611 apply (blast intro: dest: pair_components_in_M ) 
   611 done
   612 done
   612 
   613 
   613 text{*Full version not assuming transitivity, but maybe not very useful.*}
   614 text{*Full version not assuming transitivity, but maybe not very useful.*}
   614 theorem (in M_recursion) wfrec_closed:
   615 theorem (in M_wfrank) wfrec_closed:
   615      "[|wf(r); M(r); M(a);
   616      "[|wf(r); M(r); M(a);
   616      strong_replacement(M, \<lambda>x z. \<exists>y g. M(y) & M(g) &
   617      strong_replacement(M, \<lambda>x z. \<exists>y[M]. \<exists>g[M].
   617           pair(M,x,y,z) & 
   618           pair(M,x,y,z) & 
   618           is_recfun(r^+, x, \<lambda>x f. H(x, restrict(f, r -`` {x})), g) & 
   619           is_recfun(r^+, x, \<lambda>x f. H(x, restrict(f, r -`` {x})), g) & 
   619           y = H(x, restrict(g, r -`` {x}))); 
   620           y = H(x, restrict(g, r -`` {x}))); 
   620         \<forall>x[M]. \<forall>g[M]. function(g) --> M(H(x,g)) |] 
   621         \<forall>x[M]. \<forall>g[M]. function(g) --> M(H(x,g)) |] 
   621       ==> M(wfrec(r,a,H))"
   622       ==> M(wfrec(r,a,H))"