src/ZF/Constructible/Internalize.thy
changeset 60770 240563fbf41d
parent 46823 57bf0cecb366
child 61798 27f3c10b0b50
equal deleted inserted replaced
60769:cf7f3465eaf1 60770:240563fbf41d
     2     Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
     2     Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
     3 *)
     3 *)
     4 
     4 
     5 theory Internalize imports L_axioms Datatype_absolute begin
     5 theory Internalize imports L_axioms Datatype_absolute begin
     6 
     6 
     7 subsection{*Internalized Forms of Data Structuring Operators*}
     7 subsection\<open>Internalized Forms of Data Structuring Operators\<close>
     8 
     8 
     9 subsubsection{*The Formula @{term is_Inl}, Internalized*}
     9 subsubsection\<open>The Formula @{term is_Inl}, Internalized\<close>
    10 
    10 
    11 (*  is_Inl(M,a,z) == \<exists>zero[M]. empty(M,zero) & pair(M,zero,a,z) *)
    11 (*  is_Inl(M,a,z) == \<exists>zero[M]. empty(M,zero) & pair(M,zero,a,z) *)
    12 definition
    12 definition
    13   Inl_fm :: "[i,i]=>i" where
    13   Inl_fm :: "[i,i]=>i" where
    14     "Inl_fm(a,z) == Exists(And(empty_fm(0), pair_fm(0,succ(a),succ(z))))"
    14     "Inl_fm(a,z) == Exists(And(empty_fm(0), pair_fm(0,succ(a),succ(z))))"
    34 apply (simp only: is_Inl_def)
    34 apply (simp only: is_Inl_def)
    35 apply (intro FOL_reflections function_reflections)
    35 apply (intro FOL_reflections function_reflections)
    36 done
    36 done
    37 
    37 
    38 
    38 
    39 subsubsection{*The Formula @{term is_Inr}, Internalized*}
    39 subsubsection\<open>The Formula @{term is_Inr}, Internalized\<close>
    40 
    40 
    41 (*  is_Inr(M,a,z) == \<exists>n1[M]. number1(M,n1) & pair(M,n1,a,z) *)
    41 (*  is_Inr(M,a,z) == \<exists>n1[M]. number1(M,n1) & pair(M,n1,a,z) *)
    42 definition
    42 definition
    43   Inr_fm :: "[i,i]=>i" where
    43   Inr_fm :: "[i,i]=>i" where
    44     "Inr_fm(a,z) == Exists(And(number1_fm(0), pair_fm(0,succ(a),succ(z))))"
    44     "Inr_fm(a,z) == Exists(And(number1_fm(0), pair_fm(0,succ(a),succ(z))))"
    64 apply (simp only: is_Inr_def)
    64 apply (simp only: is_Inr_def)
    65 apply (intro FOL_reflections function_reflections)
    65 apply (intro FOL_reflections function_reflections)
    66 done
    66 done
    67 
    67 
    68 
    68 
    69 subsubsection{*The Formula @{term is_Nil}, Internalized*}
    69 subsubsection\<open>The Formula @{term is_Nil}, Internalized\<close>
    70 
    70 
    71 (* is_Nil(M,xs) == \<exists>zero[M]. empty(M,zero) & is_Inl(M,zero,xs) *)
    71 (* is_Nil(M,xs) == \<exists>zero[M]. empty(M,zero) & is_Inl(M,zero,xs) *)
    72 
    72 
    73 definition
    73 definition
    74   Nil_fm :: "i=>i" where
    74   Nil_fm :: "i=>i" where
    93 apply (simp only: is_Nil_def)
    93 apply (simp only: is_Nil_def)
    94 apply (intro FOL_reflections function_reflections Inl_reflection)
    94 apply (intro FOL_reflections function_reflections Inl_reflection)
    95 done
    95 done
    96 
    96 
    97 
    97 
    98 subsubsection{*The Formula @{term is_Cons}, Internalized*}
    98 subsubsection\<open>The Formula @{term is_Cons}, Internalized\<close>
    99 
    99 
   100 
   100 
   101 (*  "is_Cons(M,a,l,Z) == \<exists>p[M]. pair(M,a,l,p) & is_Inr(M,p,Z)" *)
   101 (*  "is_Cons(M,a,l,Z) == \<exists>p[M]. pair(M,a,l,p) & is_Inr(M,p,Z)" *)
   102 definition
   102 definition
   103   Cons_fm :: "[i,i,i]=>i" where
   103   Cons_fm :: "[i,i,i]=>i" where
   125                \<lambda>i x. is_Cons(##Lset(i),f(x),g(x),h(x))]"
   125                \<lambda>i x. is_Cons(##Lset(i),f(x),g(x),h(x))]"
   126 apply (simp only: is_Cons_def)
   126 apply (simp only: is_Cons_def)
   127 apply (intro FOL_reflections pair_reflection Inr_reflection)
   127 apply (intro FOL_reflections pair_reflection Inr_reflection)
   128 done
   128 done
   129 
   129 
   130 subsubsection{*The Formula @{term is_quasilist}, Internalized*}
   130 subsubsection\<open>The Formula @{term is_quasilist}, Internalized\<close>
   131 
   131 
   132 (* is_quasilist(M,xs) == is_Nil(M,z) | (\<exists>x[M]. \<exists>l[M]. is_Cons(M,x,l,z))" *)
   132 (* is_quasilist(M,xs) == is_Nil(M,z) | (\<exists>x[M]. \<exists>l[M]. is_Cons(M,x,l,z))" *)
   133 
   133 
   134 definition
   134 definition
   135   quasilist_fm :: "i=>i" where
   135   quasilist_fm :: "i=>i" where
   155 apply (simp only: is_quasilist_def)
   155 apply (simp only: is_quasilist_def)
   156 apply (intro FOL_reflections Nil_reflection Cons_reflection)
   156 apply (intro FOL_reflections Nil_reflection Cons_reflection)
   157 done
   157 done
   158 
   158 
   159 
   159 
   160 subsection{*Absoluteness for the Function @{term nth}*}
   160 subsection\<open>Absoluteness for the Function @{term nth}\<close>
   161 
   161 
   162 
   162 
   163 subsubsection{*The Formula @{term is_hd}, Internalized*}
   163 subsubsection\<open>The Formula @{term is_hd}, Internalized\<close>
   164 
   164 
   165 (*   "is_hd(M,xs,H) == 
   165 (*   "is_hd(M,xs,H) == 
   166        (is_Nil(M,xs) \<longrightarrow> empty(M,H)) &
   166        (is_Nil(M,xs) \<longrightarrow> empty(M,H)) &
   167        (\<forall>x[M]. \<forall>l[M]. ~ is_Cons(M,x,l,xs) | H=x) &
   167        (\<forall>x[M]. \<forall>l[M]. ~ is_Cons(M,x,l,xs) | H=x) &
   168        (is_quasilist(M,xs) | empty(M,H))" *)
   168        (is_quasilist(M,xs) | empty(M,H))" *)
   195 apply (intro FOL_reflections Nil_reflection Cons_reflection
   195 apply (intro FOL_reflections Nil_reflection Cons_reflection
   196              quasilist_reflection empty_reflection)  
   196              quasilist_reflection empty_reflection)  
   197 done
   197 done
   198 
   198 
   199 
   199 
   200 subsubsection{*The Formula @{term is_tl}, Internalized*}
   200 subsubsection\<open>The Formula @{term is_tl}, Internalized\<close>
   201 
   201 
   202 (*     "is_tl(M,xs,T) ==
   202 (*     "is_tl(M,xs,T) ==
   203        (is_Nil(M,xs) \<longrightarrow> T=xs) &
   203        (is_Nil(M,xs) \<longrightarrow> T=xs) &
   204        (\<forall>x[M]. \<forall>l[M]. ~ is_Cons(M,x,l,xs) | T=l) &
   204        (\<forall>x[M]. \<forall>l[M]. ~ is_Cons(M,x,l,xs) | T=l) &
   205        (is_quasilist(M,xs) | empty(M,T))" *)
   205        (is_quasilist(M,xs) | empty(M,T))" *)
   232 apply (intro FOL_reflections Nil_reflection Cons_reflection
   232 apply (intro FOL_reflections Nil_reflection Cons_reflection
   233              quasilist_reflection empty_reflection)
   233              quasilist_reflection empty_reflection)
   234 done
   234 done
   235 
   235 
   236 
   236 
   237 subsubsection{*The Operator @{term is_bool_of_o}*}
   237 subsubsection\<open>The Operator @{term is_bool_of_o}\<close>
   238 
   238 
   239 (*   is_bool_of_o :: "[i=>o, o, i] => o"
   239 (*   is_bool_of_o :: "[i=>o, o, i] => o"
   240    "is_bool_of_o(M,P,z) == (P & number1(M,z)) | (~P & empty(M,z))" *)
   240    "is_bool_of_o(M,P,z) == (P & number1(M,z)) | (~P & empty(M,z))" *)
   241 
   241 
   242 text{*The formula @{term p} has no free variables.*}
   242 text\<open>The formula @{term p} has no free variables.\<close>
   243 definition
   243 definition
   244   bool_of_o_fm :: "[i, i]=>i" where
   244   bool_of_o_fm :: "[i, i]=>i" where
   245   "bool_of_o_fm(p,z) == 
   245   "bool_of_o_fm(p,z) == 
   246     Or(And(p,number1_fm(z)),
   246     Or(And(p,number1_fm(z)),
   247        And(Neg(p),empty_fm(z)))"
   247        And(Neg(p),empty_fm(z)))"
   270 apply (simp (no_asm) only: is_bool_of_o_def)
   270 apply (simp (no_asm) only: is_bool_of_o_def)
   271 apply (intro FOL_reflections function_reflections, assumption+)
   271 apply (intro FOL_reflections function_reflections, assumption+)
   272 done
   272 done
   273 
   273 
   274 
   274 
   275 subsection{*More Internalizations*}
   275 subsection\<open>More Internalizations\<close>
   276 
   276 
   277 subsubsection{*The Operator @{term is_lambda}*}
   277 subsubsection\<open>The Operator @{term is_lambda}\<close>
   278 
   278 
   279 text{*The two arguments of @{term p} are always 1, 0. Remember that
   279 text\<open>The two arguments of @{term p} are always 1, 0. Remember that
   280  @{term p} will be enclosed by three quantifiers.*}
   280  @{term p} will be enclosed by three quantifiers.\<close>
   281 
   281 
   282 (* is_lambda :: "[i=>o, i, [i,i]=>o, i] => o"
   282 (* is_lambda :: "[i=>o, i, [i,i]=>o, i] => o"
   283     "is_lambda(M, A, is_b, z) == 
   283     "is_lambda(M, A, is_b, z) == 
   284        \<forall>p[M]. p \<in> z \<longleftrightarrow>
   284        \<forall>p[M]. p \<in> z \<longleftrightarrow>
   285         (\<exists>u[M]. \<exists>v[M]. u\<in>A & pair(M,u,v,p) & is_b(u,v))" *)
   285         (\<exists>u[M]. \<exists>v[M]. u\<in>A & pair(M,u,v,p) & is_b(u,v))" *)
   288   "lambda_fm(p,A,z) == 
   288   "lambda_fm(p,A,z) == 
   289     Forall(Iff(Member(0,succ(z)),
   289     Forall(Iff(Member(0,succ(z)),
   290             Exists(Exists(And(Member(1,A#+3),
   290             Exists(Exists(And(Member(1,A#+3),
   291                            And(pair_fm(1,0,2), p))))))"
   291                            And(pair_fm(1,0,2), p))))))"
   292 
   292 
   293 text{*We call @{term p} with arguments x, y by equating them with 
   293 text\<open>We call @{term p} with arguments x, y by equating them with 
   294   the corresponding quantified variables with de Bruijn indices 1, 0.*}
   294   the corresponding quantified variables with de Bruijn indices 1, 0.\<close>
   295 
   295 
   296 lemma is_lambda_type [TC]:
   296 lemma is_lambda_type [TC]:
   297      "[| p \<in> formula; x \<in> nat; y \<in> nat |] 
   297      "[| p \<in> formula; x \<in> nat; y \<in> nat |] 
   298       ==> lambda_fm(p,x,y) \<in> formula"
   298       ==> lambda_fm(p,x,y) \<in> formula"
   299 by (simp add: lambda_fm_def) 
   299 by (simp add: lambda_fm_def) 
   317                \<lambda>i x. is_lambda(##Lset(i), A(x), is_b(##Lset(i),x), f(x))]"
   317                \<lambda>i x. is_lambda(##Lset(i), A(x), is_b(##Lset(i),x), f(x))]"
   318 apply (simp (no_asm_use) only: is_lambda_def)
   318 apply (simp (no_asm_use) only: is_lambda_def)
   319 apply (intro FOL_reflections is_b_reflection pair_reflection)
   319 apply (intro FOL_reflections is_b_reflection pair_reflection)
   320 done
   320 done
   321 
   321 
   322 subsubsection{*The Operator @{term is_Member}, Internalized*}
   322 subsubsection\<open>The Operator @{term is_Member}, Internalized\<close>
   323 
   323 
   324 (*    "is_Member(M,x,y,Z) ==
   324 (*    "is_Member(M,x,y,Z) ==
   325         \<exists>p[M]. \<exists>u[M]. pair(M,x,y,p) & is_Inl(M,p,u) & is_Inl(M,u,Z)" *)
   325         \<exists>p[M]. \<exists>u[M]. pair(M,x,y,p) & is_Inl(M,p,u) & is_Inl(M,u,Z)" *)
   326 definition
   326 definition
   327   Member_fm :: "[i,i,i]=>i" where
   327   Member_fm :: "[i,i,i]=>i" where
   350                \<lambda>i x. is_Member(##Lset(i),f(x),g(x),h(x))]"
   350                \<lambda>i x. is_Member(##Lset(i),f(x),g(x),h(x))]"
   351 apply (simp only: is_Member_def)
   351 apply (simp only: is_Member_def)
   352 apply (intro FOL_reflections pair_reflection Inl_reflection)
   352 apply (intro FOL_reflections pair_reflection Inl_reflection)
   353 done
   353 done
   354 
   354 
   355 subsubsection{*The Operator @{term is_Equal}, Internalized*}
   355 subsubsection\<open>The Operator @{term is_Equal}, Internalized\<close>
   356 
   356 
   357 (*    "is_Equal(M,x,y,Z) ==
   357 (*    "is_Equal(M,x,y,Z) ==
   358         \<exists>p[M]. \<exists>u[M]. pair(M,x,y,p) & is_Inr(M,p,u) & is_Inl(M,u,Z)" *)
   358         \<exists>p[M]. \<exists>u[M]. pair(M,x,y,p) & is_Inr(M,p,u) & is_Inl(M,u,Z)" *)
   359 definition
   359 definition
   360   Equal_fm :: "[i,i,i]=>i" where
   360   Equal_fm :: "[i,i,i]=>i" where
   383                \<lambda>i x. is_Equal(##Lset(i),f(x),g(x),h(x))]"
   383                \<lambda>i x. is_Equal(##Lset(i),f(x),g(x),h(x))]"
   384 apply (simp only: is_Equal_def)
   384 apply (simp only: is_Equal_def)
   385 apply (intro FOL_reflections pair_reflection Inl_reflection Inr_reflection)
   385 apply (intro FOL_reflections pair_reflection Inl_reflection Inr_reflection)
   386 done
   386 done
   387 
   387 
   388 subsubsection{*The Operator @{term is_Nand}, Internalized*}
   388 subsubsection\<open>The Operator @{term is_Nand}, Internalized\<close>
   389 
   389 
   390 (*    "is_Nand(M,x,y,Z) ==
   390 (*    "is_Nand(M,x,y,Z) ==
   391         \<exists>p[M]. \<exists>u[M]. pair(M,x,y,p) & is_Inl(M,p,u) & is_Inr(M,u,Z)" *)
   391         \<exists>p[M]. \<exists>u[M]. pair(M,x,y,p) & is_Inl(M,p,u) & is_Inr(M,u,Z)" *)
   392 definition
   392 definition
   393   Nand_fm :: "[i,i,i]=>i" where
   393   Nand_fm :: "[i,i,i]=>i" where
   416                \<lambda>i x. is_Nand(##Lset(i),f(x),g(x),h(x))]"
   416                \<lambda>i x. is_Nand(##Lset(i),f(x),g(x),h(x))]"
   417 apply (simp only: is_Nand_def)
   417 apply (simp only: is_Nand_def)
   418 apply (intro FOL_reflections pair_reflection Inl_reflection Inr_reflection)
   418 apply (intro FOL_reflections pair_reflection Inl_reflection Inr_reflection)
   419 done
   419 done
   420 
   420 
   421 subsubsection{*The Operator @{term is_Forall}, Internalized*}
   421 subsubsection\<open>The Operator @{term is_Forall}, Internalized\<close>
   422 
   422 
   423 (* "is_Forall(M,p,Z) == \<exists>u[M]. is_Inr(M,p,u) & is_Inr(M,u,Z)" *)
   423 (* "is_Forall(M,p,Z) == \<exists>u[M]. is_Inr(M,p,u) & is_Inr(M,u,Z)" *)
   424 definition
   424 definition
   425   Forall_fm :: "[i,i]=>i" where
   425   Forall_fm :: "[i,i]=>i" where
   426     "Forall_fm(x,Z) ==
   426     "Forall_fm(x,Z) ==
   448 apply (simp only: is_Forall_def)
   448 apply (simp only: is_Forall_def)
   449 apply (intro FOL_reflections pair_reflection Inr_reflection)
   449 apply (intro FOL_reflections pair_reflection Inr_reflection)
   450 done
   450 done
   451 
   451 
   452 
   452 
   453 subsubsection{*The Operator @{term is_and}, Internalized*}
   453 subsubsection\<open>The Operator @{term is_and}, Internalized\<close>
   454 
   454 
   455 (* is_and(M,a,b,z) == (number1(M,a)  & z=b) | 
   455 (* is_and(M,a,b,z) == (number1(M,a)  & z=b) | 
   456                        (~number1(M,a) & empty(M,z)) *)
   456                        (~number1(M,a) & empty(M,z)) *)
   457 definition
   457 definition
   458   and_fm :: "[i,i,i]=>i" where
   458   and_fm :: "[i,i,i]=>i" where
   482 apply (simp only: is_and_def)
   482 apply (simp only: is_and_def)
   483 apply (intro FOL_reflections function_reflections)
   483 apply (intro FOL_reflections function_reflections)
   484 done
   484 done
   485 
   485 
   486 
   486 
   487 subsubsection{*The Operator @{term is_or}, Internalized*}
   487 subsubsection\<open>The Operator @{term is_or}, Internalized\<close>
   488 
   488 
   489 (* is_or(M,a,b,z) == (number1(M,a)  & number1(M,z)) | 
   489 (* is_or(M,a,b,z) == (number1(M,a)  & number1(M,z)) | 
   490                      (~number1(M,a) & z=b) *)
   490                      (~number1(M,a) & z=b) *)
   491 
   491 
   492 definition
   492 definition
   518 apply (intro FOL_reflections function_reflections)
   518 apply (intro FOL_reflections function_reflections)
   519 done
   519 done
   520 
   520 
   521 
   521 
   522 
   522 
   523 subsubsection{*The Operator @{term is_not}, Internalized*}
   523 subsubsection\<open>The Operator @{term is_not}, Internalized\<close>
   524 
   524 
   525 (* is_not(M,a,z) == (number1(M,a)  & empty(M,z)) | 
   525 (* is_not(M,a,z) == (number1(M,a)  & empty(M,z)) | 
   526                      (~number1(M,a) & number1(M,z)) *)
   526                      (~number1(M,a) & number1(M,z)) *)
   527 definition
   527 definition
   528   not_fm :: "[i,i]=>i" where
   528   not_fm :: "[i,i]=>i" where
   557     Inl_reflection Inr_reflection Nil_reflection Cons_reflection
   557     Inl_reflection Inr_reflection Nil_reflection Cons_reflection
   558     quasilist_reflection hd_reflection tl_reflection bool_of_o_reflection
   558     quasilist_reflection hd_reflection tl_reflection bool_of_o_reflection
   559     is_lambda_reflection Member_reflection Equal_reflection Nand_reflection
   559     is_lambda_reflection Member_reflection Equal_reflection Nand_reflection
   560     Forall_reflection is_and_reflection is_or_reflection is_not_reflection
   560     Forall_reflection is_and_reflection is_or_reflection is_not_reflection
   561 
   561 
   562 subsection{*Well-Founded Recursion!*}
   562 subsection\<open>Well-Founded Recursion!\<close>
   563 
   563 
   564 subsubsection{*The Operator @{term M_is_recfun}*}
   564 subsubsection\<open>The Operator @{term M_is_recfun}\<close>
   565 
   565 
   566 text{*Alternative definition, minimizing nesting of quantifiers around MH*}
   566 text\<open>Alternative definition, minimizing nesting of quantifiers around MH\<close>
   567 lemma M_is_recfun_iff:
   567 lemma M_is_recfun_iff:
   568    "M_is_recfun(M,MH,r,a,f) \<longleftrightarrow>
   568    "M_is_recfun(M,MH,r,a,f) \<longleftrightarrow>
   569     (\<forall>z[M]. z \<in> f \<longleftrightarrow> 
   569     (\<forall>z[M]. z \<in> f \<longleftrightarrow> 
   570      (\<exists>x[M]. \<exists>f_r_sx[M]. \<exists>y[M]. 
   570      (\<exists>x[M]. \<exists>f_r_sx[M]. \<exists>y[M]. 
   571              MH(x, f_r_sx, y) & pair(M,x,y,z) &
   571              MH(x, f_r_sx, y) & pair(M,x,y,z) &
   588                 pair(M,x,a,xa) & upair(M,x,x,sx) &
   588                 pair(M,x,a,xa) & upair(M,x,x,sx) &
   589                pre_image(M,r,sx,r_sx) & restriction(M,f,r_sx,f_r_sx) &
   589                pre_image(M,r,sx,r_sx) & restriction(M,f,r_sx,f_r_sx) &
   590                xa \<in> r)"
   590                xa \<in> r)"
   591 *)
   591 *)
   592 
   592 
   593 text{*The three arguments of @{term p} are always 2, 1, 0 and z*}
   593 text\<open>The three arguments of @{term p} are always 2, 1, 0 and z\<close>
   594 definition
   594 definition
   595   is_recfun_fm :: "[i, i, i, i]=>i" where
   595   is_recfun_fm :: "[i, i, i, i]=>i" where
   596   "is_recfun_fm(p,r,a,f) == 
   596   "is_recfun_fm(p,r,a,f) == 
   597    Forall(Iff(Member(0,succ(f)),
   597    Forall(Iff(Member(0,succ(f)),
   598     Exists(Exists(Exists(
   598     Exists(Exists(Exists(
   630   "[| nth(i,env) = x; nth(j,env) = y; nth(k,env) = z; 
   630   "[| nth(i,env) = x; nth(j,env) = y; nth(k,env) = z; 
   631       i \<in> nat; j \<in> nat; k \<in> nat; env \<in> list(A)|]
   631       i \<in> nat; j \<in> nat; k \<in> nat; env \<in> list(A)|]
   632    ==> M_is_recfun(##A, MH, x, y, z) \<longleftrightarrow> sats(A, is_recfun_fm(p,i,j,k), env)"
   632    ==> M_is_recfun(##A, MH, x, y, z) \<longleftrightarrow> sats(A, is_recfun_fm(p,i,j,k), env)"
   633 by (simp add: sats_is_recfun_fm [OF MH_iff_sats]) 
   633 by (simp add: sats_is_recfun_fm [OF MH_iff_sats]) 
   634 
   634 
   635 text{*The additional variable in the premise, namely @{term f'}, is essential.
   635 text\<open>The additional variable in the premise, namely @{term f'}, is essential.
   636 It lets @{term MH} depend upon @{term x}, which seems often necessary.
   636 It lets @{term MH} depend upon @{term x}, which seems often necessary.
   637 The same thing occurs in @{text is_wfrec_reflection}.*}
   637 The same thing occurs in @{text is_wfrec_reflection}.\<close>
   638 theorem is_recfun_reflection:
   638 theorem is_recfun_reflection:
   639   assumes MH_reflection:
   639   assumes MH_reflection:
   640     "!!f' f g h. REFLECTS[\<lambda>x. MH(L, f'(x), f(x), g(x), h(x)), 
   640     "!!f' f g h. REFLECTS[\<lambda>x. MH(L, f'(x), f(x), g(x), h(x)), 
   641                      \<lambda>i x. MH(##Lset(i), f'(x), f(x), g(x), h(x))]"
   641                      \<lambda>i x. MH(##Lset(i), f'(x), f(x), g(x), h(x))]"
   642   shows "REFLECTS[\<lambda>x. M_is_recfun(L, MH(L,x), f(x), g(x), h(x)), 
   642   shows "REFLECTS[\<lambda>x. M_is_recfun(L, MH(L,x), f(x), g(x), h(x)), 
   644 apply (simp (no_asm_use) only: M_is_recfun_def)
   644 apply (simp (no_asm_use) only: M_is_recfun_def)
   645 apply (intro FOL_reflections function_reflections
   645 apply (intro FOL_reflections function_reflections
   646              restriction_reflection MH_reflection)
   646              restriction_reflection MH_reflection)
   647 done
   647 done
   648 
   648 
   649 subsubsection{*The Operator @{term is_wfrec}*}
   649 subsubsection\<open>The Operator @{term is_wfrec}\<close>
   650 
   650 
   651 text{*The three arguments of @{term p} are always 2, 1, 0;
   651 text\<open>The three arguments of @{term p} are always 2, 1, 0;
   652       @{term p} is enclosed by 5 quantifiers.*}
   652       @{term p} is enclosed by 5 quantifiers.\<close>
   653 
   653 
   654 (* is_wfrec :: "[i=>o, i, [i,i,i]=>o, i, i] => o"
   654 (* is_wfrec :: "[i=>o, i, [i,i,i]=>o, i, i] => o"
   655     "is_wfrec(M,MH,r,a,z) == 
   655     "is_wfrec(M,MH,r,a,z) == 
   656       \<exists>f[M]. M_is_recfun(M,MH,r,a,f) & MH(a,f,z)" *)
   656       \<exists>f[M]. M_is_recfun(M,MH,r,a,f) & MH(a,f,z)" *)
   657 definition
   657 definition
   659   "is_wfrec_fm(p,r,a,z) == 
   659   "is_wfrec_fm(p,r,a,z) == 
   660     Exists(And(is_recfun_fm(p, succ(r), succ(a), 0),
   660     Exists(And(is_recfun_fm(p, succ(r), succ(a), 0),
   661            Exists(Exists(Exists(Exists(
   661            Exists(Exists(Exists(Exists(
   662              And(Equal(2,a#+5), And(Equal(1,4), And(Equal(0,z#+5), p)))))))))"
   662              And(Equal(2,a#+5), And(Equal(1,4), And(Equal(0,z#+5), p)))))))))"
   663 
   663 
   664 text{*We call @{term p} with arguments a, f, z by equating them with 
   664 text\<open>We call @{term p} with arguments a, f, z by equating them with 
   665   the corresponding quantified variables with de Bruijn indices 2, 1, 0.*}
   665   the corresponding quantified variables with de Bruijn indices 2, 1, 0.\<close>
   666 
   666 
   667 text{*There's an additional existential quantifier to ensure that the
   667 text\<open>There's an additional existential quantifier to ensure that the
   668       environments in both calls to MH have the same length.*}
   668       environments in both calls to MH have the same length.\<close>
   669 
   669 
   670 lemma is_wfrec_type [TC]:
   670 lemma is_wfrec_type [TC]:
   671      "[| p \<in> formula; x \<in> nat; y \<in> nat; z \<in> nat |] 
   671      "[| p \<in> formula; x \<in> nat; y \<in> nat; z \<in> nat |] 
   672       ==> is_wfrec_fm(p,x,y,z) \<in> formula"
   672       ==> is_wfrec_fm(p,x,y,z) \<in> formula"
   673 by (simp add: is_wfrec_fm_def) 
   673 by (simp add: is_wfrec_fm_def) 
   707 apply (simp (no_asm_use) only: is_wfrec_def)
   707 apply (simp (no_asm_use) only: is_wfrec_def)
   708 apply (intro FOL_reflections MH_reflection is_recfun_reflection)
   708 apply (intro FOL_reflections MH_reflection is_recfun_reflection)
   709 done
   709 done
   710 
   710 
   711 
   711 
   712 subsection{*For Datatypes*}
   712 subsection\<open>For Datatypes\<close>
   713 
   713 
   714 subsubsection{*Binary Products, Internalized*}
   714 subsubsection\<open>Binary Products, Internalized\<close>
   715 
   715 
   716 definition
   716 definition
   717   cartprod_fm :: "[i,i,i]=>i" where
   717   cartprod_fm :: "[i,i,i]=>i" where
   718 (* "cartprod(M,A,B,z) ==
   718 (* "cartprod(M,A,B,z) ==
   719         \<forall>u[M]. u \<in> z \<longleftrightarrow> (\<exists>x[M]. x\<in>A & (\<exists>y[M]. y\<in>B & pair(M,x,y,u)))" *)
   719         \<forall>u[M]. u \<in> z \<longleftrightarrow> (\<exists>x[M]. x\<in>A & (\<exists>y[M]. y\<in>B & pair(M,x,y,u)))" *)
   745 apply (simp only: cartprod_def)
   745 apply (simp only: cartprod_def)
   746 apply (intro FOL_reflections pair_reflection)
   746 apply (intro FOL_reflections pair_reflection)
   747 done
   747 done
   748 
   748 
   749 
   749 
   750 subsubsection{*Binary Sums, Internalized*}
   750 subsubsection\<open>Binary Sums, Internalized\<close>
   751 
   751 
   752 (* "is_sum(M,A,B,Z) ==
   752 (* "is_sum(M,A,B,Z) ==
   753        \<exists>A0[M]. \<exists>n1[M]. \<exists>s1[M]. \<exists>B1[M].
   753        \<exists>A0[M]. \<exists>n1[M]. \<exists>s1[M]. \<exists>B1[M].
   754          3      2       1        0
   754          3      2       1        0
   755        number1(M,n1) & cartprod(M,n1,A,A0) & upair(M,n1,n1,s1) &
   755        number1(M,n1) & cartprod(M,n1,A,A0) & upair(M,n1,n1,s1) &
   785 apply (simp only: is_sum_def)
   785 apply (simp only: is_sum_def)
   786 apply (intro FOL_reflections function_reflections cartprod_reflection)
   786 apply (intro FOL_reflections function_reflections cartprod_reflection)
   787 done
   787 done
   788 
   788 
   789 
   789 
   790 subsubsection{*The Operator @{term quasinat}*}
   790 subsubsection\<open>The Operator @{term quasinat}\<close>
   791 
   791 
   792 (* "is_quasinat(M,z) == empty(M,z) | (\<exists>m[M]. successor(M,m,z))" *)
   792 (* "is_quasinat(M,z) == empty(M,z) | (\<exists>m[M]. successor(M,m,z))" *)
   793 definition
   793 definition
   794   quasinat_fm :: "i=>i" where
   794   quasinat_fm :: "i=>i" where
   795     "quasinat_fm(z) == Or(empty_fm(z), Exists(succ_fm(0,succ(z))))"
   795     "quasinat_fm(z) == Or(empty_fm(z), Exists(succ_fm(0,succ(z))))"
   815 apply (simp only: is_quasinat_def)
   815 apply (simp only: is_quasinat_def)
   816 apply (intro FOL_reflections function_reflections)
   816 apply (intro FOL_reflections function_reflections)
   817 done
   817 done
   818 
   818 
   819 
   819 
   820 subsubsection{*The Operator @{term is_nat_case}*}
   820 subsubsection\<open>The Operator @{term is_nat_case}\<close>
   821 text{*I could not get it to work with the more natural assumption that 
   821 text\<open>I could not get it to work with the more natural assumption that 
   822  @{term is_b} takes two arguments.  Instead it must be a formula where 1 and 0
   822  @{term is_b} takes two arguments.  Instead it must be a formula where 1 and 0
   823  stand for @{term m} and @{term b}, respectively.*}
   823  stand for @{term m} and @{term b}, respectively.\<close>
   824 
   824 
   825 (* is_nat_case :: "[i=>o, i, [i,i]=>o, i, i] => o"
   825 (* is_nat_case :: "[i=>o, i, [i,i]=>o, i, i] => o"
   826     "is_nat_case(M, a, is_b, k, z) ==
   826     "is_nat_case(M, a, is_b, k, z) ==
   827        (empty(M,k) \<longrightarrow> z=a) &
   827        (empty(M,k) \<longrightarrow> z=a) &
   828        (\<forall>m[M]. successor(M,m,k) \<longrightarrow> is_b(m,z)) &
   828        (\<forall>m[M]. successor(M,m,k) \<longrightarrow> is_b(m,z)) &
   829        (is_quasinat(M,k) | empty(M,z))" *)
   829        (is_quasinat(M,k) | empty(M,z))" *)
   830 text{*The formula @{term is_b} has free variables 1 and 0.*}
   830 text\<open>The formula @{term is_b} has free variables 1 and 0.\<close>
   831 definition
   831 definition
   832   is_nat_case_fm :: "[i, i, i, i]=>i" where
   832   is_nat_case_fm :: "[i, i, i, i]=>i" where
   833  "is_nat_case_fm(a,is_b,k,z) == 
   833  "is_nat_case_fm(a,is_b,k,z) == 
   834     And(Implies(empty_fm(k), Equal(z,a)),
   834     And(Implies(empty_fm(k), Equal(z,a)),
   835         And(Forall(Implies(succ_fm(0,succ(k)), 
   835         And(Forall(Implies(succ_fm(0,succ(k)), 
   861       i \<in> nat; j \<in> nat; k < length(env); env \<in> list(A)|]
   861       i \<in> nat; j \<in> nat; k < length(env); env \<in> list(A)|]
   862    ==> is_nat_case(##A, x, is_b, y, z) \<longleftrightarrow> sats(A, is_nat_case_fm(i,p,j,k), env)"
   862    ==> is_nat_case(##A, x, is_b, y, z) \<longleftrightarrow> sats(A, is_nat_case_fm(i,p,j,k), env)"
   863 by (simp add: sats_is_nat_case_fm [of A is_b])
   863 by (simp add: sats_is_nat_case_fm [of A is_b])
   864 
   864 
   865 
   865 
   866 text{*The second argument of @{term is_b} gives it direct access to @{term x},
   866 text\<open>The second argument of @{term is_b} gives it direct access to @{term x},
   867   which is essential for handling free variable references.  Without this
   867   which is essential for handling free variable references.  Without this
   868   argument, we cannot prove reflection for @{term iterates_MH}.*}
   868   argument, we cannot prove reflection for @{term iterates_MH}.\<close>
   869 theorem is_nat_case_reflection:
   869 theorem is_nat_case_reflection:
   870   assumes is_b_reflection:
   870   assumes is_b_reflection:
   871     "!!h f g. REFLECTS[\<lambda>x. is_b(L, h(x), f(x), g(x)),
   871     "!!h f g. REFLECTS[\<lambda>x. is_b(L, h(x), f(x), g(x)),
   872                      \<lambda>i x. is_b(##Lset(i), h(x), f(x), g(x))]"
   872                      \<lambda>i x. is_b(##Lset(i), h(x), f(x), g(x))]"
   873   shows "REFLECTS[\<lambda>x. is_nat_case(L, f(x), is_b(L,x), g(x), h(x)),
   873   shows "REFLECTS[\<lambda>x. is_nat_case(L, f(x), is_b(L,x), g(x), h(x)),
   876 apply (intro FOL_reflections function_reflections
   876 apply (intro FOL_reflections function_reflections
   877              restriction_reflection is_b_reflection quasinat_reflection)
   877              restriction_reflection is_b_reflection quasinat_reflection)
   878 done
   878 done
   879 
   879 
   880 
   880 
   881 subsection{*The Operator @{term iterates_MH}, Needed for Iteration*}
   881 subsection\<open>The Operator @{term iterates_MH}, Needed for Iteration\<close>
   882 
   882 
   883 (*  iterates_MH :: "[i=>o, [i,i]=>o, i, i, i, i] => o"
   883 (*  iterates_MH :: "[i=>o, [i,i]=>o, i, i, i, i] => o"
   884    "iterates_MH(M,isF,v,n,g,z) ==
   884    "iterates_MH(M,isF,v,n,g,z) ==
   885         is_nat_case(M, v, \<lambda>m u. \<exists>gm[M]. fun_apply(M,g,m,gm) & isF(gm,u),
   885         is_nat_case(M, v, \<lambda>m u. \<exists>gm[M]. fun_apply(M,g,m,gm) & isF(gm,u),
   886                     n, z)" *)
   886                     n, z)" *)
   924       i' \<in> nat; i \<in> nat; j \<in> nat; k < length(env); env \<in> list(A)|]
   924       i' \<in> nat; i \<in> nat; j \<in> nat; k < length(env); env \<in> list(A)|]
   925    ==> iterates_MH(##A, is_F, v, x, y, z) \<longleftrightarrow>
   925    ==> iterates_MH(##A, is_F, v, x, y, z) \<longleftrightarrow>
   926        sats(A, iterates_MH_fm(p,i',i,j,k), env)"
   926        sats(A, iterates_MH_fm(p,i',i,j,k), env)"
   927 by (simp add: sats_iterates_MH_fm [OF is_F_iff_sats]) 
   927 by (simp add: sats_iterates_MH_fm [OF is_F_iff_sats]) 
   928 
   928 
   929 text{*The second argument of @{term p} gives it direct access to @{term x},
   929 text\<open>The second argument of @{term p} gives it direct access to @{term x},
   930   which is essential for handling free variable references.  Without this
   930   which is essential for handling free variable references.  Without this
   931   argument, we cannot prove reflection for @{term list_N}.*}
   931   argument, we cannot prove reflection for @{term list_N}.\<close>
   932 theorem iterates_MH_reflection:
   932 theorem iterates_MH_reflection:
   933   assumes p_reflection:
   933   assumes p_reflection:
   934     "!!f g h. REFLECTS[\<lambda>x. p(L, h(x), f(x), g(x)),
   934     "!!f g h. REFLECTS[\<lambda>x. p(L, h(x), f(x), g(x)),
   935                      \<lambda>i x. p(##Lset(i), h(x), f(x), g(x))]"
   935                      \<lambda>i x. p(##Lset(i), h(x), f(x), g(x))]"
   936  shows "REFLECTS[\<lambda>x. iterates_MH(L, p(L,x), e(x), f(x), g(x), h(x)),
   936  shows "REFLECTS[\<lambda>x. iterates_MH(L, p(L,x), e(x), f(x), g(x), h(x)),
   939 apply (intro FOL_reflections function_reflections is_nat_case_reflection
   939 apply (intro FOL_reflections function_reflections is_nat_case_reflection
   940              restriction_reflection p_reflection)
   940              restriction_reflection p_reflection)
   941 done
   941 done
   942 
   942 
   943 
   943 
   944 subsubsection{*The Operator @{term is_iterates}*}
   944 subsubsection\<open>The Operator @{term is_iterates}\<close>
   945 
   945 
   946 text{*The three arguments of @{term p} are always 2, 1, 0;
   946 text\<open>The three arguments of @{term p} are always 2, 1, 0;
   947       @{term p} is enclosed by 9 (??) quantifiers.*}
   947       @{term p} is enclosed by 9 (??) quantifiers.\<close>
   948 
   948 
   949 (*    "is_iterates(M,isF,v,n,Z) == 
   949 (*    "is_iterates(M,isF,v,n,Z) == 
   950       \<exists>sn[M]. \<exists>msn[M]. successor(M,n,sn) & membership(M,sn,msn) &
   950       \<exists>sn[M]. \<exists>msn[M]. successor(M,n,sn) & membership(M,sn,msn) &
   951        1       0       is_wfrec(M, iterates_MH(M,isF,v), msn, n, Z)"*)
   951        1       0       is_wfrec(M, iterates_MH(M,isF,v), msn, n, Z)"*)
   952 
   952 
   957       And(succ_fm(n#+2,1),
   957       And(succ_fm(n#+2,1),
   958        And(Memrel_fm(1,0),
   958        And(Memrel_fm(1,0),
   959               is_wfrec_fm(iterates_MH_fm(p, v#+7, 2, 1, 0), 
   959               is_wfrec_fm(iterates_MH_fm(p, v#+7, 2, 1, 0), 
   960                           0, n#+2, Z#+2)))))"
   960                           0, n#+2, Z#+2)))))"
   961 
   961 
   962 text{*We call @{term p} with arguments a, f, z by equating them with 
   962 text\<open>We call @{term p} with arguments a, f, z by equating them with 
   963   the corresponding quantified variables with de Bruijn indices 2, 1, 0.*}
   963   the corresponding quantified variables with de Bruijn indices 2, 1, 0.\<close>
   964 
   964 
   965 
   965 
   966 lemma is_iterates_type [TC]:
   966 lemma is_iterates_type [TC]:
   967      "[| p \<in> formula; x \<in> nat; y \<in> nat; z \<in> nat |] 
   967      "[| p \<in> formula; x \<in> nat; y \<in> nat; z \<in> nat |] 
   968       ==> is_iterates_fm(p,x,y,z) \<in> formula"
   968       ==> is_iterates_fm(p,x,y,z) \<in> formula"
  1000       i \<in> nat; j < length(env); k < length(env); env \<in> list(A)|]
  1000       i \<in> nat; j < length(env); k < length(env); env \<in> list(A)|]
  1001    ==> is_iterates(##A, is_F, x, y, z) \<longleftrightarrow>
  1001    ==> is_iterates(##A, is_F, x, y, z) \<longleftrightarrow>
  1002        sats(A, is_iterates_fm(p,i,j,k), env)"
  1002        sats(A, is_iterates_fm(p,i,j,k), env)"
  1003 by (simp add: sats_is_iterates_fm [OF is_F_iff_sats]) 
  1003 by (simp add: sats_is_iterates_fm [OF is_F_iff_sats]) 
  1004 
  1004 
  1005 text{*The second argument of @{term p} gives it direct access to @{term x},
  1005 text\<open>The second argument of @{term p} gives it direct access to @{term x},
  1006   which is essential for handling free variable references.  Without this
  1006   which is essential for handling free variable references.  Without this
  1007   argument, we cannot prove reflection for @{term list_N}.*}
  1007   argument, we cannot prove reflection for @{term list_N}.\<close>
  1008 theorem is_iterates_reflection:
  1008 theorem is_iterates_reflection:
  1009   assumes p_reflection:
  1009   assumes p_reflection:
  1010     "!!f g h. REFLECTS[\<lambda>x. p(L, h(x), f(x), g(x)),
  1010     "!!f g h. REFLECTS[\<lambda>x. p(L, h(x), f(x), g(x)),
  1011                      \<lambda>i x. p(##Lset(i), h(x), f(x), g(x))]"
  1011                      \<lambda>i x. p(##Lset(i), h(x), f(x), g(x))]"
  1012  shows "REFLECTS[\<lambda>x. is_iterates(L, p(L,x), f(x), g(x), h(x)),
  1012  shows "REFLECTS[\<lambda>x. is_iterates(L, p(L,x), f(x), g(x), h(x)),
  1015 apply (intro FOL_reflections function_reflections p_reflection
  1015 apply (intro FOL_reflections function_reflections p_reflection
  1016              is_wfrec_reflection iterates_MH_reflection)
  1016              is_wfrec_reflection iterates_MH_reflection)
  1017 done
  1017 done
  1018 
  1018 
  1019 
  1019 
  1020 subsubsection{*The Formula @{term is_eclose_n}, Internalized*}
  1020 subsubsection\<open>The Formula @{term is_eclose_n}, Internalized\<close>
  1021 
  1021 
  1022 (* is_eclose_n(M,A,n,Z) == is_iterates(M, big_union(M), A, n, Z) *)
  1022 (* is_eclose_n(M,A,n,Z) == is_iterates(M, big_union(M), A, n, Z) *)
  1023 
  1023 
  1024 definition
  1024 definition
  1025   eclose_n_fm :: "[i,i,i]=>i" where
  1025   eclose_n_fm :: "[i,i,i]=>i" where
  1051 apply (simp only: is_eclose_n_def)
  1051 apply (simp only: is_eclose_n_def)
  1052 apply (intro FOL_reflections function_reflections is_iterates_reflection) 
  1052 apply (intro FOL_reflections function_reflections is_iterates_reflection) 
  1053 done
  1053 done
  1054 
  1054 
  1055 
  1055 
  1056 subsubsection{*Membership in @{term "eclose(A)"}*}
  1056 subsubsection\<open>Membership in @{term "eclose(A)"}\<close>
  1057 
  1057 
  1058 (* mem_eclose(M,A,l) == 
  1058 (* mem_eclose(M,A,l) == 
  1059       \<exists>n[M]. \<exists>eclosen[M]. 
  1059       \<exists>n[M]. \<exists>eclosen[M]. 
  1060        finite_ordinal(M,n) & is_eclose_n(M,A,n,eclosen) & l \<in> eclosen *)
  1060        finite_ordinal(M,n) & is_eclose_n(M,A,n,eclosen) & l \<in> eclosen *)
  1061 definition
  1061 definition
  1086 apply (simp only: mem_eclose_def)
  1086 apply (simp only: mem_eclose_def)
  1087 apply (intro FOL_reflections finite_ordinal_reflection eclose_n_reflection)
  1087 apply (intro FOL_reflections finite_ordinal_reflection eclose_n_reflection)
  1088 done
  1088 done
  1089 
  1089 
  1090 
  1090 
  1091 subsubsection{*The Predicate ``Is @{term "eclose(A)"}''*}
  1091 subsubsection\<open>The Predicate ``Is @{term "eclose(A)"}''\<close>
  1092 
  1092 
  1093 (* is_eclose(M,A,Z) == \<forall>l[M]. l \<in> Z \<longleftrightarrow> mem_eclose(M,A,l) *)
  1093 (* is_eclose(M,A,Z) == \<forall>l[M]. l \<in> Z \<longleftrightarrow> mem_eclose(M,A,l) *)
  1094 definition
  1094 definition
  1095   is_eclose_fm :: "[i,i]=>i" where
  1095   is_eclose_fm :: "[i,i]=>i" where
  1096     "is_eclose_fm(A,Z) ==
  1096     "is_eclose_fm(A,Z) ==
  1117 apply (simp only: is_eclose_def)
  1117 apply (simp only: is_eclose_def)
  1118 apply (intro FOL_reflections mem_eclose_reflection)
  1118 apply (intro FOL_reflections mem_eclose_reflection)
  1119 done
  1119 done
  1120 
  1120 
  1121 
  1121 
  1122 subsubsection{*The List Functor, Internalized*}
  1122 subsubsection\<open>The List Functor, Internalized\<close>
  1123 
  1123 
  1124 definition
  1124 definition
  1125   list_functor_fm :: "[i,i,i]=>i" where
  1125   list_functor_fm :: "[i,i,i]=>i" where
  1126 (* "is_list_functor(M,A,X,Z) ==
  1126 (* "is_list_functor(M,A,X,Z) ==
  1127         \<exists>n1[M]. \<exists>AX[M].
  1127         \<exists>n1[M]. \<exists>AX[M].
  1154 apply (intro FOL_reflections number1_reflection
  1154 apply (intro FOL_reflections number1_reflection
  1155              cartprod_reflection sum_reflection)
  1155              cartprod_reflection sum_reflection)
  1156 done
  1156 done
  1157 
  1157 
  1158 
  1158 
  1159 subsubsection{*The Formula @{term is_list_N}, Internalized*}
  1159 subsubsection\<open>The Formula @{term is_list_N}, Internalized\<close>
  1160 
  1160 
  1161 (* "is_list_N(M,A,n,Z) == 
  1161 (* "is_list_N(M,A,n,Z) == 
  1162       \<exists>zero[M]. empty(M,zero) & 
  1162       \<exists>zero[M]. empty(M,zero) & 
  1163                 is_iterates(M, is_list_functor(M,A), zero, n, Z)" *)
  1163                 is_iterates(M, is_list_functor(M,A), zero, n, Z)" *)
  1164 
  1164 
  1196              is_iterates_reflection list_functor_reflection) 
  1196              is_iterates_reflection list_functor_reflection) 
  1197 done
  1197 done
  1198 
  1198 
  1199 
  1199 
  1200 
  1200 
  1201 subsubsection{*The Predicate ``Is A List''*}
  1201 subsubsection\<open>The Predicate ``Is A List''\<close>
  1202 
  1202 
  1203 (* mem_list(M,A,l) == 
  1203 (* mem_list(M,A,l) == 
  1204       \<exists>n[M]. \<exists>listn[M]. 
  1204       \<exists>n[M]. \<exists>listn[M]. 
  1205        finite_ordinal(M,n) & is_list_N(M,A,n,listn) & l \<in> listn *)
  1205        finite_ordinal(M,n) & is_list_N(M,A,n,listn) & l \<in> listn *)
  1206 definition
  1206 definition
  1231 apply (simp only: mem_list_def)
  1231 apply (simp only: mem_list_def)
  1232 apply (intro FOL_reflections finite_ordinal_reflection list_N_reflection)
  1232 apply (intro FOL_reflections finite_ordinal_reflection list_N_reflection)
  1233 done
  1233 done
  1234 
  1234 
  1235 
  1235 
  1236 subsubsection{*The Predicate ``Is @{term "list(A)"}''*}
  1236 subsubsection\<open>The Predicate ``Is @{term "list(A)"}''\<close>
  1237 
  1237 
  1238 (* is_list(M,A,Z) == \<forall>l[M]. l \<in> Z \<longleftrightarrow> mem_list(M,A,l) *)
  1238 (* is_list(M,A,Z) == \<forall>l[M]. l \<in> Z \<longleftrightarrow> mem_list(M,A,l) *)
  1239 definition
  1239 definition
  1240   is_list_fm :: "[i,i]=>i" where
  1240   is_list_fm :: "[i,i]=>i" where
  1241     "is_list_fm(A,Z) ==
  1241     "is_list_fm(A,Z) ==
  1262 apply (simp only: is_list_def)
  1262 apply (simp only: is_list_def)
  1263 apply (intro FOL_reflections mem_list_reflection)
  1263 apply (intro FOL_reflections mem_list_reflection)
  1264 done
  1264 done
  1265 
  1265 
  1266 
  1266 
  1267 subsubsection{*The Formula Functor, Internalized*}
  1267 subsubsection\<open>The Formula Functor, Internalized\<close>
  1268 
  1268 
  1269 definition formula_functor_fm :: "[i,i]=>i" where
  1269 definition formula_functor_fm :: "[i,i]=>i" where
  1270 (*     "is_formula_functor(M,X,Z) ==
  1270 (*     "is_formula_functor(M,X,Z) ==
  1271         \<exists>nat'[M]. \<exists>natnat[M]. \<exists>natnatsum[M]. \<exists>XX[M]. \<exists>X3[M].
  1271         \<exists>nat'[M]. \<exists>natnat[M]. \<exists>natnatsum[M]. \<exists>XX[M]. \<exists>X3[M].
  1272            4           3               2       1       0
  1272            4           3               2       1       0
  1305 apply (intro FOL_reflections omega_reflection
  1305 apply (intro FOL_reflections omega_reflection
  1306              cartprod_reflection sum_reflection)
  1306              cartprod_reflection sum_reflection)
  1307 done
  1307 done
  1308 
  1308 
  1309 
  1309 
  1310 subsubsection{*The Formula @{term is_formula_N}, Internalized*}
  1310 subsubsection\<open>The Formula @{term is_formula_N}, Internalized\<close>
  1311 
  1311 
  1312 (*  "is_formula_N(M,n,Z) == 
  1312 (*  "is_formula_N(M,n,Z) == 
  1313       \<exists>zero[M]. empty(M,zero) & 
  1313       \<exists>zero[M]. empty(M,zero) & 
  1314                 is_iterates(M, is_formula_functor(M), zero, n, Z)" *) 
  1314                 is_iterates(M, is_formula_functor(M), zero, n, Z)" *) 
  1315 definition
  1315 definition
  1346              is_iterates_reflection formula_functor_reflection) 
  1346              is_iterates_reflection formula_functor_reflection) 
  1347 done
  1347 done
  1348 
  1348 
  1349 
  1349 
  1350 
  1350 
  1351 subsubsection{*The Predicate ``Is A Formula''*}
  1351 subsubsection\<open>The Predicate ``Is A Formula''\<close>
  1352 
  1352 
  1353 (*  mem_formula(M,p) == 
  1353 (*  mem_formula(M,p) == 
  1354       \<exists>n[M]. \<exists>formn[M]. 
  1354       \<exists>n[M]. \<exists>formn[M]. 
  1355        finite_ordinal(M,n) & is_formula_N(M,n,formn) & p \<in> formn *)
  1355        finite_ordinal(M,n) & is_formula_N(M,n,formn) & p \<in> formn *)
  1356 definition
  1356 definition
  1381 apply (intro FOL_reflections finite_ordinal_reflection formula_N_reflection)
  1381 apply (intro FOL_reflections finite_ordinal_reflection formula_N_reflection)
  1382 done
  1382 done
  1383 
  1383 
  1384 
  1384 
  1385 
  1385 
  1386 subsubsection{*The Predicate ``Is @{term "formula"}''*}
  1386 subsubsection\<open>The Predicate ``Is @{term "formula"}''\<close>
  1387 
  1387 
  1388 (* is_formula(M,Z) == \<forall>p[M]. p \<in> Z \<longleftrightarrow> mem_formula(M,p) *)
  1388 (* is_formula(M,Z) == \<forall>p[M]. p \<in> Z \<longleftrightarrow> mem_formula(M,p) *)
  1389 definition
  1389 definition
  1390   is_formula_fm :: "i=>i" where
  1390   is_formula_fm :: "i=>i" where
  1391     "is_formula_fm(Z) == Forall(Iff(Member(0,succ(Z)), mem_formula_fm(0)))"
  1391     "is_formula_fm(Z) == Forall(Iff(Member(0,succ(Z)), mem_formula_fm(0)))"
  1410 apply (simp only: is_formula_def)
  1410 apply (simp only: is_formula_def)
  1411 apply (intro FOL_reflections mem_formula_reflection)
  1411 apply (intro FOL_reflections mem_formula_reflection)
  1412 done
  1412 done
  1413 
  1413 
  1414 
  1414 
  1415 subsubsection{*The Operator @{term is_transrec}*}
  1415 subsubsection\<open>The Operator @{term is_transrec}\<close>
  1416 
  1416 
  1417 text{*The three arguments of @{term p} are always 2, 1, 0.  It is buried
  1417 text\<open>The three arguments of @{term p} are always 2, 1, 0.  It is buried
  1418    within eight quantifiers!
  1418    within eight quantifiers!
  1419    We call @{term p} with arguments a, f, z by equating them with 
  1419    We call @{term p} with arguments a, f, z by equating them with 
  1420   the corresponding quantified variables with de Bruijn indices 2, 1, 0.*}
  1420   the corresponding quantified variables with de Bruijn indices 2, 1, 0.\<close>
  1421 
  1421 
  1422 (* is_transrec :: "[i=>o, [i,i,i]=>o, i, i] => o"
  1422 (* is_transrec :: "[i=>o, [i,i,i]=>o, i, i] => o"
  1423    "is_transrec(M,MH,a,z) == 
  1423    "is_transrec(M,MH,a,z) == 
  1424       \<exists>sa[M]. \<exists>esa[M]. \<exists>mesa[M]. 
  1424       \<exists>sa[M]. \<exists>esa[M]. \<exists>mesa[M]. 
  1425        2       1         0
  1425        2       1         0