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