src/ZF/Constructible/Rec_Separation.thy
author paulson
Thu Feb 06 11:01:05 2003 +0100 (2003-02-06)
changeset 13807 a28a8fbc76d4
parent 13687 22dce9134953
child 15766 b08feb003f3c
permissions -rw-r--r--
changed ** to ## to avoid conflict with new comment syntax
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
wenzelm@13428
   187
lemmas iterates_abs = M_trancl.iterates_abs [OF M_trancl_L]
wenzelm@13428
   188
  and rtran_closure_rtrancl = M_trancl.rtran_closure_rtrancl [OF M_trancl_L]
wenzelm@13428
   189
  and trans_wfrec_abs = M_trancl.trans_wfrec_abs [OF M_trancl_L]
wenzelm@13428
   190
  and eq_pair_wfrec_iff = M_trancl.eq_pair_wfrec_iff [OF M_trancl_L]
paulson@13363
   191
paulson@13363
   192
paulson@13363
   193
wenzelm@13428
   194
subsection{*@{term L} is Closed Under the Operator @{term list}*}
paulson@13363
   195
paulson@13386
   196
subsubsection{*Instances of Replacement for Lists*}
paulson@13386
   197
paulson@13363
   198
lemma list_replacement1_Reflects:
paulson@13363
   199
 "REFLECTS
