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