src/ZF/Constructible/WF_absolute.thy
author paulson
Thu Jul 04 10:54:04 2002 +0200 (2002-07-04)
changeset 13293 09276ee04361
parent 13269 3ba9be497c33
child 13299 3a932abf97e8
permissions -rw-r--r--
tweaks
     1 theory WF_absolute = WFrec:
     2 
     3 subsection{*Every well-founded relation is a subset of some inverse image of
     4       an ordinal*}
     5 
     6 lemma wf_rvimage_Ord: "Ord(i) \<Longrightarrow> wf(rvimage(A, f, Memrel(i)))"
     7 by (blast intro: wf_rvimage wf_Memrel)
     8 
     9 
    10 constdefs
    11   wfrank :: "[i,i]=>i"
    12     "wfrank(r,a) == wfrec(r, a, %x f. \<Union>y \<in> r-``{x}. succ(f`y))"
    13 
    14 constdefs
    15   wftype :: "i=>i"
    16     "wftype(r) == \<Union>y \<in> range(r). succ(wfrank(r,y))"
    17 
    18 lemma wfrank: "wf(r) ==> wfrank(r,a) = (\<Union>y \<in> r-``{a}. succ(wfrank(r,y)))"
    19 by (subst wfrank_def [THEN def_wfrec], simp_all)
    20 
    21 lemma Ord_wfrank: "wf(r) ==> Ord(wfrank(r,a))"
    22 apply (rule_tac a="a" in wf_induct, assumption)
    23 apply (subst wfrank, assumption)
    24 apply (rule Ord_succ [THEN Ord_UN], blast)
    25 done
    26 
    27 lemma wfrank_lt: "[|wf(r); <a,b> \<in> r|] ==> wfrank(r,a) < wfrank(r,b)"
    28 apply (rule_tac a1 = "b" in wfrank [THEN ssubst], assumption)
    29 apply (rule UN_I [THEN ltI])
    30 apply (simp add: Ord_wfrank vimage_iff)+
    31 done
    32 
    33 lemma Ord_wftype: "wf(r) ==> Ord(wftype(r))"
    34 by (simp add: wftype_def Ord_wfrank)
    35 
    36 lemma wftypeI: "\<lbrakk>wf(r);  x \<in> field(r)\<rbrakk> \<Longrightarrow> wfrank(r,x) \<in> wftype(r)"
    37 apply (simp add: wftype_def)
    38 apply (blast intro: wfrank_lt [THEN ltD])
    39 done
    40 
    41 
    42 lemma wf_imp_subset_rvimage:
    43      "[|wf(r); r \<subseteq> A*A|] ==> \<exists>i f. Ord(i) & r <= rvimage(A, f, Memrel(i))"
    44 apply (rule_tac x="wftype(r)" in exI)
    45 apply (rule_tac x="\<lambda>x\<in>A. wfrank(r,x)" in exI)
    46 apply (simp add: Ord_wftype, clarify)
    47 apply (frule subsetD, assumption, clarify)
    48 apply (simp add: rvimage_iff wfrank_lt [THEN ltD])
    49 apply (blast intro: wftypeI)
    50 done
    51 
    52 theorem wf_iff_subset_rvimage:
    53   "relation(r) ==> wf(r) <-> (\<exists>i f A. Ord(i) & r <= rvimage(A, f, Memrel(i)))"
    54 by (blast dest!: relation_field_times_field wf_imp_subset_rvimage
    55           intro: wf_rvimage_Ord [THEN wf_subset])
    56 
    57 
    58 subsection{*Transitive closure without fixedpoints*}
    59 
    60 constdefs
    61   rtrancl_alt :: "[i,i]=>i"
    62     "rtrancl_alt(A,r) ==
    63        {p \<in> A*A. \<exists>n\<in>nat. \<exists>f \<in> succ(n) -> A.
    64                  (\<exists>x y. p = <x,y> &  f`0 = x & f`n = y) &
    65                        (\<forall>i\<in>n. <f`i, f`succ(i)> \<in> r)}"
    66 
    67 lemma alt_rtrancl_lemma1 [rule_format]:
    68     "n \<in> nat
    69      ==> \<forall>f \<in> succ(n) -> field(r).
    70          (\<forall>i\<in>n. \<langle>f`i, f ` succ(i)\<rangle> \<in> r) --> \<langle>f`0, f`n\<rangle> \<in> r^*"
    71 apply (induct_tac n)
    72 apply (simp_all add: apply_funtype rtrancl_refl, clarify)
    73 apply (rename_tac n f)
    74 apply (rule rtrancl_into_rtrancl)
    75  prefer 2 apply assumption
    76 apply (drule_tac x="restrict(f,succ(n))" in bspec)
    77  apply (blast intro: restrict_type2)
    78 apply (simp add: Ord_succ_mem_iff nat_0_le [THEN ltD] leI [THEN ltD] ltI)
    79 done
    80 
    81 lemma rtrancl_alt_subset_rtrancl: "rtrancl_alt(field(r),r) <= r^*"
    82 apply (simp add: rtrancl_alt_def)
    83 apply (blast intro: alt_rtrancl_lemma1)
    84 done
    85 
    86 lemma rtrancl_subset_rtrancl_alt: "r^* <= rtrancl_alt(field(r),r)"
    87 apply (simp add: rtrancl_alt_def, clarify)
    88 apply (frule rtrancl_type [THEN subsetD], clarify, simp)
    89 apply (erule rtrancl_induct)
    90  txt{*Base case, trivial*}
    91  apply (rule_tac x=0 in bexI)
    92   apply (rule_tac x="lam x:1. xa" in bexI)
    93    apply simp_all
    94 txt{*Inductive step*}
    95 apply clarify
    96 apply (rename_tac n f)
    97 apply (rule_tac x="succ(n)" in bexI)
    98  apply (rule_tac x="lam i:succ(succ(n)). if i=succ(n) then z else f`i" in bexI)
    99   apply (simp add: Ord_succ_mem_iff nat_0_le [THEN ltD] leI [THEN ltD] ltI)
   100   apply (blast intro: mem_asym)
   101  apply typecheck
   102  apply auto
   103 done
   104 
   105 lemma rtrancl_alt_eq_rtrancl: "rtrancl_alt(field(r),r) = r^*"
   106 by (blast del: subsetI
   107 	  intro: rtrancl_alt_subset_rtrancl rtrancl_subset_rtrancl_alt)
   108 
   109 
   110 constdefs
   111 
   112   rtran_closure :: "[i=>o,i,i] => o"
   113     "rtran_closure(M,r,s) ==
   114         \<forall>A. M(A) --> is_field(M,r,A) -->
   115  	 (\<forall>p. M(p) -->
   116           (p \<in> s <->
   117            (\<exists>n\<in>nat. M(n) &
   118             (\<exists>n'. M(n') & successor(M,n,n') &
   119              (\<exists>f. M(f) & typed_function(M,n',A,f) &
   120               (\<exists>x\<in>A. M(x) & (\<exists>y\<in>A. M(y) & pair(M,x,y,p) &
   121                    fun_apply(M,f,0,x) & fun_apply(M,f,n,y))) &
   122               (\<forall>i\<in>n. M(i) -->
   123                 (\<forall>i'. M(i') --> successor(M,i,i') -->
   124                  (\<forall>fi. M(fi) --> fun_apply(M,f,i,fi) -->
   125                   (\<forall>fi'. M(fi') --> fun_apply(M,f,i',fi') -->
   126                    (\<forall>q. M(q) --> pair(M,fi,fi',q) --> q \<in> r))))))))))"
   127 
   128   tran_closure :: "[i=>o,i,i] => o"
   129     "tran_closure(M,r,t) ==
   130          \<exists>s[M]. rtran_closure(M,r,s) & composition(M,r,s,t)"
   131 
   132 
   133 locale M_trancl = M_axioms +
   134 (*THEY NEED RELATIVIZATION*)
   135   assumes rtrancl_separation:
   136      "[| M(r); M(A) |] ==>
   137 	separation
   138 	   (M, \<lambda>p. \<exists>n[M]. n\<in>nat & 
   139                     (\<exists>f[M]. 
   140                      f \<in> succ(n) -> A &
   141                      (\<exists>x[M]. \<exists>y[M]. pair(M,x,y,p) &  
   142                            f`0 = x & f`n = y) &
   143                            (\<forall>i\<in>n. <f`i, f`succ(i)> \<in> r)))"
   144       and wellfounded_trancl_separation:
   145      "[| M(r); M(Z) |] ==> separation (M, \<lambda>x. \<exists>w[M]. w \<in> Z & \<langle>w,x\<rangle> \<in> r^+)"
   146 
   147 
   148 lemma (in M_trancl) rtran_closure_rtrancl:
   149      "M(r) ==> rtran_closure(M,r,rtrancl(r))"
   150 apply (simp add: rtran_closure_def rtrancl_alt_eq_rtrancl [symmetric]
   151                  rtrancl_alt_def field_closed typed_apply_abs apply_closed
   152                  Ord_succ_mem_iff M_nat  nat_0_le [THEN ltD], clarify)
   153 apply (rule iffI)
   154  apply clarify
   155  apply simp
   156  apply (rename_tac n f)
   157  apply (rule_tac x=n in bexI)
   158   apply (rule_tac x=f in exI)
   159   apply simp
   160   apply (blast dest: finite_fun_closed dest: transM)
   161  apply assumption
   162 apply clarify
   163 apply (simp add: nat_0_le [THEN ltD] apply_funtype, blast)
   164 done
   165 
   166 lemma (in M_trancl) rtrancl_closed [intro,simp]:
   167      "M(r) ==> M(rtrancl(r))"
   168 apply (insert rtrancl_separation [of r "field(r)"])
   169 apply (simp add: rtrancl_alt_eq_rtrancl [symmetric]
   170                  rtrancl_alt_def field_closed typed_apply_abs apply_closed
   171                  Ord_succ_mem_iff M_nat nat_into_M
   172                  nat_0_le [THEN ltD] leI [THEN ltD] ltI apply_funtype)
   173 done
   174 
   175 lemma (in M_trancl) rtrancl_abs [simp]:
   176      "[| M(r); M(z) |] ==> rtran_closure(M,r,z) <-> z = rtrancl(r)"
   177 apply (rule iffI)
   178  txt{*Proving the right-to-left implication*}
   179  prefer 2 apply (blast intro: rtran_closure_rtrancl)
   180 apply (rule M_equalityI)
   181 apply (simp add: rtran_closure_def rtrancl_alt_eq_rtrancl [symmetric]
   182                  rtrancl_alt_def field_closed typed_apply_abs apply_closed
   183                  Ord_succ_mem_iff M_nat
   184                  nat_0_le [THEN ltD] leI [THEN ltD] ltI apply_funtype)
   185  prefer 2 apply assumption
   186  prefer 2 apply blast
   187 apply (rule iffI, clarify)
   188 apply (simp add: nat_0_le [THEN ltD]  apply_funtype, blast, clarify, simp)
   189  apply (rename_tac n f)
   190  apply (rule_tac x=n in bexI)
   191   apply (rule_tac x=f in exI)
   192   apply (blast dest!: finite_fun_closed, assumption)
   193 done
   194 
   195 
   196 lemma (in M_trancl) trancl_closed [intro,simp]:
   197      "M(r) ==> M(trancl(r))"
   198 by (simp add: trancl_def comp_closed rtrancl_closed)
   199 
   200 lemma (in M_trancl) trancl_abs [simp]:
   201      "[| M(r); M(z) |] ==> tran_closure(M,r,z) <-> z = trancl(r)"
   202 by (simp add: tran_closure_def trancl_def)
   203 
   204 
   205 text{*Alternative proof of @{text wf_on_trancl}; inspiration for the
   206       relativized version.  Original version is on theory WF.*}
   207 lemma "[| wf[A](r);  r-``A <= A |] ==> wf[A](r^+)"
   208 apply (simp add: wf_on_def wf_def)
   209 apply (safe intro!: equalityI)
   210 apply (drule_tac x = "{x\<in>A. \<exists>w. \<langle>w,x\<rangle> \<in> r^+ & w \<in> Z}" in spec)
   211 apply (blast elim: tranclE)
   212 done
   213 
   214 
   215 lemma (in M_trancl) wellfounded_on_trancl:
   216      "[| wellfounded_on(M,A,r);  r-``A <= A; M(r); M(A) |]
   217       ==> wellfounded_on(M,A,r^+)"
   218 apply (simp add: wellfounded_on_def)
   219 apply (safe intro!: equalityI)
   220 apply (rename_tac Z x)
   221 apply (subgoal_tac "M({x\<in>A. \<exists>w[M]. w \<in> Z & \<langle>w,x\<rangle> \<in> r^+})")
   222  prefer 2
   223  apply (blast intro: wellfounded_trancl_separation) 
   224 apply (drule_tac x = "{x\<in>A. \<exists>w[M]. w \<in> Z & \<langle>w,x\<rangle> \<in> r^+}" in spec, safe)
   225 apply (blast dest: transM, simp)
   226 apply (rename_tac y w)
   227 apply (drule_tac x=w in bspec, assumption, clarify)
   228 apply (erule tranclE)
   229   apply (blast dest: transM)   (*transM is needed to prove M(xa)*)
   230  apply blast
   231 done
   232 
   233 lemma (in M_trancl) wellfounded_trancl:
   234      "[|wellfounded(M,r); M(r)|] ==> wellfounded(M,r^+)"
   235 apply (rotate_tac -1)
   236 apply (simp add: wellfounded_iff_wellfounded_on_field)
   237 apply (rule wellfounded_on_subset_A, erule wellfounded_on_trancl)
   238    apply blast
   239   apply (simp_all add: trancl_type [THEN field_rel_subset])
   240 done
   241 
   242 text{*Relativized to M: Every well-founded relation is a subset of some
   243 inverse image of an ordinal.  Key step is the construction (in M) of a
   244 rank function.*}
   245 
   246 
   247 (*NEEDS RELATIVIZATION*)
   248 locale M_wfrank = M_trancl +
   249   assumes wfrank_separation':
   250      "M(r) ==>
   251 	separation
   252 	   (M, \<lambda>x. ~ (\<exists>f[M]. is_recfun(r^+, x, %x f. range(f), f)))"
   253  and wfrank_strong_replacement':
   254      "M(r) ==>
   255       strong_replacement(M, \<lambda>x z. \<exists>y[M]. \<exists>f[M]. 
   256 		  pair(M,x,y,z) & is_recfun(r^+, x, %x f. range(f), f) &
   257 		  y = range(f))"
   258  and Ord_wfrank_separation:
   259      "M(r) ==>
   260       separation (M, \<lambda>x. ~ (\<forall>f. M(f) \<longrightarrow>
   261                        is_recfun(r^+, x, \<lambda>x. range, f) \<longrightarrow> Ord(range(f))))"
   262 
   263 text{*This function, defined using replacement, is a rank function for
   264 well-founded relations within the class M.*}
   265 constdefs
   266  wellfoundedrank :: "[i=>o,i,i] => i"
   267     "wellfoundedrank(M,r,A) ==
   268         {p. x\<in>A, \<exists>y[M]. \<exists>f[M]. 
   269                        p = <x,y> & is_recfun(r^+, x, %x f. range(f), f) &
   270                        y = range(f)}"
   271 
   272 lemma (in M_wfrank) exists_wfrank:
   273     "[| wellfounded(M,r); M(a); M(r) |]
   274      ==> \<exists>f[M]. is_recfun(r^+, a, %x f. range(f), f)"
   275 apply (rule wellfounded_exists_is_recfun)
   276       apply (blast intro: wellfounded_trancl)
   277      apply (rule trans_trancl)
   278     apply (erule wfrank_separation')
   279    apply (erule wfrank_strong_replacement')
   280 apply (simp_all add: trancl_subset_times)
   281 done
   282 
   283 lemma (in M_wfrank) M_wellfoundedrank:
   284     "[| wellfounded(M,r); M(r); M(A) |] ==> M(wellfoundedrank(M,r,A))"
   285 apply (insert wfrank_strong_replacement' [of r])
   286 apply (simp add: wellfoundedrank_def)
   287 apply (rule strong_replacement_closed)
   288    apply assumption+
   289  apply (rule univalent_is_recfun)
   290    apply (blast intro: wellfounded_trancl)
   291   apply (rule trans_trancl)
   292  apply (simp add: trancl_subset_times, blast)
   293 done
   294 
   295 lemma (in M_wfrank) Ord_wfrank_range [rule_format]:
   296     "[| wellfounded(M,r); a\<in>A; M(r); M(A) |]
   297      ==> \<forall>f. M(f) --> is_recfun(r^+, a, %x f. range(f), f) --> Ord(range(f))"
   298 apply (drule wellfounded_trancl, assumption)
   299 apply (rule wellfounded_induct, assumption+)
   300   apply simp
   301  apply (blast intro: Ord_wfrank_separation, clarify)
   302 txt{*The reasoning in both cases is that we get @{term y} such that
   303    @{term "\<langle>y, x\<rangle> \<in> r^+"}.  We find that
   304    @{term "f`y = restrict(f, r^+ -`` {y})"}. *}
   305 apply (rule OrdI [OF _ Ord_is_Transset])
   306  txt{*An ordinal is a transitive set...*}
   307  apply (simp add: Transset_def)
   308  apply clarify
   309  apply (frule apply_recfun2, assumption)
   310  apply (force simp add: restrict_iff)
   311 txt{*...of ordinals.  This second case requires the induction hyp.*}
   312 apply clarify
   313 apply (rename_tac i y)
   314 apply (frule apply_recfun2, assumption)
   315 apply (frule is_recfun_imp_in_r, assumption)
   316 apply (frule is_recfun_restrict)
   317     (*simp_all won't work*)
   318     apply (simp add: trans_trancl trancl_subset_times)+
   319 apply (drule spec [THEN mp], assumption)
   320 apply (subgoal_tac "M(restrict(f, r^+ -`` {y}))")
   321  apply (drule_tac x="restrict(f, r^+ -`` {y})" in spec)
   322  apply (simp add: function_apply_equality [OF _ is_recfun_imp_function])
   323 apply (blast dest: pair_components_in_M)
   324 done
   325 
   326 lemma (in M_wfrank) Ord_range_wellfoundedrank:
   327     "[| wellfounded(M,r); r \<subseteq> A*A;  M(r); M(A) |]
   328      ==> Ord (range(wellfoundedrank(M,r,A)))"
   329 apply (frule wellfounded_trancl, assumption)
   330 apply (frule trancl_subset_times)
   331 apply (simp add: wellfoundedrank_def)
   332 apply (rule OrdI [OF _ Ord_is_Transset])
   333  prefer 2
   334  txt{*by our previous result the range consists of ordinals.*}
   335  apply (blast intro: Ord_wfrank_range)
   336 txt{*We still must show that the range is a transitive set.*}
   337 apply (simp add: Transset_def, clarify, simp)
   338 apply (rename_tac x i f u)
   339 apply (frule is_recfun_imp_in_r, assumption)
   340 apply (subgoal_tac "M(u) & M(i) & M(x)")
   341  prefer 2 apply (blast dest: transM, clarify)
   342 apply (rule_tac a=u in rangeI)
   343 apply (rule_tac x=u in ReplaceI)
   344   apply simp 
   345   apply (rule_tac x="restrict(f, r^+ -`` {u})" in rexI)
   346    apply (blast intro: is_recfun_restrict trans_trancl dest: apply_recfun2)
   347   apply simp 
   348 apply blast 
   349 txt{*Unicity requirement of Replacement*}
   350 apply clarify
   351 apply (frule apply_recfun2, assumption)
   352 apply (simp add: trans_trancl is_recfun_cut)
   353 done
   354 
   355 lemma (in M_wfrank) function_wellfoundedrank:
   356     "[| wellfounded(M,r); M(r); M(A)|]
   357      ==> function(wellfoundedrank(M,r,A))"
   358 apply (simp add: wellfoundedrank_def function_def, clarify)
   359 txt{*Uniqueness: repeated below!*}
   360 apply (drule is_recfun_functional, assumption)
   361      apply (blast intro: wellfounded_trancl)
   362     apply (simp_all add: trancl_subset_times trans_trancl)
   363 done
   364 
   365 lemma (in M_wfrank) domain_wellfoundedrank:
   366     "[| wellfounded(M,r); M(r); M(A)|]
   367      ==> domain(wellfoundedrank(M,r,A)) = A"
   368 apply (simp add: wellfoundedrank_def function_def)
   369 apply (rule equalityI, auto)
   370 apply (frule transM, assumption)
   371 apply (frule_tac a=x in exists_wfrank, assumption+, clarify)
   372 apply (rule_tac b="range(f)" in domainI)
   373 apply (rule_tac x=x in ReplaceI)
   374   apply simp 
   375   apply (rule_tac x=f in rexI, blast, simp_all)
   376 txt{*Uniqueness (for Replacement): repeated above!*}
   377 apply clarify
   378 apply (drule is_recfun_functional, assumption)
   379     apply (blast intro: wellfounded_trancl)
   380     apply (simp_all add: trancl_subset_times trans_trancl)
   381 done
   382 
   383 lemma (in M_wfrank) wellfoundedrank_type:
   384     "[| wellfounded(M,r);  M(r); M(A)|]
   385      ==> wellfoundedrank(M,r,A) \<in> A -> range(wellfoundedrank(M,r,A))"
   386 apply (frule function_wellfoundedrank [of r A], assumption+)
   387 apply (frule function_imp_Pi)
   388  apply (simp add: wellfoundedrank_def relation_def)
   389  apply blast
   390 apply (simp add: domain_wellfoundedrank)
   391 done
   392 
   393 lemma (in M_wfrank) Ord_wellfoundedrank:
   394     "[| wellfounded(M,r); a \<in> A; r \<subseteq> A*A;  M(r); M(A) |]
   395      ==> Ord(wellfoundedrank(M,r,A) ` a)"
   396 by (blast intro: apply_funtype [OF wellfoundedrank_type]
   397                  Ord_in_Ord [OF Ord_range_wellfoundedrank])
   398 
   399 lemma (in M_wfrank) wellfoundedrank_eq:
   400      "[| is_recfun(r^+, a, %x. range, f);
   401          wellfounded(M,r);  a \<in> A; M(f); M(r); M(A)|]
   402       ==> wellfoundedrank(M,r,A) ` a = range(f)"
   403 apply (rule apply_equality)
   404  prefer 2 apply (blast intro: wellfoundedrank_type)
   405 apply (simp add: wellfoundedrank_def)
   406 apply (rule ReplaceI)
   407   apply (rule_tac x="range(f)" in rexI) 
   408   apply blast
   409  apply simp_all
   410 txt{*Unicity requirement of Replacement*}
   411 apply clarify
   412 apply (drule is_recfun_functional, assumption)
   413     apply (blast intro: wellfounded_trancl)
   414     apply (simp_all add: trancl_subset_times trans_trancl)
   415 done
   416 
   417 
   418 lemma (in M_wfrank) wellfoundedrank_lt:
   419      "[| <a,b> \<in> r;
   420          wellfounded(M,r); r \<subseteq> A*A;  M(r); M(A)|]
   421       ==> wellfoundedrank(M,r,A) ` a < wellfoundedrank(M,r,A) ` b"
   422 apply (frule wellfounded_trancl, assumption)
   423 apply (subgoal_tac "a\<in>A & b\<in>A")
   424  prefer 2 apply blast
   425 apply (simp add: lt_def Ord_wellfoundedrank, clarify)
   426 apply (frule exists_wfrank [of concl: _ b], assumption+, clarify)
   427 apply (rename_tac fb)
   428 apply (frule is_recfun_restrict [of concl: "r^+" a])
   429     apply (rule trans_trancl, assumption)
   430    apply (simp_all add: r_into_trancl trancl_subset_times)
   431 txt{*Still the same goal, but with new @{text is_recfun} assumptions.*}
   432 apply (simp add: wellfoundedrank_eq)
   433 apply (frule_tac a=a in wellfoundedrank_eq, assumption+)
   434    apply (simp_all add: transM [of a])
   435 txt{*We have used equations for wellfoundedrank and now must use some
   436     for  @{text is_recfun}. *}
   437 apply (rule_tac a=a in rangeI)
   438 apply (simp add: is_recfun_type [THEN apply_iff] vimage_singleton_iff
   439                  r_into_trancl apply_recfun r_into_trancl)
   440 done
   441 
   442 
   443 lemma (in M_wfrank) wellfounded_imp_subset_rvimage:
   444      "[|wellfounded(M,r); r \<subseteq> A*A; M(r); M(A)|]
   445       ==> \<exists>i f. Ord(i) & r <= rvimage(A, f, Memrel(i))"
   446 apply (rule_tac x="range(wellfoundedrank(M,r,A))" in exI)
   447 apply (rule_tac x="wellfoundedrank(M,r,A)" in exI)
   448 apply (simp add: Ord_range_wellfoundedrank, clarify)
   449 apply (frule subsetD, assumption, clarify)
   450 apply (simp add: rvimage_iff wellfoundedrank_lt [THEN ltD])
   451 apply (blast intro: apply_rangeI wellfoundedrank_type)
   452 done
   453 
   454 lemma (in M_wfrank) wellfounded_imp_wf:
   455      "[|wellfounded(M,r); relation(r); M(r)|] ==> wf(r)"
   456 by (blast dest!: relation_field_times_field wellfounded_imp_subset_rvimage
   457           intro: wf_rvimage_Ord [THEN wf_subset])
   458 
   459 lemma (in M_wfrank) wellfounded_on_imp_wf_on:
   460      "[|wellfounded_on(M,A,r); relation(r); M(r); M(A)|] ==> wf[A](r)"
   461 apply (simp add: wellfounded_on_iff_wellfounded wf_on_def)
   462 apply (rule wellfounded_imp_wf)
   463 apply (simp_all add: relation_def)
   464 done
   465 
   466 
   467 theorem (in M_wfrank) wf_abs [simp]:
   468      "[|relation(r); M(r)|] ==> wellfounded(M,r) <-> wf(r)"
   469 by (blast intro: wellfounded_imp_wf wf_imp_relativized)
   470 
   471 theorem (in M_wfrank) wf_on_abs [simp]:
   472      "[|relation(r); M(r); M(A)|] ==> wellfounded_on(M,A,r) <-> wf[A](r)"
   473 by (blast intro: wellfounded_on_imp_wf_on wf_on_imp_relativized)
   474 
   475 
   476 text{*absoluteness for wfrec-defined functions.*}
   477 
   478 (*first use is_recfun, then M_is_recfun*)
   479 
   480 lemma (in M_trancl) wfrec_relativize:
   481   "[|wf(r); M(a); M(r);  
   482      strong_replacement(M, \<lambda>x z. \<exists>y[M]. \<exists>g[M].
   483           pair(M,x,y,z) & 
   484           is_recfun(r^+, x, \<lambda>x f. H(x, restrict(f, r -`` {x})), g) & 
   485           y = H(x, restrict(g, r -`` {x}))); 
   486      \<forall>x[M]. \<forall>g[M]. function(g) --> M(H(x,g))|] 
   487    ==> wfrec(r,a,H) = z <-> 
   488        (\<exists>f[M]. is_recfun(r^+, a, \<lambda>x f. H(x, restrict(f, r -`` {x})), f) & 
   489             z = H(a,restrict(f,r-``{a})))"
   490 apply (frule wf_trancl) 
   491 apply (simp add: wftrec_def wfrec_def, safe)
   492  apply (frule wf_exists_is_recfun 
   493               [of concl: "r^+" a "\<lambda>x f. H(x, restrict(f, r -`` {x}))"]) 
   494       apply (simp_all add: trans_trancl function_restrictI trancl_subset_times)
   495  apply (clarify, rule_tac x=x in rexI) 
   496  apply (simp_all add: the_recfun_eq trans_trancl trancl_subset_times)
   497 done
   498 
   499 
   500 text{*Assuming @{term r} is transitive simplifies the occurrences of @{text H}.
   501       The premise @{term "relation(r)"} is necessary 
   502       before we can replace @{term "r^+"} by @{term r}. *}
   503 theorem (in M_trancl) trans_wfrec_relativize:
   504   "[|wf(r);  trans(r);  relation(r);  M(r);  M(a);
   505      strong_replacement(M, \<lambda>x z. \<exists>y[M]. 
   506                 pair(M,x,y,z) & (\<exists>g[M]. is_recfun(r,x,H,g) & y = H(x,g))); 
   507      \<forall>x[M]. \<forall>g[M]. function(g) --> M(H(x,g))|] 
   508    ==> wfrec(r,a,H) = z <-> (\<exists>f[M]. is_recfun(r,a,H,f) & z = H(a,f))" 
   509 by (simp cong: is_recfun_cong
   510          add: wfrec_relativize trancl_eq_r
   511                is_recfun_restrict_idem domain_restrict_idem)
   512 
   513 
   514 lemma (in M_trancl) trans_eq_pair_wfrec_iff:
   515   "[|wf(r);  trans(r); relation(r); M(r);  M(y); 
   516      strong_replacement(M, \<lambda>x z. \<exists>y[M]. 
   517                 pair(M,x,y,z) & (\<exists>g[M]. is_recfun(r,x,H,g) & y = H(x,g))); 
   518      \<forall>x[M]. \<forall>g[M]. function(g) --> M(H(x,g))|] 
   519    ==> y = <x, wfrec(r, x, H)> <-> 
   520        (\<exists>f[M]. is_recfun(r,x,H,f) & y = <x, H(x,f)>)"
   521 apply safe 
   522  apply (simp add: trans_wfrec_relativize [THEN iff_sym, of concl: _ x]) 
   523 txt{*converse direction*}
   524 apply (rule sym)
   525 apply (simp add: trans_wfrec_relativize, blast) 
   526 done
   527 
   528 
   529 subsection{*M is closed under well-founded recursion*}
   530 
   531 text{*Lemma with the awkward premise mentioning @{text wfrec}.*}
   532 lemma (in M_wfrank) wfrec_closed_lemma [rule_format]:
   533      "[|wf(r); M(r); 
   534         strong_replacement(M, \<lambda>x y. y = \<langle>x, wfrec(r, x, H)\<rangle>);
   535         \<forall>x[M]. \<forall>g[M]. function(g) --> M(H(x,g)) |] 
   536       ==> M(a) --> M(wfrec(r,a,H))"
   537 apply (rule_tac a=a in wf_induct, assumption+)
   538 apply (subst wfrec, assumption, clarify)
   539 apply (drule_tac x1=x and x="\<lambda>x\<in>r -`` {x}. wfrec(r, x, H)" 
   540        in rspec [THEN rspec]) 
   541 apply (simp_all add: function_lam) 
   542 apply (blast intro: dest: pair_components_in_M ) 
   543 done
   544 
   545 text{*Eliminates one instance of replacement.*}
   546 lemma (in M_wfrank) wfrec_replacement_iff:
   547      "strong_replacement(M, \<lambda>x z. \<exists>y[M]. \<exists>g[M]. 
   548                 pair(M,x,y,z) & is_recfun(r,x,H,g) & y = H(x,g)) <->
   549       strong_replacement(M, 
   550            \<lambda>x y. \<exists>f[M]. is_recfun(r,x,H,f) & y = <x, H(x,f)>)"
   551 apply simp 
   552 apply (rule strong_replacement_cong, blast) 
   553 done
   554 
   555 text{*Useful version for transitive relations*}
   556 theorem (in M_wfrank) trans_wfrec_closed:
   557      "[|wf(r); trans(r); relation(r); M(r); M(a);
   558         strong_replacement(M, 
   559              \<lambda>x z. \<exists>y[M]. \<exists>g[M].
   560                     pair(M,x,y,z) & is_recfun(r,x,H,g) & y = H(x,g)); 
   561         \<forall>x[M]. \<forall>g[M]. function(g) --> M(H(x,g)) |] 
   562       ==> M(wfrec(r,a,H))"
   563 apply (frule wfrec_replacement_iff [THEN iffD1]) 
   564 apply (rule wfrec_closed_lemma, assumption+) 
   565 apply (simp_all add: wfrec_replacement_iff trans_eq_pair_wfrec_iff) 
   566 done
   567 
   568 section{*Absoluteness without assuming transitivity*}
   569 lemma (in M_trancl) eq_pair_wfrec_iff:
   570   "[|wf(r);  M(r);  M(y); 
   571      strong_replacement(M, \<lambda>x z. \<exists>y[M]. \<exists>g[M].
   572           pair(M,x,y,z) & 
   573           is_recfun(r^+, x, \<lambda>x f. H(x, restrict(f, r -`` {x})), g) & 
   574           y = H(x, restrict(g, r -`` {x}))); 
   575      \<forall>x[M]. \<forall>g[M]. function(g) --> M(H(x,g))|] 
   576    ==> y = <x, wfrec(r, x, H)> <-> 
   577        (\<exists>f[M]. is_recfun(r^+, x, \<lambda>x f. H(x, restrict(f, r -`` {x})), f) & 
   578             y = <x, H(x,restrict(f,r-``{x}))>)"
   579 apply safe  
   580  apply (simp add: wfrec_relativize [THEN iff_sym, of concl: _ x]) 
   581 txt{*converse direction*}
   582 apply (rule sym)
   583 apply (simp add: wfrec_relativize, blast) 
   584 done
   585 
   586 lemma (in M_wfrank) wfrec_closed_lemma [rule_format]:
   587      "[|wf(r); M(r); 
   588         strong_replacement(M, \<lambda>x y. y = \<langle>x, wfrec(r, x, H)\<rangle>);
   589         \<forall>x[M]. \<forall>g[M]. function(g) --> M(H(x,g)) |] 
   590       ==> M(a) --> M(wfrec(r,a,H))"
   591 apply (rule_tac a=a in wf_induct, assumption+)
   592 apply (subst wfrec, assumption, clarify)
   593 apply (drule_tac x1=x and x="\<lambda>x\<in>r -`` {x}. wfrec(r, x, H)" 
   594        in rspec [THEN rspec]) 
   595 apply (simp_all add: function_lam) 
   596 apply (blast intro: dest: pair_components_in_M ) 
   597 done
   598 
   599 text{*Full version not assuming transitivity, but maybe not very useful.*}
   600 theorem (in M_wfrank) wfrec_closed:
   601      "[|wf(r); M(r); M(a);
   602      strong_replacement(M, \<lambda>x z. \<exists>y[M]. \<exists>g[M].
   603           pair(M,x,y,z) & 
   604           is_recfun(r^+, x, \<lambda>x f. H(x, restrict(f, r -`` {x})), g) & 
   605           y = H(x, restrict(g, r -`` {x}))); 
   606         \<forall>x[M]. \<forall>g[M]. function(g) --> M(H(x,g)) |] 
   607       ==> M(wfrec(r,a,H))"
   608 apply (frule wfrec_replacement_iff [THEN iffD1]) 
   609 apply (rule wfrec_closed_lemma, assumption+) 
   610 apply (simp_all add: eq_pair_wfrec_iff) 
   611 done
   612 
   613 end