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
paulson@13242
     1
theory WF_absolute = WFrec:
paulson@13223
     2
paulson@13247
     3
subsection{*Every well-founded relation is a subset of some inverse image of 
paulson@13247
     4
      an ordinal*}
paulson@13247
     5
paulson@13247
     6
lemma wf_rvimage_Ord: "Ord(i) \<Longrightarrow> wf(rvimage(A, f, Memrel(i)))"
paulson@13247
     7
by (blast intro: wf_rvimage wf_Memrel )
paulson@13247
     8
paulson@13247
     9
paulson@13247
    10
constdefs
paulson@13247
    11
  wfrank :: "[i,i]=>i"
paulson@13247
    12
    "wfrank(r,a) == wfrec(r, a, %x f. \<Union>y \<in> r-``{x}. succ(f`y))"
paulson@13247
    13
paulson@13247
    14
constdefs
paulson@13247
    15
  wftype :: "i=>i"
paulson@13247
    16
    "wftype(r) == \<Union>y \<in> range(r). succ(wfrank(r,y))"
paulson@13247
    17
paulson@13247
    18
lemma wfrank: "wf(r) ==> wfrank(r,a) = (\<Union>y \<in> r-``{a}. succ(wfrank(r,y)))"
paulson@13247
    19
by (subst wfrank_def [THEN def_wfrec], simp_all)
paulson@13247
    20
paulson@13247
    21
lemma Ord_wfrank: "wf(r) ==> Ord(wfrank(r,a))"
paulson@13247
    22
apply (rule_tac a="a" in wf_induct, assumption)
paulson@13247
    23
apply (subst wfrank, assumption)
paulson@13247
    24
apply (rule Ord_succ [THEN Ord_UN], blast) 
paulson@13247
    25
done
paulson@13247
    26
paulson@13247
    27
lemma wfrank_lt: "[|wf(r); <a,b> \<in> r|] ==> wfrank(r,a) < wfrank(r,b)"
paulson@13247
    28
apply (rule_tac a1 = "b" in wfrank [THEN ssubst], assumption)
paulson@13247
    29
apply (rule UN_I [THEN ltI])
paulson@13247
    30
apply (simp add: Ord_wfrank vimage_iff)+
paulson@13247
    31
done
paulson@13247
    32
paulson@13247
    33
lemma Ord_wftype: "wf(r) ==> Ord(wftype(r))"
paulson@13247
    34
by (simp add: wftype_def Ord_wfrank)
paulson@13247
    35
paulson@13247
    36
lemma wftypeI: "\<lbrakk>wf(r);  x \<in> field(r)\<rbrakk> \<Longrightarrow> wfrank(r,x) \<in> wftype(r)"
paulson@13247
    37
apply (simp add: wftype_def) 
paulson@13247
    38
apply (blast intro: wfrank_lt [THEN ltD]) 
paulson@13247
    39
done
paulson@13247
    40
paulson@13247
    41
paulson@13247
    42
lemma wf_imp_subset_rvimage:
paulson@13247
    43
     "[|wf(r); r \<subseteq> A*A|] ==> \<exists>i f. Ord(i) & r <= rvimage(A, f, Memrel(i))"
paulson@13247
    44
apply (rule_tac x="wftype(r)" in exI) 
paulson@13247
    45
apply (rule_tac x="\<lambda>x\<in>A. wfrank(r,x)" in exI) 
paulson@13247
    46
apply (simp add: Ord_wftype, clarify) 
paulson@13247
    47
apply (frule subsetD, assumption, clarify) 
paulson@13247
    48
apply (simp add: rvimage_iff wfrank_lt [THEN ltD])
paulson@13247
    49
apply (blast intro: wftypeI  ) 
paulson@13247
    50
done
paulson@13247
    51
paulson@13247
    52
theorem wf_iff_subset_rvimage:
paulson@13247
    53
  "relation(r) ==> wf(r) <-> (\<exists>i f A. Ord(i) & r <= rvimage(A, f, Memrel(i)))"
paulson@13247
    54
by (blast dest!: relation_field_times_field wf_imp_subset_rvimage
paulson@13247
    55
          intro: wf_rvimage_Ord [THEN wf_subset])
paulson@13247
    56
paulson@13247
    57
paulson@13223
    58
subsection{*Transitive closure without fixedpoints*}
paulson@13223
    59
paulson@13223
    60
constdefs
paulson@13223
    61
  rtrancl_alt :: "[i,i]=>i"
paulson@13223
    62
    "rtrancl_alt(A,r) == 
