src/ZF/Constructible/Rec_Separation.thy
author paulson
Tue Sep 10 16:51:31 2002 +0200 (2002-09-10)
changeset 13564 1500a2e48d44
parent 13506 acc18a5d2b1a
child 13566 52a419210d5c
permissions -rw-r--r--
renamed M_triv_axioms to M_trivial and M_axioms to M_basic
paulson@13437
     1
(*  Title:      ZF/Constructible/Rec_Separation.thy
paulson@13437
     2
    ID:         $Id$
paulson@13437
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
paulson@13437
     4
    Copyright   2002  University of Cambridge
paulson@13437
     5
*)
wenzelm@13429
     6
wenzelm@13429
     7
header {*Separation for Facts About Recursion*}
paulson@13348
     8
paulson@13496
     9
theory Rec_Separation = Separation + Internalize:
paulson@13348
    10
paulson@13348
    11
text{*This theory proves all instances needed for locales @{text
paulson@13348
    12
"M_trancl"}, @{text "M_wfrank"} and @{text "M_datatypes"}*}
paulson@13348
    13
paulson@13363
    14
lemma eq_succ_imp_lt: "[|i = succ(j); Ord(i)|] ==> j<i"
wenzelm@13428
    15
by simp
paulson@13363
    16
paulson@13493
    17
paulson@13348
    18
subsection{*The Locale @{text "M_trancl"}*}
paulson@13348
    19
paulson@13348
    20
subsubsection{*Separation for Reflexive/Transitive Closure*}
paulson@13348
    21
paulson@13348
    22
text{*First, The Defining Formula*}
paulson@13348
    23
paulson@13348
    24
