src/ZF/Constructible/Rec_Separation.thy
author wenzelm
Thu Dec 14 11:24:26 2017 +0100 (21 months ago)
changeset 67198 694f29a5433b
parent 61798 27f3c10b0b50
child 69593 3dda49e08b9d
permissions -rw-r--r--
merged
paulson@13437
     1
(*  Title:      ZF/Constructible/Rec_Separation.thy
paulson@13437
     2
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
paulson@13437
     3
*)
wenzelm@13429
     4
wenzelm@60770
     5
section \<open>Separation for Facts About Recursion\<close>
paulson@13348
     6
haftmann@16417
     7
theory Rec_Separation imports Separation Internalize begin
paulson@13348
     8
wenzelm@61798
     9
text\<open>This theory proves all instances needed for locales \<open>M_trancl\<close> and \<open>M_datatypes\<close>\<close>
paulson@13348
    10
paulson@13363
    11
lemma eq_succ_imp_lt: "[|i = succ(j); Ord(i)|] ==> j<i"
wenzelm@13428
    12
by simp
paulson@13363
    13
paulson@13493
    14
wenzelm@61798
    15
subsection\<open>The Locale \<open>M_trancl\<close>\<close>
paulson@13348
    16
wenzelm@60770
    17
subsubsection\<open>Separation for Reflexive/Transitive Closure\<close>
paulson@13348
    18
wenzelm@60770
    19
text\<open>First, The Defining Formula\<close>
paulson@13348
    20
paulson@13348
    21