paulson@13223
    63
       {p \<in> A*A. \<exists>n\<in>nat. \<exists>f \<in> succ(n) -> A.
paulson@13242
    64
                 (\<exists>x y. p = <x,y> &  f`0 = x & f`n = y) &
paulson@13223
    65
                       (\<forall>i\<in>n. <f`i, f`succ(i)> \<in> r)}"
paulson@13223
    66
paulson@13223
    67
lemma alt_rtrancl_lemma1 [rule_format]: 
paulson@13223
    68
    "n \<in> nat
paulson@13223
    69
     ==> \<forall>f \<in> succ(n) -> field(r). 
paulson@13223
    70
         (\<forall>i\<in>n. \<langle>f`i, f ` succ(i)\<rangle> \<in> r) --> \<langle>f`0, f`n\<rangle> \<in> r^*"
paulson@13223
    71
apply (induct_tac n) 
paulson@13223
    72
apply (simp_all add: apply_funtype rtrancl_refl, clarify) 
paulson@13223
    73
apply (rename_tac n f) 
paulson@13223
    74
apply (rule rtrancl_into_rtrancl) 
paulson@13223
    75
 prefer 2 apply assumption
paulson@13223
    76
apply (drule_tac x="restrict(f,succ(n))" in bspec)
paulson@13223
    77
 apply (blast intro: restrict_type2) 
paulson@13223
    78
apply (simp add: Ord_succ_mem_iff nat_0_le [THEN ltD] leI [THEN ltD] ltI) 
paulson@13223
    79
done
paulson@13223
    80
paulson@13223
    81
lemma rtrancl_alt_subset_rtrancl: "rtrancl_alt(field(r),r) <= r^*"
paulson@13223
    82
apply (simp add: rtrancl_alt_def)
paulson@13223
    83
apply (blast intro: alt_rtrancl_lemma1 )  
paulson@13223
    84
done
paulson@13223
    85
paulson@13223
    86
lemma rtrancl_subset_rtrancl_alt: "r^* <= rtrancl_alt(field(r),r)"
paulson@13223
    87
apply (simp add: rtrancl_alt_def, clarify) 
paulson@13242
    88
apply (frule rtrancl_type [THEN subsetD], clarify, simp) 
paulson@13223
    89
apply (erule rtrancl_induct) 
paulson@13223
    90
 txt{*Base case, trivial*}
paulson@13223
    91
 apply (rule_tac x=0 in bexI) 
paulson@13223
    92
  apply (rule_tac x="lam x:1. xa" in bexI) 
paulson@13223
    93
   apply simp_all 
paulson@13223
    94
txt{*Inductive step*}
paulson@13223
    95
apply clarify 
paulson@13223
    96
apply (rename_tac n f) 
paulson@13223
    97
apply (rule_tac x="succ(n)" in bexI) 
paulson@13223
    98
 apply (rule_tac x="lam i:succ(succ(n)). if i=succ(n) then z else f`i" in bexI)
paulson@13223
    99
  apply (simp add: Ord_succ_mem_iff nat_0_le [THEN ltD] leI [THEN ltD] ltI) 
paulson@13223
   100
  apply (blast intro: mem_asym)  
paulson@13223
   101
 apply typecheck 
paulson@13223
   102
 apply auto 
paulson@13223
   103
done
paulson@13223
   104
paulson@13223
   105
lemma rtrancl_alt_eq_rtrancl: "rtrancl_alt(field(r),r) = r^*"
paulson@13223
   106
by (blast del: subsetI
paulson@13223
   107
	  intro: rtrancl_alt_subset_rtrancl rtrancl_subset_rtrancl_alt) 
paulson@13223
   108
paulson@13223
   109
paulson@13242
   110
constdefs
paulson@13242
   111
paulson@13242
   112
  rtran_closure :: "[i=>o,i,i] => o"
paulson@13242
   113
    "rtran_closure(M,r,s) == 
paulson@13242
   114
        \<forall>A. M(A) --> is_field(M,r,A) -->
