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