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