src/ZF/Constructible/WF_absolute.thy
author paulson
Wed Oct 09 11:07:13 2002 +0200 (2002-10-09)
changeset 13634 99a593b49b04
parent 13615 449a70d88b38
child 13647 7f6f0ffc45c3
permissions -rw-r--r--
Re-organization of Constructible theories
     1 (*  Title:      ZF/Constructible/WF_absolute.thy
     2     ID:         $Id$
     3     Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
     4 *)
     5 
     6 header {*Absoluteness for Well-Founded Relations and Well-Founded Recursion*}
     7 
     8 theory WF_absolute = WFrec:
     9 
    10 subsection{*Transitive closure without fixedpoints*}
    11 
    12 constdefs
    13   rtrancl_alt :: "[i,i]=>i"
    14     "rtrancl_alt(A,r) ==
    15        {p \<in> A*A. \<exists>n\<in>nat. \<exists>f \<in> succ(n) -> A.
    16                  (\<exists>x y. p = <x,y> &  f`0 = x & f`n = y) &
    17                        (\<forall>i\<in>n. <f`i, f`succ(i)> \<in> r)}"
    18 
    19 lemma alt_rtrancl_lemma1 [rule_format]:
    20     "n \<in> nat
    21      ==> \<forall>f \<in> succ(n) -> field(r).
    22          (\<forall>i\<in>n. \<langle>f`i, f ` succ(i)\<rangle> \<in> r) --> \<langle>f`0, f`n\<rangle> \<in> r^*"
    23 apply (induct_tac n)
    24 apply (simp_all add: apply_funtype rtrancl_refl, clarify)
    25 apply (rename_tac n f)
    26 apply (rule rtrancl_into_rtrancl)
    27  prefer 2 apply assumption
    28 apply (drule_tac x="restrict(f,succ(n))" in bspec)
    29  apply (blast intro: restrict_type2)
    30 apply (simp add: Ord_succ_mem_iff nat_0_le [THEN ltD] leI [THEN ltD] ltI)
    31 done
    32 
    33 lemma rtrancl_alt_subset_rtrancl: "rtrancl_alt(field(r),r) <= r^*"
    34 apply (simp add: rtrancl_alt_def)
    35 apply (blast intro: alt_rtrancl_lemma1)
    36 done
    37 
    38 lemma rtrancl_subset_rtrancl_alt: "r^* <= rtrancl_alt(field(r),r)"
    39 apply (simp add: rtrancl_alt_def, clarify)
    40 apply (frule rtrancl_type [THEN subsetD], clarify, simp)
    41 apply (erule rtrancl_induct)
    42  txt{*Base case, trivial*}
    43  apply (rule_tac x=0 in bexI)
    44   apply (rule_tac x="lam x:1. xa" in bexI)
    45    apply simp_all
    46 txt{*Inductive step*}
    47 apply clarify
    48 apply (rename_tac n f)
    49 apply (rule_tac x="succ(n)" in bexI)
    50  apply (rule_tac x="lam i:succ(succ(n)). if i=succ(n) then z else f`i" in bexI)
    51   apply (simp add: Ord_succ_mem_iff nat_0_le [THEN ltD] leI [THEN ltD] ltI)
    52   apply (blast intro: mem_asym)
    53  apply typecheck
    54  apply auto
    55 done
    56 
    57 lemma rtrancl_alt_eq_rtrancl: "rtrancl_alt(field(r),r) = r^*"
    58 by (blast del: subsetI
    59 	  intro: rtrancl_alt_subset_rtrancl rtrancl_subset_rtrancl_alt)
    60 
    61 
    62 constdefs
    63 
    64   rtran_closure_mem :: "[i=>o,i,i,i] => o"
    65     --{*The property of belonging to @{text "rtran_closure(r)"}*}
    66     "rtran_closure_mem(M,A,r,p) ==
    67 	      \<exists>nnat[M]. \<exists>n[M]. \<exists>n'[M]. 
    68                omega(M,nnat) & n\<in>nnat & successor(M,n,n') &
    69 	       (\<exists>f[M]. typed_function(M,n',A,f) &
    70 		(\<exists>x[M]. \<exists>y[M]. \<exists>zero[M]. pair(M,x,y,p) & empty(M,zero) &
    71 		  fun_apply(M,f,zero,x) & fun_apply(M,f,n,y)) &
    72 		  (\<forall>j[M]. j\<in>n --> 
    73 		    (\<exists>fj[M]. \<exists>sj[M]. \<exists>fsj[M]. \<exists>ffp[M]. 
    74 		      fun_apply(M,f,j,fj) & successor(M,j,sj) &
    75 		      fun_apply(M,f,sj,fsj) & pair(M,fj,fsj,ffp) & ffp \<in> r)))"
    76 
    77   rtran_closure :: "[i=>o,i,i] => o"
    78     "rtran_closure(M,r,s) == 
    79         \<forall>A[M]. is_field(M,r,A) -->
    80  	 (\<forall>p[M]. p \<in> s <-> rtran_closure_mem(M,A,r,p))"
    81 
    82   tran_closure :: "[i=>o,i,i] => o"
    83     "tran_closure(M,r,t) ==
    84          \<exists>s[M]. rtran_closure(M,r,s) & composition(M,r,s,t)"
    85 
    86 lemma (in M_basic) rtran_closure_mem_iff:
    87      "[|M(A); M(r); M(p)|]
    88       ==> rtran_closure_mem(M,A,r,p) <->
    89           (\<exists>n[M]. n\<in>nat & 
    90            (\<exists>f[M]. f \<in> succ(n) -> A &
    91             (\<exists>x[M]. \<exists>y[M]. p = <x,y> & f`0 = x & f`n = y) &
    92                            (\<forall>i\<in>n. <f`i, f`succ(i)> \<in> r)))"
    93 by (simp add: rtran_closure_mem_def Ord_succ_mem_iff nat_0_le [THEN ltD]) 
    94 
    95 
    96 locale M_trancl = M_basic +
    97   assumes rtrancl_separation:
    98 	 "[| M(r); M(A) |] ==> separation (M, rtran_closure_mem(M,A,r))"
    99       and wellfounded_trancl_separation:
   100 	 "[| M(r); M(Z) |] ==> 
   101 	  separation (M, \<lambda>x. 
   102 	      \<exists>w[M]. \<exists>wx[M]. \<exists>rp[M]. 
   103 	       w \<in> Z & pair(M,w,x,wx) & tran_closure(M,r,rp) & wx \<in> rp)"
   104 
   105 
   106 lemma (in M_trancl) rtran_closure_rtrancl:
   107      "M(r) ==> rtran_closure(M,r,rtrancl(r))"
   108 apply (simp add: rtran_closure_def rtran_closure_mem_iff 
   109                  rtrancl_alt_eq_rtrancl [symmetric] rtrancl_alt_def)
   110 apply (auto simp add: nat_0_le [THEN ltD] apply_funtype) 
   111 done
   112 
   113 lemma (in M_trancl) rtrancl_closed [intro,simp]:
   114      "M(r) ==> M(rtrancl(r))"
   115 apply (insert rtrancl_separation [of r "field(r)"])
   116 apply (simp add: rtrancl_alt_eq_rtrancl [symmetric]
   117                  rtrancl_alt_def rtran_closure_mem_iff)
   118 done
   119 
   120 lemma (in M_trancl) rtrancl_abs [simp]:
   121      "[| M(r); M(z) |] ==> rtran_closure(M,r,z) <-> z = rtrancl(r)"
   122 apply (rule iffI)
   123  txt{*Proving the right-to-left implication*}
   124  prefer 2 apply (blast intro: rtran_closure_rtrancl)
   125 apply (rule M_equalityI)
   126 apply (simp add: rtran_closure_def rtrancl_alt_eq_rtrancl [symmetric]
   127                  rtrancl_alt_def rtran_closure_mem_iff)
   128 apply (auto simp add: nat_0_le [THEN ltD] apply_funtype) 
   129 done
   130 
   131 lemma (in M_trancl) trancl_closed [intro,simp]:
   132      "M(r) ==> M(trancl(r))"
   133 by (simp add: trancl_def comp_closed rtrancl_closed)
   134 
   135 lemma (in M_trancl) trancl_abs [simp]:
   136      "[| M(r); M(z) |] ==> tran_closure(M,r,z) <-> z = trancl(r)"
   137 by (simp add: tran_closure_def trancl_def)
   138 
   139 lemma (in M_trancl) wellfounded_trancl_separation':
   140      "[| M(r); M(Z) |] ==> separation (M, \<lambda>x. \<exists>w[M]. w \<in> Z & <w,x> \<in> r^+)"
   141 by (insert wellfounded_trancl_separation [of r Z], simp) 
   142 
   143 text{*Alternative proof of @{text wf_on_trancl}; inspiration for the
   144       relativized version.  Original version is on theory WF.*}
   145 lemma "[| wf[A](r);  r-``A <= A |] ==> wf[A](r^+)"
   146 apply (simp add: wf_on_def wf_def)
   147 apply (safe intro!: equalityI)
   148 apply (drule_tac x = "{x\<in>A. \<exists>w. \<langle>w,x\<rangle> \<in> r^+ & w \<in> Z}" in spec)
   149 apply (blast elim: tranclE)
   150 done
   151 
   152 lemma (in M_trancl) wellfounded_on_trancl:
   153      "[| wellfounded_on(M,A,r);  r-``A <= A; M(r); M(A) |]
   154       ==> wellfounded_on(M,A,r^+)"
   155 apply (simp add: wellfounded_on_def)
   156 apply (safe intro!: equalityI)
   157 apply (rename_tac Z x)
   158 apply (subgoal_tac "M({x\<in>A. \<exists>w[M]. w \<in> Z & \<langle>w,x\<rangle> \<in> r^+})")
   159  prefer 2
   160  apply (blast intro: wellfounded_trancl_separation') 
   161 apply (drule_tac x = "{x\<in>A. \<exists>w[M]. w \<in> Z & \<langle>w,x\<rangle> \<in> r^+}" in rspec, safe)
   162 apply (blast dest: transM, simp)
   163 apply (rename_tac y w)
   164 apply (drule_tac x=w in bspec, assumption, clarify)
   165 apply (erule tranclE)
   166   apply (blast dest: transM)   (*transM is needed to prove M(xa)*)
   167  apply blast
   168 done
   169 
   170 lemma (in M_trancl) wellfounded_trancl:
   171      "[|wellfounded(M,r); M(r)|] ==> wellfounded(M,r^+)"
   172 apply (simp add: wellfounded_iff_wellfounded_on_field)
   173 apply (rule wellfounded_on_subset_A, erule wellfounded_on_trancl)
   174    apply blast
   175   apply (simp_all add: trancl_type [THEN field_rel_subset])
   176 done
   177 
   178 text{*Relativized to M: Every well-founded relation is a subset of some
   179 inverse image of an ordinal.  Key step is the construction (in M) of a
   180 rank function.*}
   181 
   182 
   183 
   184 text{*absoluteness for wfrec-defined functions.*}
   185 
   186 (*first use is_recfun, then M_is_recfun*)
   187 
   188 lemma (in M_trancl) wfrec_relativize:
   189   "[|wf(r); M(a); M(r);  
   190      strong_replacement(M, \<lambda>x z. \<exists>y[M]. \<exists>g[M].
   191           pair(M,x,y,z) & 
   192           is_recfun(r^+, x, \<lambda>x f. H(x, restrict(f, r -`` {x})), g) & 
   193           y = H(x, restrict(g, r -`` {x}))); 
   194      \<forall>x[M]. \<forall>g[M]. function(g) --> M(H(x,g))|] 
   195    ==> wfrec(r,a,H) = z <-> 
   196        (\<exists>f[M]. is_recfun(r^+, a, \<lambda>x f. H(x, restrict(f, r -`` {x})), f) & 
   197             z = H(a,restrict(f,r-``{a})))"
   198 apply (frule wf_trancl) 
   199 apply (simp add: wftrec_def wfrec_def, safe)
   200  apply (frule wf_exists_is_recfun 
   201               [of concl: "r^+" a "\<lambda>x f. H(x, restrict(f, r -`` {x}))"]) 
   202       apply (simp_all add: trans_trancl function_restrictI trancl_subset_times)
   203  apply (clarify, rule_tac x=x in rexI) 
   204  apply (simp_all add: the_recfun_eq trans_trancl trancl_subset_times)
   205 done
   206 
   207 
   208 text{*Assuming @{term r} is transitive simplifies the occurrences of @{text H}.
   209       The premise @{term "relation(r)"} is necessary 
   210       before we can replace @{term "r^+"} by @{term r}. *}
   211 theorem (in M_trancl) trans_wfrec_relativize:
   212   "[|wf(r);  trans(r);  relation(r);  M(r);  M(a);
   213      wfrec_replacement(M,MH,r);  relation2(M,MH,H);
   214      \<forall>x[M]. \<forall>g[M]. function(g) --> M(H(x,g))|] 
   215    ==> wfrec(r,a,H) = z <-> (\<exists>f[M]. is_recfun(r,a,H,f) & z = H(a,f))" 
   216 apply (frule wfrec_replacement', assumption+) 
   217 apply (simp cong: is_recfun_cong
   218            add: wfrec_relativize trancl_eq_r
   219                 is_recfun_restrict_idem domain_restrict_idem)
   220 done
   221 
   222 theorem (in M_trancl) trans_wfrec_abs:
   223   "[|wf(r);  trans(r);  relation(r);  M(r);  M(a);  M(z);
   224      wfrec_replacement(M,MH,r);  relation2(M,MH,H);
   225      \<forall>x[M]. \<forall>g[M]. function(g) --> M(H(x,g))|] 
   226    ==> is_wfrec(M,MH,r,a,z) <-> z=wfrec(r,a,H)" 
   227 by (simp add: trans_wfrec_relativize [THEN iff_sym] is_wfrec_abs, blast) 
   228 
   229 
   230 lemma (in M_trancl) trans_eq_pair_wfrec_iff:
   231   "[|wf(r);  trans(r); relation(r); M(r);  M(y); 
   232      wfrec_replacement(M,MH,r);  relation2(M,MH,H);
   233      \<forall>x[M]. \<forall>g[M]. function(g) --> M(H(x,g))|] 
   234    ==> y = <x, wfrec(r, x, H)> <-> 
   235        (\<exists>f[M]. is_recfun(r,x,H,f) & y = <x, H(x,f)>)"
   236 apply safe 
   237  apply (simp add: trans_wfrec_relativize [THEN iff_sym, of concl: _ x]) 
   238 txt{*converse direction*}
   239 apply (rule sym)
   240 apply (simp add: trans_wfrec_relativize, blast) 
   241 done
   242 
   243 
   244 subsection{*M is closed under well-founded recursion*}
   245 
   246 text{*Lemma with the awkward premise mentioning @{text wfrec}.*}
   247 lemma (in M_trancl) wfrec_closed_lemma [rule_format]:
   248      "[|wf(r); M(r); 
   249         strong_replacement(M, \<lambda>x y. y = \<langle>x, wfrec(r, x, H)\<rangle>);
   250         \<forall>x[M]. \<forall>g[M]. function(g) --> M(H(x,g)) |] 
   251       ==> M(a) --> M(wfrec(r,a,H))"
   252 apply (rule_tac a=a in wf_induct, assumption+)
   253 apply (subst wfrec, assumption, clarify)
   254 apply (drule_tac x1=x and x="\<lambda>x\<in>r -`` {x}. wfrec(r, x, H)" 
   255        in rspec [THEN rspec]) 
   256 apply (simp_all add: function_lam) 
   257 apply (blast intro: lam_closed dest: pair_components_in_M) 
   258 done
   259 
   260 text{*Eliminates one instance of replacement.*}
   261 lemma (in M_trancl) wfrec_replacement_iff:
   262      "strong_replacement(M, \<lambda>x z. 
   263           \<exists>y[M]. pair(M,x,y,z) & (\<exists>g[M]. is_recfun(r,x,H,g) & y = H(x,g))) <->
   264       strong_replacement(M, 
   265            \<lambda>x y. \<exists>f[M]. is_recfun(r,x,H,f) & y = <x, H(x,f)>)"
   266 apply simp 
   267 apply (rule strong_replacement_cong, blast) 
   268 done
   269 
   270 text{*Useful version for transitive relations*}
   271 theorem (in M_trancl) trans_wfrec_closed:
   272      "[|wf(r); trans(r); relation(r); M(r); M(a);
   273        wfrec_replacement(M,MH,r);  relation2(M,MH,H);
   274         \<forall>x[M]. \<forall>g[M]. function(g) --> M(H(x,g)) |] 
   275       ==> M(wfrec(r,a,H))"
   276 apply (frule wfrec_replacement', assumption+) 
   277 apply (frule wfrec_replacement_iff [THEN iffD1]) 
   278 apply (rule wfrec_closed_lemma, assumption+) 
   279 apply (simp_all add: wfrec_replacement_iff trans_eq_pair_wfrec_iff) 
   280 done
   281 
   282 subsection{*Absoluteness without assuming transitivity*}
   283 lemma (in M_trancl) eq_pair_wfrec_iff:
   284   "[|wf(r);  M(r);  M(y); 
   285      strong_replacement(M, \<lambda>x z. \<exists>y[M]. \<exists>g[M].
   286           pair(M,x,y,z) & 
   287           is_recfun(r^+, x, \<lambda>x f. H(x, restrict(f, r -`` {x})), g) & 
   288           y = H(x, restrict(g, r -`` {x}))); 
   289      \<forall>x[M]. \<forall>g[M]. function(g) --> M(H(x,g))|] 
   290    ==> y = <x, wfrec(r, x, H)> <-> 
   291        (\<exists>f[M]. is_recfun(r^+, x, \<lambda>x f. H(x, restrict(f, r -`` {x})), f) & 
   292             y = <x, H(x,restrict(f,r-``{x}))>)"
   293 apply safe  
   294  apply (simp add: wfrec_relativize [THEN iff_sym, of concl: _ x]) 
   295 txt{*converse direction*}
   296 apply (rule sym)
   297 apply (simp add: wfrec_relativize, blast) 
   298 done
   299 
   300 text{*Full version not assuming transitivity, but maybe not very useful.*}
   301 theorem (in M_trancl) wfrec_closed:
   302      "[|wf(r); M(r); M(a);
   303         wfrec_replacement(M,MH,r^+);  
   304         relation2(M,MH, \<lambda>x f. H(x, restrict(f, r -`` {x})));
   305         \<forall>x[M]. \<forall>g[M]. function(g) --> M(H(x,g)) |] 
   306       ==> M(wfrec(r,a,H))"
   307 apply (frule wfrec_replacement' 
   308                [of MH "r^+" "\<lambda>x f. H(x, restrict(f, r -`` {x}))"])
   309    prefer 4
   310    apply (frule wfrec_replacement_iff [THEN iffD1]) 
   311    apply (rule wfrec_closed_lemma, assumption+) 
   312      apply (simp_all add: eq_pair_wfrec_iff func.function_restrictI) 
   313 done
   314 
   315 end