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