paulson@13242
   115
 	 (\<forall>p. M(p) --> 
paulson@13242
   116
          (p \<in> s <-> 
paulson@13242
   117
           (\<exists>n\<in>nat. M(n) & 
paulson@13242
   118
            (\<exists>n'. M(n') & successor(M,n,n') &
paulson@13242
   119
             (\<exists>f. M(f) & typed_function(M,n',A,f) &
paulson@13242
   120
              (\<exists>x\<in>A. M(x) & (\<exists>y\<in>A. M(y) & pair(M,x,y,p) &  
paulson@13242
   121
                   fun_apply(M,f,0,x) & fun_apply(M,f,n,y))) &
paulson@13242
   122
              (\<forall>i\<in>n. M(i) -->
paulson@13242
   123
                (\<forall>i'. M(i') --> successor(M,i,i') -->
paulson@13242
   124
                 (\<forall>fi. M(fi) --> fun_apply(M,f,i,fi) -->
paulson@13242
   125
                  (\<forall>fi'. M(fi') --> fun_apply(M,f,i',fi') -->
paulson@13242
   126
                   (\<forall>q. M(q) --> pair(M,fi,fi',q) --> q \<in> r))))))))))"
paulson@13242
   127
paulson@13242
   128
  tran_closure :: "[i=>o,i,i] => o"
paulson@13242
   129
    "tran_closure(M,r,t) == 
paulson@13242
   130
         \<exists>s. M(s) & rtran_closure(M,r,s) & composition(M,r,s,t)"
paulson@13242
   131
paulson@13242
   132
paulson@13242
   133
locale M_trancl = M_axioms +
paulson@13242
   134
(*THEY NEED RELATIVIZATION*)
paulson@13242
   135
  assumes rtrancl_separation:
paulson@13242
   136
     "[| M(r); M(A) |] ==>
paulson@13242
   137
	separation
paulson@13242
   138
	   (M, \<lambda>p. \<exists>n\<in>nat. \<exists>f \<in> succ(n) -> A.
paulson@13242
   139
                    (\<exists>x y. p = <x,y> &  f`0 = x & f`n = y) &
paulson@13242
   140
                          (\<forall>i\<in>n. <f`i, f`succ(i)> \<in> r))"
paulson@13242
   141
      and wellfounded_trancl_separation:
paulson@13242
   142
     "[| M(r); M(Z) |] ==> separation (M, \<lambda>x. \<exists>w. M(w) & \<langle>w,x\<rangle> \<in> r^+ & w \<in> Z)"
paulson@13242
   143
paulson@13242
   144
paulson@13242
   145
lemma (in M_trancl) rtran_closure_rtrancl: 
paulson@13242
   146
     "M(r) ==> rtran_closure(M,r,rtrancl(r))"
paulson@13242
   147
apply (simp add: rtran_closure_def rtrancl_alt_eq_rtrancl [symmetric] 
paulson@13242
   148
                 rtrancl_alt_def field_closed typed_apply_abs apply_closed
paulson@13242
   149
                 Ord_succ_mem_iff M_nat  nat_0_le [THEN ltD], clarify) 
paulson@13242
   150
apply (rule iffI) 
paulson@13242
   151
 apply clarify 
paulson@13242
   152
 apply simp 
paulson@13242
   153
 apply (rename_tac n f) 
paulson@13242
   154
 apply (rule_tac x=n in bexI) 
paulson@13242
   155
  apply (rule_tac x=f in exI) 
paulson@13242
   156
  apply simp
paulson@13242
   157
  apply (blast dest: finite_fun_closed dest: transM)
paulson@13242
   158
 apply assumption
paulson@13242
   159
apply clarify
paulson@13242
   160
apply (simp add: nat_0_le [THEN ltD] apply_funtype, blast)  
paulson@13242
   161
done
paulson@13242
   162
paulson@13242
   163
lemma (in M_trancl) rtrancl_closed [intro,simp]: 
paulson@13242
   164
     "M(r) ==> M(rtrancl(r))"
paulson@13242
   165
apply (insert rtrancl_separation [of r "field(r)"]) 
paulson@13242
   166
apply (simp add: rtrancl_alt_eq_rtrancl [symmetric] 
paulson@13242
   167
                 rtrancl_alt_def field_closed typed_apply_abs apply_closed
paulson@13242
   168
                 Ord_succ_mem_iff M_nat
paulson@13242
   169
                 nat_0_le [THEN ltD] leI [THEN ltD] ltI apply_funtype)
paulson@13242
   170
done
paulson@13242
   171
paulson@13242
   172
lemma (in M_trancl) rtrancl_abs [simp]: 
paulson@13242
   173
     "[| M(r); M(z) |] ==> rtran_closure(M,r,z) <-> z = rtrancl(r)"
paulson@13242
   174
apply (rule iffI)
paulson@13242
   175
 txt{*Proving the right-to-left implication*}
paulson@13242
   176
 prefer 2 apply (blast intro: rtran_closure_rtrancl) 
paulson@13242
   177
apply (rule M_equalityI)
paulson@13242
   178
apply (simp add: rtran_closure_def rtrancl_alt_eq_rtrancl [symmetric] 
paulson@13242
   179
                 rtrancl_alt_def field_closed typed_apply_abs apply_closed
paulson@13242
   180
                 Ord_succ_mem_iff M_nat
paulson@13242
   181
                 nat_0_le [THEN ltD] leI [THEN ltD] ltI apply_funtype) 
paulson@13242
   182
 prefer 2 apply assumption
paulson@13242
   183
 prefer 2 apply blast
paulson@13242
   184
apply (rule iffI, clarify) 
paulson@13247
   185
apply (simp add: nat_0_le [THEN ltD]  apply_funtype, blast, clarify, simp) 
paulson@13242
   186
 apply (rename_tac n f) 
paulson@13242
   187
 apply (rule_tac x=n in bexI) 
paulson@13242
   188
  apply (rule_tac x=f in exI)
paulson@13242
   189
  apply (blast dest!: finite_fun_closed, assumption)
paulson@13242
   190
done
paulson@13242
   191
paulson@13242
   192
paulson@13242
   193
lemma (in M_trancl) trancl_closed [intro,simp]: 
paulson@13242
   194
     "M(r) ==> M(trancl(r))"
paulson@13242
   195
by (simp add: trancl_def comp_closed rtrancl_closed) 
paulson@13242
   196
paulson@13242
   197
lemma (in M_trancl) trancl_abs [simp]: 
paulson@13242
   198
     "[| M(r); M(z) |] ==> tran_closure(M,r,z) <-> z = trancl(r)"
paulson@13242
   199
by (simp add: tran_closure_def trancl_def) 
paulson@13242
   200
paulson@13242
   201
paulson@13242
   202
text{*Alternative proof of @{text wf_on_trancl}; inspiration for the 
paulson@13242
   203
      relativized version.  Original version is on theory WF.*}
paulson@13242
   204
lemma "[| wf[A](r);  r-``A <= A |] ==> wf[A](r^+)"
paulson@13242
   205
apply (simp add: wf_on_def wf_def) 
paulson@13242
   206
apply (safe intro!: equalityI)
paulson@13242
   207
apply (drule_tac x = "{x\<in>A. \<exists>w. \<langle>w,x\<rangle> \<in> r^+ & w \<in> Z}" in spec) 
paulson@13242
   208
apply (blast elim: tranclE) 
paulson@13242
   209
done
paulson@13242
   210
paulson@13242
   211
paulson@13242
   212
lemma (in M_trancl) wellfounded_on_trancl:
paulson@13242
   213
     "[| wellfounded_on(M,A,r);  r-``A <= A; M(r); M(A) |]
paulson@13242
   214
      ==> wellfounded_on(M,A,r^+)" 
paulson@13242
   215
apply (simp add: wellfounded_on_def) 
paulson@13242
   216
apply (safe intro!: equalityI)
paulson@13242
   217
apply (rename_tac Z x)
paulson@13242
   218
apply (subgoal_tac "M({x\<in>A. \<exists>w. M(w) & \<langle>w,x\<rangle> \<in> r^+ & w \<in> Z})") 
paulson@13242
   219
 prefer 2 
paulson@13242
   220
 apply (simp add: wellfounded_trancl_separation) 
paulson@13242
   221
apply (drule_tac x = "{x\<in>A. \<exists>w. M(w) & \<langle>w,x\<rangle> \<in> r^+ & w \<in> Z}" in spec) 
paulson@13242
   222
apply safe
paulson@13242
   223
apply (blast dest: transM, simp) 
paulson@13242
   224
apply (rename_tac y w) 
paulson@13242
   225
apply (drule_tac x=w in bspec, assumption, clarify)
paulson@13242
   226
apply (erule tranclE)
paulson@13242
   227
  apply (blast dest: transM)   (*transM is needed to prove M(xa)*)
paulson@13242
   228
 apply blast 
paulson@13242
   229
done
paulson@13242
   230
paulson@13242
   231
paulson@13223
   232
text{*Relativized to M: Every well-founded relation is a subset of some
paulson@13223
   233
inverse image of an ordinal.  Key step is the construction (in M) of a 
paulson@13223
   234
rank function.*}
paulson@13223
   235
paulson@13223
   236
paulson@13223
   237
(*NEEDS RELATIVIZATION*)
paulson@13242
   238
locale M_recursion = M_trancl +
paulson@13223
   239
  assumes wfrank_separation':
paulson@13242
   240
     "[| M(r); M(A) |] ==>
paulson@13223
   241
	separation
paulson@13223
   242
	   (M, \<lambda>x. x \<in> A --> 
paulson@13242
   243
		~(\<exists>f. M(f) \<and> is_recfun(r^+, x, %x f. range(f), f)))"
paulson@13223
   244
 and wfrank_strong_replacement':
paulson@13242
   245
     "M(r) ==>
paulson@13242
   246
      strong_replacement(M, \<lambda>x z. \<exists>y f. M(y) & M(f) &
paulson@13242
   247
		  pair(M,x,y,z) & is_recfun(r^+, x, %x f. range(f), f) & 
paulson@13242
   248
		  y = range(f))"
paulson@13242
   249
 and Ord_wfrank_separation:
paulson@13242
   250
     "[| M(r); M(A) |] ==>
paulson@13242
   251
      separation (M, \<lambda>x. x \<in> A \<longrightarrow>
paulson@13242
   252
                \<not> (\<forall>f. M(f) \<longrightarrow>
paulson@13242
   253
                       is_recfun(r^+, x, \<lambda>x. range, f) \<longrightarrow> Ord(range(f))))"
paulson@13223
   254
paulson@13242
   255
constdefs 
paulson@13242
   256
 wellfoundedrank :: "[i=>o,i,i] => i"
paulson@13242
   257
    "wellfoundedrank(M,r,A) == 
paulson@13242
   258
        {p. x\<in>A, \<exists>y f. M(y) & M(f) & 
paulson@13242
   259
                       p = <x,y> & is_recfun(r^+, x, %x f. range(f), f) & 
paulson@13242
   260
                       y = range(f)}"
paulson@13223
   261
paulson@13223
   262
lemma (in M_recursion) exists_wfrank:
paulson@13223
   263
    "[| wellfounded(M,r); r \<subseteq> A*A; a\<in>A; M(r); M(A) |]
paulson@13242
   264
     ==> \<exists>f. M(f) & is_recfun(r^+, a, %x f. range(f), f)"
paulson@13242
   265
apply (rule wellfounded_exists_is_recfun [of A]) 
paulson@13242
   266
apply (blast intro: wellfounded_on_trancl wellfounded_imp_wellfounded_on)
paulson@13242
   267
apply (rule trans_trancl [THEN trans_imp_trans_on], assumption+)
paulson@13242
   268
apply (simp_all add: trancl_subset_times) 
paulson@13223
   269
done
paulson@13223
   270
paulson@13242
   271
lemma (in M_recursion) M_wellfoundedrank:
paulson@13242
   272
    "[| wellfounded(M,r); r \<subseteq> A*A; M(r); M(A) |] 
paulson@13242
   273
     ==> M(wellfoundedrank(M,r,A))"
paulson@13242
   274
apply (insert wfrank_strong_replacement' [of r]) 
paulson@13242
   275
apply (simp add: wellfoundedrank_def) 
paulson@13242
   276
apply (rule strong_replacement_closed) 
paulson@13242
   277
   apply assumption+
paulson@13242
   278
 apply (rule univalent_is_recfun) 
paulson@13242
   279
     apply (blast intro: wellfounded_on_trancl wellfounded_imp_wellfounded_on)
paulson@13242
   280
    apply (rule trans_on_trancl) 
paulson@13242
   281
   apply (simp add: trancl_subset_times) 
paulson@13242
   282
  apply blast+
paulson@13223
   283
done
paulson@13223
   284
paulson@13242
   285
lemma (in M_recursion) Ord_wfrank_range [rule_format]:
paulson@13242
   286
    "[| wellfounded(M,r); r \<subseteq> A*A; a\<in>A; M(r); M(A) |]
paulson@13242
   287
     ==> \<forall>f. M(f) --> is_recfun(r^+, a, %x f. range(f), f) --> Ord(range(f))"
paulson@13242
   288
apply (subgoal_tac "wellfounded_on(M, A, r^+)") 
paulson@13242
   289
 prefer 2
paulson@13242
   290
 apply (blast intro: wellfounded_on_trancl wellfounded_imp_wellfounded_on)
paulson@13242
   291
apply (erule wellfounded_on_induct2, assumption+)
paulson@13242
   292
apply (simp add: trancl_subset_times) 
paulson@13242
   293
apply (blast intro: Ord_wfrank_separation, clarify)
paulson@13242
   294
txt{*The reasoning in both cases is that we get @{term y} such that
paulson@13242
   295
   @{term "\<langle>y, x\<rangle> \<in> r^+"}.  We find that 
paulson@13242
   296
   @{term "f`y = restrict(f, r^+ -`` {y})"}. *}
paulson@13242
   297
apply (rule OrdI [OF _ Ord_is_Transset])
paulson@13242
   298
 txt{*An ordinal is a transitive set...*}
paulson@13242
   299
 apply (simp add: Transset_def) 
paulson@13242
   300
 apply clarify
paulson@13242
   301
 apply (frule apply_recfun2, assumption) 
paulson@13242
   302
 apply (force simp add: restrict_iff)
paulson@13242
   303
txt{*...of ordinals.  This second case requires the induction hyp.*} 
paulson@13242
   304
apply clarify 
paulson@13242
   305
apply (rename_tac i y)
paulson@13242
   306
apply (frule apply_recfun2, assumption) 
paulson@13242
   307
apply (frule is_recfun_imp_in_r, assumption) 
paulson@13242
   308
apply (frule is_recfun_restrict) 
paulson@13242
   309
    (*simp_all won't work*)
paulson@13242
   310
    apply (simp add: trans_on_trancl trancl_subset_times)+  
paulson@13242
   311
apply (drule spec [THEN mp], assumption)
paulson@13242
   312
apply (subgoal_tac "M(restrict(f, r^+ -`` {y}))")
paulson@13242
   313
 apply (drule_tac x="restrict(f, r^+ -`` {y})" in spec) 
paulson@13242
   314
 apply (simp add: function_apply_equality [OF _ is_recfun_imp_function])
paulson@13242
   315
apply (blast dest: pair_components_in_M)
paulson@13223
   316
done
paulson@13223
   317
paulson@13242
   318
lemma (in M_recursion) Ord_range_wellfoundedrank:
paulson@13242
   319
    "[| wellfounded(M,r); r \<subseteq> A*A;  M(r); M(A) |] 
paulson@13242
   320
     ==> Ord (range(wellfoundedrank(M,r,A)))"
paulson@13242
   321
apply (subgoal_tac "wellfounded_on(M, A, r^+)") 
paulson@13242
   322
 prefer 2
paulson@13242
   323
 apply (blast intro: wellfounded_on_trancl wellfounded_imp_wellfounded_on)
paulson@13242
   324
apply (frule trancl_subset_times) 
paulson@13242
   325
apply (simp add: wellfoundedrank_def)
paulson@13242
   326
apply (rule OrdI [OF _ Ord_is_Transset])
paulson@13242
   327
 prefer 2
paulson@13242
   328
 txt{*by our previous result the range consists of ordinals.*} 
paulson@13242
   329
 apply (blast intro: Ord_wfrank_range) 
paulson@13242
   330
txt{*We still must show that the range is a transitive set.*}
paulson@13247
   331
apply (simp add: Transset_def, clarify, simp)
paulson@13242
   332
apply (rename_tac x i f u)   
paulson@13242
   333
apply (frule is_recfun_imp_in_r, assumption) 
paulson@13242
   334
apply (subgoal_tac "M(u) & M(i) & M(x)") 
paulson@13242
   335
 prefer 2 apply (blast dest: transM, clarify) 
paulson@13242
   336
apply (rule_tac a=u in rangeI) 
paulson@13242
   337
apply (rule ReplaceI) 
paulson@13242
   338
  apply (rule_tac x=i in exI, simp) 
paulson@13242
   339
  apply (rule_tac x="restrict(f, r^+ -`` {u})" in exI)
paulson@13242
   340
  apply (blast intro: is_recfun_restrict trans_on_trancl dest: apply_recfun2)
paulson@13242
   341
 apply blast
paulson@13242
   342
txt{*Unicity requirement of Replacement*} 
paulson@13242
   343
apply clarify
paulson@13242
   344
apply (frule apply_recfun2, assumption) 
paulson@13242
   345
apply (simp add: trans_on_trancl is_recfun_cut)+
paulson@13223
   346
done
paulson@13223
   347
paulson@13242
   348
lemma (in M_recursion) function_wellfoundedrank:
paulson@13242
   349
    "[| wellfounded(M,r); r \<subseteq> A*A;  M(r); M(A)|]
paulson@13242
   350
     ==> function(wellfoundedrank(M,r,A))"
paulson@13242
   351
apply (simp add: wellfoundedrank_def function_def, clarify) 
paulson@13242
   352
txt{*Uniqueness: repeated below!*}
paulson@13242
   353
apply (drule is_recfun_functional, assumption)
paulson@13242
   354
    apply (blast intro: wellfounded_on_trancl wellfounded_imp_wellfounded_on)
paulson@13242
   355
    apply (simp_all add: trancl_subset_times 
paulson@13242
   356
                         trans_trancl [THEN trans_imp_trans_on]) 
paulson@13242
   357
apply (blast dest: transM) 
paulson@13223
   358
done
paulson@13223
   359
paulson@13242
   360
lemma (in M_recursion) domain_wellfoundedrank:
paulson@13242
   361
    "[| wellfounded(M,r); r \<subseteq> A*A;  M(r); M(A)|]
paulson@13242
   362
     ==> domain(wellfoundedrank(M,r,A)) = A"
paulson@13242
   363
apply (simp add: wellfoundedrank_def function_def) 
paulson@13242
   364
apply (rule equalityI, auto)
paulson@13242
   365
apply (frule transM, assumption)  
paulson@13247
   366
apply (frule exists_wfrank, assumption+, clarify) 
paulson@13242
   367
apply (rule domainI) 
paulson@13242
   368
apply (rule ReplaceI)
paulson@13242
   369
apply (rule_tac x="range(f)" in exI)
paulson@13242
   370
apply simp  
paulson@13247
   371
apply (rule_tac x=f in exI, blast, assumption)
paulson@13242
   372
txt{*Uniqueness (for Replacement): repeated above!*}
paulson@13242
   373
apply clarify
paulson@13242
   374
apply (drule is_recfun_functional, assumption)
paulson@13242
   375
    apply (blast intro: wellfounded_on_trancl wellfounded_imp_wellfounded_on)
paulson@13242
   376
    apply (simp_all add: trancl_subset_times 
paulson@13242
   377
                         trans_trancl [THEN trans_imp_trans_on]) 
paulson@13223
   378
done
paulson@13223
   379
paulson@13242
   380
lemma (in M_recursion) wellfoundedrank_type:
paulson@13242
   381
    "[| wellfounded(M,r); r \<subseteq> A*A;  M(r); M(A)|]
paulson@13242
   382
     ==> wellfoundedrank(M,r,A) \<in> A -> range(wellfoundedrank(M,r,A))"
paulson@13242
   383
apply (frule function_wellfoundedrank, assumption+) 
paulson@13242
   384
apply (frule function_imp_Pi) 
paulson@13242
   385
 apply (simp add: wellfoundedrank_def relation_def) 
paulson@13242
   386
 apply blast  
paulson@13242
   387
apply (simp add: domain_wellfoundedrank)
paulson@13223
   388
done
paulson@13223
   389
paulson@13242
   390
lemma (in M_recursion) Ord_wellfoundedrank:
paulson@13242
   391
    "[| wellfounded(M,r); a \<in> A; r \<subseteq> A*A;  M(r); M(A) |] 
paulson@13242
   392
     ==> Ord(wellfoundedrank(M,r,A) ` a)"
paulson@13242
   393
by (blast intro: apply_funtype [OF wellfoundedrank_type]
paulson@13242
   394
                 Ord_in_Ord [OF Ord_range_wellfoundedrank])
paulson@13223
   395
paulson@13242
   396
lemma (in M_recursion) wellfoundedrank_eq:
paulson@13242
   397
     "[| is_recfun(r^+, a, %x. range, f);
paulson@13242
   398
         wellfounded(M,r);  a \<in> A; r \<subseteq> A*A;  M(f); M(r); M(A)|] 
paulson@13242
   399
      ==> wellfoundedrank(M,r,A) ` a = range(f)"
paulson@13242
   400
apply (rule apply_equality) 
paulson@13242
   401
 prefer 2 apply (blast intro: wellfoundedrank_type ) 
paulson@13242
   402
apply (simp add: wellfoundedrank_def)
paulson@13242
   403
apply (rule ReplaceI)
paulson@13242
   404
  apply (rule_tac x="range(f)" in exI) 
paulson@13242
   405
  apply blast 
paulson@13242
   406
 apply assumption
paulson@13242
   407
txt{*Unicity requirement of Replacement*} 
paulson@13242
   408
apply clarify
paulson@13242
   409
apply (drule is_recfun_functional, assumption)
paulson@13242
   410
    apply (blast intro: wellfounded_on_trancl wellfounded_imp_wellfounded_on)
paulson@13242
   411
    apply (simp_all add: trancl_subset_times 
paulson@13242
   412
                         trans_trancl [THEN trans_imp_trans_on])
paulson@13242
   413
apply (blast dest: transM) 
paulson@13223
   414
done
paulson@13223
   415
paulson@13247
   416
paulson@13247
   417
lemma (in M_recursion) wellfoundedrank_lt:
paulson@13247
   418
     "[| <a,b> \<in> r;
paulson@13247
   419
         wellfounded(M,r); r \<subseteq> A*A;  M(r); M(A)|] 
paulson@13247
   420
      ==> wellfoundedrank(M,r,A) ` a < wellfoundedrank(M,r,A) ` b"
paulson@13247
   421
apply (subgoal_tac "wellfounded_on(M, A, r^+)") 
paulson@13247
   422
 prefer 2
paulson@13247
   423
 apply (blast intro: wellfounded_on_trancl wellfounded_imp_wellfounded_on)
paulson@13247
   424
apply (subgoal_tac "a\<in>A & b\<in>A")
paulson@13247
   425
 prefer 2 apply blast
paulson@13247
   426
apply (simp add: lt_def Ord_wellfoundedrank, clarify)   
paulson@13247
   427
apply (frule exists_wfrank [of concl: _ b], assumption+, clarify) 
paulson@13247
   428
apply (rename_tac fb)
paulson@13247
   429
apply (frule is_recfun_restrict [of concl: _ a])
paulson@13247
   430
    apply (rule trans_on_trancl, assumption)
paulson@13247
   431
   apply (simp_all add: r_into_trancl trancl_subset_times) 
paulson@13247
   432
txt{*Still the same goal, but with new @{text is_recfun} assumptions.*}
paulson@13247
   433
apply (simp add: wellfoundedrank_eq) 
paulson@13247
   434
apply (frule_tac a=a in wellfoundedrank_eq, assumption+)
paulson@13247
   435
   apply (simp_all add: transM [of a])
paulson@13247
   436
txt{*We have used equations for wellfoundedrank and now must use some
paulson@13247
   437
    for  @{text is_recfun}. *}
paulson@13247
   438
apply (rule_tac a=a in rangeI) 
paulson@13247
   439
apply (simp add: is_recfun_type [THEN apply_iff] vimage_singleton_iff 
paulson@13247
   440
                 r_into_trancl apply_recfun r_into_trancl)  
paulson@13247
   441
done
paulson@13247
   442
paulson@13247
   443
paulson@13247
   444
lemma (in M_recursion) wellfounded_imp_subset_rvimage:
paulson@13247
   445
     "[|wellfounded(M,r); r \<subseteq> A*A; M(r); M(A)|] 
paulson@13247
   446
      ==> \<exists>i f. Ord(i) & r <= rvimage(A, f, Memrel(i))"
paulson@13247
   447
apply (rule_tac x="range(wellfoundedrank(M,r,A))" in exI)
paulson@13247
   448
apply (rule_tac x="wellfoundedrank(M,r,A)" in exI)
paulson@13247
   449
apply (simp add: Ord_range_wellfoundedrank, clarify) 
paulson@13247
   450
apply (frule subsetD, assumption, clarify) 
paulson@13247
   451
apply (simp add: rvimage_iff wellfoundedrank_lt [THEN ltD])
paulson@13247
   452
apply (blast intro: apply_rangeI wellfoundedrank_type) 
paulson@13247
   453
done
paulson@13247
   454
paulson@13247
   455
lemma (in M_recursion) wellfounded_imp_wf: 
paulson@13247
   456
     "[|wellfounded(M,r); relation(r); M(r)|] ==> wf(r)" 
paulson@13247
   457
by (blast dest!: relation_field_times_field wellfounded_imp_subset_rvimage
paulson@13247
   458
          intro: wf_rvimage_Ord [THEN wf_subset])
paulson@13247
   459
paulson@13247
   460
lemma (in M_recursion) wellfounded_on_imp_wf_on: 
paulson@13247
   461
     "[|wellfounded_on(M,A,r); relation(r); M(r); M(A)|] ==> wf[A](r)" 
paulson@13247
   462
apply (simp add: wellfounded_on_iff_wellfounded wf_on_def) 
paulson@13247
   463
apply (rule wellfounded_imp_wf)
paulson@13247
   464
apply (simp_all add: relation_def)  
paulson@13247
   465
done
paulson@13247
   466
paulson@13247
   467
paulson@13247
   468
theorem (in M_recursion) wf_abs [simp]: 
paulson@13247
   469
     "[|relation(r); M(r)|] ==> wellfounded(M,r) <-> wf(r)"
paulson@13247
   470
by (blast intro: wellfounded_imp_wf wf_imp_relativized) 
paulson@13247
   471
paulson@13247
   472
theorem (in M_recursion) wf_on_abs [simp]: 
paulson@13247
   473
     "[|relation(r); M(r); M(A)|] ==> wellfounded_on(M,A,r) <-> wf[A](r)"
paulson@13247
   474
by (blast intro: wellfounded_on_imp_wf_on wf_on_imp_relativized) 
paulson@13247
   475
paulson@13223
   476
end