(* "rtran_closure_mem(M,A,r,p) ==
wenzelm@13428
    25
      \<exists>nnat[M]. \<exists>n[M]. \<exists>n'[M].
paulson@13348
    26
       omega(M,nnat) & n\<in>nnat & successor(M,n,n') &
paulson@13348
    27
       (\<exists>f[M]. typed_function(M,n',A,f) &
wenzelm@13428
    28
        (\<exists>x[M]. \<exists>y[M]. \<exists>zero[M]. pair(M,x,y,p) & empty(M,zero) &
wenzelm@13428
    29
          fun_apply(M,f,zero,x) & fun_apply(M,f,n,y)) &
wenzelm@13428
    30
        (\<forall>j[M]. j\<in>n -->
wenzelm@13428
    31
          (\<exists>fj[M]. \<exists>sj[M]. \<exists>fsj[M]. \<exists>ffp[M].
wenzelm@13428
    32
            fun_apply(M,f,j,fj) & successor(M,j,sj) &
wenzelm@13428
    33
            fun_apply(M,f,sj,fsj) & pair(M,fj,fsj,ffp) & ffp \<in> r)))"*)
paulson@13348
    34
constdefs rtran_closure_mem_fm :: "[i,i,i]=>i"
wenzelm@13428
    35
 "rtran_closure_mem_fm(A,r,p) ==
paulson@13348
    36
   Exists(Exists(Exists(
paulson@13348
    37
    And(omega_fm(2),
paulson@13348
    38
     And(Member(1,2),
paulson@13348
    39
      And(succ_fm(1,0),
paulson@13348
    40
       Exists(And(typed_function_fm(1, A#+4, 0),
wenzelm@13428
    41
        And(Exists(Exists(Exists(
wenzelm@13428
    42
              And(pair_fm(2,1,p#+7),
wenzelm@13428
    43
               And(empty_fm(0),
wenzelm@13428
    44
                And(fun_apply_fm(3,0,2), fun_apply_fm(3,5,1))))))),
wenzelm@13428
    45
            Forall(Implies(Member(0,3),
wenzelm@13428
    46
             Exists(Exists(Exists(Exists(
wenzelm@13428
    47
              And(fun_apply_fm(5,4,3),
wenzelm@13428
    48
               And(succ_fm(4,2),
wenzelm@13428
    49
                And(fun_apply_fm(5,2,1),
wenzelm@13428
    50
                 And(pair_fm(3,1,0), Member(0,r#+9))))))))))))))))))))"
paulson@13348
    51
paulson@13348
    52
paulson@13348
    53
lemma rtran_closure_mem_type [TC]:
paulson@13348
    54
 "[| x \<in> nat; y \<in> nat; z \<in> nat |] ==> rtran_closure_mem_fm(x,y,z) \<in> formula"
wenzelm@13428
    55
by (simp add: rtran_closure_mem_fm_def)
paulson@13348
    56
paulson@13348
    57
lemma arity_rtran_closure_mem_fm [simp]:
wenzelm@13428
    58
     "[| x \<in> nat; y \<in> nat; z \<in> nat |]
paulson@13348
    59
      ==> arity(rtran_closure_mem_fm(x,y,z)) = succ(x) \<union> succ(y) \<union> succ(z)"
wenzelm@13428
    60
by (simp add: rtran_closure_mem_fm_def succ_Un_distrib [symmetric] Un_ac)
paulson@13348
    61
paulson@13348
    62
lemma sats_rtran_closure_mem_fm [simp]:
paulson@13348
    63
   "[| x \<in> nat; y \<in> nat; z \<in> nat; env \<in> list(A)|]
wenzelm@13428
    64
    ==> sats(A, rtran_closure_mem_fm(x,y,z), env) <->
paulson@13348
    65
        rtran_closure_mem(**A, nth(x,env), nth(y,env), nth(z,env))"
paulson@13348
    66
by (simp add: rtran_closure_mem_fm_def rtran_closure_mem_def)
paulson@13348
    67
paulson@13348
    68
lemma rtran_closure_mem_iff_sats:
wenzelm@13428
    69
      "[| nth(i,env) = x; nth(j,env) = y; nth(k,env) = z;
paulson@13348
    70
          i \<in> nat; j \<in> nat; k \<in> nat; env \<in> list(A)|]
paulson@13348
    71
       ==> rtran_closure_mem(**A, x, y, z) <-> sats(A, rtran_closure_mem_fm(i,j,k), env)"
paulson@13348
    72
by (simp add: sats_rtran_closure_mem_fm)
paulson@13348
    73
paulson@13348
    74
theorem rtran_closure_mem_reflection:
wenzelm@13428
    75
     "REFLECTS[\<lambda>x. rtran_closure_mem(L,f(x),g(x),h(x)),
paulson@13348
    76
               \<lambda>i x. rtran_closure_mem(**Lset(i),f(x),g(x),h(x))]"
paulson@13348
    77
apply (simp only: rtran_closure_mem_def setclass_simps)
wenzelm@13428
    78
apply (intro FOL_reflections function_reflections fun_plus_reflections)
paulson@13348
    79
done
paulson@13348
    80
paulson@13348
    81
text{*Separation for @{term "rtrancl(r)"}.*}
paulson@13348
    82
lemma rtrancl_separation:
paulson@13348
    83
     "[| L(r); L(A) |] ==> separation (L, rtran_closure_mem(L,A,r))"
wenzelm@13428
    84
apply (rule separation_CollectI)
paulson@13505
    85
apply (rule_tac A="{r,A,z}" in subset_LsetE, blast)
paulson@13348
    86
apply (rule ReflectsE [OF rtran_closure_mem_reflection], assumption)
wenzelm@13428
    87
apply (drule subset_Lset_ltD, assumption)
paulson@13348
    88
apply (erule reflection_imp_L_separation)
paulson@13348
    89
  apply (simp_all add: lt_Ord2)
paulson@13385
    90
apply (rule DPow_LsetI)
paulson@13348
    91
apply (rename_tac u)
paulson@13348
    92
apply (rule_tac env = "[u,r,A]" in rtran_closure_mem_iff_sats)
paulson@13348
    93
apply (rule sep_rules | simp)+
paulson@13348
    94
done
paulson@13348
    95
paulson@13348
    96
paulson@13348
    97
subsubsection{*Reflexive/Transitive Closure, Internalized*}
paulson@13348
    98
wenzelm@13428
    99
(*  "rtran_closure(M,r,s) ==
paulson@13348
   100
        \<forall>A[M]. is_field(M,r,A) -->
wenzelm@13428
   101
         (\<forall>p[M]. p \<in> s <-> rtran_closure_mem(M,A,r,p))" *)
paulson@13348
   102
constdefs rtran_closure_fm :: "[i,i]=>i"
wenzelm@13428
   103
 "rtran_closure_fm(r,s) ==
paulson@13348
   104
   Forall(Implies(field_fm(succ(r),0),
paulson@13348
   105
                  Forall(Iff(Member(0,succ(succ(s))),
paulson@13348
   106
                             rtran_closure_mem_fm(1,succ(succ(r)),0)))))"
paulson@13348
   107
paulson@13348
   108
lemma rtran_closure_type [TC]:
paulson@13348
   109
     "[| x \<in> nat; y \<in> nat |] ==> rtran_closure_fm(x,y) \<in> formula"
wenzelm@13428
   110
by (simp add: rtran_closure_fm_def)
paulson@13348
   111
paulson@13348
   112
lemma arity_rtran_closure_fm [simp]:
wenzelm@13428
   113
     "[| x \<in> nat; y \<in> nat |]
paulson@13348
   114
      ==> arity(rtran_closure_fm(x,y)) = succ(x) \<union> succ(y)"
paulson@13348
   115
by (simp add: rtran_closure_fm_def succ_Un_distrib [symmetric] Un_ac)
paulson@13348
   116
paulson@13348
   117
lemma sats_rtran_closure_fm [simp]:
paulson@13348
   118
   "[| x \<in> nat; y \<in> nat; env \<in> list(A)|]
wenzelm@13428
   119
    ==> sats(A, rtran_closure_fm(x,y), env) <->
paulson@13348
   120
        rtran_closure(**A, nth(x,env), nth(y,env))"
paulson@13348
   121
by (simp add: rtran_closure_fm_def rtran_closure_def)
paulson@13348
   122
paulson@13348
   123
lemma rtran_closure_iff_sats:
wenzelm@13428
   124
      "[| nth(i,env) = x; nth(j,env) = y;
paulson@13348
   125
          i \<in> nat; j \<in> nat; env \<in> list(A)|]
paulson@13348
   126
       ==> rtran_closure(**A, x, y) <-> sats(A, rtran_closure_fm(i,j), env)"
paulson@13348
   127
by simp
paulson@13348
   128
paulson@13348
   129
theorem rtran_closure_reflection:
wenzelm@13428
   130
     "REFLECTS[\<lambda>x. rtran_closure(L,f(x),g(x)),
paulson@13348
   131
               \<lambda>i x. rtran_closure(**Lset(i),f(x),g(x))]"
paulson@13348
   132
apply (simp only: rtran_closure_def setclass_simps)
paulson@13348
   133
apply (intro FOL_reflections function_reflections rtran_closure_mem_reflection)
paulson@13348
   134
done
paulson@13348
   135
paulson@13348
   136
paulson@13348
   137
subsubsection{*Transitive Closure of a Relation, Internalized*}
paulson@13348
   138
paulson@13348
   139
(*  "tran_closure(M,r,t) ==
paulson@13348
   140
         \<exists>s[M]. rtran_closure(M,r,s) & composition(M,r,s,t)" *)
paulson@13348
   141
constdefs tran_closure_fm :: "[i,i]=>i"
wenzelm@13428
   142
 "tran_closure_fm(r,s) ==
paulson@13348
   143
   Exists(And(rtran_closure_fm(succ(r),0), composition_fm(succ(r),0,succ(s))))"
paulson@13348
   144
paulson@13348
   145
lemma tran_closure_type [TC]:
paulson@13348
   146
     "[| x \<in> nat; y \<in> nat |] ==> tran_closure_fm(x,y) \<in> formula"
wenzelm@13428
   147
by (simp add: tran_closure_fm_def)
paulson@13348
   148
paulson@13348
   149
lemma arity_tran_closure_fm [simp]:
wenzelm@13428
   150
     "[| x \<in> nat; y \<in> nat |]
paulson@13348
   151
      ==> arity(tran_closure_fm(x,y)) = succ(x) \<union> succ(y)"
paulson@13348
   152
by (simp add: tran_closure_fm_def succ_Un_distrib [symmetric] Un_ac)
paulson@13348
   153
paulson@13348
   154
lemma sats_tran_closure_fm [simp]:
paulson@13348
   155
   "[| x \<in> nat; y \<in> nat; env \<in> list(A)|]
wenzelm@13428
   156
    ==> sats(A, tran_closure_fm(x,y), env) <->
paulson@13348
   157
        tran_closure(**A, nth(x,env), nth(y,env))"
paulson@13348
   158
by (simp add: tran_closure_fm_def tran_closure_def)
paulson@13348
   159
paulson@13348
   160
lemma tran_closure_iff_sats:
wenzelm@13428
   161
      "[| nth(i,env) = x; nth(j,env) = y;
paulson@13348
   162
          i \<in> nat; j \<in> nat; env \<in> list(A)|]
paulson@13348
   163
       ==> tran_closure(**A, x, y) <-> sats(A, tran_closure_fm(i,j), env)"
paulson@13348
   164
by simp
paulson@13348
   165
paulson@13348
   166
theorem tran_closure_reflection:
wenzelm@13428
   167
     "REFLECTS[\<lambda>x. tran_closure(L,f(x),g(x)),
paulson@13348
   168
               \<lambda>i x. tran_closure(**Lset(i),f(x),g(x))]"
paulson@13348
   169
apply (simp only: tran_closure_def setclass_simps)
wenzelm@13428
   170
apply (intro FOL_reflections function_reflections
paulson@13348
   171
             rtran_closure_reflection composition_reflection)
paulson@13348
   172
done
paulson@13348
   173
paulson@13348
   174
paulson@13506
   175
subsubsection{*Separation for the Proof of @{text "wellfounded_on_trancl"}*}
paulson@13348
   176
paulson@13348
   177
lemma wellfounded_trancl_reflects:
wenzelm@13428
   178
  "REFLECTS[\<lambda>x. \<exists>w[L]. \<exists>wx[L]. \<exists>rp[L].
wenzelm@13428
   179
                 w \<in> Z & pair(L,w,x,wx) & tran_closure(L,r,rp) & wx \<in> rp,
wenzelm@13428
   180
   \<lambda>i x. \<exists>w \<in> Lset(i). \<exists>wx \<in> Lset(i). \<exists>rp \<in> Lset(i).
paulson@13348
   181
       w \<in> Z & pair(**Lset(i),w,x,wx) & tran_closure(**Lset(i),r,rp) &
paulson@13348
   182
       wx \<in> rp]"
wenzelm@13428
   183
by (intro FOL_reflections function_reflections fun_plus_reflections
paulson@13348
   184
          tran_closure_reflection)
paulson@13348
   185
paulson@13348
   186
paulson@13348
   187
lemma wellfounded_trancl_separation:
wenzelm@13428
   188
         "[| L(r); L(Z) |] ==>
wenzelm@13428
   189
          separation (L, \<lambda>x.
wenzelm@13428
   190
              \<exists>w[L]. \<exists>wx[L]. \<exists>rp[L].
wenzelm@13428
   191
               w \<in> Z & pair(L,w,x,wx) & tran_closure(L,r,rp) & wx \<in> rp)"
wenzelm@13428
   192
apply (rule separation_CollectI)
paulson@13505
   193
apply (rule_tac A="{r,Z,z}" in subset_LsetE, blast)
paulson@13348
   194
apply (rule ReflectsE [OF wellfounded_trancl_reflects], assumption)
wenzelm@13428
   195
apply (drule subset_Lset_ltD, assumption)
paulson@13348
   196
apply (erule reflection_imp_L_separation)
paulson@13348
   197
  apply (simp_all add: lt_Ord2)
paulson@13385
   198
apply (rule DPow_LsetI)
wenzelm@13428
   199
apply (rename_tac u)
paulson@13348
   200
apply (rule bex_iff_sats conj_iff_sats)+
wenzelm@13428
   201
apply (rule_tac env = "[w,u,r,Z]" in mem_iff_sats)
paulson@13348
   202
apply (rule sep_rules tran_closure_iff_sats | simp)+
paulson@13348
   203
done
paulson@13348
   204
paulson@13363
   205
paulson@13363
   206
subsubsection{*Instantiating the locale @{text M_trancl}*}
wenzelm@13428
   207
paulson@13437
   208
lemma M_trancl_axioms_L: "M_trancl_axioms(L)"
wenzelm@13428
   209
  apply (rule M_trancl_axioms.intro)
paulson@13437
   210
   apply (assumption | rule rtrancl_separation wellfounded_trancl_separation)+
wenzelm@13428
   211
  done
paulson@13363
   212
paulson@13437
   213
theorem M_trancl_L: "PROP M_trancl(L)"
paulson@13437
   214
by (rule M_trancl.intro
paulson@13564
   215
         [OF M_trivial_L M_basic_axioms_L M_trancl_axioms_L])
paulson@13437
   216
wenzelm@13428
   217
lemmas iterates_abs = M_trancl.iterates_abs [OF M_trancl_L]
wenzelm@13428
   218
  and rtran_closure_rtrancl = M_trancl.rtran_closure_rtrancl [OF M_trancl_L]
wenzelm@13428
   219
  and rtrancl_closed = M_trancl.rtrancl_closed [OF M_trancl_L]
wenzelm@13428
   220
  and rtrancl_abs = M_trancl.rtrancl_abs [OF M_trancl_L]
wenzelm@13428
   221
  and trancl_closed = M_trancl.trancl_closed [OF M_trancl_L]
wenzelm@13428
   222
  and trancl_abs = M_trancl.trancl_abs [OF M_trancl_L]
wenzelm@13428
   223
  and wellfounded_on_trancl = M_trancl.wellfounded_on_trancl [OF M_trancl_L]
wenzelm@13428
   224
  and wellfounded_trancl = M_trancl.wellfounded_trancl [OF M_trancl_L]
wenzelm@13428
   225
  and wfrec_relativize = M_trancl.wfrec_relativize [OF M_trancl_L]
wenzelm@13428
   226
  and trans_wfrec_relativize = M_trancl.trans_wfrec_relativize [OF M_trancl_L]
wenzelm@13428
   227
  and trans_wfrec_abs = M_trancl.trans_wfrec_abs [OF M_trancl_L]
wenzelm@13428
   228
  and trans_eq_pair_wfrec_iff = M_trancl.trans_eq_pair_wfrec_iff [OF M_trancl_L]
wenzelm@13428
   229
  and eq_pair_wfrec_iff = M_trancl.eq_pair_wfrec_iff [OF M_trancl_L]
paulson@13363
   230
paulson@13363
   231
declare rtrancl_closed [intro,simp]
paulson@13363
   232
declare rtrancl_abs [simp]
paulson@13363
   233
declare trancl_closed [intro,simp]
paulson@13363
   234
declare trancl_abs [simp]
paulson@13363
   235
paulson@13363
   236
paulson@13363
   237
subsection{*The Locale @{text "M_wfrank"}*}
paulson@13363
   238
paulson@13363
   239
subsubsection{*Separation for @{term "wfrank"}*}
paulson@13348
   240
paulson@13348
   241
lemma wfrank_Reflects:
paulson@13348
   242
 "REFLECTS[\<lambda>x. \<forall>rplus[L]. tran_closure(L,r,rplus) -->
paulson@13352
   243
              ~ (\<exists>f[L]. M_is_recfun(L, %x f y. is_range(L,f,y), rplus, x, f)),
paulson@13348
   244
      \<lambda>i x. \<forall>rplus \<in> Lset(i). tran_closure(**Lset(i),r,rplus) -->
wenzelm@13428
   245
         ~ (\<exists>f \<in> Lset(i).
wenzelm@13428
   246
            M_is_recfun(**Lset(i), %x f y. is_range(**Lset(i),f,y),
paulson@13352
   247
                        rplus, x, f))]"
wenzelm@13428
   248
by (intro FOL_reflections function_reflections is_recfun_reflection tran_closure_reflection)
paulson@13348
   249
paulson@13348
   250
lemma wfrank_separation:
paulson@13348
   251
     "L(r) ==>
paulson@13348
   252
      separation (L, \<lambda>x. \<forall>rplus[L]. tran_closure(L,r,rplus) -->
paulson@13352
   253
         ~ (\<exists>f[L]. M_is_recfun(L, %x f y. is_range(L,f,y), rplus, x, f)))"
wenzelm@13428
   254
apply (rule separation_CollectI)
paulson@13505
   255
apply (rule_tac A="{r,z}" in subset_LsetE, blast)
paulson@13348
   256
apply (rule ReflectsE [OF wfrank_Reflects], assumption)
wenzelm@13428
   257
apply (drule subset_Lset_ltD, assumption)
paulson@13348
   258
apply (erule reflection_imp_L_separation)
paulson@13348
   259
  apply (simp_all add: lt_Ord2, clarify)
paulson@13385
   260
apply (rule DPow_LsetI)
wenzelm@13428
   261
apply (rename_tac u)
paulson@13348
   262
apply (rule ball_iff_sats imp_iff_sats)+
paulson@13348
   263
apply (rule_tac env="[rplus,u,r]" in tran_closure_iff_sats)
paulson@13441
   264
apply (rule sep_rules | simp)+
paulson@13348
   265
apply (rule sep_rules is_recfun_iff_sats | simp)+
paulson@13348
   266
done
paulson@13348
   267
paulson@13348
   268
paulson@13363
   269
subsubsection{*Replacement for @{term "wfrank"}*}
paulson@13348
   270
paulson@13348
   271
lemma wfrank_replacement_Reflects:
wenzelm@13428
   272
 "REFLECTS[\<lambda>z. \<exists>x[L]. x \<in> A &
paulson@13348
   273
        (\<forall>rplus[L]. tran_closure(L,r,rplus) -->
wenzelm@13428
   274
         (\<exists>y[L]. \<exists>f[L]. pair(L,x,y,z)  &
paulson@13352
   275
                        M_is_recfun(L, %x f y. is_range(L,f,y), rplus, x, f) &
paulson@13348
   276
                        is_range(L,f,y))),
wenzelm@13428
   277
 \<lambda>i z. \<exists>x \<in> Lset(i). x \<in> A &
paulson@13348
   278
      (\<forall>rplus \<in> Lset(i). tran_closure(**Lset(i),r,rplus) -->
wenzelm@13428
   279
       (\<exists>y \<in> Lset(i). \<exists>f \<in> Lset(i). pair(**Lset(i),x,y,z)  &
paulson@13352
   280
         M_is_recfun(**Lset(i), %x f y. is_range(**Lset(i),f,y), rplus, x, f) &
paulson@13348
   281
         is_range(**Lset(i),f,y)))]"
paulson@13348
   282
by (intro FOL_reflections function_reflections fun_plus_reflections
paulson@13348
   283
             is_recfun_reflection tran_closure_reflection)
paulson@13348
   284
paulson@13348
   285
paulson@13348
   286
lemma wfrank_strong_replacement:
paulson@13348
   287
     "L(r) ==>
wenzelm@13428
   288
      strong_replacement(L, \<lambda>x z.
paulson@13348
   289
         \<forall>rplus[L]. tran_closure(L,r,rplus) -->
wenzelm@13428
   290
         (\<exists>y[L]. \<exists>f[L]. pair(L,x,y,z)  &
paulson@13352
   291
                        M_is_recfun(L, %x f y. is_range(L,f,y), rplus, x, f) &
paulson@13348
   292
                        is_range(L,f,y)))"
wenzelm@13428
   293
apply (rule strong_replacementI)
paulson@13348
   294
apply (rule rallI)
wenzelm@13428
   295
apply (rename_tac B)
wenzelm@13428
   296
apply (rule separation_CollectI)
paulson@13505
   297
apply (rule_tac A="{B,r,z}" in subset_LsetE, blast)
paulson@13348
   298
apply (rule ReflectsE [OF wfrank_replacement_Reflects], assumption)
wenzelm@13428
   299
apply (drule subset_Lset_ltD, assumption)
paulson@13348
   300
apply (erule reflection_imp_L_separation)
paulson@13348
   301
  apply (simp_all add: lt_Ord2)
paulson@13385
   302
apply (rule DPow_LsetI)
wenzelm@13428
   303
apply (rename_tac u)
paulson@13348
   304
apply (rule bex_iff_sats ball_iff_sats conj_iff_sats)+
wenzelm@13428
   305
apply (rule_tac env = "[x,u,B,r]" in mem_iff_sats)
paulson@13441
   306
apply (rule sep_rules list.intros app_type tran_closure_iff_sats is_recfun_iff_sats | simp)+
paulson@13348
   307
done
paulson@13348
   308
paulson@13348
   309
paulson@13363
   310
subsubsection{*Separation for Proving @{text Ord_wfrank_range}*}
paulson@13348
   311
paulson@13348
   312
lemma Ord_wfrank_Reflects:
wenzelm@13428
   313
 "REFLECTS[\<lambda>x. \<forall>rplus[L]. tran_closure(L,r,rplus) -->
wenzelm@13428
   314
          ~ (\<forall>f[L]. \<forall>rangef[L].
paulson@13348
   315
             is_range(L,f,rangef) -->
paulson@13352
   316
             M_is_recfun(L, \<lambda>x f y. is_range(L,f,y), rplus, x, f) -->
paulson@13348
   317
             ordinal(L,rangef)),
wenzelm@13428
   318
      \<lambda>i x. \<forall>rplus \<in> Lset(i). tran_closure(**Lset(i),r,rplus) -->
wenzelm@13428
   319
          ~ (\<forall>f \<in> Lset(i). \<forall>rangef \<in> Lset(i).
paulson@13348
   320
             is_range(**Lset(i),f,rangef) -->
wenzelm@13428
   321
             M_is_recfun(**Lset(i), \<lambda>x f y. is_range(**Lset(i),f,y),
paulson@13352
   322
                         rplus, x, f) -->
paulson@13348
   323
             ordinal(**Lset(i),rangef))]"
wenzelm@13428
   324
by (intro FOL_reflections function_reflections is_recfun_reflection
paulson@13348
   325
          tran_closure_reflection ordinal_reflection)
paulson@13348
   326
paulson@13348
   327
lemma  Ord_wfrank_separation:
paulson@13348
   328
     "L(r) ==>
paulson@13348
   329
      separation (L, \<lambda>x.
wenzelm@13428
   330
         \<forall>rplus[L]. tran_closure(L,r,rplus) -->
wenzelm@13428
   331
          ~ (\<forall>f[L]. \<forall>rangef[L].
paulson@13348
   332
             is_range(L,f,rangef) -->
paulson@13352
   333
             M_is_recfun(L, \<lambda>x f y. is_range(L,f,y), rplus, x, f) -->
wenzelm@13428
   334
             ordinal(L,rangef)))"
wenzelm@13428
   335
apply (rule separation_CollectI)
paulson@13505
   336
apply (rule_tac A="{r,z}" in subset_LsetE, blast)
paulson@13348
   337
apply (rule ReflectsE [OF Ord_wfrank_Reflects], assumption)
wenzelm@13428
   338
apply (drule subset_Lset_ltD, assumption)
paulson@13348
   339
apply (erule reflection_imp_L_separation)
paulson@13348
   340
  apply (simp_all add: lt_Ord2, clarify)
paulson@13385
   341
apply (rule DPow_LsetI)
wenzelm@13428
   342
apply (rename_tac u)
paulson@13348
   343
apply (rule ball_iff_sats imp_iff_sats)+
paulson@13348
   344
apply (rule_tac env="[rplus,u,r]" in tran_closure_iff_sats)
paulson@13348
   345
apply (rule sep_rules is_recfun_iff_sats | simp)+
paulson@13348
   346
done
paulson@13348
   347
paulson@13348
   348
paulson@13363
   349
subsubsection{*Instantiating the locale @{text M_wfrank}*}
wenzelm@13428
   350
paulson@13437
   351
lemma M_wfrank_axioms_L: "M_wfrank_axioms(L)"
paulson@13437
   352
  apply (rule M_wfrank_axioms.intro)
paulson@13437
   353
   apply (assumption | rule
paulson@13437
   354
     wfrank_separation wfrank_strong_replacement Ord_wfrank_separation)+
paulson@13437
   355
  done
paulson@13437
   356
wenzelm@13428
   357
theorem M_wfrank_L: "PROP M_wfrank(L)"
wenzelm@13428
   358
  apply (rule M_wfrank.intro)
wenzelm@13429
   359
     apply (rule M_trancl.axioms [OF M_trancl_L])+
paulson@13437
   360
  apply (rule M_wfrank_axioms_L) 
wenzelm@13428
   361
  done
paulson@13363
   362
wenzelm@13428
   363
lemmas iterates_closed = M_wfrank.iterates_closed [OF M_wfrank_L]
wenzelm@13428
   364
  and exists_wfrank = M_wfrank.exists_wfrank [OF M_wfrank_L]
wenzelm@13428
   365
  and M_wellfoundedrank = M_wfrank.M_wellfoundedrank [OF M_wfrank_L]
wenzelm@13428
   366
  and Ord_wfrank_range = M_wfrank.Ord_wfrank_range [OF M_wfrank_L]
wenzelm@13428
   367
  and Ord_range_wellfoundedrank = M_wfrank.Ord_range_wellfoundedrank [OF M_wfrank_L]
wenzelm@13428
   368
  and function_wellfoundedrank = M_wfrank.function_wellfoundedrank [OF M_wfrank_L]
wenzelm@13428
   369
  and domain_wellfoundedrank = M_wfrank.domain_wellfoundedrank [OF M_wfrank_L]
wenzelm@13428
   370
  and wellfoundedrank_type = M_wfrank.wellfoundedrank_type [OF M_wfrank_L]
wenzelm@13428
   371
  and Ord_wellfoundedrank = M_wfrank.Ord_wellfoundedrank [OF M_wfrank_L]
wenzelm@13428
   372
  and wellfoundedrank_eq = M_wfrank.wellfoundedrank_eq [OF M_wfrank_L]
wenzelm@13428
   373
  and wellfoundedrank_lt = M_wfrank.wellfoundedrank_lt [OF M_wfrank_L]
wenzelm@13428
   374
  and wellfounded_imp_subset_rvimage = M_wfrank.wellfounded_imp_subset_rvimage [OF M_wfrank_L]
wenzelm@13428
   375
  and wellfounded_imp_wf = M_wfrank.wellfounded_imp_wf [OF M_wfrank_L]
wenzelm@13428
   376
  and wellfounded_on_imp_wf_on = M_wfrank.wellfounded_on_imp_wf_on [OF M_wfrank_L]
wenzelm@13428
   377
  and wf_abs = M_wfrank.wf_abs [OF M_wfrank_L]
wenzelm@13428
   378
  and wf_on_abs = M_wfrank.wf_on_abs [OF M_wfrank_L]
wenzelm@13428
   379
  and wfrec_replacement_iff = M_wfrank.wfrec_replacement_iff [OF M_wfrank_L]
wenzelm@13428
   380
  and trans_wfrec_closed = M_wfrank.trans_wfrec_closed [OF M_wfrank_L]
wenzelm@13428
   381
  and wfrec_closed = M_wfrank.wfrec_closed [OF M_wfrank_L]
paulson@13363
   382
paulson@13363
   383
declare iterates_closed [intro,simp]
paulson@13363
   384
declare Ord_wfrank_range [rule_format]
paulson@13363
   385
declare wf_abs [simp]
paulson@13363
   386
declare wf_on_abs [simp]
paulson@13363
   387
paulson@13363
   388
wenzelm@13428
   389
subsection{*@{term L} is Closed Under the Operator @{term list}*}
paulson@13363
   390
paulson@13386
   391
subsubsection{*Instances of Replacement for Lists*}
paulson@13386
   392
paulson@13363
   393
lemma list_replacement1_Reflects:
paulson@13363
   394
 "REFLECTS
paulson@13363
   395
   [\<lambda>x. \<exists>u[L]. u \<in> B \<and> (\<exists>y[L]. pair(L,u,y,x) \<and>
paulson@13363
   396
         is_wfrec(L, iterates_MH(L, is_list_functor(L,A), 0), memsn, u, y)),
paulson@13363
   397
    \<lambda>i x. \<exists>u \<in> Lset(i). u \<in> B \<and> (\<exists>y \<in> Lset(i). pair(**Lset(i), u, y, x) \<and>
wenzelm@13428
   398
         is_wfrec(**Lset(i),
wenzelm@13428
   399
                  iterates_MH(**Lset(i),
paulson@13363
   400
                          is_list_functor(**Lset(i), A), 0), memsn, u, y))]"
wenzelm@13428
   401
by (intro FOL_reflections function_reflections is_wfrec_reflection
wenzelm@13428
   402
          iterates_MH_reflection list_functor_reflection)
paulson@13363
   403
paulson@13441
   404
wenzelm@13428
   405
lemma list_replacement1:
paulson@13363
   406
   "L(A) ==> iterates_replacement(L, is_list_functor(L,A), 0)"
paulson@13363
   407
apply (unfold iterates_replacement_def wfrec_replacement_def, clarify)
wenzelm@13428
   408
apply (rule strong_replacementI)
paulson@13363
   409
apply (rule rallI)
wenzelm@13428
   410
apply (rename_tac B)
wenzelm@13428
   411
apply (rule separation_CollectI)
wenzelm@13428
   412
apply (insert nonempty)
wenzelm@13428
   413
apply (subgoal_tac "L(Memrel(succ(n)))")
paulson@13505
   414
apply (rule_tac A="{B,A,n,z,0,Memrel(succ(n))}" in subset_LsetE, blast)
paulson@13363
   415
apply (rule ReflectsE [OF list_replacement1_Reflects], assumption)
wenzelm@13428
   416
apply (drule subset_Lset_ltD, assumption)
paulson@13363
   417
apply (erule reflection_imp_L_separation)
paulson@13386
   418
  apply (simp_all add: lt_Ord2 Memrel_closed)
wenzelm@13428
   419
apply (elim conjE)
paulson@13385
   420
apply (rule DPow_LsetI)
wenzelm@13428
   421
apply (rename_tac v)
paulson@13363
   422
apply (rule bex_iff_sats conj_iff_sats)+
paulson@13363
   423
apply (rule_tac env = "[u,v,A,n,B,0,Memrel(succ(n))]" in mem_iff_sats)
paulson@13434
   424
apply (rule sep_rules is_nat_case_iff_sats list_functor_iff_sats
paulson@13441
   425
            is_wfrec_iff_sats iterates_MH_iff_sats quasinat_iff_sats | simp)+
paulson@13363
   426
done
paulson@13363
   427
paulson@13441
   428
paulson@13363
   429
lemma list_replacement2_Reflects:
paulson@13363
   430
 "REFLECTS
paulson@13363
   431
   [\<lambda>x. \<exists>u[L]. u \<in> B \<and> u \<in> nat \<and>
paulson@13363
   432
         (\<exists>sn[L]. \<exists>msn[L]. successor(L, u, sn) \<and> membership(L, sn, msn) \<and>
paulson@13363
   433
           is_wfrec (L, iterates_MH (L, is_list_functor(L, A), 0),
paulson@13363
   434
                              msn, u, x)),
paulson@13363
   435
    \<lambda>i x. \<exists>u \<in> Lset(i). u \<in> B \<and> u \<in> nat \<and>
wenzelm@13428
   436
         (\<exists>sn \<in> Lset(i). \<exists>msn \<in> Lset(i).
paulson@13363
   437
          successor(**Lset(i), u, sn) \<and> membership(**Lset(i), sn, msn) \<and>
wenzelm@13428
   438
           is_wfrec (**Lset(i),
paulson@13363
   439
                 iterates_MH (**Lset(i), is_list_functor(**Lset(i), A), 0),
paulson@13363
   440
                     msn, u, x))]"
wenzelm@13428
   441
by (intro FOL_reflections function_reflections is_wfrec_reflection
wenzelm@13428
   442
          iterates_MH_reflection list_functor_reflection)
paulson@13363
   443
paulson@13363
   444
wenzelm@13428
   445
lemma list_replacement2:
wenzelm@13428
   446
   "L(A) ==> strong_replacement(L,
wenzelm@13428
   447
         \<lambda>n y. n\<in>nat &
paulson@13363
   448
               (\<exists>sn[L]. \<exists>msn[L]. successor(L,n,sn) & membership(L,sn,msn) &
wenzelm@13428
   449
               is_wfrec(L, iterates_MH(L,is_list_functor(L,A), 0),
paulson@13363
   450
                        msn, n, y)))"
wenzelm@13428
   451
apply (rule strong_replacementI)
paulson@13363
   452
apply (rule rallI)
wenzelm@13428
   453
apply (rename_tac B)
wenzelm@13428
   454
apply (rule separation_CollectI)
wenzelm@13428
   455
apply (insert nonempty)
wenzelm@13428
   456
apply (rule_tac A="{A,B,z,0,nat}" in subset_LsetE)
wenzelm@13428
   457
apply (blast intro: L_nat)
paulson@13363
   458
apply (rule ReflectsE [OF list_replacement2_Reflects], assumption)
wenzelm@13428
   459
apply (drule subset_Lset_ltD, assumption)
paulson@13363
   460
apply (erule reflection_imp_L_separation)
paulson@13363
   461
  apply (simp_all add: lt_Ord2)
paulson@13385
   462
apply (rule DPow_LsetI)
wenzelm@13428
   463
apply (rename_tac v)
paulson@13363
   464
apply (rule bex_iff_sats conj_iff_sats)+
paulson@13363
   465
apply (rule_tac env = "[u,v,A,B,0,nat]" in mem_iff_sats)
paulson@13434
   466
apply (rule sep_rules is_nat_case_iff_sats list_functor_iff_sats
paulson@13441
   467
            is_wfrec_iff_sats iterates_MH_iff_sats quasinat_iff_sats | simp)+
paulson@13363
   468
done
paulson@13363
   469
paulson@13386
   470
wenzelm@13428
   471
subsection{*@{term L} is Closed Under the Operator @{term formula}*}
paulson@13386
   472
paulson@13386
   473
subsubsection{*Instances of Replacement for Formulas*}
paulson@13386
   474
paulson@13386
   475
lemma formula_replacement1_Reflects:
paulson@13386
   476
 "REFLECTS
paulson@13386
   477
   [\<lambda>x. \<exists>u[L]. u \<in> B \<and> (\<exists>y[L]. pair(L,u,y,x) \<and>
paulson@13386
   478
         is_wfrec(L, iterates_MH(L, is_formula_functor(L), 0), memsn, u, y)),
paulson@13386
   479
    \<lambda>i x. \<exists>u \<in> Lset(i). u \<in> B \<and> (\<exists>y \<in> Lset(i). pair(**Lset(i), u, y, x) \<and>
wenzelm@13428
   480
         is_wfrec(**Lset(i),
wenzelm@13428
   481
                  iterates_MH(**Lset(i),
paulson@13386
   482
                          is_formula_functor(**Lset(i)), 0), memsn, u, y))]"
wenzelm@13428
   483
by (intro FOL_reflections function_reflections is_wfrec_reflection
wenzelm@13428
   484
          iterates_MH_reflection formula_functor_reflection)
paulson@13386
   485
wenzelm@13428
   486
lemma formula_replacement1:
paulson@13386
   487
   "iterates_replacement(L, is_formula_functor(L), 0)"
paulson@13386
   488
apply (unfold iterates_replacement_def wfrec_replacement_def, clarify)
wenzelm@13428
   489
apply (rule strong_replacementI)
paulson@13386
   490
apply (rule rallI)
wenzelm@13428
   491
apply (rename_tac B)
wenzelm@13428
   492
apply (rule separation_CollectI)
wenzelm@13428
   493
apply (insert nonempty)
wenzelm@13428
   494
apply (subgoal_tac "L(Memrel(succ(n)))")
paulson@13505
   495
apply (rule_tac A="{B,n,z,0,Memrel(succ(n))}" in subset_LsetE, blast)
paulson@13386
   496
apply (rule ReflectsE [OF formula_replacement1_Reflects], assumption)
wenzelm@13428
   497
apply (drule subset_Lset_ltD, assumption)
paulson@13386
   498
apply (erule reflection_imp_L_separation)
paulson@13386
   499
  apply (simp_all add: lt_Ord2 Memrel_closed)
paulson@13386
   500
apply (rule DPow_LsetI)
wenzelm@13428
   501
apply (rename_tac v)
paulson@13386
   502
apply (rule bex_iff_sats conj_iff_sats)+
paulson@13386
   503
apply (rule_tac env = "[u,v,n,B,0,Memrel(succ(n))]" in mem_iff_sats)
paulson@13434
   504
apply (rule sep_rules is_nat_case_iff_sats formula_functor_iff_sats
paulson@13441
   505
            is_wfrec_iff_sats iterates_MH_iff_sats quasinat_iff_sats | simp)+
paulson@13386
   506
done
paulson@13386
   507
paulson@13386
   508
lemma formula_replacement2_Reflects:
paulson@13386
   509
 "REFLECTS
paulson@13386
   510
   [\<lambda>x. \<exists>u[L]. u \<in> B \<and> u \<in> nat \<and>
paulson@13386
   511
         (\<exists>sn[L]. \<exists>msn[L]. successor(L, u, sn) \<and> membership(L, sn, msn) \<and>
paulson@13386
   512
           is_wfrec (L, iterates_MH (L, is_formula_functor(L), 0),
paulson@13386
   513
                              msn, u, x)),
paulson@13386
   514
    \<lambda>i x. \<exists>u \<in> Lset(i). u \<in> B \<and> u \<in> nat \<and>
wenzelm@13428
   515
         (\<exists>sn \<in> Lset(i). \<exists>msn \<in> Lset(i).
paulson@13386
   516
          successor(**Lset(i), u, sn) \<and> membership(**Lset(i), sn, msn) \<and>
wenzelm@13428
   517
           is_wfrec (**Lset(i),
paulson@13386
   518
                 iterates_MH (**Lset(i), is_formula_functor(**Lset(i)), 0),
paulson@13386
   519
                     msn, u, x))]"
wenzelm@13428
   520
by (intro FOL_reflections function_reflections is_wfrec_reflection
wenzelm@13428
   521
          iterates_MH_reflection formula_functor_reflection)
paulson@13386
   522
paulson@13386
   523
wenzelm@13428
   524
lemma formula_replacement2:
wenzelm@13428
   525
   "strong_replacement(L,
wenzelm@13428
   526
         \<lambda>n y. n\<in>nat &
paulson@13386
   527
               (\<exists>sn[L]. \<exists>msn[L]. successor(L,n,sn) & membership(L,sn,msn) &
wenzelm@13428
   528
               is_wfrec(L, iterates_MH(L,is_formula_functor(L), 0),
paulson@13386
   529
                        msn, n, y)))"
wenzelm@13428
   530
apply (rule strong_replacementI)
paulson@13386
   531
apply (rule rallI)
wenzelm@13428
   532
apply (rename_tac B)
wenzelm@13428
   533
apply (rule separation_CollectI)
wenzelm@13428
   534
apply (insert nonempty)
wenzelm@13428
   535
apply (rule_tac A="{B,z,0,nat}" in subset_LsetE)
wenzelm@13428
   536
apply (blast intro: L_nat)
paulson@13386
   537
apply (rule ReflectsE [OF formula_replacement2_Reflects], assumption)
wenzelm@13428
   538
apply (drule subset_Lset_ltD, assumption)
paulson@13386
   539
apply (erule reflection_imp_L_separation)
paulson@13386
   540
  apply (simp_all add: lt_Ord2)
paulson@13386
   541
apply (rule DPow_LsetI)
wenzelm@13428
   542
apply (rename_tac v)
paulson@13386
   543
apply (rule bex_iff_sats conj_iff_sats)+
paulson@13386
   544
apply (rule_tac env = "[u,v,B,0,nat]" in mem_iff_sats)
paulson@13434
   545
apply (rule sep_rules is_nat_case_iff_sats formula_functor_iff_sats
paulson@13441
   546
            is_wfrec_iff_sats iterates_MH_iff_sats quasinat_iff_sats | simp)+
paulson@13386
   547
done
paulson@13386
   548
paulson@13386
   549
text{*NB The proofs for type @{term formula} are virtually identical to those
paulson@13386
   550
for @{term "list(A)"}.  It was a cut-and-paste job! *}
paulson@13386
   551
paulson@13387
   552
paulson@13437
   553
subsubsection{*The Formula @{term is_nth}, Internalized*}
paulson@13437
   554
paulson@13437
   555
(* "is_nth(M,n,l,Z) == 
paulson@13437
   556
      \<exists>X[M]. \<exists>sn[M]. \<exists>msn[M]. 
paulson@13437
   557
       2       1       0
paulson@13437
   558
       successor(M,n,sn) & membership(M,sn,msn) &
paulson@13437
   559
       is_wfrec(M, iterates_MH(M, is_tl(M), l), msn, n, X) &
paulson@13493
   560
       is_hd(M,X,Z)" *)
paulson@13437
   561
constdefs nth_fm :: "[i,i,i]=>i"
paulson@13437
   562
    "nth_fm(n,l,Z) == 
paulson@13437
   563
       Exists(Exists(Exists(
paulson@13493
   564
         And(succ_fm(n#+3,1),
paulson@13493
   565
          And(Memrel_fm(1,0),
paulson@13493
   566
           And(is_wfrec_fm(iterates_MH_fm(tl_fm(1,0),l#+8,2,1,0), 0, n#+3, 2), hd_fm(2,Z#+3)))))))"
paulson@13493
   567
paulson@13493
   568
lemma nth_fm_type [TC]:
paulson@13493
   569
 "[| x \<in> nat; y \<in> nat; z \<in> nat |] ==> nth_fm(x,y,z) \<in> formula"
paulson@13493
   570
by (simp add: nth_fm_def)
paulson@13493
   571
paulson@13493
   572
lemma sats_nth_fm [simp]:
paulson@13493
   573
   "[| x < length(env); y \<in> nat; z \<in> nat; env \<in> list(A)|]
paulson@13493
   574
    ==> sats(A, nth_fm(x,y,z), env) <->
paulson@13493
   575
        is_nth(**A, nth(x,env), nth(y,env), nth(z,env))"
paulson@13493
   576
apply (frule lt_length_in_nat, assumption)  
paulson@13493
   577
apply (simp add: nth_fm_def is_nth_def sats_is_wfrec_fm sats_iterates_MH_fm) 
paulson@13493
   578
done
paulson@13493
   579
paulson@13493
   580
lemma nth_iff_sats:
paulson@13493
   581
      "[| nth(i,env) = x; nth(j,env) = y; nth(k,env) = z;
paulson@13493
   582
          i < length(env); j \<in> nat; k \<in> nat; env \<in> list(A)|]
paulson@13493
   583
       ==> is_nth(**A, x, y, z) <-> sats(A, nth_fm(i,j,k), env)"
paulson@13493
   584
by (simp add: sats_nth_fm)
paulson@13437
   585
paulson@13437
   586
theorem nth_reflection:
paulson@13437
   587
     "REFLECTS[\<lambda>x. is_nth(L, f(x), g(x), h(x)),  
paulson@13437
   588
               \<lambda>i x. is_nth(**Lset(i), f(x), g(x), h(x))]"
paulson@13437
   589
apply (simp only: is_nth_def setclass_simps)
paulson@13437
   590
apply (intro FOL_reflections function_reflections is_wfrec_reflection 
paulson@13437
   591
             iterates_MH_reflection hd_reflection tl_reflection) 
paulson@13437
   592
done
paulson@13437
   593
paulson@13437
   594
paulson@13409
   595
subsubsection{*An Instance of Replacement for @{term nth}*}
paulson@13409
   596
paulson@13409
   597
lemma nth_replacement_Reflects:
paulson@13409
   598
 "REFLECTS
paulson@13409
   599
   [\<lambda>x. \<exists>u[L]. u \<in> B \<and> (\<exists>y[L]. pair(L,u,y,x) \<and>
paulson@13409
   600
         is_wfrec(L, iterates_MH(L, is_tl(L), z), memsn, u, y)),
paulson@13409
   601
    \<lambda>i x. \<exists>u \<in> Lset(i). u \<in> B \<and> (\<exists>y \<in> Lset(i). pair(**Lset(i), u, y, x) \<and>
wenzelm@13428
   602
         is_wfrec(**Lset(i),
wenzelm@13428
   603
                  iterates_MH(**Lset(i),
paulson@13409
   604
                          is_tl(**Lset(i)), z), memsn, u, y))]"
wenzelm@13428
   605
by (intro FOL_reflections function_reflections is_wfrec_reflection
wenzelm@13428
   606
          iterates_MH_reflection list_functor_reflection tl_reflection)
paulson@13409
   607
wenzelm@13428
   608
lemma nth_replacement:
paulson@13409
   609
   "L(w) ==> iterates_replacement(L, %l t. is_tl(L,l,t), w)"
paulson@13409
   610
apply (unfold iterates_replacement_def wfrec_replacement_def, clarify)
wenzelm@13428
   611
apply (rule strong_replacementI)
wenzelm@13428
   612
apply (rule rallI)
wenzelm@13428
   613
apply (rule separation_CollectI)
wenzelm@13428
   614
apply (subgoal_tac "L(Memrel(succ(n)))")
paulson@13505
   615
apply (rule_tac A="{A,n,w,z,Memrel(succ(n))}" in subset_LsetE, blast)
paulson@13409
   616
apply (rule ReflectsE [OF nth_replacement_Reflects], assumption)
wenzelm@13428
   617
apply (drule subset_Lset_ltD, assumption)
paulson@13409
   618
apply (erule reflection_imp_L_separation)
paulson@13409
   619
  apply (simp_all add: lt_Ord2 Memrel_closed)
wenzelm@13428
   620
apply (elim conjE)
paulson@13409
   621
apply (rule DPow_LsetI)
wenzelm@13428
   622
apply (rename_tac v)
paulson@13409
   623
apply (rule bex_iff_sats conj_iff_sats)+
paulson@13409
   624
apply (rule_tac env = "[u,v,A,z,w,Memrel(succ(n))]" in mem_iff_sats)
paulson@13434
   625
apply (rule sep_rules is_nat_case_iff_sats tl_iff_sats
paulson@13441
   626
            is_wfrec_iff_sats iterates_MH_iff_sats quasinat_iff_sats | simp)+
paulson@13409
   627
done
paulson@13409
   628
paulson@13422
   629
paulson@13422
   630
paulson@13422
   631
subsubsection{*Instantiating the locale @{text M_datatypes}*}
wenzelm@13428
   632
paulson@13437
   633
lemma M_datatypes_axioms_L: "M_datatypes_axioms(L)"
wenzelm@13428
   634
  apply (rule M_datatypes_axioms.intro)
wenzelm@13428
   635
      apply (assumption | rule
wenzelm@13428
   636
        list_replacement1 list_replacement2
wenzelm@13428
   637
        formula_replacement1 formula_replacement2
wenzelm@13428
   638
        nth_replacement)+
wenzelm@13428
   639
  done
paulson@13422
   640
paulson@13437
   641
theorem M_datatypes_L: "PROP M_datatypes(L)"
paulson@13437
   642
  apply (rule M_datatypes.intro)
paulson@13437
   643
      apply (rule M_wfrank.axioms [OF M_wfrank_L])+
paulson@13441
   644
 apply (rule M_datatypes_axioms_L) 
paulson@13437
   645
 done
paulson@13437
   646
wenzelm@13428
   647
lemmas list_closed = M_datatypes.list_closed [OF M_datatypes_L]
wenzelm@13428
   648
  and formula_closed = M_datatypes.formula_closed [OF M_datatypes_L]
wenzelm@13428
   649
  and list_abs = M_datatypes.list_abs [OF M_datatypes_L]
wenzelm@13428
   650
  and formula_abs = M_datatypes.formula_abs [OF M_datatypes_L]
wenzelm@13428
   651
  and nth_abs = M_datatypes.nth_abs [OF M_datatypes_L]
paulson@13409
   652
paulson@13422
   653
declare list_closed [intro,simp]
paulson@13422
   654
declare formula_closed [intro,simp]
paulson@13422
   655
declare list_abs [simp]
paulson@13422
   656
declare formula_abs [simp]
paulson@13422
   657
declare nth_abs [simp]
paulson@13422
   658
paulson@13422
   659
wenzelm@13428
   660
subsection{*@{term L} is Closed Under the Operator @{term eclose}*}
paulson@13422
   661
paulson@13422
   662
subsubsection{*Instances of Replacement for @{term eclose}*}
paulson@13422
   663
paulson@13422
   664
lemma eclose_replacement1_Reflects:
paulson@13422
   665
 "REFLECTS
paulson@13422
   666
   [\<lambda>x. \<exists>u[L]. u \<in> B \<and> (\<exists>y[L]. pair(L,u,y,x) \<and>
paulson@13422
   667
         is_wfrec(L, iterates_MH(L, big_union(L), A), memsn, u, y)),
paulson@13422
   668
    \<lambda>i x. \<exists>u \<in> Lset(i). u \<in> B \<and> (\<exists>y \<in> Lset(i). pair(**Lset(i), u, y, x) \<and>
wenzelm@13428
   669
         is_wfrec(**Lset(i),
wenzelm@13428
   670
                  iterates_MH(**Lset(i), big_union(**Lset(i)), A),
paulson@13422
   671
                  memsn, u, y))]"
wenzelm@13428
   672
by (intro FOL_reflections function_reflections is_wfrec_reflection
wenzelm@13428
   673
          iterates_MH_reflection)
paulson@13422
   674
wenzelm@13428
   675
lemma eclose_replacement1:
paulson@13422
   676
   "L(A) ==> iterates_replacement(L, big_union(L), A)"
paulson@13422
   677
apply (unfold iterates_replacement_def wfrec_replacement_def, clarify)
wenzelm@13428
   678
apply (rule strong_replacementI)
paulson@13422
   679
apply (rule rallI)
wenzelm@13428
   680
apply (rename_tac B)
wenzelm@13428
   681
apply (rule separation_CollectI)
wenzelm@13428
   682
apply (subgoal_tac "L(Memrel(succ(n)))")
paulson@13505
   683
apply (rule_tac A="{B,A,n,z,Memrel(succ(n))}" in subset_LsetE, blast)
paulson@13422
   684
apply (rule ReflectsE [OF eclose_replacement1_Reflects], assumption)
wenzelm@13428
   685
apply (drule subset_Lset_ltD, assumption)
paulson@13422
   686
apply (erule reflection_imp_L_separation)
paulson@13422
   687
  apply (simp_all add: lt_Ord2 Memrel_closed)
wenzelm@13428
   688
apply (elim conjE)
paulson@13422
   689
apply (rule DPow_LsetI)
wenzelm@13428
   690
apply (rename_tac v)
paulson@13422
   691
apply (rule bex_iff_sats conj_iff_sats)+
paulson@13422
   692
apply (rule_tac env = "[u,v,A,n,B,Memrel(succ(n))]" in mem_iff_sats)
paulson@13434
   693
apply (rule sep_rules iterates_MH_iff_sats is_nat_case_iff_sats
paulson@13441
   694
             is_wfrec_iff_sats big_union_iff_sats quasinat_iff_sats | simp)+
paulson@13409
   695
done
paulson@13409
   696
paulson@13422
   697
paulson@13422
   698
lemma eclose_replacement2_Reflects:
paulson@13422
   699
 "REFLECTS
paulson@13422
   700
   [\<lambda>x. \<exists>u[L]. u \<in> B \<and> u \<in> nat \<and>
paulson@13422
   701
         (\<exists>sn[L]. \<exists>msn[L]. successor(L, u, sn) \<and> membership(L, sn, msn) \<and>
paulson@13422
   702
           is_wfrec (L, iterates_MH (L, big_union(L), A),
paulson@13422
   703
                              msn, u, x)),
paulson@13422
   704
    \<lambda>i x. \<exists>u \<in> Lset(i). u \<in> B \<and> u \<in> nat \<and>
wenzelm@13428
   705
         (\<exists>sn \<in> Lset(i). \<exists>msn \<in> Lset(i).
paulson@13422
   706
          successor(**Lset(i), u, sn) \<and> membership(**Lset(i), sn, msn) \<and>
wenzelm@13428
   707
           is_wfrec (**Lset(i),
paulson@13422
   708
                 iterates_MH (**Lset(i), big_union(**Lset(i)), A),
paulson@13422
   709
                     msn, u, x))]"
wenzelm@13428
   710
by (intro FOL_reflections function_reflections is_wfrec_reflection
wenzelm@13428
   711
          iterates_MH_reflection)
paulson@13422
   712
paulson@13422
   713
wenzelm@13428
   714
lemma eclose_replacement2:
wenzelm@13428
   715
   "L(A) ==> strong_replacement(L,
wenzelm@13428
   716
         \<lambda>n y. n\<in>nat &
paulson@13422
   717
               (\<exists>sn[L]. \<exists>msn[L]. successor(L,n,sn) & membership(L,sn,msn) &
wenzelm@13428
   718
               is_wfrec(L, iterates_MH(L,big_union(L), A),
paulson@13422
   719
                        msn, n, y)))"
wenzelm@13428
   720
apply (rule strong_replacementI)
paulson@13422
   721
apply (rule rallI)
wenzelm@13428
   722
apply (rename_tac B)
wenzelm@13428
   723
apply (rule separation_CollectI)
wenzelm@13428
   724
apply (rule_tac A="{A,B,z,nat}" in subset_LsetE)
wenzelm@13428
   725
apply (blast intro: L_nat)
paulson@13422
   726
apply (rule ReflectsE [OF eclose_replacement2_Reflects], assumption)
wenzelm@13428
   727
apply (drule subset_Lset_ltD, assumption)
paulson@13422
   728
apply (erule reflection_imp_L_separation)
paulson@13422
   729
  apply (simp_all add: lt_Ord2)
paulson@13422
   730
apply (rule DPow_LsetI)
wenzelm@13428
   731
apply (rename_tac v)
paulson@13422
   732
apply (rule bex_iff_sats conj_iff_sats)+
paulson@13422
   733
apply (rule_tac env = "[u,v,A,B,nat]" in mem_iff_sats)
paulson@13434
   734
apply (rule sep_rules is_nat_case_iff_sats iterates_MH_iff_sats
paulson@13441
   735
              is_wfrec_iff_sats big_union_iff_sats quasinat_iff_sats | simp)+
paulson@13422
   736
done
paulson@13422
   737
paulson@13422
   738
paulson@13422
   739
subsubsection{*Instantiating the locale @{text M_eclose}*}
paulson@13422
   740
paulson@13437
   741
lemma M_eclose_axioms_L: "M_eclose_axioms(L)"
paulson@13437
   742
  apply (rule M_eclose_axioms.intro)
paulson@13437
   743
   apply (assumption | rule eclose_replacement1 eclose_replacement2)+
paulson@13437
   744
  done
paulson@13437
   745
wenzelm@13428
   746
theorem M_eclose_L: "PROP M_eclose(L)"
wenzelm@13428
   747
  apply (rule M_eclose.intro)
wenzelm@13429
   748
       apply (rule M_datatypes.axioms [OF M_datatypes_L])+
paulson@13437
   749
  apply (rule M_eclose_axioms_L)
wenzelm@13428
   750
  done
paulson@13422
   751
wenzelm@13428
   752
lemmas eclose_closed [intro, simp] = M_eclose.eclose_closed [OF M_eclose_L]
wenzelm@13428
   753
  and eclose_abs [intro, simp] = M_eclose.eclose_abs [OF M_eclose_L]
paulson@13440
   754
  and transrec_replacementI = M_eclose.transrec_replacementI [OF M_eclose_L]
paulson@13422
   755
paulson@13348
   756
end