src/ZF/Constructible/Rec_Separation.thy
author ballarin
Mon Apr 18 15:54:23 2005 +0200 (2005-04-18)
changeset 15766 b08feb003f3c
parent 13807 a28a8fbc76d4
child 16417 9bc16273c2d4
permissions -rw-r--r--
Cleaned up, now use interpretation.
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
paulson@13496
     8
theory Rec_Separation = Separation + Internalize:
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)))"*)
paulson@13348
    33
constdefs 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))" *)
paulson@13348
    90
constdefs 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)" *)
paulson@13348
   124
constdefs 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)"
paulson@13437
   184
by (rule M_trancl.intro
paulson@13564
   185
         [OF M_trivial_L M_basic_axioms_L M_trancl_axioms_L])
paulson@13437
   186
ballarin@15766
   187
interpretation M_trancl [L] by (rule M_trancl_axioms_L)
paulson@13363
   188
paulson@13363
   189
wenzelm@13428
   190
subsection{*@{term L} is Closed Under the Operator @{term list}*}
paulson@13363
   191
paulson@13386
   192
subsubsection{*Instances of Replacement for Lists*}
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@13428
   240
subsection{*@{term L} is Closed Under the Operator @{term formula}*}
paulson@13386
   241
paulson@13386
   242
subsubsection{*Instances of Replacement for Formulas*}
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
paulson@13386
   289
text{*NB The proofs for type @{term formula} are virtually identical to those
paulson@13386
   290
for @{term "list(A)"}.  It was a cut-and-paste job! *}
paulson@13386
   291
paulson@13387
   292
paulson@13437
   293
subsubsection{*The Formula @{term is_nth}, Internalized*}
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)" *)
paulson@13437
   297
constdefs nth_fm :: "[i,i,i]=>i"
paulson@13437
   298
    "nth_fm(n,l,Z) == 
paulson@13655
   299
       Exists(And(is_iterates_fm(tl_fm(1,0), succ(l), succ(n), 0), 
paulson@13655
   300
              hd_fm(0,succ(Z))))"
paulson@13493
   301
paulson@13493
   302
lemma nth_fm_type [TC]:
paulson@13493
   303
 "[| x \<in> nat; y \<in> nat; z \<in> nat |] ==> nth_fm(x,y,z) \<in> formula"
paulson@13493
   304
by (simp add: nth_fm_def)
paulson@13493
   305
paulson@13493
   306
lemma sats_nth_fm [simp]:
paulson@13493
   307
   "[| x < length(env); y \<in> nat; z \<in> nat; env \<in> list(A)|]
paulson@13493
   308
    ==> sats(A, nth_fm(x,y,z), env) <->
paulson@13807
   309
        is_nth(##A, nth(x,env), nth(y,env), nth(z,env))"
paulson@13493
   310
apply (frule lt_length_in_nat, assumption)  
paulson@13655
   311
apply (simp add: nth_fm_def is_nth_def sats_is_iterates_fm) 
paulson@13493
   312
done
paulson@13493
   313
paulson@13493
   314
lemma nth_iff_sats:
paulson@13493
   315
      "[| nth(i,env) = x; nth(j,env) = y; nth(k,env) = z;
paulson@13493
   316
          i < length(env); j \<in> nat; k \<in> nat; env \<in> list(A)|]
