src/ZF/Constructible/WF_absolute.thy
author paulson
Wed Jun 26 10:25:36 2002 +0200 (2002-06-26)
changeset 13247 e3c289f0724b
parent 13242 f96bd927dd37
child 13251 74cb2af8811e
permissions -rw-r--r--
towards absoluteness of wfrec-defined functions
     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(s) & 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\<in>nat. \<exists>f \<in> succ(n) -> A.
   139                     (\<exists>x y. p = <x,y> &  f`0 = x & f`n = y) &
   140                           (\<forall>i\<in>n. <f`i, f`succ(i)> \<in> r))"
   141       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)"
   143 
   144 
   145 lemma (in M_trancl) rtran_closure_rtrancl: 
   146      "M(r) ==> rtran_closure(M,r,rtrancl(r))"
   147 apply (simp add: rtran_closure_def rtrancl_alt_eq_rtrancl [symmetric] 
   148                  rtrancl_alt_def field_closed typed_apply_abs apply_closed
   149                  Ord_succ_mem_iff M_nat  nat_0_le [THEN ltD], clarify) 
   150 apply (rule iffI) 
   151  apply clarify 
   152  apply simp 
   153  apply (rename_tac n f) 
   154  apply (rule_tac x=n in bexI) 
   155   apply (rule_tac x=f in exI) 
   156   apply simp
   157   apply (blast dest: finite_fun_closed dest: transM)
   158  apply assumption
   159 apply clarify
   160 apply (simp add: nat_0_le [THEN ltD] apply_funtype, blast)  
   161 done
   162 
   163 lemma (in M_trancl) rtrancl_closed [intro,simp]: 
   164      "M(r) ==> M(rtrancl(r))"
   165 apply (insert rtrancl_separation [of r "field(r)"]) 
   166 apply (simp add: rtrancl_alt_eq_rtrancl [symmetric] 
   167                  rtrancl_alt_def field_closed typed_apply_abs apply_closed
   168                  Ord_succ_mem_iff M_nat
   169                  nat_0_le [THEN ltD] leI [THEN ltD] ltI apply_funtype)
   170 done
   171 
   172 lemma (in M_trancl) rtrancl_abs [simp]: 
   173      "[| M(r); M(z) |] ==> rtran_closure(M,r,z) <-> z = rtrancl(r)"
   174 apply (rule iffI)
   175  txt{*Proving the right-to-left implication*}
   176  prefer 2 apply (blast intro: rtran_closure_rtrancl) 
   177 apply (rule M_equalityI)
   178 apply (simp add: rtran_closure_def rtrancl_alt_eq_rtrancl [symmetric] 
   179                  rtrancl_alt_def field_closed typed_apply_abs apply_closed
   180                  Ord_succ_mem_iff M_nat
   181                  nat_0_le [THEN ltD] leI [THEN ltD] ltI apply_funtype) 
   182  prefer 2 apply assumption
   183  prefer 2 apply blast
   184 apply (rule iffI, clarify) 
   185 apply (simp add: nat_0_le [THEN ltD]  apply_funtype, blast, clarify, simp) 
   186  apply (rename_tac n f) 
   187  apply (rule_tac x=n in bexI) 
   188   apply (rule_tac x=f in exI)
   189   apply (blast dest!: finite_fun_closed, assumption)
   190 done
   191 
   192 
   193 lemma (in M_trancl) trancl_closed [intro,simp]: 
   194      "M(r) ==> M(trancl(r))"
   195 by (simp add: trancl_def comp_closed rtrancl_closed) 
   196 
   197 lemma (in M_trancl) trancl_abs [simp]: 
   198      "[| M(r); M(z) |] ==> tran_closure(M,r,z) <-> z = trancl(r)"
   199 by (simp add: tran_closure_def trancl_def) 
   200 
   201 
   202 text{*Alternative proof of @{text wf_on_trancl}; inspiration for the 
   203       relativized version.  Original version is on theory WF.*}
   204 lemma "[| wf[A](r);  r-``A <= A |] ==> wf[A](r^+)"
   205 apply (simp add: wf_on_def wf_def) 
   206 apply (safe intro!: equalityI)
   207 apply (drule_tac x = "{x\<in>A. \<exists>w. \<langle>w,x\<rangle> \<in> r^+ & w \<in> Z}" in spec) 
   208 apply (blast elim: tranclE) 
   209 done
   210 
   211 
   212 lemma (in M_trancl) wellfounded_on_trancl:
   213      "[| wellfounded_on(M,A,r);  r-``A <= A; M(r); M(A) |]
   214       ==> wellfounded_on(M,A,r^+)" 
   215 apply (simp add: wellfounded_on_def) 
   216 apply (safe intro!: equalityI)
   217 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})") 
   219  prefer 2 
   220  apply (simp add: 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) 
   222 apply safe
   223 apply (blast dest: transM, simp) 
   224 apply (rename_tac y w) 
   225 apply (drule_tac x=w in bspec, assumption, clarify)
   226 apply (erule tranclE)
   227   apply (blast dest: transM)   (*transM is needed to prove M(xa)*)
   228  apply blast 
   229 done
   230 
   231 
   232 text{*Relativized to M: Every well-founded relation is a subset of some
   233 inverse image of an ordinal.  Key step is the construction (in M) of a 
   234 rank function.*}
   235 
   236 
   237 (*NEEDS RELATIVIZATION*)
   238 locale M_recursion = M_trancl +
   239   assumes wfrank_separation':
   240      "[| M(r); M(A) |] ==>
   241 	separation
   242 	   (M, \<lambda>x. x \<in> A --> 
   243 		~(\<exists>f. M(f) \<and> is_recfun(r^+, x, %x f. range(f), f)))"
   244  and wfrank_strong_replacement':
   245      "M(r) ==>
   246       strong_replacement(M, \<lambda>x z. \<exists>y f. M(y) & M(f) &
   247 		  pair(M,x,y,z) & is_recfun(r^+, x, %x f. range(f), f) & 
   248 		  y = range(f))"
   249  and Ord_wfrank_separation:
   250      "[| M(r); M(A) |] ==>
   251       separation (M, \<lambda>x. x \<in> A \<longrightarrow>
   252                 \<not> (\<forall>f. M(f) \<longrightarrow>
   253                        is_recfun(r^+, x, \<lambda>x. range, f) \<longrightarrow> Ord(range(f))))"
   254 
   255 constdefs 
   256  wellfoundedrank :: "[i=>o,i,i] => i"
   257     "wellfoundedrank(M,r,A) == 
   258         {p. x\<in>A, \<exists>y f. M(y) & M(f) & 
   259                        p = <x,y> & is_recfun(r^+, x, %x f. range(f), f) & 
   260                        y = range(f)}"
   261 
   262 lemma (in M_recursion) exists_wfrank:
   263     "[| wellfounded(M,r); r \<subseteq> A*A; a\<in>A; M(r); M(A) |]
   264      ==> \<exists>f. M(f) & is_recfun(r^+, a, %x f. range(f), f)"
   265 apply (rule wellfounded_exists_is_recfun [of A]) 
   266 apply (blast intro: wellfounded_on_trancl wellfounded_imp_wellfounded_on)
   267 apply (rule trans_trancl [THEN trans_imp_trans_on], assumption+)
   268 apply (simp_all add: trancl_subset_times) 
   269 done
   270 
   271 lemma (in M_recursion) M_wellfoundedrank:
   272     "[| wellfounded(M,r); r \<subseteq> A*A; M(r); M(A) |] 
   273      ==> M(wellfoundedrank(M,r,A))"
   274 apply (insert wfrank_strong_replacement' [of r]) 
   275 apply (simp add: wellfoundedrank_def) 
   276 apply (rule strong_replacement_closed) 
   277    apply assumption+
   278  apply (rule univalent_is_recfun) 
   279      apply (blast intro: wellfounded_on_trancl wellfounded_imp_wellfounded_on)
   280     apply (rule trans_on_trancl) 
   281    apply (simp add: trancl_subset_times) 
   282   apply blast+
   283 done
   284 
   285 lemma (in M_recursion) Ord_wfrank_range [rule_format]:
   286     "[| wellfounded(M,r); r \<subseteq> A*A; a\<in>A; M(r); M(A) |]
   287      ==> \<forall>f. M(f) --> is_recfun(r^+, a, %x f. range(f), f) --> Ord(range(f))"
   288 apply (subgoal_tac "wellfounded_on(M, A, r^+)") 
   289  prefer 2
   290  apply (blast intro: wellfounded_on_trancl wellfounded_imp_wellfounded_on)
   291 apply (erule wellfounded_on_induct2, assumption+)
   292 apply (simp add: trancl_subset_times) 
   293 apply (blast intro: Ord_wfrank_separation, clarify)
   294 txt{*The reasoning in both cases is that we get @{term y} such that
   295    @{term "\<langle>y, x\<rangle> \<in> r^+"}.  We find that 
   296    @{term "f`y = restrict(f, r^+ -`` {y})"}. *}
   297 apply (rule OrdI [OF _ Ord_is_Transset])
   298  txt{*An ordinal is a transitive set...*}
   299  apply (simp add: Transset_def) 
   300  apply clarify
   301  apply (frule apply_recfun2, assumption) 
   302  apply (force simp add: restrict_iff)
   303 txt{*...of ordinals.  This second case requires the induction hyp.*} 
   304 apply clarify 
   305 apply (rename_tac i y)
   306 apply (frule apply_recfun2, assumption) 
   307 apply (frule is_recfun_imp_in_r, assumption) 
   308 apply (frule is_recfun_restrict) 
   309     (*simp_all won't work*)
   310     apply (simp add: trans_on_trancl trancl_subset_times)+  
   311 apply (drule spec [THEN mp], assumption)
   312 apply (subgoal_tac "M(restrict(f, r^+ -`` {y}))")
   313  apply (drule_tac x="restrict(f, r^+ -`` {y})" in spec) 
   314  apply (simp add: function_apply_equality [OF _ is_recfun_imp_function])
   315 apply (blast dest: pair_components_in_M)
   316 done
   317 
   318 lemma (in M_recursion) Ord_range_wellfoundedrank:
   319     "[| wellfounded(M,r); r \<subseteq> A*A;  M(r); M(A) |] 
   320      ==> Ord (range(wellfoundedrank(M,r,A)))"
   321 apply (subgoal_tac "wellfounded_on(M, A, r^+)") 
   322  prefer 2
   323  apply (blast intro: wellfounded_on_trancl wellfounded_imp_wellfounded_on)
   324 apply (frule trancl_subset_times) 
   325 apply (simp add: wellfoundedrank_def)
   326 apply (rule OrdI [OF _ Ord_is_Transset])
   327  prefer 2
   328  txt{*by our previous result the range consists of ordinals.*} 
   329  apply (blast intro: Ord_wfrank_range) 
   330 txt{*We still must show that the range is a transitive set.*}
   331 apply (simp add: Transset_def, clarify, simp)
   332 apply (rename_tac x i f u)   
   333 apply (frule is_recfun_imp_in_r, assumption) 
   334 apply (subgoal_tac "M(u) & M(i) & M(x)") 
   335  prefer 2 apply (blast dest: transM, clarify) 
   336 apply (rule_tac a=u in rangeI) 
   337 apply (rule ReplaceI) 
   338   apply (rule_tac x=i in exI, simp) 
   339   apply (rule_tac x="restrict(f, r^+ -`` {u})" in exI)
   340   apply (blast intro: is_recfun_restrict trans_on_trancl dest: apply_recfun2)
   341  apply blast
   342 txt{*Unicity requirement of Replacement*} 
   343 apply clarify
   344 apply (frule apply_recfun2, assumption) 
   345 apply (simp add: trans_on_trancl is_recfun_cut)+
   346 done
   347 
   348 lemma (in M_recursion) function_wellfoundedrank:
   349     "[| wellfounded(M,r); r \<subseteq> A*A;  M(r); M(A)|]
   350      ==> function(wellfoundedrank(M,r,A))"
   351 apply (simp add: wellfoundedrank_def function_def, clarify) 
   352 txt{*Uniqueness: repeated below!*}
   353 apply (drule is_recfun_functional, assumption)
   354     apply (blast intro: wellfounded_on_trancl wellfounded_imp_wellfounded_on)
   355     apply (simp_all add: trancl_subset_times 
   356                          trans_trancl [THEN trans_imp_trans_on]) 
   357 apply (blast dest: transM) 
   358 done
   359 
   360 lemma (in M_recursion) domain_wellfoundedrank:
   361     "[| wellfounded(M,r); r \<subseteq> A*A;  M(r); M(A)|]
   362      ==> domain(wellfoundedrank(M,r,A)) = A"
   363 apply (simp add: wellfoundedrank_def function_def) 
   364 apply (rule equalityI, auto)
   365 apply (frule transM, assumption)  
   366 apply (frule exists_wfrank, assumption+, clarify) 
   367 apply (rule domainI) 
   368 apply (rule ReplaceI)
   369 apply (rule_tac x="range(f)" in exI)
   370 apply simp  
   371 apply (rule_tac x=f in exI, blast, assumption)
   372 txt{*Uniqueness (for Replacement): repeated above!*}
   373 apply clarify
   374 apply (drule is_recfun_functional, assumption)
   375     apply (blast intro: wellfounded_on_trancl wellfounded_imp_wellfounded_on)
   376     apply (simp_all add: trancl_subset_times 
   377                          trans_trancl [THEN trans_imp_trans_on]) 
   378 done
   379 
   380 lemma (in M_recursion) wellfoundedrank_type:
   381     "[| wellfounded(M,r); r \<subseteq> A*A;  M(r); M(A)|]
   382      ==> wellfoundedrank(M,r,A) \<in> A -> range(wellfoundedrank(M,r,A))"
   383 apply (frule function_wellfoundedrank, assumption+) 
   384 apply (frule function_imp_Pi) 
   385  apply (simp add: wellfoundedrank_def relation_def) 
   386  apply blast  
   387 apply (simp add: domain_wellfoundedrank)
   388 done
   389 
   390 lemma (in M_recursion) Ord_wellfoundedrank:
   391     "[| wellfounded(M,r); a \<in> A; r \<subseteq> A*A;  M(r); M(A) |] 
   392      ==> Ord(wellfoundedrank(M,r,A) ` a)"
   393 by (blast intro: apply_funtype [OF wellfoundedrank_type]
   394                  Ord_in_Ord [OF Ord_range_wellfoundedrank])
   395 
   396 lemma (in M_recursion) wellfoundedrank_eq:
   397      "[| is_recfun(r^+, a, %x. range, f);
   398          wellfounded(M,r);  a \<in> A; r \<subseteq> A*A;  M(f); M(r); M(A)|] 
   399       ==> wellfoundedrank(M,r,A) ` a = range(f)"
   400 apply (rule apply_equality) 
   401  prefer 2 apply (blast intro: wellfoundedrank_type ) 
   402 apply (simp add: wellfoundedrank_def)
   403 apply (rule ReplaceI)
   404   apply (rule_tac x="range(f)" in exI) 
   405   apply blast 
   406  apply assumption
   407 txt{*Unicity requirement of Replacement*} 
   408 apply clarify
   409 apply (drule is_recfun_functional, assumption)
   410     apply (blast intro: wellfounded_on_trancl wellfounded_imp_wellfounded_on)
   411     apply (simp_all add: trancl_subset_times 
   412                          trans_trancl [THEN trans_imp_trans_on])
   413 apply (blast dest: transM) 
   414 done
   415 
   416 
   417 lemma (in M_recursion) wellfoundedrank_lt:
   418      "[| <a,b> \<in> r;
   419          wellfounded(M,r); r \<subseteq> A*A;  M(r); M(A)|] 
   420       ==> wellfoundedrank(M,r,A) ` a < wellfoundedrank(M,r,A) ` b"
   421 apply (subgoal_tac "wellfounded_on(M, A, r^+)") 
   422  prefer 2
   423  apply (blast intro: wellfounded_on_trancl wellfounded_imp_wellfounded_on)
   424 apply (subgoal_tac "a\<in>A & b\<in>A")
   425  prefer 2 apply blast
   426 apply (simp add: lt_def Ord_wellfoundedrank, clarify)   
   427 apply (frule exists_wfrank [of concl: _ b], assumption+, clarify) 
   428 apply (rename_tac fb)
   429 apply (frule is_recfun_restrict [of concl: _ a])
   430     apply (rule trans_on_trancl, assumption)
   431    apply (simp_all add: r_into_trancl trancl_subset_times) 
   432 txt{*Still the same goal, but with new @{text is_recfun} assumptions.*}
   433 apply (simp add: wellfoundedrank_eq) 
   434 apply (frule_tac a=a in wellfoundedrank_eq, assumption+)
   435    apply (simp_all add: transM [of a])
   436 txt{*We have used equations for wellfoundedrank and now must use some
   437     for  @{text is_recfun}. *}
   438 apply (rule_tac a=a in rangeI) 
   439 apply (simp add: is_recfun_type [THEN apply_iff] vimage_singleton_iff 
   440                  r_into_trancl apply_recfun r_into_trancl)  
   441 done
   442 
   443 
   444 lemma (in M_recursion) wellfounded_imp_subset_rvimage:
   445      "[|wellfounded(M,r); r \<subseteq> A*A; M(r); M(A)|] 
   446       ==> \<exists>i f. Ord(i) & r <= rvimage(A, f, Memrel(i))"
   447 apply (rule_tac x="range(wellfoundedrank(M,r,A))" in exI)
   448 apply (rule_tac x="wellfoundedrank(M,r,A)" in exI)
   449 apply (simp add: Ord_range_wellfoundedrank, clarify) 
   450 apply (frule subsetD, assumption, clarify) 
   451 apply (simp add: rvimage_iff wellfoundedrank_lt [THEN ltD])
   452 apply (blast intro: apply_rangeI wellfoundedrank_type) 
   453 done
   454 
   455 lemma (in M_recursion) wellfounded_imp_wf: 
   456      "[|wellfounded(M,r); relation(r); M(r)|] ==> wf(r)" 
   457 by (blast dest!: relation_field_times_field wellfounded_imp_subset_rvimage
   458           intro: wf_rvimage_Ord [THEN wf_subset])
   459 
   460 lemma (in M_recursion) wellfounded_on_imp_wf_on: 
   461      "[|wellfounded_on(M,A,r); relation(r); M(r); M(A)|] ==> wf[A](r)" 
   462 apply (simp add: wellfounded_on_iff_wellfounded wf_on_def) 
   463 apply (rule wellfounded_imp_wf)
   464 apply (simp_all add: relation_def)  
   465 done
   466 
   467 
   468 theorem (in M_recursion) wf_abs [simp]: 
   469      "[|relation(r); M(r)|] ==> wellfounded(M,r) <-> wf(r)"
   470 by (blast intro: wellfounded_imp_wf wf_imp_relativized) 
   471 
   472 theorem (in M_recursion) wf_on_abs [simp]: 
   473      "[|relation(r); M(r); M(A)|] ==> wellfounded_on(M,A,r) <-> wf[A](r)"
   474 by (blast intro: wellfounded_on_imp_wf_on wf_on_imp_relativized) 
   475 
   476 end