src/ZF/Constructible/Rec_Separation.thy
author paulson
Tue Aug 13 17:42:34 2002 +0200 (2002-08-13)
changeset 13496 6f0c57def6d5
parent 13493 5aa68c051725
child 13503 d93f41fe35d2
permissions -rw-r--r--
In ZF/Constructible, moved many results from Satisfies_absolute, etc., to
the new theory Internalize.thy
     1 (*  Title:      ZF/Constructible/Rec_Separation.thy
     2     ID:         $Id$
     3     Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
     4     Copyright   2002  University of Cambridge
     5 *)
     6 
     7 header {*Separation for Facts About Recursion*}
     8 
     9 theory Rec_Separation = Separation + Internalize:
    10 
    11 text{*This theory proves all instances needed for locales @{text
    12 "M_trancl"}, @{text "M_wfrank"} and @{text "M_datatypes"}*}
    13 
    14 lemma eq_succ_imp_lt: "[|i = succ(j); Ord(i)|] ==> j<i"
    15 by simp
    16 
    17 
    18 subsection{*The Locale @{text "M_trancl"}*}
    19 
    20 subsubsection{*Separation for Reflexive/Transitive Closure*}
    21 
    22 text{*First, The Defining Formula*}
    23 
    24 (* "rtran_closure_mem(M,A,r,p) ==
    25       \<exists>nnat[M]. \<exists>n[M]. \<exists>n'[M].
    26        omega(M,nnat) & n\<in>nnat & successor(M,n,n') &
    27        (\<exists>f[M]. typed_function(M,n',A,f) &
    28         (\<exists>x[M]. \<exists>y[M]. \<exists>zero[M]. pair(M,x,y,p) & empty(M,zero) &
    29           fun_apply(M,f,zero,x) & fun_apply(M,f,n,y)) &
    30         (\<forall>j[M]. j\<in>n -->
    31           (\<exists>fj[M]. \<exists>sj[M]. \<exists>fsj[M]. \<exists>ffp[M].
    32             fun_apply(M,f,j,fj) & successor(M,j,sj) &
    33             fun_apply(M,f,sj,fsj) & pair(M,fj,fsj,ffp) & ffp \<in> r)))"*)
    34 constdefs rtran_closure_mem_fm :: "[i,i,i]=>i"
    35  "rtran_closure_mem_fm(A,r,p) ==
    36    Exists(Exists(Exists(
    37     And(omega_fm(2),
    38      And(Member(1,2),
    39       And(succ_fm(1,0),
    40        Exists(And(typed_function_fm(1, A#+4, 0),
    41         And(Exists(Exists(Exists(
    42               And(pair_fm(2,1,p#+7),
    43                And(empty_fm(0),
    44                 And(fun_apply_fm(3,0,2), fun_apply_fm(3,5,1))))))),
    45             Forall(Implies(Member(0,3),
    46              Exists(Exists(Exists(Exists(
    47               And(fun_apply_fm(5,4,3),
    48                And(succ_fm(4,2),
    49                 And(fun_apply_fm(5,2,1),
    50                  And(pair_fm(3,1,0), Member(0,r#+9))))))))))))))))))))"
    51 
    52 
    53 lemma rtran_closure_mem_type [TC]:
    54  "[| x \<in> nat; y \<in> nat; z \<in> nat |] ==> rtran_closure_mem_fm(x,y,z) \<in> formula"
    55 by (simp add: rtran_closure_mem_fm_def)
    56 
    57 lemma arity_rtran_closure_mem_fm [simp]:
    58      "[| x \<in> nat; y \<in> nat; z \<in> nat |]
    59       ==> arity(rtran_closure_mem_fm(x,y,z)) = succ(x) \<union> succ(y) \<union> succ(z)"
    60 by (simp add: rtran_closure_mem_fm_def succ_Un_distrib [symmetric] Un_ac)
    61 
    62 lemma sats_rtran_closure_mem_fm [simp]:
    63    "[| x \<in> nat; y \<in> nat; z \<in> nat; env \<in> list(A)|]
    64     ==> sats(A, rtran_closure_mem_fm(x,y,z), env) <->
    65         rtran_closure_mem(**A, nth(x,env), nth(y,env), nth(z,env))"
    66 by (simp add: rtran_closure_mem_fm_def rtran_closure_mem_def)
    67 
    68 lemma rtran_closure_mem_iff_sats:
    69       "[| nth(i,env) = x; nth(j,env) = y; nth(k,env) = z;
    70           i \<in> nat; j \<in> nat; k \<in> nat; env \<in> list(A)|]
    71        ==> rtran_closure_mem(**A, x, y, z) <-> sats(A, rtran_closure_mem_fm(i,j,k), env)"
    72 by (simp add: sats_rtran_closure_mem_fm)
    73 
    74 theorem rtran_closure_mem_reflection:
    75      "REFLECTS[\<lambda>x. rtran_closure_mem(L,f(x),g(x),h(x)),
    76                \<lambda>i x. rtran_closure_mem(**Lset(i),f(x),g(x),h(x))]"
    77 apply (simp only: rtran_closure_mem_def setclass_simps)
    78 apply (intro FOL_reflections function_reflections fun_plus_reflections)
    79 done
    80 
    81 text{*Separation for @{term "rtrancl(r)"}.*}
    82 lemma rtrancl_separation:
    83      "[| L(r); L(A) |] ==> separation (L, rtran_closure_mem(L,A,r))"
    84 apply (rule separation_CollectI)
    85 apply (rule_tac A="{r,A,z}" in subset_LsetE, blast )
    86 apply (rule ReflectsE [OF rtran_closure_mem_reflection], assumption)
    87 apply (drule subset_Lset_ltD, assumption)
    88 apply (erule reflection_imp_L_separation)
    89   apply (simp_all add: lt_Ord2)
    90 apply (rule DPow_LsetI)
    91 apply (rename_tac u)
    92 apply (rule_tac env = "[u,r,A]" in rtran_closure_mem_iff_sats)
    93 apply (rule sep_rules | simp)+
    94 done
    95 
    96 
    97 subsubsection{*Reflexive/Transitive Closure, Internalized*}
    98 
    99 (*  "rtran_closure(M,r,s) ==
   100         \<forall>A[M]. is_field(M,r,A) -->
   101          (\<forall>p[M]. p \<in> s <-> rtran_closure_mem(M,A,r,p))" *)
   102 constdefs rtran_closure_fm :: "[i,i]=>i"
   103  "rtran_closure_fm(r,s) ==
   104    Forall(Implies(field_fm(succ(r),0),
   105                   Forall(Iff(Member(0,succ(succ(s))),
   106                              rtran_closure_mem_fm(1,succ(succ(r)),0)))))"
   107 
   108 lemma rtran_closure_type [TC]:
   109      "[| x \<in> nat; y \<in> nat |] ==> rtran_closure_fm(x,y) \<in> formula"
   110 by (simp add: rtran_closure_fm_def)
   111 
   112 lemma arity_rtran_closure_fm [simp]:
   113      "[| x \<in> nat; y \<in> nat |]
   114       ==> arity(rtran_closure_fm(x,y)) = succ(x) \<union> succ(y)"
   115 by (simp add: rtran_closure_fm_def succ_Un_distrib [symmetric] Un_ac)
   116 
   117 lemma sats_rtran_closure_fm [simp]:
   118    "[| x \<in> nat; y \<in> nat; env \<in> list(A)|]
   119     ==> sats(A, rtran_closure_fm(x,y), env) <->
   120         rtran_closure(**A, nth(x,env), nth(y,env))"
   121 by (simp add: rtran_closure_fm_def rtran_closure_def)
   122 
   123 lemma rtran_closure_iff_sats:
   124       "[| nth(i,env) = x; nth(j,env) = y;
   125           i \<in> nat; j \<in> nat; env \<in> list(A)|]
   126        ==> rtran_closure(**A, x, y) <-> sats(A, rtran_closure_fm(i,j), env)"
   127 by simp
   128 
   129 theorem rtran_closure_reflection:
   130      "REFLECTS[\<lambda>x. rtran_closure(L,f(x),g(x)),
   131                \<lambda>i x. rtran_closure(**Lset(i),f(x),g(x))]"
   132 apply (simp only: rtran_closure_def setclass_simps)
   133 apply (intro FOL_reflections function_reflections rtran_closure_mem_reflection)
   134 done
   135 
   136 
   137 subsubsection{*Transitive Closure of a Relation, Internalized*}
   138 
   139 (*  "tran_closure(M,r,t) ==
   140          \<exists>s[M]. rtran_closure(M,r,s) & composition(M,r,s,t)" *)
   141 constdefs tran_closure_fm :: "[i,i]=>i"
   142  "tran_closure_fm(r,s) ==
   143    Exists(And(rtran_closure_fm(succ(r),0), composition_fm(succ(r),0,succ(s))))"
   144 
   145 lemma tran_closure_type [TC]:
   146      "[| x \<in> nat; y \<in> nat |] ==> tran_closure_fm(x,y) \<in> formula"
   147 by (simp add: tran_closure_fm_def)
   148 
   149 lemma arity_tran_closure_fm [simp]:
   150      "[| x \<in> nat; y \<in> nat |]
   151       ==> arity(tran_closure_fm(x,y)) = succ(x) \<union> succ(y)"
   152 by (simp add: tran_closure_fm_def succ_Un_distrib [symmetric] Un_ac)
   153 
   154 lemma sats_tran_closure_fm [simp]:
   155    "[| x \<in> nat; y \<in> nat; env \<in> list(A)|]
   156     ==> sats(A, tran_closure_fm(x,y), env) <->
   157         tran_closure(**A, nth(x,env), nth(y,env))"
   158 by (simp add: tran_closure_fm_def tran_closure_def)
   159 
   160 lemma tran_closure_iff_sats:
   161       "[| nth(i,env) = x; nth(j,env) = y;
   162           i \<in> nat; j \<in> nat; env \<in> list(A)|]
   163        ==> tran_closure(**A, x, y) <-> sats(A, tran_closure_fm(i,j), env)"
   164 by simp
   165 
   166 theorem tran_closure_reflection:
   167      "REFLECTS[\<lambda>x. tran_closure(L,f(x),g(x)),
   168                \<lambda>i x. tran_closure(**Lset(i),f(x),g(x))]"
   169 apply (simp only: tran_closure_def setclass_simps)
   170 apply (intro FOL_reflections function_reflections
   171              rtran_closure_reflection composition_reflection)
   172 done
   173 
   174 
   175 subsection{*Separation for the Proof of @{text "wellfounded_on_trancl"}*}
   176 
   177 lemma wellfounded_trancl_reflects:
   178   "REFLECTS[\<lambda>x. \<exists>w[L]. \<exists>wx[L]. \<exists>rp[L].
   179                  w \<in> Z & pair(L,w,x,wx) & tran_closure(L,r,rp) & wx \<in> rp,
   180    \<lambda>i x. \<exists>w \<in> Lset(i). \<exists>wx \<in> Lset(i). \<exists>rp \<in> Lset(i).
   181        w \<in> Z & pair(**Lset(i),w,x,wx) & tran_closure(**Lset(i),r,rp) &
   182        wx \<in> rp]"
   183 by (intro FOL_reflections function_reflections fun_plus_reflections
   184           tran_closure_reflection)
   185 
   186 
   187 lemma wellfounded_trancl_separation:
   188          "[| L(r); L(Z) |] ==>
   189           separation (L, \<lambda>x.
   190               \<exists>w[L]. \<exists>wx[L]. \<exists>rp[L].
   191                w \<in> Z & pair(L,w,x,wx) & tran_closure(L,r,rp) & wx \<in> rp)"
   192 apply (rule separation_CollectI)
   193 apply (rule_tac A="{r,Z,z}" in subset_LsetE, blast )
   194 apply (rule ReflectsE [OF wellfounded_trancl_reflects], assumption)
   195 apply (drule subset_Lset_ltD, assumption)
   196 apply (erule reflection_imp_L_separation)
   197   apply (simp_all add: lt_Ord2)
   198 apply (rule DPow_LsetI)
   199 apply (rename_tac u)
   200 apply (rule bex_iff_sats conj_iff_sats)+
   201 apply (rule_tac env = "[w,u,r,Z]" in mem_iff_sats)
   202 apply (rule sep_rules tran_closure_iff_sats | simp)+
   203 done
   204 
   205 
   206 subsubsection{*Instantiating the locale @{text M_trancl}*}
   207 
   208 lemma M_trancl_axioms_L: "M_trancl_axioms(L)"
   209   apply (rule M_trancl_axioms.intro)
   210    apply (assumption | rule rtrancl_separation wellfounded_trancl_separation)+
   211   done
   212 
   213 theorem M_trancl_L: "PROP M_trancl(L)"
   214 by (rule M_trancl.intro
   215          [OF M_triv_axioms_L M_axioms_axioms_L M_trancl_axioms_L])
   216 
   217 lemmas iterates_abs = M_trancl.iterates_abs [OF M_trancl_L]
   218   and rtran_closure_rtrancl = M_trancl.rtran_closure_rtrancl [OF M_trancl_L]
   219   and rtrancl_closed = M_trancl.rtrancl_closed [OF M_trancl_L]
   220   and rtrancl_abs = M_trancl.rtrancl_abs [OF M_trancl_L]
   221   and trancl_closed = M_trancl.trancl_closed [OF M_trancl_L]
   222   and trancl_abs = M_trancl.trancl_abs [OF M_trancl_L]
   223   and wellfounded_on_trancl = M_trancl.wellfounded_on_trancl [OF M_trancl_L]
   224   and wellfounded_trancl = M_trancl.wellfounded_trancl [OF M_trancl_L]
   225   and wfrec_relativize = M_trancl.wfrec_relativize [OF M_trancl_L]
   226   and trans_wfrec_relativize = M_trancl.trans_wfrec_relativize [OF M_trancl_L]
   227   and trans_wfrec_abs = M_trancl.trans_wfrec_abs [OF M_trancl_L]
   228   and trans_eq_pair_wfrec_iff = M_trancl.trans_eq_pair_wfrec_iff [OF M_trancl_L]
   229   and eq_pair_wfrec_iff = M_trancl.eq_pair_wfrec_iff [OF M_trancl_L]
   230 
   231 declare rtrancl_closed [intro,simp]
   232 declare rtrancl_abs [simp]
   233 declare trancl_closed [intro,simp]
   234 declare trancl_abs [simp]
   235 
   236 
   237 subsection{*Well-Founded Recursion!*}
   238 
   239 
   240 text{*Alternative definition, minimizing nesting of quantifiers around MH*}
   241 lemma M_is_recfun_iff:
   242    "M_is_recfun(M,MH,r,a,f) <->
   243     (\<forall>z[M]. z \<in> f <-> 
   244      (\<exists>x[M]. \<exists>f_r_sx[M]. \<exists>y[M]. 
   245              MH(x, f_r_sx, y) & pair(M,x,y,z) &
   246              (\<exists>xa[M]. \<exists>sx[M]. \<exists>r_sx[M]. 
   247                 pair(M,x,a,xa) & upair(M,x,x,sx) &
   248                pre_image(M,r,sx,r_sx) & restriction(M,f,r_sx,f_r_sx) &
   249                xa \<in> r)))"
   250 apply (simp add: M_is_recfun_def)
   251 apply (rule rall_cong, blast) 
   252 done
   253 
   254 
   255 (* M_is_recfun :: "[i=>o, [i,i,i]=>o, i, i, i] => o"
   256    "M_is_recfun(M,MH,r,a,f) ==
   257      \<forall>z[M]. z \<in> f <->
   258                2      1           0
   259 new def     (\<exists>x[M]. \<exists>f_r_sx[M]. \<exists>y[M]. 
   260              MH(x, f_r_sx, y) & pair(M,x,y,z) &
   261              (\<exists>xa[M]. \<exists>sx[M]. \<exists>r_sx[M]. 
   262                 pair(M,x,a,xa) & upair(M,x,x,sx) &
   263                pre_image(M,r,sx,r_sx) & restriction(M,f,r_sx,f_r_sx) &
   264                xa \<in> r)"
   265 *)
   266 
   267 text{*The three arguments of @{term p} are always 2, 1, 0 and z*}
   268 constdefs is_recfun_fm :: "[i, i, i, i]=>i"
   269  "is_recfun_fm(p,r,a,f) == 
   270    Forall(Iff(Member(0,succ(f)),
   271     Exists(Exists(Exists(
   272      And(p, 
   273       And(pair_fm(2,0,3),
   274        Exists(Exists(Exists(
   275 	And(pair_fm(5,a#+7,2),
   276 	 And(upair_fm(5,5,1),
   277 	  And(pre_image_fm(r#+7,1,0),
   278 	   And(restriction_fm(f#+7,0,4), Member(2,r#+7)))))))))))))))"
   279 
   280 lemma is_recfun_type [TC]:
   281      "[| p \<in> formula; x \<in> nat; y \<in> nat; z \<in> nat |] 
   282       ==> is_recfun_fm(p,x,y,z) \<in> formula"
   283 by (simp add: is_recfun_fm_def)
   284 
   285 
   286 lemma sats_is_recfun_fm:
   287   assumes MH_iff_sats: 
   288       "!!a0 a1 a2 a3. 
   289         [|a0\<in>A; a1\<in>A; a2\<in>A; a3\<in>A|] 
   290         ==> MH(a2, a1, a0) <-> sats(A, p, Cons(a0,Cons(a1,Cons(a2,Cons(a3,env)))))"
   291   shows 
   292       "[|x \<in> nat; y \<in> nat; z \<in> nat; env \<in> list(A)|]
   293        ==> sats(A, is_recfun_fm(p,x,y,z), env) <->
   294            M_is_recfun(**A, MH, nth(x,env), nth(y,env), nth(z,env))"
   295 by (simp add: is_recfun_fm_def M_is_recfun_iff MH_iff_sats [THEN iff_sym])
   296 
   297 lemma is_recfun_iff_sats:
   298   assumes MH_iff_sats: 
   299       "!!a0 a1 a2 a3. 
   300         [|a0\<in>A; a1\<in>A; a2\<in>A; a3\<in>A|] 
   301         ==> MH(a2, a1, a0) <-> sats(A, p, Cons(a0,Cons(a1,Cons(a2,Cons(a3,env)))))"
   302   shows
   303   "[| nth(i,env) = x; nth(j,env) = y; nth(k,env) = z; 
   304       i \<in> nat; j \<in> nat; k \<in> nat; env \<in> list(A)|]
   305    ==> M_is_recfun(**A, MH, x, y, z) <-> sats(A, is_recfun_fm(p,i,j,k), env)"
   306 by (simp add: sats_is_recfun_fm [OF MH_iff_sats]) 
   307 
   308 text{*The additional variable in the premise, namely @{term f'}, is essential.
   309 It lets @{term MH} depend upon @{term x}, which seems often necessary.
   310 The same thing occurs in @{text is_wfrec_reflection}.*}
   311 theorem is_recfun_reflection:
   312   assumes MH_reflection:
   313     "!!f' f g h. REFLECTS[\<lambda>x. MH(L, f'(x), f(x), g(x), h(x)), 
   314                      \<lambda>i x. MH(**Lset(i), f'(x), f(x), g(x), h(x))]"
   315   shows "REFLECTS[\<lambda>x. M_is_recfun(L, MH(L,x), f(x), g(x), h(x)), 
   316              \<lambda>i x. M_is_recfun(**Lset(i), MH(**Lset(i),x), f(x), g(x), h(x))]"
   317 apply (simp (no_asm_use) only: M_is_recfun_def setclass_simps)
   318 apply (intro FOL_reflections function_reflections
   319              restriction_reflection MH_reflection)
   320 done
   321 
   322 subsubsection{*The Operator @{term is_wfrec}*}
   323 
   324 text{*The three arguments of @{term p} are always 2, 1, 0*}
   325 
   326 (* is_wfrec :: "[i=>o, i, [i,i,i]=>o, i, i] => o"
   327     "is_wfrec(M,MH,r,a,z) == 
   328       \<exists>f[M]. M_is_recfun(M,MH,r,a,f) & MH(a,f,z)" *)
   329 constdefs is_wfrec_fm :: "[i, i, i, i]=>i"
   330  "is_wfrec_fm(p,r,a,z) == 
   331     Exists(And(is_recfun_fm(p, succ(r), succ(a), 0),
   332            Exists(Exists(Exists(Exists(
   333              And(Equal(2,a#+5), And(Equal(1,4), And(Equal(0,z#+5), p)))))))))"
   334 
   335 text{*We call @{term p} with arguments a, f, z by equating them with 
   336   the corresponding quantified variables with de Bruijn indices 2, 1, 0.*}
   337 
   338 text{*There's an additional existential quantifier to ensure that the
   339       environments in both calls to MH have the same length.*}
   340 
   341 lemma is_wfrec_type [TC]:
   342      "[| p \<in> formula; x \<in> nat; y \<in> nat; z \<in> nat |] 
   343       ==> is_wfrec_fm(p,x,y,z) \<in> formula"
   344 by (simp add: is_wfrec_fm_def) 
   345 
   346 lemma sats_is_wfrec_fm:
   347   assumes MH_iff_sats: 
   348       "!!a0 a1 a2 a3 a4. 
   349         [|a0\<in>A; a1\<in>A; a2\<in>A; a3\<in>A; a4\<in>A|] 
   350         ==> MH(a2, a1, a0) <-> sats(A, p, Cons(a0,Cons(a1,Cons(a2,Cons(a3,Cons(a4,env))))))"
   351   shows 
   352       "[|x \<in> nat; y < length(env); z < length(env); env \<in> list(A)|]
   353        ==> sats(A, is_wfrec_fm(p,x,y,z), env) <-> 
   354            is_wfrec(**A, MH, nth(x,env), nth(y,env), nth(z,env))"
   355 apply (frule_tac x=z in lt_length_in_nat, assumption)  
   356 apply (frule lt_length_in_nat, assumption)  
   357 apply (simp add: is_wfrec_fm_def sats_is_recfun_fm is_wfrec_def MH_iff_sats [THEN iff_sym], blast) 
   358 done
   359 
   360 
   361 lemma is_wfrec_iff_sats:
   362   assumes MH_iff_sats: 
   363       "!!a0 a1 a2 a3 a4. 
   364         [|a0\<in>A; a1\<in>A; a2\<in>A; a3\<in>A; a4\<in>A|] 
   365         ==> MH(a2, a1, a0) <-> sats(A, p, Cons(a0,Cons(a1,Cons(a2,Cons(a3,Cons(a4,env))))))"
   366   shows
   367   "[|nth(i,env) = x; nth(j,env) = y; nth(k,env) = z; 
   368       i \<in> nat; j < length(env); k < length(env); env \<in> list(A)|]
   369    ==> is_wfrec(**A, MH, x, y, z) <-> sats(A, is_wfrec_fm(p,i,j,k), env)" 
   370 by (simp add: sats_is_wfrec_fm [OF MH_iff_sats])
   371 
   372 theorem is_wfrec_reflection:
   373   assumes MH_reflection:
   374     "!!f' f g h. REFLECTS[\<lambda>x. MH(L, f'(x), f(x), g(x), h(x)), 
   375                      \<lambda>i x. MH(**Lset(i), f'(x), f(x), g(x), h(x))]"
   376   shows "REFLECTS[\<lambda>x. is_wfrec(L, MH(L,x), f(x), g(x), h(x)), 
   377                \<lambda>i x. is_wfrec(**Lset(i), MH(**Lset(i),x), f(x), g(x), h(x))]"
   378 apply (simp (no_asm_use) only: is_wfrec_def setclass_simps)
   379 apply (intro FOL_reflections MH_reflection is_recfun_reflection)
   380 done
   381 
   382 subsection{*The Locale @{text "M_wfrank"}*}
   383 
   384 subsubsection{*Separation for @{term "wfrank"}*}
   385 
   386 lemma wfrank_Reflects:
   387  "REFLECTS[\<lambda>x. \<forall>rplus[L]. tran_closure(L,r,rplus) -->
   388               ~ (\<exists>f[L]. M_is_recfun(L, %x f y. is_range(L,f,y), rplus, x, f)),
   389       \<lambda>i x. \<forall>rplus \<in> Lset(i). tran_closure(**Lset(i),r,rplus) -->
   390          ~ (\<exists>f \<in> Lset(i).
   391             M_is_recfun(**Lset(i), %x f y. is_range(**Lset(i),f,y),
   392                         rplus, x, f))]"
   393 by (intro FOL_reflections function_reflections is_recfun_reflection tran_closure_reflection)
   394 
   395 lemma wfrank_separation:
   396      "L(r) ==>
   397       separation (L, \<lambda>x. \<forall>rplus[L]. tran_closure(L,r,rplus) -->
   398          ~ (\<exists>f[L]. M_is_recfun(L, %x f y. is_range(L,f,y), rplus, x, f)))"
   399 apply (rule separation_CollectI)
   400 apply (rule_tac A="{r,z}" in subset_LsetE, blast )
   401 apply (rule ReflectsE [OF wfrank_Reflects], assumption)
   402 apply (drule subset_Lset_ltD, assumption)
   403 apply (erule reflection_imp_L_separation)
   404   apply (simp_all add: lt_Ord2, clarify)
   405 apply (rule DPow_LsetI)
   406 apply (rename_tac u)
   407 apply (rule ball_iff_sats imp_iff_sats)+
   408 apply (rule_tac env="[rplus,u,r]" in tran_closure_iff_sats)
   409 apply (rule sep_rules | simp)+
   410 apply (rule sep_rules is_recfun_iff_sats | simp)+
   411 done
   412 
   413 
   414 subsubsection{*Replacement for @{term "wfrank"}*}
   415 
   416 lemma wfrank_replacement_Reflects:
   417  "REFLECTS[\<lambda>z. \<exists>x[L]. x \<in> A &
   418         (\<forall>rplus[L]. tran_closure(L,r,rplus) -->
   419          (\<exists>y[L]. \<exists>f[L]. pair(L,x,y,z)  &
   420                         M_is_recfun(L, %x f y. is_range(L,f,y), rplus, x, f) &
   421                         is_range(L,f,y))),
   422  \<lambda>i z. \<exists>x \<in> Lset(i). x \<in> A &
   423       (\<forall>rplus \<in> Lset(i). tran_closure(**Lset(i),r,rplus) -->
   424        (\<exists>y \<in> Lset(i). \<exists>f \<in> Lset(i). pair(**Lset(i),x,y,z)  &
   425          M_is_recfun(**Lset(i), %x f y. is_range(**Lset(i),f,y), rplus, x, f) &
   426          is_range(**Lset(i),f,y)))]"
   427 by (intro FOL_reflections function_reflections fun_plus_reflections
   428              is_recfun_reflection tran_closure_reflection)
   429 
   430 
   431 lemma wfrank_strong_replacement:
   432      "L(r) ==>
   433       strong_replacement(L, \<lambda>x z.
   434          \<forall>rplus[L]. tran_closure(L,r,rplus) -->
   435          (\<exists>y[L]. \<exists>f[L]. pair(L,x,y,z)  &
   436                         M_is_recfun(L, %x f y. is_range(L,f,y), rplus, x, f) &
   437                         is_range(L,f,y)))"
   438 apply (rule strong_replacementI)
   439 apply (rule rallI)
   440 apply (rename_tac B)
   441 apply (rule separation_CollectI)
   442 apply (rule_tac A="{B,r,z}" in subset_LsetE, blast )
   443 apply (rule ReflectsE [OF wfrank_replacement_Reflects], assumption)
   444 apply (drule subset_Lset_ltD, assumption)
   445 apply (erule reflection_imp_L_separation)
   446   apply (simp_all add: lt_Ord2)
   447 apply (rule DPow_LsetI)
   448 apply (rename_tac u)
   449 apply (rule bex_iff_sats ball_iff_sats conj_iff_sats)+
   450 apply (rule_tac env = "[x,u,B,r]" in mem_iff_sats)
   451 apply (rule sep_rules list.intros app_type tran_closure_iff_sats is_recfun_iff_sats | simp)+
   452 done
   453 
   454 
   455 subsubsection{*Separation for Proving @{text Ord_wfrank_range}*}
   456 
   457 lemma Ord_wfrank_Reflects:
   458  "REFLECTS[\<lambda>x. \<forall>rplus[L]. tran_closure(L,r,rplus) -->
   459           ~ (\<forall>f[L]. \<forall>rangef[L].
   460              is_range(L,f,rangef) -->
   461              M_is_recfun(L, \<lambda>x f y. is_range(L,f,y), rplus, x, f) -->
   462              ordinal(L,rangef)),
   463       \<lambda>i x. \<forall>rplus \<in> Lset(i). tran_closure(**Lset(i),r,rplus) -->
   464           ~ (\<forall>f \<in> Lset(i). \<forall>rangef \<in> Lset(i).
   465              is_range(**Lset(i),f,rangef) -->
   466              M_is_recfun(**Lset(i), \<lambda>x f y. is_range(**Lset(i),f,y),
   467                          rplus, x, f) -->
   468              ordinal(**Lset(i),rangef))]"
   469 by (intro FOL_reflections function_reflections is_recfun_reflection
   470           tran_closure_reflection ordinal_reflection)
   471 
   472 lemma  Ord_wfrank_separation:
   473      "L(r) ==>
   474       separation (L, \<lambda>x.
   475          \<forall>rplus[L]. tran_closure(L,r,rplus) -->
   476           ~ (\<forall>f[L]. \<forall>rangef[L].
   477              is_range(L,f,rangef) -->
   478              M_is_recfun(L, \<lambda>x f y. is_range(L,f,y), rplus, x, f) -->
   479              ordinal(L,rangef)))"
   480 apply (rule separation_CollectI)
   481 apply (rule_tac A="{r,z}" in subset_LsetE, blast )
   482 apply (rule ReflectsE [OF Ord_wfrank_Reflects], assumption)
   483 apply (drule subset_Lset_ltD, assumption)
   484 apply (erule reflection_imp_L_separation)
   485   apply (simp_all add: lt_Ord2, clarify)
   486 apply (rule DPow_LsetI)
   487 apply (rename_tac u)
   488 apply (rule ball_iff_sats imp_iff_sats)+
   489 apply (rule_tac env="[rplus,u,r]" in tran_closure_iff_sats)
   490 apply (rule sep_rules is_recfun_iff_sats | simp)+
   491 done
   492 
   493 
   494 subsubsection{*Instantiating the locale @{text M_wfrank}*}
   495 
   496 lemma M_wfrank_axioms_L: "M_wfrank_axioms(L)"
   497   apply (rule M_wfrank_axioms.intro)
   498    apply (assumption | rule
   499      wfrank_separation wfrank_strong_replacement Ord_wfrank_separation)+
   500   done
   501 
   502 theorem M_wfrank_L: "PROP M_wfrank(L)"
   503   apply (rule M_wfrank.intro)
   504      apply (rule M_trancl.axioms [OF M_trancl_L])+
   505   apply (rule M_wfrank_axioms_L) 
   506   done
   507 
   508 lemmas iterates_closed = M_wfrank.iterates_closed [OF M_wfrank_L]
   509   and exists_wfrank = M_wfrank.exists_wfrank [OF M_wfrank_L]
   510   and M_wellfoundedrank = M_wfrank.M_wellfoundedrank [OF M_wfrank_L]
   511   and Ord_wfrank_range = M_wfrank.Ord_wfrank_range [OF M_wfrank_L]
   512   and Ord_range_wellfoundedrank = M_wfrank.Ord_range_wellfoundedrank [OF M_wfrank_L]
   513   and function_wellfoundedrank = M_wfrank.function_wellfoundedrank [OF M_wfrank_L]
   514   and domain_wellfoundedrank = M_wfrank.domain_wellfoundedrank [OF M_wfrank_L]
   515   and wellfoundedrank_type = M_wfrank.wellfoundedrank_type [OF M_wfrank_L]
   516   and Ord_wellfoundedrank = M_wfrank.Ord_wellfoundedrank [OF M_wfrank_L]
   517   and wellfoundedrank_eq = M_wfrank.wellfoundedrank_eq [OF M_wfrank_L]
   518   and wellfoundedrank_lt = M_wfrank.wellfoundedrank_lt [OF M_wfrank_L]
   519   and wellfounded_imp_subset_rvimage = M_wfrank.wellfounded_imp_subset_rvimage [OF M_wfrank_L]
   520   and wellfounded_imp_wf = M_wfrank.wellfounded_imp_wf [OF M_wfrank_L]
   521   and wellfounded_on_imp_wf_on = M_wfrank.wellfounded_on_imp_wf_on [OF M_wfrank_L]
   522   and wf_abs = M_wfrank.wf_abs [OF M_wfrank_L]
   523   and wf_on_abs = M_wfrank.wf_on_abs [OF M_wfrank_L]
   524   and wfrec_replacement_iff = M_wfrank.wfrec_replacement_iff [OF M_wfrank_L]
   525   and trans_wfrec_closed = M_wfrank.trans_wfrec_closed [OF M_wfrank_L]
   526   and wfrec_closed = M_wfrank.wfrec_closed [OF M_wfrank_L]
   527 
   528 declare iterates_closed [intro,simp]
   529 declare Ord_wfrank_range [rule_format]
   530 declare wf_abs [simp]
   531 declare wf_on_abs [simp]
   532 
   533 
   534 subsection{*For Datatypes*}
   535 
   536 subsubsection{*Binary Products, Internalized*}
   537 
   538 constdefs cartprod_fm :: "[i,i,i]=>i"
   539 (* "cartprod(M,A,B,z) ==
   540         \<forall>u[M]. u \<in> z <-> (\<exists>x[M]. x\<in>A & (\<exists>y[M]. y\<in>B & pair(M,x,y,u)))" *)
   541     "cartprod_fm(A,B,z) ==
   542        Forall(Iff(Member(0,succ(z)),
   543                   Exists(And(Member(0,succ(succ(A))),
   544                          Exists(And(Member(0,succ(succ(succ(B)))),
   545                                     pair_fm(1,0,2)))))))"
   546 
   547 lemma cartprod_type [TC]:
   548      "[| x \<in> nat; y \<in> nat; z \<in> nat |] ==> cartprod_fm(x,y,z) \<in> formula"
   549 by (simp add: cartprod_fm_def)
   550 
   551 lemma arity_cartprod_fm [simp]:
   552      "[| x \<in> nat; y \<in> nat; z \<in> nat |]
   553       ==> arity(cartprod_fm(x,y,z)) = succ(x) \<union> succ(y) \<union> succ(z)"
   554 by (simp add: cartprod_fm_def succ_Un_distrib [symmetric] Un_ac)
   555 
   556 lemma sats_cartprod_fm [simp]:
   557    "[| x \<in> nat; y \<in> nat; z \<in> nat; env \<in> list(A)|]
   558     ==> sats(A, cartprod_fm(x,y,z), env) <->
   559         cartprod(**A, nth(x,env), nth(y,env), nth(z,env))"
   560 by (simp add: cartprod_fm_def cartprod_def)
   561 
   562 lemma cartprod_iff_sats:
   563       "[| nth(i,env) = x; nth(j,env) = y; nth(k,env) = z;
   564           i \<in> nat; j \<in> nat; k \<in> nat; env \<in> list(A)|]
   565        ==> cartprod(**A, x, y, z) <-> sats(A, cartprod_fm(i,j,k), env)"
   566 by (simp add: sats_cartprod_fm)
   567 
   568 theorem cartprod_reflection:
   569      "REFLECTS[\<lambda>x. cartprod(L,f(x),g(x),h(x)),
   570                \<lambda>i x. cartprod(**Lset(i),f(x),g(x),h(x))]"
   571 apply (simp only: cartprod_def setclass_simps)
   572 apply (intro FOL_reflections pair_reflection)
   573 done
   574 
   575 
   576 subsubsection{*Binary Sums, Internalized*}
   577 
   578 (* "is_sum(M,A,B,Z) ==
   579        \<exists>A0[M]. \<exists>n1[M]. \<exists>s1[M]. \<exists>B1[M].
   580          3      2       1        0
   581        number1(M,n1) & cartprod(M,n1,A,A0) & upair(M,n1,n1,s1) &
   582        cartprod(M,s1,B,B1) & union(M,A0,B1,Z)"  *)
   583 constdefs sum_fm :: "[i,i,i]=>i"
   584     "sum_fm(A,B,Z) ==
   585        Exists(Exists(Exists(Exists(
   586         And(number1_fm(2),
   587             And(cartprod_fm(2,A#+4,3),
   588                 And(upair_fm(2,2,1),
   589                     And(cartprod_fm(1,B#+4,0), union_fm(3,0,Z#+4)))))))))"
   590 
   591 lemma sum_type [TC]:
   592      "[| x \<in> nat; y \<in> nat; z \<in> nat |] ==> sum_fm(x,y,z) \<in> formula"
   593 by (simp add: sum_fm_def)
   594 
   595 lemma arity_sum_fm [simp]:
   596      "[| x \<in> nat; y \<in> nat; z \<in> nat |]
   597       ==> arity(sum_fm(x,y,z)) = succ(x) \<union> succ(y) \<union> succ(z)"
   598 by (simp add: sum_fm_def succ_Un_distrib [symmetric] Un_ac)
   599 
   600 lemma sats_sum_fm [simp]:
   601    "[| x \<in> nat; y \<in> nat; z \<in> nat; env \<in> list(A)|]
   602     ==> sats(A, sum_fm(x,y,z), env) <->
   603         is_sum(**A, nth(x,env), nth(y,env), nth(z,env))"
   604 by (simp add: sum_fm_def is_sum_def)
   605 
   606 lemma sum_iff_sats:
   607       "[| nth(i,env) = x; nth(j,env) = y; nth(k,env) = z;
   608           i \<in> nat; j \<in> nat; k \<in> nat; env \<in> list(A)|]
   609        ==> is_sum(**A, x, y, z) <-> sats(A, sum_fm(i,j,k), env)"
   610 by simp
   611 
   612 theorem sum_reflection:
   613      "REFLECTS[\<lambda>x. is_sum(L,f(x),g(x),h(x)),
   614                \<lambda>i x. is_sum(**Lset(i),f(x),g(x),h(x))]"
   615 apply (simp only: is_sum_def setclass_simps)
   616 apply (intro FOL_reflections function_reflections cartprod_reflection)
   617 done
   618 
   619 
   620 subsubsection{*The Operator @{term quasinat}*}
   621 
   622 (* "is_quasinat(M,z) == empty(M,z) | (\<exists>m[M]. successor(M,m,z))" *)
   623 constdefs quasinat_fm :: "i=>i"
   624     "quasinat_fm(z) == Or(empty_fm(z), Exists(succ_fm(0,succ(z))))"
   625 
   626 lemma quasinat_type [TC]:
   627      "x \<in> nat ==> quasinat_fm(x) \<in> formula"
   628 by (simp add: quasinat_fm_def)
   629 
   630 lemma arity_quasinat_fm [simp]:
   631      "x \<in> nat ==> arity(quasinat_fm(x)) = succ(x)"
   632 by (simp add: quasinat_fm_def succ_Un_distrib [symmetric] Un_ac)
   633 
   634 lemma sats_quasinat_fm [simp]:
   635    "[| x \<in> nat; env \<in> list(A)|]
   636     ==> sats(A, quasinat_fm(x), env) <-> is_quasinat(**A, nth(x,env))"
   637 by (simp add: quasinat_fm_def is_quasinat_def)
   638 
   639 lemma quasinat_iff_sats:
   640       "[| nth(i,env) = x; nth(j,env) = y;
   641           i \<in> nat; env \<in> list(A)|]
   642        ==> is_quasinat(**A, x) <-> sats(A, quasinat_fm(i), env)"
   643 by simp
   644 
   645 theorem quasinat_reflection:
   646      "REFLECTS[\<lambda>x. is_quasinat(L,f(x)),
   647                \<lambda>i x. is_quasinat(**Lset(i),f(x))]"
   648 apply (simp only: is_quasinat_def setclass_simps)
   649 apply (intro FOL_reflections function_reflections)
   650 done
   651 
   652 
   653 subsubsection{*The Operator @{term is_nat_case}*}
   654 text{*I could not get it to work with the more natural assumption that 
   655  @{term is_b} takes two arguments.  Instead it must be a formula where 1 and 0
   656  stand for @{term m} and @{term b}, respectively.*}
   657 
   658 (* is_nat_case :: "[i=>o, i, [i,i]=>o, i, i] => o"
   659     "is_nat_case(M, a, is_b, k, z) ==
   660        (empty(M,k) --> z=a) &
   661        (\<forall>m[M]. successor(M,m,k) --> is_b(m,z)) &
   662        (is_quasinat(M,k) | empty(M,z))" *)
   663 text{*The formula @{term is_b} has free variables 1 and 0.*}
   664 constdefs is_nat_case_fm :: "[i, i, i, i]=>i"
   665  "is_nat_case_fm(a,is_b,k,z) == 
   666     And(Implies(empty_fm(k), Equal(z,a)),
   667         And(Forall(Implies(succ_fm(0,succ(k)), 
   668                    Forall(Implies(Equal(0,succ(succ(z))), is_b)))),
   669             Or(quasinat_fm(k), empty_fm(z))))"
   670 
   671 lemma is_nat_case_type [TC]:
   672      "[| is_b \<in> formula;  
   673          x \<in> nat; y \<in> nat; z \<in> nat |] 
   674       ==> is_nat_case_fm(x,is_b,y,z) \<in> formula"
   675 by (simp add: is_nat_case_fm_def)
   676 
   677 lemma sats_is_nat_case_fm:
   678   assumes is_b_iff_sats: 
   679       "!!a. a \<in> A ==> is_b(a,nth(z, env)) <-> 
   680                       sats(A, p, Cons(nth(z,env), Cons(a, env)))"
   681   shows 
   682       "[|x \<in> nat; y \<in> nat; z < length(env); env \<in> list(A)|]
   683        ==> sats(A, is_nat_case_fm(x,p,y,z), env) <->
   684            is_nat_case(**A, nth(x,env), is_b, nth(y,env), nth(z,env))"
   685 apply (frule lt_length_in_nat, assumption)
   686 apply (simp add: is_nat_case_fm_def is_nat_case_def is_b_iff_sats [THEN iff_sym])
   687 done
   688 
   689 lemma is_nat_case_iff_sats:
   690   "[| (!!a. a \<in> A ==> is_b(a,z) <->
   691                       sats(A, p, Cons(z, Cons(a,env))));
   692       nth(i,env) = x; nth(j,env) = y; nth(k,env) = z; 
   693       i \<in> nat; j \<in> nat; k < length(env); env \<in> list(A)|]
   694    ==> is_nat_case(**A, x, is_b, y, z) <-> sats(A, is_nat_case_fm(i,p,j,k), env)"
   695 by (simp add: sats_is_nat_case_fm [of A is_b])
   696 
   697 
   698 text{*The second argument of @{term is_b} gives it direct access to @{term x},
   699   which is essential for handling free variable references.  Without this
   700   argument, we cannot prove reflection for @{term iterates_MH}.*}
   701 theorem is_nat_case_reflection:
   702   assumes is_b_reflection:
   703     "!!h f g. REFLECTS[\<lambda>x. is_b(L, h(x), f(x), g(x)),
   704                      \<lambda>i x. is_b(**Lset(i), h(x), f(x), g(x))]"
   705   shows "REFLECTS[\<lambda>x. is_nat_case(L, f(x), is_b(L,x), g(x), h(x)),
   706                \<lambda>i x. is_nat_case(**Lset(i), f(x), is_b(**Lset(i), x), g(x), h(x))]"
   707 apply (simp (no_asm_use) only: is_nat_case_def setclass_simps)
   708 apply (intro FOL_reflections function_reflections
   709              restriction_reflection is_b_reflection quasinat_reflection)
   710 done
   711 
   712 
   713 
   714 subsection{*The Operator @{term iterates_MH}, Needed for Iteration*}
   715 
   716 (*  iterates_MH :: "[i=>o, [i,i]=>o, i, i, i, i] => o"
   717    "iterates_MH(M,isF,v,n,g,z) ==
   718         is_nat_case(M, v, \<lambda>m u. \<exists>gm[M]. fun_apply(M,g,m,gm) & isF(gm,u),
   719                     n, z)" *)
   720 constdefs iterates_MH_fm :: "[i, i, i, i, i]=>i"
   721  "iterates_MH_fm(isF,v,n,g,z) == 
   722     is_nat_case_fm(v, 
   723       Exists(And(fun_apply_fm(succ(succ(succ(g))),2,0), 
   724                      Forall(Implies(Equal(0,2), isF)))), 
   725       n, z)"
   726 
   727 lemma iterates_MH_type [TC]:
   728      "[| p \<in> formula;  
   729          v \<in> nat; x \<in> nat; y \<in> nat; z \<in> nat |] 
   730       ==> iterates_MH_fm(p,v,x,y,z) \<in> formula"
   731 by (simp add: iterates_MH_fm_def)
   732 
   733 lemma sats_iterates_MH_fm:
   734   assumes is_F_iff_sats:
   735       "!!a b c d. [| a \<in> A; b \<in> A; c \<in> A; d \<in> A|]
   736               ==> is_F(a,b) <->
   737                   sats(A, p, Cons(b, Cons(a, Cons(c, Cons(d,env)))))"
   738   shows 
   739       "[|v \<in> nat; x \<in> nat; y \<in> nat; z < length(env); env \<in> list(A)|]
   740        ==> sats(A, iterates_MH_fm(p,v,x,y,z), env) <->
   741            iterates_MH(**A, is_F, nth(v,env), nth(x,env), nth(y,env), nth(z,env))"
   742 apply (frule lt_length_in_nat, assumption)  
   743 apply (simp add: iterates_MH_fm_def iterates_MH_def sats_is_nat_case_fm 
   744               is_F_iff_sats [symmetric])
   745 apply (rule is_nat_case_cong) 
   746 apply (simp_all add: setclass_def)
   747 done
   748 
   749 lemma iterates_MH_iff_sats:
   750   assumes is_F_iff_sats:
   751       "!!a b c d. [| a \<in> A; b \<in> A; c \<in> A; d \<in> A|]
   752               ==> is_F(a,b) <->
   753                   sats(A, p, Cons(b, Cons(a, Cons(c, Cons(d,env)))))"
   754   shows 
   755   "[| nth(i',env) = v; nth(i,env) = x; nth(j,env) = y; nth(k,env) = z; 
   756       i' \<in> nat; i \<in> nat; j \<in> nat; k < length(env); env \<in> list(A)|]
   757    ==> iterates_MH(**A, is_F, v, x, y, z) <->
   758        sats(A, iterates_MH_fm(p,i',i,j,k), env)"
   759 by (simp add: sats_iterates_MH_fm [OF is_F_iff_sats]) 
   760 
   761 text{*The second argument of @{term p} gives it direct access to @{term x},
   762   which is essential for handling free variable references.  Without this
   763   argument, we cannot prove reflection for @{term list_N}.*}
   764 theorem iterates_MH_reflection:
   765   assumes p_reflection:
   766     "!!f g h. REFLECTS[\<lambda>x. p(L, h(x), f(x), g(x)),
   767                      \<lambda>i x. p(**Lset(i), h(x), f(x), g(x))]"
   768  shows "REFLECTS[\<lambda>x. iterates_MH(L, p(L,x), e(x), f(x), g(x), h(x)),
   769                \<lambda>i x. iterates_MH(**Lset(i), p(**Lset(i),x), e(x), f(x), g(x), h(x))]"
   770 apply (simp (no_asm_use) only: iterates_MH_def)
   771 txt{*Must be careful: simplifying with @{text setclass_simps} above would
   772      change @{text "\<exists>gm[**Lset(i)]"} into @{text "\<exists>gm \<in> Lset(i)"}, when
   773      it would no longer match rule @{text is_nat_case_reflection}. *}
   774 apply (rule is_nat_case_reflection)
   775 apply (simp (no_asm_use) only: setclass_simps)
   776 apply (intro FOL_reflections function_reflections is_nat_case_reflection
   777              restriction_reflection p_reflection)
   778 done
   779 
   780 
   781 
   782 subsection{*@{term L} is Closed Under the Operator @{term list}*}
   783 
   784 subsubsection{*The List Functor, Internalized*}
   785 
   786 constdefs list_functor_fm :: "[i,i,i]=>i"
   787 (* "is_list_functor(M,A,X,Z) ==
   788         \<exists>n1[M]. \<exists>AX[M].
   789          number1(M,n1) & cartprod(M,A,X,AX) & is_sum(M,n1,AX,Z)" *)
   790     "list_functor_fm(A,X,Z) ==
   791        Exists(Exists(
   792         And(number1_fm(1),
   793             And(cartprod_fm(A#+2,X#+2,0), sum_fm(1,0,Z#+2)))))"
   794 
   795 lemma list_functor_type [TC]:
   796      "[| x \<in> nat; y \<in> nat; z \<in> nat |] ==> list_functor_fm(x,y,z) \<in> formula"
   797 by (simp add: list_functor_fm_def)
   798 
   799 lemma arity_list_functor_fm [simp]:
   800      "[| x \<in> nat; y \<in> nat; z \<in> nat |]
   801       ==> arity(list_functor_fm(x,y,z)) = succ(x) \<union> succ(y) \<union> succ(z)"
   802 by (simp add: list_functor_fm_def succ_Un_distrib [symmetric] Un_ac)
   803 
   804 lemma sats_list_functor_fm [simp]:
   805    "[| x \<in> nat; y \<in> nat; z \<in> nat; env \<in> list(A)|]
   806     ==> sats(A, list_functor_fm(x,y,z), env) <->
   807         is_list_functor(**A, nth(x,env), nth(y,env), nth(z,env))"
   808 by (simp add: list_functor_fm_def is_list_functor_def)
   809 
   810 lemma list_functor_iff_sats:
   811   "[| nth(i,env) = x; nth(j,env) = y; nth(k,env) = z;
   812       i \<in> nat; j \<in> nat; k \<in> nat; env \<in> list(A)|]
   813    ==> is_list_functor(**A, x, y, z) <-> sats(A, list_functor_fm(i,j,k), env)"
   814 by simp
   815 
   816 theorem list_functor_reflection:
   817      "REFLECTS[\<lambda>x. is_list_functor(L,f(x),g(x),h(x)),
   818                \<lambda>i x. is_list_functor(**Lset(i),f(x),g(x),h(x))]"
   819 apply (simp only: is_list_functor_def setclass_simps)
   820 apply (intro FOL_reflections number1_reflection
   821              cartprod_reflection sum_reflection)
   822 done
   823 
   824 
   825 subsubsection{*Instances of Replacement for Lists*}
   826 
   827 lemma list_replacement1_Reflects:
   828  "REFLECTS
   829    [\<lambda>x. \<exists>u[L]. u \<in> B \<and> (\<exists>y[L]. pair(L,u,y,x) \<and>
   830          is_wfrec(L, iterates_MH(L, is_list_functor(L,A), 0), memsn, u, y)),
   831     \<lambda>i x. \<exists>u \<in> Lset(i). u \<in> B \<and> (\<exists>y \<in> Lset(i). pair(**Lset(i), u, y, x) \<and>
   832          is_wfrec(**Lset(i),
   833                   iterates_MH(**Lset(i),
   834                           is_list_functor(**Lset(i), A), 0), memsn, u, y))]"
   835 by (intro FOL_reflections function_reflections is_wfrec_reflection
   836           iterates_MH_reflection list_functor_reflection)
   837 
   838 
   839 lemma list_replacement1:
   840    "L(A) ==> iterates_replacement(L, is_list_functor(L,A), 0)"
   841 apply (unfold iterates_replacement_def wfrec_replacement_def, clarify)
   842 apply (rule strong_replacementI)
   843 apply (rule rallI)
   844 apply (rename_tac B)
   845 apply (rule separation_CollectI)
   846 apply (insert nonempty)
   847 apply (subgoal_tac "L(Memrel(succ(n)))")
   848 apply (rule_tac A="{B,A,n,z,0,Memrel(succ(n))}" in subset_LsetE, blast )
   849 apply (rule ReflectsE [OF list_replacement1_Reflects], assumption)
   850 apply (drule subset_Lset_ltD, assumption)
   851 apply (erule reflection_imp_L_separation)
   852   apply (simp_all add: lt_Ord2 Memrel_closed)
   853 apply (elim conjE)
   854 apply (rule DPow_LsetI)
   855 apply (rename_tac v)
   856 apply (rule bex_iff_sats conj_iff_sats)+
   857 apply (rule_tac env = "[u,v,A,n,B,0,Memrel(succ(n))]" in mem_iff_sats)
   858 apply (rule sep_rules is_nat_case_iff_sats list_functor_iff_sats
   859             is_wfrec_iff_sats iterates_MH_iff_sats quasinat_iff_sats | simp)+
   860 done
   861 
   862 
   863 lemma list_replacement2_Reflects:
   864  "REFLECTS
   865    [\<lambda>x. \<exists>u[L]. u \<in> B \<and> u \<in> nat \<and>
   866          (\<exists>sn[L]. \<exists>msn[L]. successor(L, u, sn) \<and> membership(L, sn, msn) \<and>
   867            is_wfrec (L, iterates_MH (L, is_list_functor(L, A), 0),
   868                               msn, u, x)),
   869     \<lambda>i x. \<exists>u \<in> Lset(i). u \<in> B \<and> u \<in> nat \<and>
   870          (\<exists>sn \<in> Lset(i). \<exists>msn \<in> Lset(i).
   871           successor(**Lset(i), u, sn) \<and> membership(**Lset(i), sn, msn) \<and>
   872            is_wfrec (**Lset(i),
   873                  iterates_MH (**Lset(i), is_list_functor(**Lset(i), A), 0),
   874                      msn, u, x))]"
   875 by (intro FOL_reflections function_reflections is_wfrec_reflection
   876           iterates_MH_reflection list_functor_reflection)
   877 
   878 
   879 lemma list_replacement2:
   880    "L(A) ==> strong_replacement(L,
   881          \<lambda>n y. n\<in>nat &
   882                (\<exists>sn[L]. \<exists>msn[L]. successor(L,n,sn) & membership(L,sn,msn) &
   883                is_wfrec(L, iterates_MH(L,is_list_functor(L,A), 0),
   884                         msn, n, y)))"
   885 apply (rule strong_replacementI)
   886 apply (rule rallI)
   887 apply (rename_tac B)
   888 apply (rule separation_CollectI)
   889 apply (insert nonempty)
   890 apply (rule_tac A="{A,B,z,0,nat}" in subset_LsetE)
   891 apply (blast intro: L_nat)
   892 apply (rule ReflectsE [OF list_replacement2_Reflects], assumption)
   893 apply (drule subset_Lset_ltD, assumption)
   894 apply (erule reflection_imp_L_separation)
   895   apply (simp_all add: lt_Ord2)
   896 apply (rule DPow_LsetI)
   897 apply (rename_tac v)
   898 apply (rule bex_iff_sats conj_iff_sats)+
   899 apply (rule_tac env = "[u,v,A,B,0,nat]" in mem_iff_sats)
   900 apply (rule sep_rules is_nat_case_iff_sats list_functor_iff_sats
   901             is_wfrec_iff_sats iterates_MH_iff_sats quasinat_iff_sats | simp)+
   902 done
   903 
   904 
   905 subsection{*@{term L} is Closed Under the Operator @{term formula}*}
   906 
   907 subsubsection{*The Formula Functor, Internalized*}
   908 
   909 constdefs formula_functor_fm :: "[i,i]=>i"
   910 (*     "is_formula_functor(M,X,Z) ==
   911         \<exists>nat'[M]. \<exists>natnat[M]. \<exists>natnatsum[M]. \<exists>XX[M]. \<exists>X3[M].
   912            4           3               2       1       0
   913           omega(M,nat') & cartprod(M,nat',nat',natnat) &
   914           is_sum(M,natnat,natnat,natnatsum) &
   915           cartprod(M,X,X,XX) & is_sum(M,XX,X,X3) &
   916           is_sum(M,natnatsum,X3,Z)" *)
   917     "formula_functor_fm(X,Z) ==
   918        Exists(Exists(Exists(Exists(Exists(
   919         And(omega_fm(4),
   920          And(cartprod_fm(4,4,3),
   921           And(sum_fm(3,3,2),
   922            And(cartprod_fm(X#+5,X#+5,1),
   923             And(sum_fm(1,X#+5,0), sum_fm(2,0,Z#+5)))))))))))"
   924 
   925 lemma formula_functor_type [TC]:
   926      "[| x \<in> nat; y \<in> nat |] ==> formula_functor_fm(x,y) \<in> formula"
   927 by (simp add: formula_functor_fm_def)
   928 
   929 lemma sats_formula_functor_fm [simp]:
   930    "[| x \<in> nat; y \<in> nat; env \<in> list(A)|]
   931     ==> sats(A, formula_functor_fm(x,y), env) <->
   932         is_formula_functor(**A, nth(x,env), nth(y,env))"
   933 by (simp add: formula_functor_fm_def is_formula_functor_def)
   934 
   935 lemma formula_functor_iff_sats:
   936   "[| nth(i,env) = x; nth(j,env) = y;
   937       i \<in> nat; j \<in> nat; env \<in> list(A)|]
   938    ==> is_formula_functor(**A, x, y) <-> sats(A, formula_functor_fm(i,j), env)"
   939 by simp
   940 
   941 theorem formula_functor_reflection:
   942      "REFLECTS[\<lambda>x. is_formula_functor(L,f(x),g(x)),
   943                \<lambda>i x. is_formula_functor(**Lset(i),f(x),g(x))]"
   944 apply (simp only: is_formula_functor_def setclass_simps)
   945 apply (intro FOL_reflections omega_reflection
   946              cartprod_reflection sum_reflection)
   947 done
   948 
   949 subsubsection{*Instances of Replacement for Formulas*}
   950 
   951 lemma formula_replacement1_Reflects:
   952  "REFLECTS
   953    [\<lambda>x. \<exists>u[L]. u \<in> B \<and> (\<exists>y[L]. pair(L,u,y,x) \<and>
   954          is_wfrec(L, iterates_MH(L, is_formula_functor(L), 0), memsn, u, y)),
   955     \<lambda>i x. \<exists>u \<in> Lset(i). u \<in> B \<and> (\<exists>y \<in> Lset(i). pair(**Lset(i), u, y, x) \<and>
   956          is_wfrec(**Lset(i),
   957                   iterates_MH(**Lset(i),
   958                           is_formula_functor(**Lset(i)), 0), memsn, u, y))]"
   959 by (intro FOL_reflections function_reflections is_wfrec_reflection
   960           iterates_MH_reflection formula_functor_reflection)
   961 
   962 lemma formula_replacement1:
   963    "iterates_replacement(L, is_formula_functor(L), 0)"
   964 apply (unfold iterates_replacement_def wfrec_replacement_def, clarify)
   965 apply (rule strong_replacementI)
   966 apply (rule rallI)
   967 apply (rename_tac B)
   968 apply (rule separation_CollectI)
   969 apply (insert nonempty)
   970 apply (subgoal_tac "L(Memrel(succ(n)))")
   971 apply (rule_tac A="{B,n,z,0,Memrel(succ(n))}" in subset_LsetE, blast )
   972 apply (rule ReflectsE [OF formula_replacement1_Reflects], assumption)
   973 apply (drule subset_Lset_ltD, assumption)
   974 apply (erule reflection_imp_L_separation)
   975   apply (simp_all add: lt_Ord2 Memrel_closed)
   976 apply (rule DPow_LsetI)
   977 apply (rename_tac v)
   978 apply (rule bex_iff_sats conj_iff_sats)+
   979 apply (rule_tac env = "[u,v,n,B,0,Memrel(succ(n))]" in mem_iff_sats)
   980 apply (rule sep_rules is_nat_case_iff_sats formula_functor_iff_sats
   981             is_wfrec_iff_sats iterates_MH_iff_sats quasinat_iff_sats | simp)+
   982 done
   983 
   984 lemma formula_replacement2_Reflects:
   985  "REFLECTS
   986    [\<lambda>x. \<exists>u[L]. u \<in> B \<and> u \<in> nat \<and>
   987          (\<exists>sn[L]. \<exists>msn[L]. successor(L, u, sn) \<and> membership(L, sn, msn) \<and>
   988            is_wfrec (L, iterates_MH (L, is_formula_functor(L), 0),
   989                               msn, u, x)),
   990     \<lambda>i x. \<exists>u \<in> Lset(i). u \<in> B \<and> u \<in> nat \<and>
   991          (\<exists>sn \<in> Lset(i). \<exists>msn \<in> Lset(i).
   992           successor(**Lset(i), u, sn) \<and> membership(**Lset(i), sn, msn) \<and>
   993            is_wfrec (**Lset(i),
   994                  iterates_MH (**Lset(i), is_formula_functor(**Lset(i)), 0),
   995                      msn, u, x))]"
   996 by (intro FOL_reflections function_reflections is_wfrec_reflection
   997           iterates_MH_reflection formula_functor_reflection)
   998 
   999 
  1000 lemma formula_replacement2:
  1001    "strong_replacement(L,
  1002          \<lambda>n y. n\<in>nat &
  1003                (\<exists>sn[L]. \<exists>msn[L]. successor(L,n,sn) & membership(L,sn,msn) &
  1004                is_wfrec(L, iterates_MH(L,is_formula_functor(L), 0),
  1005                         msn, n, y)))"
  1006 apply (rule strong_replacementI)
  1007 apply (rule rallI)
  1008 apply (rename_tac B)
  1009 apply (rule separation_CollectI)
  1010 apply (insert nonempty)
  1011 apply (rule_tac A="{B,z,0,nat}" in subset_LsetE)
  1012 apply (blast intro: L_nat)
  1013 apply (rule ReflectsE [OF formula_replacement2_Reflects], assumption)
  1014 apply (drule subset_Lset_ltD, assumption)
  1015 apply (erule reflection_imp_L_separation)
  1016   apply (simp_all add: lt_Ord2)
  1017 apply (rule DPow_LsetI)
  1018 apply (rename_tac v)
  1019 apply (rule bex_iff_sats conj_iff_sats)+
  1020 apply (rule_tac env = "[u,v,B,0,nat]" in mem_iff_sats)
  1021 apply (rule sep_rules is_nat_case_iff_sats formula_functor_iff_sats
  1022             is_wfrec_iff_sats iterates_MH_iff_sats quasinat_iff_sats | simp)+
  1023 done
  1024 
  1025 text{*NB The proofs for type @{term formula} are virtually identical to those
  1026 for @{term "list(A)"}.  It was a cut-and-paste job! *}
  1027 
  1028 
  1029 subsubsection{*The Formula @{term is_nth}, Internalized*}
  1030 
  1031 (* "is_nth(M,n,l,Z) == 
  1032       \<exists>X[M]. \<exists>sn[M]. \<exists>msn[M]. 
  1033        2       1       0
  1034        successor(M,n,sn) & membership(M,sn,msn) &
  1035        is_wfrec(M, iterates_MH(M, is_tl(M), l), msn, n, X) &
  1036        is_hd(M,X,Z)" *)
  1037 constdefs nth_fm :: "[i,i,i]=>i"
  1038     "nth_fm(n,l,Z) == 
  1039        Exists(Exists(Exists(
  1040          And(succ_fm(n#+3,1),
  1041           And(Memrel_fm(1,0),
  1042            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)))))))"
  1043 
  1044 lemma nth_fm_type [TC]:
  1045  "[| x \<in> nat; y \<in> nat; z \<in> nat |] ==> nth_fm(x,y,z) \<in> formula"
  1046 by (simp add: nth_fm_def)
  1047 
  1048 lemma sats_nth_fm [simp]:
  1049    "[| x < length(env); y \<in> nat; z \<in> nat; env \<in> list(A)|]
  1050     ==> sats(A, nth_fm(x,y,z), env) <->
  1051         is_nth(**A, nth(x,env), nth(y,env), nth(z,env))"
  1052 apply (frule lt_length_in_nat, assumption)  
  1053 apply (simp add: nth_fm_def is_nth_def sats_is_wfrec_fm sats_iterates_MH_fm) 
  1054 done
  1055 
  1056 lemma nth_iff_sats:
  1057       "[| nth(i,env) = x; nth(j,env) = y; nth(k,env) = z;
  1058           i < length(env); j \<in> nat; k \<in> nat; env \<in> list(A)|]
  1059        ==> is_nth(**A, x, y, z) <-> sats(A, nth_fm(i,j,k), env)"
  1060 by (simp add: sats_nth_fm)
  1061 
  1062 theorem nth_reflection:
  1063      "REFLECTS[\<lambda>x. is_nth(L, f(x), g(x), h(x)),  
  1064                \<lambda>i x. is_nth(**Lset(i), f(x), g(x), h(x))]"
  1065 apply (simp only: is_nth_def setclass_simps)
  1066 apply (intro FOL_reflections function_reflections is_wfrec_reflection 
  1067              iterates_MH_reflection hd_reflection tl_reflection) 
  1068 done
  1069 
  1070 
  1071 subsubsection{*An Instance of Replacement for @{term nth}*}
  1072 
  1073 lemma nth_replacement_Reflects:
  1074  "REFLECTS
  1075    [\<lambda>x. \<exists>u[L]. u \<in> B \<and> (\<exists>y[L]. pair(L,u,y,x) \<and>
  1076          is_wfrec(L, iterates_MH(L, is_tl(L), z), memsn, u, y)),
  1077     \<lambda>i x. \<exists>u \<in> Lset(i). u \<in> B \<and> (\<exists>y \<in> Lset(i). pair(**Lset(i), u, y, x) \<and>
  1078          is_wfrec(**Lset(i),
  1079                   iterates_MH(**Lset(i),
  1080                           is_tl(**Lset(i)), z), memsn, u, y))]"
  1081 by (intro FOL_reflections function_reflections is_wfrec_reflection
  1082           iterates_MH_reflection list_functor_reflection tl_reflection)
  1083 
  1084 lemma nth_replacement:
  1085    "L(w) ==> iterates_replacement(L, %l t. is_tl(L,l,t), w)"
  1086 apply (unfold iterates_replacement_def wfrec_replacement_def, clarify)
  1087 apply (rule strong_replacementI)
  1088 apply (rule rallI)
  1089 apply (rule separation_CollectI)
  1090 apply (subgoal_tac "L(Memrel(succ(n)))")
  1091 apply (rule_tac A="{A,n,w,z,Memrel(succ(n))}" in subset_LsetE, blast )
  1092 apply (rule ReflectsE [OF nth_replacement_Reflects], assumption)
  1093 apply (drule subset_Lset_ltD, assumption)
  1094 apply (erule reflection_imp_L_separation)
  1095   apply (simp_all add: lt_Ord2 Memrel_closed)
  1096 apply (elim conjE)
  1097 apply (rule DPow_LsetI)
  1098 apply (rename_tac v)
  1099 apply (rule bex_iff_sats conj_iff_sats)+
  1100 apply (rule_tac env = "[u,v,A,z,w,Memrel(succ(n))]" in mem_iff_sats)
  1101 apply (rule sep_rules is_nat_case_iff_sats tl_iff_sats
  1102             is_wfrec_iff_sats iterates_MH_iff_sats quasinat_iff_sats | simp)+
  1103 done
  1104 
  1105 
  1106 
  1107 subsubsection{*Instantiating the locale @{text M_datatypes}*}
  1108 
  1109 lemma M_datatypes_axioms_L: "M_datatypes_axioms(L)"
  1110   apply (rule M_datatypes_axioms.intro)
  1111       apply (assumption | rule
  1112         list_replacement1 list_replacement2
  1113         formula_replacement1 formula_replacement2
  1114         nth_replacement)+
  1115   done
  1116 
  1117 theorem M_datatypes_L: "PROP M_datatypes(L)"
  1118   apply (rule M_datatypes.intro)
  1119       apply (rule M_wfrank.axioms [OF M_wfrank_L])+
  1120  apply (rule M_datatypes_axioms_L) 
  1121  done
  1122 
  1123 lemmas list_closed = M_datatypes.list_closed [OF M_datatypes_L]
  1124   and formula_closed = M_datatypes.formula_closed [OF M_datatypes_L]
  1125   and list_abs = M_datatypes.list_abs [OF M_datatypes_L]
  1126   and formula_abs = M_datatypes.formula_abs [OF M_datatypes_L]
  1127   and nth_abs = M_datatypes.nth_abs [OF M_datatypes_L]
  1128 
  1129 declare list_closed [intro,simp]
  1130 declare formula_closed [intro,simp]
  1131 declare list_abs [simp]
  1132 declare formula_abs [simp]
  1133 declare nth_abs [simp]
  1134 
  1135 
  1136 subsection{*@{term L} is Closed Under the Operator @{term eclose}*}
  1137 
  1138 subsubsection{*Instances of Replacement for @{term eclose}*}
  1139 
  1140 lemma eclose_replacement1_Reflects:
  1141  "REFLECTS
  1142    [\<lambda>x. \<exists>u[L]. u \<in> B \<and> (\<exists>y[L]. pair(L,u,y,x) \<and>
  1143          is_wfrec(L, iterates_MH(L, big_union(L), A), memsn, u, y)),
  1144     \<lambda>i x. \<exists>u \<in> Lset(i). u \<in> B \<and> (\<exists>y \<in> Lset(i). pair(**Lset(i), u, y, x) \<and>
  1145          is_wfrec(**Lset(i),
  1146                   iterates_MH(**Lset(i), big_union(**Lset(i)), A),
  1147                   memsn, u, y))]"
  1148 by (intro FOL_reflections function_reflections is_wfrec_reflection
  1149           iterates_MH_reflection)
  1150 
  1151 lemma eclose_replacement1:
  1152    "L(A) ==> iterates_replacement(L, big_union(L), A)"
  1153 apply (unfold iterates_replacement_def wfrec_replacement_def, clarify)
  1154 apply (rule strong_replacementI)
  1155 apply (rule rallI)
  1156 apply (rename_tac B)
  1157 apply (rule separation_CollectI)
  1158 apply (subgoal_tac "L(Memrel(succ(n)))")
  1159 apply (rule_tac A="{B,A,n,z,Memrel(succ(n))}" in subset_LsetE, blast )
  1160 apply (rule ReflectsE [OF eclose_replacement1_Reflects], assumption)
  1161 apply (drule subset_Lset_ltD, assumption)
  1162 apply (erule reflection_imp_L_separation)
  1163   apply (simp_all add: lt_Ord2 Memrel_closed)
  1164 apply (elim conjE)
  1165 apply (rule DPow_LsetI)
  1166 apply (rename_tac v)
  1167 apply (rule bex_iff_sats conj_iff_sats)+
  1168 apply (rule_tac env = "[u,v,A,n,B,Memrel(succ(n))]" in mem_iff_sats)
  1169 apply (rule sep_rules iterates_MH_iff_sats is_nat_case_iff_sats
  1170              is_wfrec_iff_sats big_union_iff_sats quasinat_iff_sats | simp)+
  1171 done
  1172 
  1173 
  1174 lemma eclose_replacement2_Reflects:
  1175  "REFLECTS
  1176    [\<lambda>x. \<exists>u[L]. u \<in> B \<and> u \<in> nat \<and>
  1177          (\<exists>sn[L]. \<exists>msn[L]. successor(L, u, sn) \<and> membership(L, sn, msn) \<and>
  1178            is_wfrec (L, iterates_MH (L, big_union(L), A),
  1179                               msn, u, x)),
  1180     \<lambda>i x. \<exists>u \<in> Lset(i). u \<in> B \<and> u \<in> nat \<and>
  1181          (\<exists>sn \<in> Lset(i). \<exists>msn \<in> Lset(i).
  1182           successor(**Lset(i), u, sn) \<and> membership(**Lset(i), sn, msn) \<and>
  1183            is_wfrec (**Lset(i),
  1184                  iterates_MH (**Lset(i), big_union(**Lset(i)), A),
  1185                      msn, u, x))]"
  1186 by (intro FOL_reflections function_reflections is_wfrec_reflection
  1187           iterates_MH_reflection)
  1188 
  1189 
  1190 lemma eclose_replacement2:
  1191    "L(A) ==> strong_replacement(L,
  1192          \<lambda>n y. n\<in>nat &
  1193                (\<exists>sn[L]. \<exists>msn[L]. successor(L,n,sn) & membership(L,sn,msn) &
  1194                is_wfrec(L, iterates_MH(L,big_union(L), A),
  1195                         msn, n, y)))"
  1196 apply (rule strong_replacementI)
  1197 apply (rule rallI)
  1198 apply (rename_tac B)
  1199 apply (rule separation_CollectI)
  1200 apply (rule_tac A="{A,B,z,nat}" in subset_LsetE)
  1201 apply (blast intro: L_nat)
  1202 apply (rule ReflectsE [OF eclose_replacement2_Reflects], assumption)
  1203 apply (drule subset_Lset_ltD, assumption)
  1204 apply (erule reflection_imp_L_separation)
  1205   apply (simp_all add: lt_Ord2)
  1206 apply (rule DPow_LsetI)
  1207 apply (rename_tac v)
  1208 apply (rule bex_iff_sats conj_iff_sats)+
  1209 apply (rule_tac env = "[u,v,A,B,nat]" in mem_iff_sats)
  1210 apply (rule sep_rules is_nat_case_iff_sats iterates_MH_iff_sats
  1211               is_wfrec_iff_sats big_union_iff_sats quasinat_iff_sats | simp)+
  1212 done
  1213 
  1214 
  1215 subsubsection{*Instantiating the locale @{text M_eclose}*}
  1216 
  1217 lemma M_eclose_axioms_L: "M_eclose_axioms(L)"
  1218   apply (rule M_eclose_axioms.intro)
  1219    apply (assumption | rule eclose_replacement1 eclose_replacement2)+
  1220   done
  1221 
  1222 theorem M_eclose_L: "PROP M_eclose(L)"
  1223   apply (rule M_eclose.intro)
  1224        apply (rule M_datatypes.axioms [OF M_datatypes_L])+
  1225   apply (rule M_eclose_axioms_L)
  1226   done
  1227 
  1228 lemmas eclose_closed [intro, simp] = M_eclose.eclose_closed [OF M_eclose_L]
  1229   and eclose_abs [intro, simp] = M_eclose.eclose_abs [OF M_eclose_L]
  1230   and transrec_replacementI = M_eclose.transrec_replacementI [OF M_eclose_L]
  1231 
  1232 end