paulson@13363
   200
   [\<lambda>x. \<exists>u[L]. u \<in> B \<and> (\<exists>y[L]. pair(L,u,y,x) \<and>
paulson@13363
   201
         is_wfrec(L, iterates_MH(L, is_list_functor(L,A), 0), memsn, u, y)),
paulson@13807
   202
    \<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
   203
         is_wfrec(##Lset(i),
paulson@13807
   204
                  iterates_MH(##Lset(i),
paulson@13807
   205
                          is_list_functor(##Lset(i), A), 0), memsn, u, y))]"
wenzelm@13428
   206
by (intro FOL_reflections function_reflections is_wfrec_reflection
wenzelm@13428
   207
          iterates_MH_reflection list_functor_reflection)
paulson@13363
   208
paulson@13441
   209
wenzelm@13428
   210
lemma list_replacement1:
paulson@13363
   211
   "L(A) ==> iterates_replacement(L, is_list_functor(L,A), 0)"
paulson@13363
   212
apply (unfold iterates_replacement_def wfrec_replacement_def, clarify)
wenzelm@13428
   213
apply (rule strong_replacementI)
paulson@13566
   214
apply (rule_tac u="{B,A,n,0,Memrel(succ(n))}" 
paulson@13687
   215
         in gen_separation_multi [OF list_replacement1_Reflects], 
paulson@13687
   216
       auto simp add: nonempty)
paulson@13687
   217
apply (rule_tac env="[B,A,n,0,Memrel(succ(n))]" in DPow_LsetI)
paulson@13434
   218
apply (rule sep_rules is_nat_case_iff_sats list_functor_iff_sats
paulson@13441
   219
            is_wfrec_iff_sats iterates_MH_iff_sats quasinat_iff_sats | simp)+
paulson@13363
   220
done
paulson@13363
   221
paulson@13441
   222
paulson@13363
   223
lemma list_replacement2_Reflects:
paulson@13363
   224
 "REFLECTS
paulson@13655
   225
   [\<lambda>x. \<exists>u[L]. u \<in> B & u \<in> nat &
paulson@13655
   226
                is_iterates(L, is_list_functor(L, A), 0, u, x),
paulson@13655
   227
    \<lambda>i x. \<exists>u \<in> Lset(i). u \<in> B & u \<in> nat &
paulson@13807
   228
               is_iterates(##Lset(i), is_list_functor(##Lset(i), A), 0, u, x)]"
paulson@13655
   229
by (intro FOL_reflections 
paulson@13655
   230
          is_iterates_reflection list_functor_reflection)
paulson@13363
   231
wenzelm@13428
   232
lemma list_replacement2:
wenzelm@13428
   233
   "L(A) ==> strong_replacement(L,
paulson@13655
   234
         \<lambda>n y. n\<in>nat & is_iterates(L, is_list_functor(L,A), 0, n, y))"
wenzelm@13428
   235
apply (rule strong_replacementI)
paulson@13566
   236
apply (rule_tac u="{A,B,0,nat}" 
paulson@13687
   237
         in gen_separation_multi [OF list_replacement2_Reflects], 
paulson@13687
   238
       auto simp add: L_nat nonempty)
paulson@13687
   239
apply (rule_tac env="[A,B,0,nat]" in DPow_LsetI)
paulson@13655
   240
apply (rule sep_rules list_functor_iff_sats is_iterates_iff_sats | simp)+
paulson@13363
   241
done
paulson@13363
   242
paulson@13386
   243
wenzelm@13428
   244
subsection{*@{term L} is Closed Under the Operator @{term formula}*}
paulson@13386
   245
paulson@13386
   246
subsubsection{*Instances of Replacement for Formulas*}
paulson@13386
   247
paulson@13655
   248
(*FIXME: could prove a lemma iterates_replacementI to eliminate the 
paulson@13655
   249
need to expand iterates_replacement and wfrec_replacement*)
paulson@13386
   250
lemma formula_replacement1_Reflects:
paulson@13386
   251
 "REFLECTS
paulson@13655
   252
   [\<lambda>x. \<exists>u[L]. u \<in> B & (\<exists>y[L]. pair(L,u,y,x) &
paulson@13386
   253
         is_wfrec(L, iterates_MH(L, is_formula_functor(L), 0), memsn, u, y)),
paulson@13807
   254
    \<lambda>i x. \<exists>u \<in> Lset(i). u \<in> B & (\<exists>y \<in> Lset(i). pair(##Lset(i), u, y, x) &
paulson@13807
   255
         is_wfrec(##Lset(i),
paulson@13807
   256
                  iterates_MH(##Lset(i),
paulson@13807
   257
                          is_formula_functor(##Lset(i)), 0), memsn, u, y))]"
wenzelm@13428
   258
by (intro FOL_reflections function_reflections is_wfrec_reflection
wenzelm@13428
   259
          iterates_MH_reflection formula_functor_reflection)
paulson@13386
   260
wenzelm@13428
   261
lemma formula_replacement1:
paulson@13386
   262
   "iterates_replacement(L, is_formula_functor(L), 0)"
paulson@13386
   263
apply (unfold iterates_replacement_def wfrec_replacement_def, clarify)
wenzelm@13428
   264
apply (rule strong_replacementI)
paulson@13566
   265
apply (rule_tac u="{B,n,0,Memrel(succ(n))}" 
paulson@13687
   266
         in gen_separation_multi [OF formula_replacement1_Reflects], 
paulson@13687
   267
       auto simp add: nonempty)
paulson@13687
   268
apply (rule_tac env="[n,B,0,Memrel(succ(n))]" in DPow_LsetI)
paulson@13434
   269
apply (rule sep_rules is_nat_case_iff_sats formula_functor_iff_sats
paulson@13441
   270
            is_wfrec_iff_sats iterates_MH_iff_sats quasinat_iff_sats | simp)+
paulson@13386
   271
done
paulson@13386
   272
paulson@13386
   273
lemma formula_replacement2_Reflects:
paulson@13386
   274
 "REFLECTS
paulson@13655
   275
   [\<lambda>x. \<exists>u[L]. u \<in> B & u \<in> nat &
paulson@13655
   276
                is_iterates(L, is_formula_functor(L), 0, u, x),
paulson@13655
   277
    \<lambda>i x. \<exists>u \<in> Lset(i). u \<in> B & u \<in> nat &
paulson@13807
   278
               is_iterates(##Lset(i), is_formula_functor(##Lset(i)), 0, u, x)]"
paulson@13655
   279
by (intro FOL_reflections 
paulson@13655
   280
          is_iterates_reflection formula_functor_reflection)
paulson@13386
   281
wenzelm@13428
   282
lemma formula_replacement2:
wenzelm@13428
   283
   "strong_replacement(L,
paulson@13655
   284
         \<lambda>n y. n\<in>nat & is_iterates(L, is_formula_functor(L), 0, n, y))"
wenzelm@13428
   285
apply (rule strong_replacementI)
paulson@13566
   286
apply (rule_tac u="{B,0,nat}" 
paulson@13687
   287
         in gen_separation_multi [OF formula_replacement2_Reflects], 
paulson@13687
   288
       auto simp add: nonempty L_nat)
paulson@13687
   289
apply (rule_tac env="[B,0,nat]" in DPow_LsetI)
paulson@13655
   290
apply (rule sep_rules formula_functor_iff_sats is_iterates_iff_sats | simp)+
paulson@13386
   291
done
paulson@13386
   292
paulson@13386
   293
text{*NB The proofs for type @{term formula} are virtually identical to those
paulson@13386
   294
for @{term "list(A)"}.  It was a cut-and-paste job! *}
paulson@13386
   295
paulson@13387
   296
paulson@13437
   297
subsubsection{*The Formula @{term is_nth}, Internalized*}
paulson@13437
   298
paulson@13655
   299
(* "is_nth(M,n,l,Z) ==
paulson@13655
   300
      \<exists>X[M]. is_iterates(M, is_tl(M), l, n, X) & is_hd(M,X,Z)" *)
paulson@13437
   301
constdefs nth_fm :: "[i,i,i]=>i"
paulson@13437
   302
    "nth_fm(n,l,Z) == 
paulson@13655
   303
       Exists(And(is_iterates_fm(tl_fm(1,0), succ(l), succ(n), 0), 
paulson@13655
   304
              hd_fm(0,succ(Z))))"
paulson@13493
   305
paulson@13493
   306
lemma nth_fm_type [TC]:
paulson@13493
   307
 "[| x \<in> nat; y \<in> nat; z \<in> nat |] ==> nth_fm(x,y,z) \<in> formula"
paulson@13493
   308
by (simp add: nth_fm_def)
paulson@13493
   309
paulson@13493
   310
lemma sats_nth_fm [simp]:
paulson@13493
   311
   "[| x < length(env); y \<in> nat; z \<in> nat; env \<in> list(A)|]
paulson@13493
   312
    ==> sats(A, nth_fm(x,y,z), env) <->
paulson@13807
   313
        is_nth(##A, nth(x,env), nth(y,env), nth(z,env))"
paulson@13493
   314
apply (frule lt_length_in_nat, assumption)  
paulson@13655
   315
apply (simp add: nth_fm_def is_nth_def sats_is_iterates_fm) 
paulson@13493
   316
done
paulson@13493
   317
paulson@13493
   318
lemma nth_iff_sats:
paulson@13493
   319
      "[| nth(i,env) = x; nth(j,env) = y; nth(k,env) = z;
paulson@13493
   320
          i < length(env); j \<in> nat; k \<in> nat; env \<in> list(A)|]
paulson@13807
   321
       ==> is_nth(##A, x, y, z) <-> sats(A, nth_fm(i,j,k), env)"
paulson@13493
   322
by (simp add: sats_nth_fm)
paulson@13437
   323
paulson@13437
   324
theorem nth_reflection:
paulson@13437
   325
     "REFLECTS[\<lambda>x. is_nth(L, f(x), g(x), h(x)),  
paulson@13807
   326
               \<lambda>i x. is_nth(##Lset(i), f(x), g(x), h(x))]"
paulson@13655
   327
apply (simp only: is_nth_def)
paulson@13655
   328
apply (intro FOL_reflections is_iterates_reflection
paulson@13655
   329
             hd_reflection tl_reflection) 
paulson@13437
   330
done
paulson@13437
   331
paulson@13437
   332
paulson@13409
   333
subsubsection{*An Instance of Replacement for @{term nth}*}
paulson@13409
   334
paulson@13655
   335
(*FIXME: could prove a lemma iterates_replacementI to eliminate the 
paulson@13655
   336
need to expand iterates_replacement and wfrec_replacement*)
paulson@13409
   337
lemma nth_replacement_Reflects:
paulson@13409
   338
 "REFLECTS
paulson@13655
   339
   [\<lambda>x. \<exists>u[L]. u \<in> B & (\<exists>y[L]. pair(L,u,y,x) &
paulson@13409
   340
         is_wfrec(L, iterates_MH(L, is_tl(L), z), memsn, u, y)),
paulson@13807
   341
    \<lambda>i x. \<exists>u \<in> Lset(i). u \<in> B & (\<exists>y \<in> Lset(i). pair(##Lset(i), u, y, x) &
paulson@13807
   342
         is_wfrec(##Lset(i),
paulson@13807
   343
                  iterates_MH(##Lset(i),
paulson@13807
   344
                          is_tl(##Lset(i)), z), memsn, u, y))]"
wenzelm@13428
   345
by (intro FOL_reflections function_reflections is_wfrec_reflection
paulson@13655
   346
          iterates_MH_reflection tl_reflection)
paulson@13409
   347
wenzelm@13428
   348
lemma nth_replacement:
paulson@13655
   349
   "L(w) ==> iterates_replacement(L, is_tl(L), w)"
paulson@13409
   350
apply (unfold iterates_replacement_def wfrec_replacement_def, clarify)
wenzelm@13428
   351
apply (rule strong_replacementI)
paulson@13687
   352
apply (rule_tac u="{B,w,Memrel(succ(n))}" 
paulson@13687
   353
         in gen_separation_multi [OF nth_replacement_Reflects], 
paulson@13687
   354
       auto)
paulson@13687
   355
apply (rule_tac env="[B,w,Memrel(succ(n))]" in DPow_LsetI)
paulson@13434
   356
apply (rule sep_rules is_nat_case_iff_sats tl_iff_sats
paulson@13441
   357
            is_wfrec_iff_sats iterates_MH_iff_sats quasinat_iff_sats | simp)+
paulson@13409
   358
done
paulson@13409
   359
paulson@13422
   360
paulson@13422
   361
subsubsection{*Instantiating the locale @{text M_datatypes}*}
wenzelm@13428
   362
paulson@13437
   363
lemma M_datatypes_axioms_L: "M_datatypes_axioms(L)"
wenzelm@13428
   364
  apply (rule M_datatypes_axioms.intro)
wenzelm@13428
   365
      apply (assumption | rule
wenzelm@13428
   366
        list_replacement1 list_replacement2
wenzelm@13428
   367
        formula_replacement1 formula_replacement2
wenzelm@13428
   368
        nth_replacement)+
wenzelm@13428
   369
  done
paulson@13422
   370
paulson@13437
   371
theorem M_datatypes_L: "PROP M_datatypes(L)"
paulson@13437
   372
  apply (rule M_datatypes.intro)
paulson@13634
   373
      apply (rule M_trancl.axioms [OF M_trancl_L])+
paulson@13441
   374
 apply (rule M_datatypes_axioms_L) 
paulson@13437
   375
 done
paulson@13437
   376
wenzelm@13428
   377
lemmas list_closed = M_datatypes.list_closed [OF M_datatypes_L]
wenzelm@13428
   378
  and formula_closed = M_datatypes.formula_closed [OF M_datatypes_L]
wenzelm@13428
   379
  and list_abs = M_datatypes.list_abs [OF M_datatypes_L]
wenzelm@13428
   380
  and formula_abs = M_datatypes.formula_abs [OF M_datatypes_L]
wenzelm@13428
   381
  and nth_abs = M_datatypes.nth_abs [OF M_datatypes_L]
paulson@13409
   382
paulson@13422
   383
declare list_closed [intro,simp]
paulson@13422
   384
declare formula_closed [intro,simp]
paulson@13422
   385
declare list_abs [simp]
paulson@13422
   386
declare formula_abs [simp]
paulson@13422
   387
declare nth_abs [simp]
paulson@13422
   388
paulson@13422
   389
wenzelm@13428
   390
subsection{*@{term L} is Closed Under the Operator @{term eclose}*}
paulson@13422
   391
paulson@13422
   392
subsubsection{*Instances of Replacement for @{term eclose}*}
paulson@13422
   393
paulson@13422
   394
lemma eclose_replacement1_Reflects:
paulson@13422
   395
 "REFLECTS
paulson@13655
   396
   [\<lambda>x. \<exists>u[L]. u \<in> B & (\<exists>y[L]. pair(L,u,y,x) &
paulson@13422
   397
         is_wfrec(L, iterates_MH(L, big_union(L), A), memsn, u, y)),
paulson@13807
   398
    \<lambda>i x. \<exists>u \<in> Lset(i). u \<in> B & (\<exists>y \<in> Lset(i). pair(##Lset(i), u, y, x) &
paulson@13807
   399
         is_wfrec(##Lset(i),
paulson@13807
   400
                  iterates_MH(##Lset(i), big_union(##Lset(i)), A),
paulson@13422
   401
                  memsn, u, y))]"
wenzelm@13428
   402
by (intro FOL_reflections function_reflections is_wfrec_reflection
wenzelm@13428
   403
          iterates_MH_reflection)
paulson@13422
   404
wenzelm@13428
   405
lemma eclose_replacement1:
paulson@13422
   406
   "L(A) ==> iterates_replacement(L, big_union(L), A)"
paulson@13422
   407
apply (unfold iterates_replacement_def wfrec_replacement_def, clarify)
wenzelm@13428
   408
apply (rule strong_replacementI)
paulson@13566
   409
apply (rule_tac u="{B,A,n,Memrel(succ(n))}" 
paulson@13687
   410
         in gen_separation_multi [OF eclose_replacement1_Reflects], auto)
paulson@13687
   411
apply (rule_tac env="[B,A,n,Memrel(succ(n))]" in DPow_LsetI)
paulson@13434
   412
apply (rule sep_rules iterates_MH_iff_sats is_nat_case_iff_sats
paulson@13441
   413
             is_wfrec_iff_sats big_union_iff_sats quasinat_iff_sats | simp)+
paulson@13409
   414
done
paulson@13409
   415
paulson@13422
   416
paulson@13422
   417
lemma eclose_replacement2_Reflects:
paulson@13422
   418
 "REFLECTS
paulson@13655
   419
   [\<lambda>x. \<exists>u[L]. u \<in> B & u \<in> nat &
paulson@13655
   420
                is_iterates(L, big_union(L), A, u, x),
paulson@13655
   421
    \<lambda>i x. \<exists>u \<in> Lset(i). u \<in> B & u \<in> nat &
paulson@13807
   422
               is_iterates(##Lset(i), big_union(##Lset(i)), A, u, x)]"
paulson@13655
   423
by (intro FOL_reflections function_reflections is_iterates_reflection)
paulson@13422
   424
wenzelm@13428
   425
lemma eclose_replacement2:
wenzelm@13428
   426
   "L(A) ==> strong_replacement(L,
paulson@13655
   427
         \<lambda>n y. n\<in>nat & is_iterates(L, big_union(L), A, n, y))"
wenzelm@13428
   428
apply (rule strong_replacementI)
paulson@13566
   429
apply (rule_tac u="{A,B,nat}" 
paulson@13687
   430
         in gen_separation_multi [OF eclose_replacement2_Reflects],
paulson@13687
   431
       auto simp add: L_nat)
paulson@13687
   432
apply (rule_tac env="[A,B,nat]" in DPow_LsetI)
paulson@13655
   433
apply (rule sep_rules is_iterates_iff_sats big_union_iff_sats | simp)+
paulson@13422
   434
done
paulson@13422
   435
paulson@13422
   436
paulson@13422
   437
subsubsection{*Instantiating the locale @{text M_eclose}*}
paulson@13422
   438
paulson@13437
   439
lemma M_eclose_axioms_L: "M_eclose_axioms(L)"
paulson@13437
   440
  apply (rule M_eclose_axioms.intro)
paulson@13437
   441
   apply (assumption | rule eclose_replacement1 eclose_replacement2)+
paulson@13437
   442
  done
paulson@13437
   443
wenzelm@13428
   444
theorem M_eclose_L: "PROP M_eclose(L)"
wenzelm@13428
   445
  apply (rule M_eclose.intro)
wenzelm@13429
   446
       apply (rule M_datatypes.axioms [OF M_datatypes_L])+
paulson@13437
   447
  apply (rule M_eclose_axioms_L)
wenzelm@13428
   448
  done
paulson@13422
   449
wenzelm@13428
   450
lemmas eclose_closed [intro, simp] = M_eclose.eclose_closed [OF M_eclose_L]
wenzelm@13428
   451
  and eclose_abs [intro, simp] = M_eclose.eclose_abs [OF M_eclose_L]
paulson@13440
   452
  and transrec_replacementI = M_eclose.transrec_replacementI [OF M_eclose_L]
paulson@13422
   453
paulson@13348
   454
end