src/ZF/Constructible/Rec_Separation.thy
author paulson
Mon Oct 14 11:32:00 2002 +0200 (2002-10-14)
changeset 13647 7f6f0ffc45c3
parent 13634 99a593b49b04
child 13651 ac80e101306a
permissions -rw-r--r--
tidying and reorganization
     1 (*  Title:      ZF/Constructible/Rec_Separation.thy
     2     ID:   $Id$
     3     Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
     4 *)
     5 
     6 header {*Separation for Facts About Recursion*}
     7 
     8 theory Rec_Separation = Separation + Internalize:
     9 
    10 text{*This theory proves all instances needed for locales @{text
    11 "M_trancl"} and @{text "M_datatypes"}*}
    12 
    13 lemma eq_succ_imp_lt: "[|i = succ(j); Ord(i)|] ==> j<i"
    14 by simp
    15 
    16 
    17 subsection{*The Locale @{text "M_trancl"}*}
    18 
    19 subsubsection{*Separation for Reflexive/Transitive Closure*}
    20 
    21 text{*First, The Defining Formula*}
    22 
    23 (* "rtran_closure_mem(M,A,r,p) ==
    24       \<exists>nnat[M]. \<exists>n[M]. \<exists>n'[M].
    25        omega(M,nnat) & n\<in>nnat & successor(M,n,n') &
    26        (\<exists>f[M]. typed_function(M,n',A,f) &
    27         (\<exists>x[M]. \<exists>y[M]. \<exists>zero[M]. pair(M,x,y,p) & empty(M,zero) &
    28           fun_apply(M,f,zero,x) & fun_apply(M,f,n,y)) &
    29         (\<forall>j[M]. j\<in>n -->
    30           (\<exists>fj[M]. \<exists>sj[M]. \<exists>fsj[M]. \<exists>ffp[M].
    31             fun_apply(M,f,j,fj) & successor(M,j,sj) &
    32             fun_apply(M,f,sj,fsj) & pair(M,fj,fsj,ffp) & ffp \<in> r)))"*)
    33 constdefs rtran_closure_mem_fm :: "[i,i,i]=>i"
    34  "rtran_closure_mem_fm(A,r,p) ==
    35    Exists(Exists(Exists(
    36     And(omega_fm(2),
    37      And(Member(1,2),
    38       And(succ_fm(1,0),
    39        Exists(And(typed_function_fm(1, A#+4, 0),
    40         And(Exists(Exists(Exists(
    41               And(pair_fm(2,1,p#+7),
    42                And(empty_fm(0),
    43                 And(fun_apply_fm(3,0,2), fun_apply_fm(3,5,1))))))),
    44             Forall(Implies(Member(0,3),
    45              Exists(Exists(Exists(Exists(
    46               And(fun_apply_fm(5,4,3),
    47                And(succ_fm(4,2),
    48                 And(fun_apply_fm(5,2,1),
    49                  And(pair_fm(3,1,0), Member(0,r#+9))))))))))))))))))))"
    50 
    51 
    52 lemma rtran_closure_mem_type [TC]:
    53  "[| x \<in> nat; y \<in> nat; z \<in> nat |] ==> rtran_closure_mem_fm(x,y,z) \<in> formula"
    54 by (simp add: rtran_closure_mem_fm_def)
    55 
    56 lemma arity_rtran_closure_mem_fm [simp]:
    57      "[| x \<in> nat; y \<in> nat; z \<in> nat |]
    58       ==> arity(rtran_closure_mem_fm(x,y,z)) = succ(x) \<union> succ(y) \<union> succ(z)"
    59 by (simp add: rtran_closure_mem_fm_def succ_Un_distrib [symmetric] Un_ac)
    60 
    61 lemma sats_rtran_closure_mem_fm [simp]:
    62    "[| x \<in> nat; y \<in> nat; z \<in> nat; env \<in> list(A)|]
    63     ==> sats(A, rtran_closure_mem_fm(x,y,z), env) <->
    64         rtran_closure_mem(**A, nth(x,env), nth(y,env), nth(z,env))"
    65 by (simp add: rtran_closure_mem_fm_def rtran_closure_mem_def)
    66 
    67 lemma rtran_closure_mem_iff_sats:
    68       "[| nth(i,env) = x; nth(j,env) = y; nth(k,env) = z;
    69           i \<in> nat; j \<in> nat; k \<in> nat; env \<in> list(A)|]
    70        ==> rtran_closure_mem(**A, x, y, z) <-> sats(A, rtran_closure_mem_fm(i,j,k), env)"
    71 by (simp add: sats_rtran_closure_mem_fm)
    72 
    73 lemma rtran_closure_mem_reflection:
    74      "REFLECTS[\<lambda>x. rtran_closure_mem(L,f(x),g(x),h(x)),
    75                \<lambda>i x. rtran_closure_mem(**Lset(i),f(x),g(x),h(x))]"
    76 apply (simp only: rtran_closure_mem_def setclass_simps)
    77 apply (intro FOL_reflections function_reflections fun_plus_reflections)
    78 done
    79 
    80 text{*Separation for @{term "rtrancl(r)"}.*}
    81 lemma rtrancl_separation:
    82      "[| L(r); L(A) |] ==> separation (L, rtran_closure_mem(L,A,r))"
    83 apply (rule gen_separation [OF rtran_closure_mem_reflection, of "{r,A}"], simp)
    84 apply (drule mem_Lset_imp_subset_Lset, clarsimp)
    85 apply (rule DPow_LsetI)
    86 apply (rule_tac env = "[x,r,A]" in rtran_closure_mem_iff_sats)
    87 apply (rule sep_rules | simp)+
    88 done
    89 
    90 
    91 subsubsection{*Reflexive/Transitive Closure, Internalized*}
    92 
    93 (*  "rtran_closure(M,r,s) ==
    94         \<forall>A[M]. is_field(M,r,A) -->
    95          (\<forall>p[M]. p \<in> s <-> rtran_closure_mem(M,A,r,p))" *)
    96 constdefs rtran_closure_fm :: "[i,i]=>i"
    97  "rtran_closure_fm(r,s) ==
    98    Forall(Implies(field_fm(succ(r),0),
    99                   Forall(Iff(Member(0,succ(succ(s))),
   100                              rtran_closure_mem_fm(1,succ(succ(r)),0)))))"
   101 
   102 lemma rtran_closure_type [TC]:
   103      "[| x \<in> nat; y \<in> nat |] ==> rtran_closure_fm(x,y) \<in> formula"
   104 by (simp add: rtran_closure_fm_def)
   105 
   106 lemma arity_rtran_closure_fm [simp]:
   107      "[| x \<in> nat; y \<in> nat |]
   108       ==> arity(rtran_closure_fm(x,y)) = succ(x) \<union> succ(y)"
   109 by (simp add: rtran_closure_fm_def succ_Un_distrib [symmetric] Un_ac)
   110 
   111 lemma sats_rtran_closure_fm [simp]:
   112    "[| x \<in> nat; y \<in> nat; env \<in> list(A)|]
   113     ==> sats(A, rtran_closure_fm(x,y), env) <->
   114         rtran_closure(**A, nth(x,env), nth(y,env))"
   115 by (simp add: rtran_closure_fm_def rtran_closure_def)
   116 
   117 lemma rtran_closure_iff_sats:
   118       "[| nth(i,env) = x; nth(j,env) = y;
   119           i \<in> nat; j \<in> nat; env \<in> list(A)|]
   120        ==> rtran_closure(**A, x, y) <-> sats(A, rtran_closure_fm(i,j), env)"
   121 by simp
   122 
   123 theorem rtran_closure_reflection:
   124      "REFLECTS[\<lambda>x. rtran_closure(L,f(x),g(x)),
   125                \<lambda>i x. rtran_closure(**Lset(i),f(x),g(x))]"
   126 apply (simp only: rtran_closure_def setclass_simps)
   127 apply (intro FOL_reflections function_reflections rtran_closure_mem_reflection)
   128 done
   129 
   130 
   131 subsubsection{*Transitive Closure of a Relation, Internalized*}
   132 
   133 (*  "tran_closure(M,r,t) ==
   134          \<exists>s[M]. rtran_closure(M,r,s) & composition(M,r,s,t)" *)
   135 constdefs tran_closure_fm :: "[i,i]=>i"
   136  "tran_closure_fm(r,s) ==
   137    Exists(And(rtran_closure_fm(succ(r),0), composition_fm(succ(r),0,succ(s))))"
   138 
   139 lemma tran_closure_type [TC]:
   140      "[| x \<in> nat; y \<in> nat |] ==> tran_closure_fm(x,y) \<in> formula"
   141 by (simp add: tran_closure_fm_def)
   142 
   143 lemma arity_tran_closure_fm [simp]:
   144      "[| x \<in> nat; y \<in> nat |]
   145       ==> arity(tran_closure_fm(x,y)) = succ(x) \<union> succ(y)"
   146 by (simp add: tran_closure_fm_def succ_Un_distrib [symmetric] Un_ac)
   147 
   148 lemma sats_tran_closure_fm [simp]:
   149    "[| x \<in> nat; y \<in> nat; env \<in> list(A)|]
   150     ==> sats(A, tran_closure_fm(x,y), env) <->
   151         tran_closure(**A, nth(x,env), nth(y,env))"
   152 by (simp add: tran_closure_fm_def tran_closure_def)
   153 
   154 lemma tran_closure_iff_sats:
   155       "[| nth(i,env) = x; nth(j,env) = y;
   156           i \<in> nat; j \<in> nat; env \<in> list(A)|]
   157        ==> tran_closure(**A, x, y) <-> sats(A, tran_closure_fm(i,j), env)"
   158 by simp
   159 
   160 theorem tran_closure_reflection:
   161      "REFLECTS[\<lambda>x. tran_closure(L,f(x),g(x)),
   162                \<lambda>i x. tran_closure(**Lset(i),f(x),g(x))]"
   163 apply (simp only: tran_closure_def setclass_simps)
   164 apply (intro FOL_reflections function_reflections
   165              rtran_closure_reflection composition_reflection)
   166 done
   167 
   168 
   169 subsubsection{*Separation for the Proof of @{text "wellfounded_on_trancl"}*}
   170 
   171 lemma wellfounded_trancl_reflects:
   172   "REFLECTS[\<lambda>x. \<exists>w[L]. \<exists>wx[L]. \<exists>rp[L].
   173                  w \<in> Z & pair(L,w,x,wx) & tran_closure(L,r,rp) & wx \<in> rp,
   174    \<lambda>i x. \<exists>w \<in> Lset(i). \<exists>wx \<in> Lset(i). \<exists>rp \<in> Lset(i).
   175        w \<in> Z & pair(**Lset(i),w,x,wx) & tran_closure(**Lset(i),r,rp) &
   176        wx \<in> rp]"
   177 by (intro FOL_reflections function_reflections fun_plus_reflections
   178           tran_closure_reflection)
   179 
   180 lemma wellfounded_trancl_separation:
   181          "[| L(r); L(Z) |] ==>
   182           separation (L, \<lambda>x.
   183               \<exists>w[L]. \<exists>wx[L]. \<exists>rp[L].
   184                w \<in> Z & pair(L,w,x,wx) & tran_closure(L,r,rp) & wx \<in> rp)"
   185 apply (rule gen_separation [OF wellfounded_trancl_reflects, of "{r,Z}"], simp)
   186 apply (drule mem_Lset_imp_subset_Lset, clarsimp)
   187 apply (rule DPow_LsetI)
   188 apply (rule bex_iff_sats conj_iff_sats)+
   189 apply (rule_tac env = "[w,x,r,Z]" in mem_iff_sats)
   190 apply (rule sep_rules tran_closure_iff_sats | simp)+
   191 done
   192 
   193 
   194 subsubsection{*Instantiating the locale @{text M_trancl}*}
   195 
   196 lemma M_trancl_axioms_L: "M_trancl_axioms(L)"
   197   apply (rule M_trancl_axioms.intro)
   198    apply (assumption | rule rtrancl_separation wellfounded_trancl_separation)+
   199   done
   200 
   201 theorem M_trancl_L: "PROP M_trancl(L)"
   202 by (rule M_trancl.intro
   203          [OF M_trivial_L M_basic_axioms_L M_trancl_axioms_L])
   204 
   205 lemmas iterates_abs = M_trancl.iterates_abs [OF M_trancl_L]
   206   and rtran_closure_rtrancl = M_trancl.rtran_closure_rtrancl [OF M_trancl_L]
   207   and trans_wfrec_abs = M_trancl.trans_wfrec_abs [OF M_trancl_L]
   208   and eq_pair_wfrec_iff = M_trancl.eq_pair_wfrec_iff [OF M_trancl_L]
   209 
   210 
   211 
   212 subsection{*@{term L} is Closed Under the Operator @{term list}*}
   213 
   214 subsubsection{*Instances of Replacement for Lists*}
   215 
   216 lemma list_replacement1_Reflects:
   217  "REFLECTS
   218    [\<lambda>x. \<exists>u[L]. u \<in> B \<and> (\<exists>y[L]. pair(L,u,y,x) \<and>
   219          is_wfrec(L, iterates_MH(L, is_list_functor(L,A), 0), memsn, u, y)),
   220     \<lambda>i x. \<exists>u \<in> Lset(i). u \<in> B \<and> (\<exists>y \<in> Lset(i). pair(**Lset(i), u, y, x) \<and>
   221          is_wfrec(**Lset(i),
   222                   iterates_MH(**Lset(i),
   223                           is_list_functor(**Lset(i), A), 0), memsn, u, y))]"
   224 by (intro FOL_reflections function_reflections is_wfrec_reflection
   225           iterates_MH_reflection list_functor_reflection)
   226 
   227 
   228 lemma list_replacement1:
   229    "L(A) ==> iterates_replacement(L, is_list_functor(L,A), 0)"
   230 apply (unfold iterates_replacement_def wfrec_replacement_def, clarify)
   231 apply (rule strong_replacementI)
   232 apply (rename_tac B)
   233 apply (rule_tac u="{B,A,n,0,Memrel(succ(n))}" 
   234          in gen_separation [OF list_replacement1_Reflects], 
   235        simp add: nonempty)
   236 apply (drule mem_Lset_imp_subset_Lset, clarsimp)
   237 apply (rule DPow_LsetI)
   238 apply (rule bex_iff_sats conj_iff_sats)+
   239 apply (rule_tac env = "[u,x,A,n,B,0,Memrel(succ(n))]" in mem_iff_sats)
   240 apply (rule sep_rules is_nat_case_iff_sats list_functor_iff_sats
   241             is_wfrec_iff_sats iterates_MH_iff_sats quasinat_iff_sats | simp)+
   242 done
   243 
   244 
   245 lemma list_replacement2_Reflects:
   246  "REFLECTS
   247    [\<lambda>x. \<exists>u[L]. u \<in> B \<and> u \<in> nat \<and>
   248          (\<exists>sn[L]. \<exists>msn[L]. successor(L, u, sn) \<and> membership(L, sn, msn) \<and>
   249            is_wfrec (L, iterates_MH (L, is_list_functor(L, A), 0),
   250                               msn, u, x)),
   251     \<lambda>i x. \<exists>u \<in> Lset(i). u \<in> B \<and> u \<in> nat \<and>
   252          (\<exists>sn \<in> Lset(i). \<exists>msn \<in> Lset(i).
   253           successor(**Lset(i), u, sn) \<and> membership(**Lset(i), sn, msn) \<and>
   254            is_wfrec (**Lset(i),
   255                  iterates_MH (**Lset(i), is_list_functor(**Lset(i), A), 0),
   256                      msn, u, x))]"
   257 by (intro FOL_reflections function_reflections is_wfrec_reflection
   258           iterates_MH_reflection list_functor_reflection)
   259 
   260 
   261 lemma list_replacement2:
   262    "L(A) ==> strong_replacement(L,
   263          \<lambda>n y. n\<in>nat &
   264                (\<exists>sn[L]. \<exists>msn[L]. successor(L,n,sn) & membership(L,sn,msn) &
   265                is_wfrec(L, iterates_MH(L,is_list_functor(L,A), 0),
   266                         msn, n, y)))"
   267 apply (rule strong_replacementI)
   268 apply (rename_tac B)
   269 apply (rule_tac u="{A,B,0,nat}" 
   270          in gen_separation [OF list_replacement2_Reflects], 
   271        simp add: L_nat nonempty)
   272 apply (drule mem_Lset_imp_subset_Lset, clarsimp)
   273 apply (rule DPow_LsetI)
   274 apply (rule bex_iff_sats conj_iff_sats)+
   275 apply (rule_tac env = "[u,x,A,B,0,nat]" in mem_iff_sats)
   276 apply (rule sep_rules is_nat_case_iff_sats list_functor_iff_sats
   277             is_wfrec_iff_sats iterates_MH_iff_sats quasinat_iff_sats | simp)+
   278 done
   279 
   280 
   281 subsection{*@{term L} is Closed Under the Operator @{term formula}*}
   282 
   283 subsubsection{*Instances of Replacement for Formulas*}
   284 
   285 lemma formula_replacement1_Reflects:
   286  "REFLECTS
   287    [\<lambda>x. \<exists>u[L]. u \<in> B \<and> (\<exists>y[L]. pair(L,u,y,x) \<and>
   288          is_wfrec(L, iterates_MH(L, is_formula_functor(L), 0), memsn, u, y)),
   289     \<lambda>i x. \<exists>u \<in> Lset(i). u \<in> B \<and> (\<exists>y \<in> Lset(i). pair(**Lset(i), u, y, x) \<and>
   290          is_wfrec(**Lset(i),
   291                   iterates_MH(**Lset(i),
   292                           is_formula_functor(**Lset(i)), 0), memsn, u, y))]"
   293 by (intro FOL_reflections function_reflections is_wfrec_reflection
   294           iterates_MH_reflection formula_functor_reflection)
   295 
   296 lemma formula_replacement1:
   297    "iterates_replacement(L, is_formula_functor(L), 0)"
   298 apply (unfold iterates_replacement_def wfrec_replacement_def, clarify)
   299 apply (rule strong_replacementI)
   300 apply (rename_tac B)
   301 apply (rule_tac u="{B,n,0,Memrel(succ(n))}" 
   302          in gen_separation [OF formula_replacement1_Reflects], 
   303        simp add: nonempty)
   304 apply (drule mem_Lset_imp_subset_Lset, clarsimp)
   305 apply (rule DPow_LsetI)
   306 apply (rule bex_iff_sats conj_iff_sats)+
   307 apply (rule_tac env = "[u,x,n,B,0,Memrel(succ(n))]" in mem_iff_sats)
   308 apply (rule sep_rules is_nat_case_iff_sats formula_functor_iff_sats
   309             is_wfrec_iff_sats iterates_MH_iff_sats quasinat_iff_sats | simp)+
   310 done
   311 
   312 lemma formula_replacement2_Reflects:
   313  "REFLECTS
   314    [\<lambda>x. \<exists>u[L]. u \<in> B \<and> u \<in> nat \<and>
   315          (\<exists>sn[L]. \<exists>msn[L]. successor(L, u, sn) \<and> membership(L, sn, msn) \<and>
   316            is_wfrec (L, iterates_MH (L, is_formula_functor(L), 0),
   317                               msn, u, x)),
   318     \<lambda>i x. \<exists>u \<in> Lset(i). u \<in> B \<and> u \<in> nat \<and>
   319          (\<exists>sn \<in> Lset(i). \<exists>msn \<in> Lset(i).
   320           successor(**Lset(i), u, sn) \<and> membership(**Lset(i), sn, msn) \<and>
   321            is_wfrec (**Lset(i),
   322                  iterates_MH (**Lset(i), is_formula_functor(**Lset(i)), 0),
   323                      msn, u, x))]"
   324 by (intro FOL_reflections function_reflections is_wfrec_reflection
   325           iterates_MH_reflection formula_functor_reflection)
   326 
   327 
   328 lemma formula_replacement2:
   329    "strong_replacement(L,
   330          \<lambda>n y. n\<in>nat &
   331                (\<exists>sn[L]. \<exists>msn[L]. successor(L,n,sn) & membership(L,sn,msn) &
   332                is_wfrec(L, iterates_MH(L,is_formula_functor(L), 0),
   333                         msn, n, y)))"
   334 apply (rule strong_replacementI)
   335 apply (rename_tac B)
   336 apply (rule_tac u="{B,0,nat}" 
   337          in gen_separation [OF formula_replacement2_Reflects], 
   338        simp add: nonempty L_nat)
   339 apply (drule mem_Lset_imp_subset_Lset, clarsimp)
   340 apply (rule DPow_LsetI)
   341 apply (rule bex_iff_sats conj_iff_sats)+
   342 apply (rule_tac env = "[u,x,B,0,nat]" in mem_iff_sats)
   343 apply (rule sep_rules is_nat_case_iff_sats formula_functor_iff_sats
   344             is_wfrec_iff_sats iterates_MH_iff_sats quasinat_iff_sats | simp)+
   345 done
   346 
   347 text{*NB The proofs for type @{term formula} are virtually identical to those
   348 for @{term "list(A)"}.  It was a cut-and-paste job! *}
   349 
   350 
   351 subsubsection{*The Formula @{term is_nth}, Internalized*}
   352 
   353 (* "is_nth(M,n,l,Z) == 
   354       \<exists>X[M]. \<exists>sn[M]. \<exists>msn[M]. 
   355        2       1       0
   356        successor(M,n,sn) & membership(M,sn,msn) &
   357        is_wfrec(M, iterates_MH(M, is_tl(M), l), msn, n, X) &
   358        is_hd(M,X,Z)" *)
   359 constdefs nth_fm :: "[i,i,i]=>i"
   360     "nth_fm(n,l,Z) == 
   361        Exists(Exists(Exists(
   362          And(succ_fm(n#+3,1),
   363           And(Memrel_fm(1,0),
   364            And(is_wfrec_fm(iterates_MH_fm(tl_fm(1,0),l#+8,2,1,0), 0, n#+3, 2), hd_fm(2,Z#+3)))))))"
   365 
   366 lemma nth_fm_type [TC]:
   367  "[| x \<in> nat; y \<in> nat; z \<in> nat |] ==> nth_fm(x,y,z) \<in> formula"
   368 by (simp add: nth_fm_def)
   369 
   370 lemma sats_nth_fm [simp]:
   371    "[| x < length(env); y \<in> nat; z \<in> nat; env \<in> list(A)|]
   372     ==> sats(A, nth_fm(x,y,z), env) <->
   373         is_nth(**A, nth(x,env), nth(y,env), nth(z,env))"
   374 apply (frule lt_length_in_nat, assumption)  
   375 apply (simp add: nth_fm_def is_nth_def sats_is_wfrec_fm sats_iterates_MH_fm) 
   376 done
   377 
   378 lemma nth_iff_sats:
   379       "[| nth(i,env) = x; nth(j,env) = y; nth(k,env) = z;
   380           i < length(env); j \<in> nat; k \<in> nat; env \<in> list(A)|]
   381        ==> is_nth(**A, x, y, z) <-> sats(A, nth_fm(i,j,k), env)"
   382 by (simp add: sats_nth_fm)
   383 
   384 theorem nth_reflection:
   385      "REFLECTS[\<lambda>x. is_nth(L, f(x), g(x), h(x)),  
   386                \<lambda>i x. is_nth(**Lset(i), f(x), g(x), h(x))]"
   387 apply (simp only: is_nth_def setclass_simps)
   388 apply (intro FOL_reflections function_reflections is_wfrec_reflection 
   389              iterates_MH_reflection hd_reflection tl_reflection) 
   390 done
   391 
   392 
   393 subsubsection{*An Instance of Replacement for @{term nth}*}
   394 
   395 lemma nth_replacement_Reflects:
   396  "REFLECTS
   397    [\<lambda>x. \<exists>u[L]. u \<in> B \<and> (\<exists>y[L]. pair(L,u,y,x) \<and>
   398          is_wfrec(L, iterates_MH(L, is_tl(L), z), memsn, u, y)),
   399     \<lambda>i x. \<exists>u \<in> Lset(i). u \<in> B \<and> (\<exists>y \<in> Lset(i). pair(**Lset(i), u, y, x) \<and>
   400          is_wfrec(**Lset(i),
   401                   iterates_MH(**Lset(i),
   402                           is_tl(**Lset(i)), z), memsn, u, y))]"
   403 by (intro FOL_reflections function_reflections is_wfrec_reflection
   404           iterates_MH_reflection list_functor_reflection tl_reflection)
   405 
   406 lemma nth_replacement:
   407    "L(w) ==> iterates_replacement(L, %l t. is_tl(L,l,t), w)"
   408 apply (unfold iterates_replacement_def wfrec_replacement_def, clarify)
   409 apply (rule strong_replacementI)
   410 apply (rule_tac u="{A,n,w,Memrel(succ(n))}" 
   411          in gen_separation [OF nth_replacement_Reflects], 
   412        simp add: nonempty)
   413 apply (drule mem_Lset_imp_subset_Lset, clarsimp)
   414 apply (rule DPow_LsetI)
   415 apply (rule bex_iff_sats conj_iff_sats)+
   416 apply (rule_tac env = "[u,x,A,w,Memrel(succ(n))]" in mem_iff_sats)
   417 apply (rule sep_rules is_nat_case_iff_sats tl_iff_sats
   418             is_wfrec_iff_sats iterates_MH_iff_sats quasinat_iff_sats | simp)+
   419 done
   420 
   421 
   422 subsubsection{*Instantiating the locale @{text M_datatypes}*}
   423 
   424 lemma M_datatypes_axioms_L: "M_datatypes_axioms(L)"
   425   apply (rule M_datatypes_axioms.intro)
   426       apply (assumption | rule
   427         list_replacement1 list_replacement2
   428         formula_replacement1 formula_replacement2
   429         nth_replacement)+
   430   done
   431 
   432 theorem M_datatypes_L: "PROP M_datatypes(L)"
   433   apply (rule M_datatypes.intro)
   434       apply (rule M_trancl.axioms [OF M_trancl_L])+
   435  apply (rule M_datatypes_axioms_L) 
   436  done
   437 
   438 lemmas list_closed = M_datatypes.list_closed [OF M_datatypes_L]
   439   and formula_closed = M_datatypes.formula_closed [OF M_datatypes_L]
   440   and list_abs = M_datatypes.list_abs [OF M_datatypes_L]
   441   and formula_abs = M_datatypes.formula_abs [OF M_datatypes_L]
   442   and nth_abs = M_datatypes.nth_abs [OF M_datatypes_L]
   443 
   444 declare list_closed [intro,simp]
   445 declare formula_closed [intro,simp]
   446 declare list_abs [simp]
   447 declare formula_abs [simp]
   448 declare nth_abs [simp]
   449 
   450 
   451 subsection{*@{term L} is Closed Under the Operator @{term eclose}*}
   452 
   453 subsubsection{*Instances of Replacement for @{term eclose}*}
   454 
   455 lemma eclose_replacement1_Reflects:
   456  "REFLECTS
   457    [\<lambda>x. \<exists>u[L]. u \<in> B \<and> (\<exists>y[L]. pair(L,u,y,x) \<and>
   458          is_wfrec(L, iterates_MH(L, big_union(L), A), memsn, u, y)),
   459     \<lambda>i x. \<exists>u \<in> Lset(i). u \<in> B \<and> (\<exists>y \<in> Lset(i). pair(**Lset(i), u, y, x) \<and>
   460          is_wfrec(**Lset(i),
   461                   iterates_MH(**Lset(i), big_union(**Lset(i)), A),
   462                   memsn, u, y))]"
   463 by (intro FOL_reflections function_reflections is_wfrec_reflection
   464           iterates_MH_reflection)
   465 
   466 lemma eclose_replacement1:
   467    "L(A) ==> iterates_replacement(L, big_union(L), A)"
   468 apply (unfold iterates_replacement_def wfrec_replacement_def, clarify)
   469 apply (rule strong_replacementI)
   470 apply (rename_tac B)
   471 apply (rule_tac u="{B,A,n,Memrel(succ(n))}" 
   472          in gen_separation [OF eclose_replacement1_Reflects], simp)
   473 apply (drule mem_Lset_imp_subset_Lset, clarsimp)
   474 apply (rule DPow_LsetI)
   475 apply (rule bex_iff_sats conj_iff_sats)+
   476 apply (rule_tac env = "[u,x,A,n,B,Memrel(succ(n))]" in mem_iff_sats)
   477 apply (rule sep_rules iterates_MH_iff_sats is_nat_case_iff_sats
   478              is_wfrec_iff_sats big_union_iff_sats quasinat_iff_sats | simp)+
   479 done
   480 
   481 
   482 lemma eclose_replacement2_Reflects:
   483  "REFLECTS
   484    [\<lambda>x. \<exists>u[L]. u \<in> B \<and> u \<in> nat \<and>
   485          (\<exists>sn[L]. \<exists>msn[L]. successor(L, u, sn) \<and> membership(L, sn, msn) \<and>
   486            is_wfrec (L, iterates_MH (L, big_union(L), A),
   487                               msn, u, x)),
   488     \<lambda>i x. \<exists>u \<in> Lset(i). u \<in> B \<and> u \<in> nat \<and>
   489          (\<exists>sn \<in> Lset(i). \<exists>msn \<in> Lset(i).
   490           successor(**Lset(i), u, sn) \<and> membership(**Lset(i), sn, msn) \<and>
   491            is_wfrec (**Lset(i),
   492                  iterates_MH (**Lset(i), big_union(**Lset(i)), A),
   493                      msn, u, x))]"
   494 by (intro FOL_reflections function_reflections is_wfrec_reflection
   495           iterates_MH_reflection)
   496 
   497 
   498 lemma eclose_replacement2:
   499    "L(A) ==> strong_replacement(L,
   500          \<lambda>n y. n\<in>nat &
   501                (\<exists>sn[L]. \<exists>msn[L]. successor(L,n,sn) & membership(L,sn,msn) &
   502                is_wfrec(L, iterates_MH(L,big_union(L), A),
   503                         msn, n, y)))"
   504 apply (rule strong_replacementI)
   505 apply (rename_tac B)
   506 apply (rule_tac u="{A,B,nat}" 
   507          in gen_separation [OF eclose_replacement2_Reflects], simp add: L_nat)
   508 apply (drule mem_Lset_imp_subset_Lset, clarsimp)
   509 apply (rule DPow_LsetI)
   510 apply (rule bex_iff_sats conj_iff_sats)+
   511 apply (rule_tac env = "[u,x,A,B,nat]" in mem_iff_sats)
   512 apply (rule sep_rules is_nat_case_iff_sats iterates_MH_iff_sats
   513               is_wfrec_iff_sats big_union_iff_sats quasinat_iff_sats | simp)+
   514 done
   515 
   516 
   517 subsubsection{*Instantiating the locale @{text M_eclose}*}
   518 
   519 lemma M_eclose_axioms_L: "M_eclose_axioms(L)"
   520   apply (rule M_eclose_axioms.intro)
   521    apply (assumption | rule eclose_replacement1 eclose_replacement2)+
   522   done
   523 
   524 theorem M_eclose_L: "PROP M_eclose(L)"
   525   apply (rule M_eclose.intro)
   526        apply (rule M_datatypes.axioms [OF M_datatypes_L])+
   527   apply (rule M_eclose_axioms_L)
   528   done
   529 
   530 lemmas eclose_closed [intro, simp] = M_eclose.eclose_closed [OF M_eclose_L]
   531   and eclose_abs [intro, simp] = M_eclose.eclose_abs [OF M_eclose_L]
   532   and transrec_replacementI = M_eclose.transrec_replacementI [OF M_eclose_L]
   533 
   534 end