paulson@13807
   317
       ==> is_nth(##A, x, y, z) <-> sats(A, nth_fm(i,j,k), env)"
paulson@13493
   318
by (simp add: sats_nth_fm)
paulson@13437
   319
paulson@13437
   320
theorem nth_reflection:
paulson@13437
   321
     "REFLECTS[\<lambda>x. is_nth(L, f(x), g(x), h(x)),  
paulson@13807
   322
               \<lambda>i x. is_nth(##Lset(i), f(x), g(x), h(x))]"
paulson@13655
   323
apply (simp only: is_nth_def)
paulson@13655
   324
apply (intro FOL_reflections is_iterates_reflection
paulson@13655
   325
             hd_reflection tl_reflection) 
paulson@13437
   326
done
paulson@13437
   327
paulson@13437
   328
paulson@13409
   329
subsubsection{*An Instance of Replacement for @{term nth}*}
paulson@13409
   330
paulson@13655
   331
(*FIXME: could prove a lemma iterates_replacementI to eliminate the 
paulson@13655
   332
need to expand iterates_replacement and wfrec_replacement*)
paulson@13409
   333
lemma nth_replacement_Reflects:
paulson@13409
   334
 "REFLECTS
paulson@13655
   335
   [\<lambda>x. \<exists>u[L]. u \<in> B & (\<exists>y[L]. pair(L,u,y,x) &
paulson@13409
   336
         is_wfrec(L, iterates_MH(L, is_tl(L), z), memsn, u, y)),
paulson@13807
   337
    \<lambda>i x. \<exists>u \<in> Lset(i). u \<in> B & (\<exists>y \<in> Lset(i). pair(##Lset(i), u, y, x) &
paulson@13807
   338
         is_wfrec(##Lset(i),
paulson@13807
   339
                  iterates_MH(##Lset(i),
paulson@13807
   340
                          is_tl(##Lset(i)), z), memsn, u, y))]"
wenzelm@13428
   341
by (intro FOL_reflections function_reflections is_wfrec_reflection
paulson@13655
   342
          iterates_MH_reflection tl_reflection)
paulson@13409
   343
wenzelm@13428
   344
lemma nth_replacement:
paulson@13655
   345
   "L(w) ==> iterates_replacement(L, is_tl(L), w)"
paulson@13409
   346
apply (unfold iterates_replacement_def wfrec_replacement_def, clarify)
wenzelm@13428
   347
apply (rule strong_replacementI)
paulson@13687
   348
apply (rule_tac u="{B,w,Memrel(succ(n))}" 
paulson@13687
   349
         in gen_separation_multi [OF nth_replacement_Reflects], 
paulson@13687
   350
       auto)
paulson@13687
   351
apply (rule_tac env="[B,w,Memrel(succ(n))]" in DPow_LsetI)
paulson@13434
   352
apply (rule sep_rules is_nat_case_iff_sats tl_iff_sats
paulson@13441
   353
            is_wfrec_iff_sats iterates_MH_iff_sats quasinat_iff_sats | simp)+
paulson@13409
   354
done
paulson@13409
   355
paulson@13422
   356
paulson@13422
   357
subsubsection{*Instantiating the locale @{text M_datatypes}*}
wenzelm@13428
   358
paulson@13437
   359
lemma M_datatypes_axioms_L: "M_datatypes_axioms(L)"
wenzelm@13428
   360
  apply (rule M_datatypes_axioms.intro)
wenzelm@13428
   361
      apply (assumption | rule
wenzelm@13428
   362
        list_replacement1 list_replacement2
wenzelm@13428
   363
        formula_replacement1 formula_replacement2
wenzelm@13428
   364
        nth_replacement)+
wenzelm@13428
   365
  done
paulson@13422
   366
paulson@13437
   367
theorem M_datatypes_L: "PROP M_datatypes(L)"
paulson@13437
   368
  apply (rule M_datatypes.intro)
paulson@13634
   369
      apply (rule M_trancl.axioms [OF M_trancl_L])+
paulson@13441
   370
 apply (rule M_datatypes_axioms_L) 
paulson@13437
   371
 done
paulson@13437
   372
ballarin@15766
   373
interpretation M_datatypes [L] by (rule M_datatypes_axioms_L)
paulson@13422
   374
paulson@13422
   375
wenzelm@13428
   376
subsection{*@{term L} is Closed Under the Operator @{term eclose}*}
paulson@13422
   377
paulson@13422
   378
subsubsection{*Instances of Replacement for @{term eclose}*}
paulson@13422
   379
paulson@13422
   380
lemma eclose_replacement1_Reflects:
paulson@13422
   381
 "REFLECTS
paulson@13655
   382
   [\<lambda>x. \<exists>u[L]. u \<in> B & (\<exists>y[L]. pair(L,u,y,x) &
paulson@13422
   383
         is_wfrec(L, iterates_MH(L, big_union(L), A), memsn, u, y)),
paulson@13807
   384
    \<lambda>i x. \<exists>u \<in> Lset(i). u \<in> B & (\<exists>y \<in> Lset(i). pair(##Lset(i), u, y, x) &
paulson@13807
   385
         is_wfrec(##Lset(i),
paulson@13807
   386
                  iterates_MH(##Lset(i), big_union(##Lset(i)), A),
paulson@13422
   387
                  memsn, u, y))]"
wenzelm@13428
   388
by (intro FOL_reflections function_reflections is_wfrec_reflection
wenzelm@13428
   389
          iterates_MH_reflection)
paulson@13422
   390
wenzelm@13428
   391
lemma eclose_replacement1:
paulson@13422
   392
   "L(A) ==> iterates_replacement(L, big_union(L), A)"
paulson@13422
   393
apply (unfold iterates_replacement_def wfrec_replacement_def, clarify)
wenzelm@13428
   394
apply (rule strong_replacementI)
paulson@13566
   395
apply (rule_tac u="{B,A,n,Memrel(succ(n))}" 
paulson@13687
   396
         in gen_separation_multi [OF eclose_replacement1_Reflects], auto)
paulson@13687
   397
apply (rule_tac env="[B,A,n,Memrel(succ(n))]" in DPow_LsetI)
paulson@13434
   398
apply (rule sep_rules iterates_MH_iff_sats is_nat_case_iff_sats
paulson@13441
   399
             is_wfrec_iff_sats big_union_iff_sats quasinat_iff_sats | simp)+
paulson@13409
   400
done
paulson@13409
   401
paulson@13422
   402
paulson@13422
   403
lemma eclose_replacement2_Reflects:
paulson@13422
   404
 "REFLECTS
paulson@13655
   405
   [\<lambda>x. \<exists>u[L]. u \<in> B & u \<in> nat &
paulson@13655
   406
                is_iterates(L, big_union(L), A, u, x),
paulson@13655
   407
    \<lambda>i x. \<exists>u \<in> Lset(i). u \<in> B & u \<in> nat &
paulson@13807
   408
               is_iterates(##Lset(i), big_union(##Lset(i)), A, u, x)]"
paulson@13655
   409
by (intro FOL_reflections function_reflections is_iterates_reflection)
paulson@13422
   410
wenzelm@13428
   411
lemma eclose_replacement2:
wenzelm@13428
   412
   "L(A) ==> strong_replacement(L,
paulson@13655
   413
         \<lambda>n y. n\<in>nat & is_iterates(L, big_union(L), A, n, y))"
wenzelm@13428
   414
apply (rule strong_replacementI)
paulson@13566
   415
apply (rule_tac u="{A,B,nat}" 
paulson@13687
   416
         in gen_separation_multi [OF eclose_replacement2_Reflects],
paulson@13687
   417
       auto simp add: L_nat)
paulson@13687
   418
apply (rule_tac env="[A,B,nat]" in DPow_LsetI)
paulson@13655
   419
apply (rule sep_rules is_iterates_iff_sats big_union_iff_sats | simp)+
paulson@13422
   420
done
paulson@13422
   421
paulson@13422
   422
paulson@13422
   423
subsubsection{*Instantiating the locale @{text M_eclose}*}
paulson@13422
   424
paulson@13437
   425
lemma M_eclose_axioms_L: "M_eclose_axioms(L)"
paulson@13437
   426
  apply (rule M_eclose_axioms.intro)
paulson@13437
   427
   apply (assumption | rule eclose_replacement1 eclose_replacement2)+
paulson@13437
   428
  done
paulson@13437
   429
wenzelm@13428
   430
theorem M_eclose_L: "PROP M_eclose(L)"
wenzelm@13428
   431
  apply (rule M_eclose.intro)
wenzelm@13429
   432
       apply (rule M_datatypes.axioms [OF M_datatypes_L])+
paulson@13437
   433
  apply (rule M_eclose_axioms_L)
wenzelm@13428
   434
  done
paulson@13422
   435
ballarin@15766
   436
interpretation M_eclose [L] by (rule M_eclose_axioms_L)
ballarin@15766
   437
paulson@13422
   438
paulson@13348
   439
end