(* "rtran_closure_mem(M,A,r,p) ==
wenzelm@13428
    22
      \<exists>nnat[M]. \<exists>n[M]. \<exists>n'[M].
paulson@13348
    23
       omega(M,nnat) & n\<in>nnat & successor(M,n,n') &
paulson@13348
    24
       (\<exists>f[M]. typed_function(M,n',A,f) &
wenzelm@13428
    25
        (\<exists>x[M]. \<exists>y[M]. \<exists>zero[M]. pair(M,x,y,p) & empty(M,zero) &
wenzelm@13428
    26
          fun_apply(M,f,zero,x) & fun_apply(M,f,n,y)) &
paulson@46823
    27
        (\<forall>j[M]. j\<in>n \<longrightarrow>
wenzelm@13428
    28
          (\<exists>fj[M]. \<exists>sj[M]. \<exists>fsj[M]. \<exists>ffp[M].
wenzelm@13428
    29
            fun_apply(M,f,j,fj) & successor(M,j,sj) &
wenzelm@13428
    30
            fun_apply(M,f,sj,fsj) & pair(M,fj,fsj,ffp) & ffp \<in> r)))"*)
wenzelm@21404
    31
definition
wenzelm@21404
    32
  rtran_closure_mem_fm :: "[i,i,i]=>i" where
wenzelm@13428
    33
 "rtran_closure_mem_fm(A,r,p) ==
paulson@13348
    34
   Exists(Exists(Exists(
paulson@13348
    35
    And(omega_fm(2),
paulson@13348
    36
     And(Member(1,2),
paulson@13348
    37
      And(succ_fm(1,0),
paulson@13348
    38
       Exists(And(typed_function_fm(1, A#+4, 0),
wenzelm@13428
    39
        And(Exists(Exists(Exists(
wenzelm@13428
    40
              And(pair_fm(2,1,p#+7),
wenzelm@13428
    41
               And(empty_fm(0),
wenzelm@13428
    42
                And(fun_apply_fm(3,0,2), fun_apply_fm(3,5,1))))))),
wenzelm@13428
    43
            Forall(Implies(Member(0,3),
wenzelm@13428
    44
             Exists(Exists(Exists(Exists(
wenzelm@13428
    45
              And(fun_apply_fm(5,4,3),
wenzelm@13428
    46
               And(succ_fm(4,2),
wenzelm@13428
    47
                And(fun_apply_fm(5,2,1),
wenzelm@13428
    48
                 And(pair_fm(3,1,0), Member(0,r#+9))))))))))))))))))))"
paulson@13348
    49
paulson@13348
    50
paulson@13348
    51
lemma rtran_closure_mem_type [TC]:
paulson@13348
    52
 "[| x \<in> nat; y \<in> nat; z \<in> nat |] ==> rtran_closure_mem_fm(x,y,z) \<in> formula"
wenzelm@13428
    53
by (simp add: rtran_closure_mem_fm_def)
paulson@13348
    54
paulson@13348
    55
lemma sats_rtran_closure_mem_fm [simp]:
paulson@13348
    56
   "[| x \<in> nat; y \<in> nat; z \<in> nat; env \<in> list(A)|]
paulson@46823
    57
    ==> sats(A, rtran_closure_mem_fm(x,y,z), env) \<longleftrightarrow>
paulson@13807
    58
        rtran_closure_mem(##A, nth(x,env), nth(y,env), nth(z,env))"
paulson@13348
    59
by (simp add: rtran_closure_mem_fm_def rtran_closure_mem_def)
paulson@13348
    60
paulson@13348
    61
lemma rtran_closure_mem_iff_sats:
wenzelm@13428
    62
      "[| nth(i,env) = x; nth(j,env) = y; nth(k,env) = z;
paulson@13348
    63
          i \<in> nat; j \<in> nat; k \<in> nat; env \<in> list(A)|]
paulson@46823
    64
       ==> rtran_closure_mem(##A, x, y, z) \<longleftrightarrow> sats(A, rtran_closure_mem_fm(i,j,k), env)"
paulson@13348
    65
by (simp add: sats_rtran_closure_mem_fm)
paulson@13348
    66
paulson@13566
    67
lemma rtran_closure_mem_reflection:
wenzelm@13428
    68
     "REFLECTS[\<lambda>x. rtran_closure_mem(L,f(x),g(x),h(x)),
paulson@13807
    69
               \<lambda>i x. rtran_closure_mem(##Lset(i),f(x),g(x),h(x))]"
paulson@13655
    70
apply (simp only: rtran_closure_mem_def)
wenzelm@13428
    71
apply (intro FOL_reflections function_reflections fun_plus_reflections)
paulson@13348
    72
done
paulson@13348
    73
wenzelm@60770
    74
text\<open>Separation for @{term "rtrancl(r)"}.\<close>
paulson@13348
    75
lemma rtrancl_separation:
paulson@13348
    76
     "[| L(r); L(A) |] ==> separation (L, rtran_closure_mem(L,A,r))"
paulson@13687
    77
apply (rule gen_separation_multi [OF rtran_closure_mem_reflection, of "{r,A}"],
paulson@13687
    78
       auto)
paulson@13687
    79
apply (rule_tac env="[r,A]" in DPow_LsetI)
paulson@13687
    80
apply (rule rtran_closure_mem_iff_sats sep_rules | simp)+
paulson@13348
    81
done
paulson@13348
    82
paulson@13348
    83
wenzelm@60770
    84
subsubsection\<open>Reflexive/Transitive Closure, Internalized\<close>
paulson@13348
    85
wenzelm@13428
    86
(*  "rtran_closure(M,r,s) ==
paulson@46823
    87
        \<forall>A[M]. is_field(M,r,A) \<longrightarrow>
paulson@46823
    88
         (\<forall>p[M]. p \<in> s \<longleftrightarrow> rtran_closure_mem(M,A,r,p))" *)
wenzelm@21404
    89
definition
wenzelm@21404
    90
  rtran_closure_fm :: "[i,i]=>i" where
wenzelm@21404
    91
  "rtran_closure_fm(r,s) ==
paulson@13348
    92
   Forall(Implies(field_fm(succ(r),0),
paulson@13348
    93
                  Forall(Iff(Member(0,succ(succ(s))),
paulson@13348
    94
                             rtran_closure_mem_fm(1,succ(succ(r)),0)))))"
paulson@13348
    95
paulson@13348
    96
lemma rtran_closure_type [TC]:
paulson@13348
    97
     "[| x \<in> nat; y \<in> nat |] ==> rtran_closure_fm(x,y) \<in> formula"
wenzelm@13428
    98
by (simp add: rtran_closure_fm_def)
paulson@13348
    99
paulson@13348
   100
lemma sats_rtran_closure_fm [simp]:
paulson@13348
   101
   "[| x \<in> nat; y \<in> nat; env \<in> list(A)|]
paulson@46823
   102
    ==> sats(A, rtran_closure_fm(x,y), env) \<longleftrightarrow>
paulson@13807
   103
        rtran_closure(##A, nth(x,env), nth(y,env))"
paulson@13348
   104
by (simp add: rtran_closure_fm_def rtran_closure_def)
paulson@13348
   105
paulson@13348
   106
lemma rtran_closure_iff_sats:
wenzelm@13428
   107
      "[| nth(i,env) = x; nth(j,env) = y;
paulson@13348
   108
          i \<in> nat; j \<in> nat; env \<in> list(A)|]
paulson@46823
   109
       ==> rtran_closure(##A, x, y) \<longleftrightarrow> sats(A, rtran_closure_fm(i,j), env)"
paulson@13348
   110
by simp
paulson@13348
   111
paulson@13348
   112
theorem rtran_closure_reflection:
wenzelm@13428
   113
     "REFLECTS[\<lambda>x. rtran_closure(L,f(x),g(x)),
paulson@13807
   114
               \<lambda>i x. rtran_closure(##Lset(i),f(x),g(x))]"
paulson@13655
   115
apply (simp only: rtran_closure_def)
paulson@13348
   116
apply (intro FOL_reflections function_reflections rtran_closure_mem_reflection)
paulson@13348
   117
done
paulson@13348
   118
paulson@13348
   119
wenzelm@60770
   120
subsubsection\<open>Transitive Closure of a Relation, Internalized\<close>
paulson@13348
   121
paulson@13348
   122
(*  "tran_closure(M,r,t) ==
paulson@13348
   123
         \<exists>s[M]. rtran_closure(M,r,s) & composition(M,r,s,t)" *)
wenzelm@21404
   124
definition
wenzelm@21404
   125
  tran_closure_fm :: "[i,i]=>i" where
wenzelm@21404
   126
  "tran_closure_fm(r,s) ==
paulson@13348
   127
   Exists(And(rtran_closure_fm(succ(r),0), composition_fm(succ(r),0,succ(s))))"
paulson@13348
   128
paulson@13348
   129
lemma tran_closure_type [TC]:
paulson@13348
   130
     "[| x \<in> nat; y \<in> nat |] ==> tran_closure_fm(x,y) \<in> formula"
wenzelm@13428
   131
by (simp add: tran_closure_fm_def)
paulson@13348
   132
paulson@13348
   133
lemma sats_tran_closure_fm [simp]:
paulson@13348
   134
   "[| x \<in> nat; y \<in> nat; env \<in> list(A)|]
paulson@46823
   135
    ==> sats(A, tran_closure_fm(x,y), env) \<longleftrightarrow>
paulson@13807
   136
        tran_closure(##A, nth(x,env), nth(y,env))"
paulson@13348
   137
by (simp add: tran_closure_fm_def tran_closure_def)
paulson@13348
   138
paulson@13348
   139
lemma tran_closure_iff_sats:
wenzelm@13428
   140
      "[| nth(i,env) = x; nth(j,env) = y;
paulson@13348
   141
          i \<in> nat; j \<in> nat; env \<in> list(A)|]
paulson@46823
   142
       ==> tran_closure(##A, x, y) \<longleftrightarrow> sats(A, tran_closure_fm(i,j), env)"
paulson@13348
   143
by simp
paulson@13348
   144
paulson@13348
   145
theorem tran_closure_reflection:
wenzelm@13428
   146
     "REFLECTS[\<lambda>x. tran_closure(L,f(x),g(x)),
paulson@13807
   147
               \<lambda>i x. tran_closure(##Lset(i),f(x),g(x))]"
paulson@13655
   148
apply (simp only: tran_closure_def)
wenzelm@13428
   149
apply (intro FOL_reflections function_reflections
paulson@13348
   150
             rtran_closure_reflection composition_reflection)
paulson@13348
   151
done
paulson@13348
   152
paulson@13348
   153
wenzelm@61798
   154
subsubsection\<open>Separation for the Proof of \<open>wellfounded_on_trancl\<close>\<close>
paulson@13348
   155
paulson@13348
   156
lemma wellfounded_trancl_reflects:
wenzelm@13428
   157
  "REFLECTS[\<lambda>x. \<exists>w[L]. \<exists>wx[L]. \<exists>rp[L].
wenzelm@13428
   158
                 w \<in> Z & pair(L,w,x,wx) & tran_closure(L,r,rp) & wx \<in> rp,
wenzelm@13428
   159
   \<lambda>i x. \<exists>w \<in> Lset(i). \<exists>wx \<in> Lset(i). \<exists>rp \<in> Lset(i).
paulson@13807
   160
       w \<in> Z & pair(##Lset(i),w,x,wx) & tran_closure(##Lset(i),r,rp) &
paulson@13348
   161
       wx \<in> rp]"
wenzelm@13428
   162
by (intro FOL_reflections function_reflections fun_plus_reflections
paulson@13348
   163
          tran_closure_reflection)
paulson@13348
   164
paulson@13348
   165
lemma wellfounded_trancl_separation:
wenzelm@13428
   166
         "[| L(r); L(Z) |] ==>
wenzelm@13428
   167
          separation (L, \<lambda>x.
wenzelm@13428
   168
              \<exists>w[L]. \<exists>wx[L]. \<exists>rp[L].
wenzelm@13428
   169
               w \<in> Z & pair(L,w,x,wx) & tran_closure(L,r,rp) & wx \<in> rp)"
paulson@13687
   170
apply (rule gen_separation_multi [OF wellfounded_trancl_reflects, of "{r,Z}"],
paulson@13687
   171
       auto)
paulson@13687
   172
apply (rule_tac env="[r,Z]" in DPow_LsetI)
paulson@13348
   173
apply (rule sep_rules tran_closure_iff_sats | simp)+
paulson@13348
   174
done
paulson@13348
   175
paulson@13363
   176
wenzelm@61798
   177
subsubsection\<open>Instantiating the locale \<open>M_trancl\<close>\<close>
wenzelm@13428
   178
paulson@13437
   179
lemma M_trancl_axioms_L: "M_trancl_axioms(L)"
wenzelm@13428
   180
  apply (rule M_trancl_axioms.intro)
paulson@13437
   181
   apply (assumption | rule rtrancl_separation wellfounded_trancl_separation)+
wenzelm@13428
   182
  done
paulson@13363
   183
paulson@13437
   184
theorem M_trancl_L: "PROP M_trancl(L)"
ballarin@19931
   185
by (rule M_trancl.intro [OF M_basic_L M_trancl_axioms_L])
paulson@13437
   186
wenzelm@30729
   187
interpretation L?: M_trancl L by (rule M_trancl_L)
paulson@13363
   188
paulson@13363
   189
wenzelm@60770
   190
subsection\<open>@{term L} is Closed Under the Operator @{term list}\<close>
paulson@13363
   191
wenzelm@60770
   192
subsubsection\<open>Instances of Replacement for Lists\<close>
paulson@13386
   193
paulson@13363
   194
lemma list_replacement1_Reflects:
paulson@13363
   195
 "REFLECTS
paulson@13363
   196
   [\<lambda>x. \<exists>u[L]. u \<in> B \<and> (\<exists>y[L]. pair(L,u,y,x) \<and>
paulson@13363
   197
         is_wfrec(L, iterates_MH(L, is_list_functor(L,A), 0), memsn, u, y)),
paulson@13807
   198
    \<lambda>i x. \<exists>u \<in> Lset(i). u \<in> B \<and> (\<exists>y \<in> Lset(i). pair(##Lset(i), u, y, x) \<and>
paulson@13807
   199
         is_wfrec(##Lset(i),
paulson@13807
   200
                  iterates_MH(##Lset(i),
paulson@13807
   201
                          is_list_functor(##Lset(i), A), 0), memsn, u, y))]"
wenzelm@13428
   202
by (intro FOL_reflections function_reflections is_wfrec_reflection
wenzelm@13428
   203
          iterates_MH_reflection list_functor_reflection)
paulson@13363
   204
paulson@13441
   205
wenzelm@13428
   206
lemma list_replacement1:
paulson@13363
   207
   "L(A) ==> iterates_replacement(L, is_list_functor(L,A), 0)"
paulson@13363
   208
apply (unfold iterates_replacement_def wfrec_replacement_def, clarify)
wenzelm@13428
   209
apply (rule strong_replacementI)
paulson@13566
   210
apply (rule_tac u="{B,A,n,0,Memrel(succ(n))}" 
paulson@13687
   211
         in gen_separation_multi [OF list_replacement1_Reflects], 
paulson@13687
   212
       auto simp add: nonempty)
paulson@13687
   213
apply (rule_tac env="[B,A,n,0,Memrel(succ(n))]" in DPow_LsetI)
paulson@13434
   214
apply (rule sep_rules is_nat_case_iff_sats list_functor_iff_sats
paulson@13441
   215
            is_wfrec_iff_sats iterates_MH_iff_sats quasinat_iff_sats | simp)+
paulson@13363
   216
done
paulson@13363
   217
paulson@13441
   218
paulson@13363
   219
lemma list_replacement2_Reflects:
paulson@13363
   220
 "REFLECTS
paulson@13655
   221
   [\<lambda>x. \<exists>u[L]. u \<in> B & u \<in> nat &
paulson@13655
   222
                is_iterates(L, is_list_functor(L, A), 0, u, x),
paulson@13655
   223
    \<lambda>i x. \<exists>u \<in> Lset(i). u \<in> B & u \<in> nat &
paulson@13807
   224
               is_iterates(##Lset(i), is_list_functor(##Lset(i), A), 0, u, x)]"
paulson@13655
   225
by (intro FOL_reflections 
paulson@13655
   226
          is_iterates_reflection list_functor_reflection)
paulson@13363
   227
wenzelm@13428
   228
lemma list_replacement2:
wenzelm@13428
   229
   "L(A) ==> strong_replacement(L,
paulson@13655
   230
         \<lambda>n y. n\<in>nat & is_iterates(L, is_list_functor(L,A), 0, n, y))"
wenzelm@13428
   231
apply (rule strong_replacementI)
paulson@13566
   232
apply (rule_tac u="{A,B,0,nat}" 
paulson@13687
   233
         in gen_separation_multi [OF list_replacement2_Reflects], 
paulson@13687
   234
       auto simp add: L_nat nonempty)
paulson@13687
   235
apply (rule_tac env="[A,B,0,nat]" in DPow_LsetI)
paulson@13655
   236
apply (rule sep_rules list_functor_iff_sats is_iterates_iff_sats | simp)+
paulson@13363
   237
done
paulson@13363
   238
paulson@13386
   239
wenzelm@60770
   240
subsection\<open>@{term L} is Closed Under the Operator @{term formula}\<close>
paulson@13386
   241
wenzelm@60770
   242
subsubsection\<open>Instances of Replacement for Formulas\<close>
paulson@13386
   243
paulson@13655
   244
(*FIXME: could prove a lemma iterates_replacementI to eliminate the 
paulson@13655
   245
need to expand iterates_replacement and wfrec_replacement*)
paulson@13386
   246
lemma formula_replacement1_Reflects:
paulson@13386
   247
 "REFLECTS
paulson@13655
   248
   [\<lambda>x. \<exists>u[L]. u \<in> B & (\<exists>y[L]. pair(L,u,y,x) &
paulson@13386
   249
         is_wfrec(L, iterates_MH(L, is_formula_functor(L), 0), memsn, u, y)),
paulson@13807
   250
    \<lambda>i x. \<exists>u \<in> Lset(i). u \<in> B & (\<exists>y \<in> Lset(i). pair(##Lset(i), u, y, x) &
paulson@13807
   251
         is_wfrec(##Lset(i),
paulson@13807
   252
                  iterates_MH(##Lset(i),
paulson@13807
   253
                          is_formula_functor(##Lset(i)), 0), memsn, u, y))]"
wenzelm@13428
   254
by (intro FOL_reflections function_reflections is_wfrec_reflection
wenzelm@13428
   255
          iterates_MH_reflection formula_functor_reflection)
paulson@13386
   256
wenzelm@13428
   257
lemma formula_replacement1:
paulson@13386
   258
   "iterates_replacement(L, is_formula_functor(L), 0)"
paulson@13386
   259
apply (unfold iterates_replacement_def wfrec_replacement_def, clarify)
wenzelm@13428
   260
apply (rule strong_replacementI)
paulson@13566
   261
apply (rule_tac u="{B,n,0,Memrel(succ(n))}" 
paulson@13687
   262
         in gen_separation_multi [OF formula_replacement1_Reflects], 
paulson@13687
   263
       auto simp add: nonempty)
paulson@13687
   264
apply (rule_tac env="[n,B,0,Memrel(succ(n))]" in DPow_LsetI)
paulson@13434
   265
apply (rule sep_rules is_nat_case_iff_sats formula_functor_iff_sats
paulson@13441
   266
            is_wfrec_iff_sats iterates_MH_iff_sats quasinat_iff_sats | simp)+
paulson@13386
   267
done
paulson@13386
   268
paulson@13386
   269
lemma formula_replacement2_Reflects:
paulson@13386
   270
 "REFLECTS
paulson@13655
   271
   [\<lambda>x. \<exists>u[L]. u \<in> B & u \<in> nat &
paulson@13655
   272
                is_iterates(L, is_formula_functor(L), 0, u, x),
paulson@13655
   273
    \<lambda>i x. \<exists>u \<in> Lset(i). u \<in> B & u \<in> nat &
paulson@13807
   274
               is_iterates(##Lset(i), is_formula_functor(##Lset(i)), 0, u, x)]"
paulson@13655
   275
by (intro FOL_reflections 
paulson@13655
   276
          is_iterates_reflection formula_functor_reflection)
paulson@13386
   277
wenzelm@13428
   278
lemma formula_replacement2:
wenzelm@13428
   279
   "strong_replacement(L,
paulson@13655
   280
         \<lambda>n y. n\<in>nat & is_iterates(L, is_formula_functor(L), 0, n, y))"
wenzelm@13428
   281
apply (rule strong_replacementI)
paulson@13566
   282
apply (rule_tac u="{B,0,nat}" 
paulson@13687
   283
         in gen_separation_multi [OF formula_replacement2_Reflects], 
paulson@13687
   284
       auto simp add: nonempty L_nat)
paulson@13687
   285
apply (rule_tac env="[B,0,nat]" in DPow_LsetI)
paulson@13655
   286
apply (rule sep_rules formula_functor_iff_sats is_iterates_iff_sats | simp)+
paulson@13386
   287
done
paulson@13386
   288
wenzelm@60770
   289
text\<open>NB The proofs for type @{term formula} are virtually identical to those
wenzelm@60770
   290
for @{term "list(A)"}.  It was a cut-and-paste job!\<close>
paulson@13386
   291
paulson@13387
   292
wenzelm@60770
   293
subsubsection\<open>The Formula @{term is_nth}, Internalized\<close>
paulson@13437
   294
paulson@13655
   295
(* "is_nth(M,n,l,Z) ==
paulson@13655
   296
      \<exists>X[M]. is_iterates(M, is_tl(M), l, n, X) & is_hd(M,X,Z)" *)
wenzelm@21404
   297
definition
wenzelm@21404
   298
  nth_fm :: "[i,i,i]=>i" where
paulson@13437
   299
    "nth_fm(n,l,Z) == 
paulson@13655
   300
       Exists(And(is_iterates_fm(tl_fm(1,0), succ(l), succ(n), 0), 
paulson@13655
   301
              hd_fm(0,succ(Z))))"
paulson@13493
   302
paulson@13493
   303
lemma nth_fm_type [TC]:
paulson@13493
   304
 "[| x \<in> nat; y \<in> nat; z \<in> nat |] ==> nth_fm(x,y,z) \<in> formula"
paulson@13493
   305
by (simp add: nth_fm_def)
paulson@13493
   306
paulson@13493
   307
lemma sats_nth_fm [simp]:
paulson@13493
   308
   "[| x < length(env); y \<in> nat; z \<in> nat; env \<in> list(A)|]
paulson@46823
   309
    ==> sats(A, nth_fm(x,y,z), env) \<longleftrightarrow>
paulson@13807
   310
        is_nth(##A, nth(x,env), nth(y,env), nth(z,env))"
paulson@13493
   311
apply (frule lt_length_in_nat, assumption)  
paulson@13655
   312
apply (simp add: nth_fm_def is_nth_def sats_is_iterates_fm) 
paulson@13493
   313
done
paulson@13493
   314
paulson@13493
   315
lemma nth_iff_sats:
paulson@13493
   316
      "[| nth(i,env) = x; nth(j,env) = y; nth(k,env) = z;
paulson@13493
   317
          i < length(env); j \<in> nat; k \<in> nat; env \<in> list(A)|]
paulson@46823
   318
       ==> is_nth(##A, x, y, z) \<longleftrightarrow> sats(A, nth_fm(i,j,k), env)"
paulson@13493
   319
by (simp add: sats_nth_fm)
paulson@13437
   320
paulson@13437
   321
theorem nth_reflection:
paulson@13437
   322
     "REFLECTS[\<lambda>x. is_nth(L, f(x), g(x), h(x)),  
paulson@13807
   323
               \<lambda>i x. is_nth(##Lset(i), f(x), g(x), h(x))]"
paulson@13655
   324
apply (simp only: is_nth_def)
paulson@13655
   325
apply (intro FOL_reflections is_iterates_reflection
paulson@13655
   326
             hd_reflection tl_reflection) 
paulson@13437
   327
done
paulson@13437
   328
paulson@13437
   329
wenzelm@60770
   330
subsubsection\<open>An Instance of Replacement for @{term nth}\<close>
paulson@13409
   331
paulson@13655
   332
(*FIXME: could prove a lemma iterates_replacementI to eliminate the 
paulson@13655
   333
need to expand iterates_replacement and wfrec_replacement*)
paulson@13409
   334
lemma nth_replacement_Reflects:
paulson@13409
   335
 "REFLECTS
paulson@13655
   336
   [\<lambda>x. \<exists>u[L]. u \<in> B & (\<exists>y[L]. pair(L,u,y,x) &
paulson@13409
   337
         is_wfrec(L, iterates_MH(L, is_tl(L), z), memsn, u, y)),
paulson@13807
   338
    \<lambda>i x. \<exists>u \<in> Lset(i). u \<in> B & (\<exists>y \<in> Lset(i). pair(##Lset(i), u, y, x) &
paulson@13807
   339
         is_wfrec(##Lset(i),
paulson@13807
   340
                  iterates_MH(##Lset(i),
paulson@13807
   341
                          is_tl(##Lset(i)), z), memsn, u, y))]"
wenzelm@13428
   342
by (intro FOL_reflections function_reflections is_wfrec_reflection
paulson@13655
   343
          iterates_MH_reflection tl_reflection)
paulson@13409
   344
wenzelm@13428
   345
lemma nth_replacement:
paulson@13655
   346
   "L(w) ==> iterates_replacement(L, is_tl(L), w)"
paulson@13409
   347
apply (unfold iterates_replacement_def wfrec_replacement_def, clarify)
wenzelm@13428
   348
apply (rule strong_replacementI)
paulson@13687
   349
apply (rule_tac u="{B,w,Memrel(succ(n))}" 
paulson@13687
   350
         in gen_separation_multi [OF nth_replacement_Reflects], 
paulson@13687
   351
       auto)
paulson@13687
   352
apply (rule_tac env="[B,w,Memrel(succ(n))]" in DPow_LsetI)
paulson@13434
   353
apply (rule sep_rules is_nat_case_iff_sats tl_iff_sats
paulson@13441
   354
            is_wfrec_iff_sats iterates_MH_iff_sats quasinat_iff_sats | simp)+
paulson@13409
   355
done
paulson@13409
   356
paulson@13422
   357
wenzelm@61798
   358
subsubsection\<open>Instantiating the locale \<open>M_datatypes\<close>\<close>
wenzelm@13428
   359
paulson@13437
   360
lemma M_datatypes_axioms_L: "M_datatypes_axioms(L)"
wenzelm@13428
   361
  apply (rule M_datatypes_axioms.intro)
wenzelm@13428
   362
      apply (assumption | rule
wenzelm@13428
   363
        list_replacement1 list_replacement2
wenzelm@13428
   364
        formula_replacement1 formula_replacement2
wenzelm@13428
   365
        nth_replacement)+
wenzelm@13428
   366
  done
paulson@13422
   367
paulson@13437
   368
theorem M_datatypes_L: "PROP M_datatypes(L)"
paulson@13437
   369
  apply (rule M_datatypes.intro)
ballarin@19931
   370
   apply (rule M_trancl_L)
ballarin@19931
   371
  apply (rule M_datatypes_axioms_L) 
ballarin@19931
   372
  done
paulson@13437
   373
wenzelm@30729
   374
interpretation L?: M_datatypes L by (rule M_datatypes_L)
paulson@13422
   375
paulson@13422
   376
wenzelm@60770
   377
subsection\<open>@{term L} is Closed Under the Operator @{term eclose}\<close>
paulson@13422
   378
wenzelm@60770
   379
subsubsection\<open>Instances of Replacement for @{term eclose}\<close>
paulson@13422
   380
paulson@13422
   381
lemma eclose_replacement1_Reflects:
paulson@13422
   382
 "REFLECTS
paulson@13655
   383
   [\<lambda>x. \<exists>u[L]. u \<in> B & (\<exists>y[L]. pair(L,u,y,x) &
paulson@13422
   384
         is_wfrec(L, iterates_MH(L, big_union(L), A), memsn, u, y)),
paulson@13807
   385
    \<lambda>i x. \<exists>u \<in> Lset(i). u \<in> B & (\<exists>y \<in> Lset(i). pair(##Lset(i), u, y, x) &
paulson@13807
   386
         is_wfrec(##Lset(i),
paulson@13807
   387
                  iterates_MH(##Lset(i), big_union(##Lset(i)), A),
paulson@13422
   388
                  memsn, u, y))]"
wenzelm@13428
   389
by (intro FOL_reflections function_reflections is_wfrec_reflection
wenzelm@13428
   390
          iterates_MH_reflection)
paulson@13422
   391
wenzelm@13428
   392
lemma eclose_replacement1:
paulson@13422
   393
   "L(A) ==> iterates_replacement(L, big_union(L), A)"
paulson@13422
   394
apply (unfold iterates_replacement_def wfrec_replacement_def, clarify)
wenzelm@13428
   395
apply (rule strong_replacementI)
paulson@13566
   396
apply (rule_tac u="{B,A,n,Memrel(succ(n))}" 
paulson@13687
   397
         in gen_separation_multi [OF eclose_replacement1_Reflects], auto)
paulson@13687
   398
apply (rule_tac env="[B,A,n,Memrel(succ(n))]" in DPow_LsetI)
paulson@13434
   399
apply (rule sep_rules iterates_MH_iff_sats is_nat_case_iff_sats
paulson@13441
   400
             is_wfrec_iff_sats big_union_iff_sats quasinat_iff_sats | simp)+
paulson@13409
   401
done
paulson@13409
   402
paulson@13422
   403
paulson@13422
   404
lemma eclose_replacement2_Reflects:
paulson@13422
   405
 "REFLECTS
paulson@13655
   406
   [\<lambda>x. \<exists>u[L]. u \<in> B & u \<in> nat &
paulson@13655
   407
                is_iterates(L, big_union(L), A, u, x),
paulson@13655
   408
    \<lambda>i x. \<exists>u \<in> Lset(i). u \<in> B & u \<in> nat &
paulson@13807
   409
               is_iterates(##Lset(i), big_union(##Lset(i)), A, u, x)]"
paulson@13655
   410
by (intro FOL_reflections function_reflections is_iterates_reflection)
paulson@13422
   411
wenzelm@13428
   412
lemma eclose_replacement2:
wenzelm@13428
   413
   "L(A) ==> strong_replacement(L,
paulson@13655
   414
         \<lambda>n y. n\<in>nat & is_iterates(L, big_union(L), A, n, y))"
wenzelm@13428
   415
apply (rule strong_replacementI)
paulson@13566
   416
apply (rule_tac u="{A,B,nat}" 
paulson@13687
   417
         in gen_separation_multi [OF eclose_replacement2_Reflects],
paulson@13687
   418
       auto simp add: L_nat)
paulson@13687
   419
apply (rule_tac env="[A,B,nat]" in DPow_LsetI)
paulson@13655
   420
apply (rule sep_rules is_iterates_iff_sats big_union_iff_sats | simp)+
paulson@13422
   421
done
paulson@13422
   422
paulson@13422
   423
wenzelm@61798
   424
subsubsection\<open>Instantiating the locale \<open>M_eclose\<close>\<close>
paulson@13422
   425
paulson@13437
   426
lemma M_eclose_axioms_L: "M_eclose_axioms(L)"
paulson@13437
   427
  apply (rule M_eclose_axioms.intro)
paulson@13437
   428
   apply (assumption | rule eclose_replacement1 eclose_replacement2)+
paulson@13437
   429
  done
paulson@13437
   430
wenzelm@13428
   431
theorem M_eclose_L: "PROP M_eclose(L)"
wenzelm@13428
   432
  apply (rule M_eclose.intro)
ballarin@19931
   433
   apply (rule M_datatypes_L)
paulson@13437
   434
  apply (rule M_eclose_axioms_L)
wenzelm@13428
   435
  done
paulson@13422
   436
wenzelm@30729
   437
interpretation L?: M_eclose L by (rule M_eclose_L)
ballarin@15766
   438
paulson@13422
   439
paulson@13348
   440
end