src/ZF/Constructible/Datatype_absolute.thy
author paulson
Wed Aug 21 15:57:24 2002 +0200 (2002-08-21)
changeset 13513 b9e14471629c
parent 13505 52a16cb7fefb
child 13557 6061d0045409
permissions -rw-r--r--
tweaks
     1 (*  Title:      ZF/Constructible/Datatype_absolute.thy
     2     ID: $Id$
     3     Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
     4     Copyright   2002  University of Cambridge
     5 *)
     6 
     7 header {*Absoluteness Properties for Recursive Datatypes*}
     8 
     9 theory Datatype_absolute = Formula + WF_absolute:
    10 
    11 
    12 subsection{*The lfp of a continuous function can be expressed as a union*}
    13 
    14 constdefs
    15   directed :: "i=>o"
    16    "directed(A) == A\<noteq>0 & (\<forall>x\<in>A. \<forall>y\<in>A. x \<union> y \<in> A)"
    17 
    18   contin :: "(i=>i) => o"
    19    "contin(h) == (\<forall>A. directed(A) --> h(\<Union>A) = (\<Union>X\<in>A. h(X)))"
    20 
    21 lemma bnd_mono_iterates_subset: "[|bnd_mono(D, h); n \<in> nat|] ==> h^n (0) <= D"
    22 apply (induct_tac n) 
    23  apply (simp_all add: bnd_mono_def, blast) 
    24 done
    25 
    26 lemma bnd_mono_increasing [rule_format]:
    27      "[|i \<in> nat; j \<in> nat; bnd_mono(D,h)|] ==> i \<le> j --> h^i(0) \<subseteq> h^j(0)"
    28 apply (rule_tac m=i and n=j in diff_induct, simp_all)
    29 apply (blast del: subsetI
    30 	     intro: bnd_mono_iterates_subset bnd_monoD2 [of concl: h]) 
    31 done
    32 
    33 lemma directed_iterates: "bnd_mono(D,h) ==> directed({h^n (0). n\<in>nat})"
    34 apply (simp add: directed_def, clarify) 
    35 apply (rename_tac i j)
    36 apply (rule_tac x="i \<union> j" in bexI) 
    37 apply (rule_tac i = i and j = j in Ord_linear_le)
    38 apply (simp_all add: subset_Un_iff [THEN iffD1] le_imp_subset
    39                      subset_Un_iff2 [THEN iffD1])
    40 apply (simp_all add: subset_Un_iff [THEN iff_sym] bnd_mono_increasing
    41                      subset_Un_iff2 [THEN iff_sym])
    42 done
    43 
    44 
    45 lemma contin_iterates_eq: 
    46     "[|bnd_mono(D, h); contin(h)|] 
    47      ==> h(\<Union>n\<in>nat. h^n (0)) = (\<Union>n\<in>nat. h^n (0))"
    48 apply (simp add: contin_def directed_iterates) 
    49 apply (rule trans) 
    50 apply (rule equalityI) 
    51  apply (simp_all add: UN_subset_iff)
    52  apply safe
    53  apply (erule_tac [2] natE) 
    54   apply (rule_tac a="succ(x)" in UN_I) 
    55    apply simp_all 
    56 apply blast 
    57 done
    58 
    59 lemma lfp_subset_Union:
    60      "[|bnd_mono(D, h); contin(h)|] ==> lfp(D,h) <= (\<Union>n\<in>nat. h^n(0))"
    61 apply (rule lfp_lowerbound) 
    62  apply (simp add: contin_iterates_eq) 
    63 apply (simp add: contin_def bnd_mono_iterates_subset UN_subset_iff) 
    64 done
    65 
    66 lemma Union_subset_lfp:
    67      "bnd_mono(D,h) ==> (\<Union>n\<in>nat. h^n(0)) <= lfp(D,h)"
    68 apply (simp add: UN_subset_iff)
    69 apply (rule ballI)  
    70 apply (induct_tac n, simp_all) 
    71 apply (rule subset_trans [of _ "h(lfp(D,h))"])
    72  apply (blast dest: bnd_monoD2 [OF _ _ lfp_subset])  
    73 apply (erule lfp_lemma2) 
    74 done
    75 
    76 lemma lfp_eq_Union:
    77      "[|bnd_mono(D, h); contin(h)|] ==> lfp(D,h) = (\<Union>n\<in>nat. h^n(0))"
    78 by (blast del: subsetI 
    79           intro: lfp_subset_Union Union_subset_lfp)
    80 
    81 
    82 subsubsection{*Some Standard Datatype Constructions Preserve Continuity*}
    83 
    84 lemma contin_imp_mono: "[|X\<subseteq>Y; contin(F)|] ==> F(X) \<subseteq> F(Y)"
    85 apply (simp add: contin_def) 
    86 apply (drule_tac x="{X,Y}" in spec) 
    87 apply (simp add: directed_def subset_Un_iff2 Un_commute) 
    88 done
    89 
    90 lemma sum_contin: "[|contin(F); contin(G)|] ==> contin(\<lambda>X. F(X) + G(X))"
    91 by (simp add: contin_def, blast)
    92 
    93 lemma prod_contin: "[|contin(F); contin(G)|] ==> contin(\<lambda>X. F(X) * G(X))" 
    94 apply (subgoal_tac "\<forall>B C. F(B) \<subseteq> F(B \<union> C)")
    95  prefer 2 apply (simp add: Un_upper1 contin_imp_mono) 
    96 apply (subgoal_tac "\<forall>B C. G(C) \<subseteq> G(B \<union> C)")
    97  prefer 2 apply (simp add: Un_upper2 contin_imp_mono) 
    98 apply (simp add: contin_def, clarify) 
    99 apply (rule equalityI) 
   100  prefer 2 apply blast 
   101 apply clarify 
   102 apply (rename_tac B C) 
   103 apply (rule_tac a="B \<union> C" in UN_I) 
   104  apply (simp add: directed_def, blast)  
   105 done
   106 
   107 lemma const_contin: "contin(\<lambda>X. A)"
   108 by (simp add: contin_def directed_def)
   109 
   110 lemma id_contin: "contin(\<lambda>X. X)"
   111 by (simp add: contin_def)
   112 
   113 
   114 
   115 subsection {*Absoluteness for "Iterates"*}
   116 
   117 constdefs
   118 
   119   iterates_MH :: "[i=>o, [i,i]=>o, i, i, i, i] => o"
   120    "iterates_MH(M,isF,v,n,g,z) ==
   121         is_nat_case(M, v, \<lambda>m u. \<exists>gm[M]. fun_apply(M,g,m,gm) & isF(gm,u),
   122                     n, z)"
   123 
   124   iterates_replacement :: "[i=>o, [i,i]=>o, i] => o"
   125    "iterates_replacement(M,isF,v) ==
   126       \<forall>n[M]. n\<in>nat --> 
   127          wfrec_replacement(M, iterates_MH(M,isF,v), Memrel(succ(n)))"
   128 
   129 lemma (in M_axioms) iterates_MH_abs:
   130   "[| relativize1(M,isF,F); M(n); M(g); M(z) |] 
   131    ==> iterates_MH(M,isF,v,n,g,z) <-> z = nat_case(v, \<lambda>m. F(g`m), n)"
   132 by (simp add: nat_case_abs [of _ "\<lambda>m. F(g ` m)"]
   133               relativize1_def iterates_MH_def)  
   134 
   135 lemma (in M_axioms) iterates_imp_wfrec_replacement:
   136   "[|relativize1(M,isF,F); n \<in> nat; iterates_replacement(M,isF,v)|] 
   137    ==> wfrec_replacement(M, \<lambda>n f z. z = nat_case(v, \<lambda>m. F(f`m), n), 
   138                        Memrel(succ(n)))" 
   139 by (simp add: iterates_replacement_def iterates_MH_abs)
   140 
   141 theorem (in M_trancl) iterates_abs:
   142   "[| iterates_replacement(M,isF,v); relativize1(M,isF,F);
   143       n \<in> nat; M(v); M(z); \<forall>x[M]. M(F(x)) |] 
   144    ==> is_wfrec(M, iterates_MH(M,isF,v), Memrel(succ(n)), n, z) <->
   145        z = iterates(F,n,v)" 
   146 apply (frule iterates_imp_wfrec_replacement, assumption+)
   147 apply (simp add: wf_Memrel trans_Memrel relation_Memrel nat_into_M
   148                  relativize2_def iterates_MH_abs 
   149                  iterates_nat_def recursor_def transrec_def 
   150                  eclose_sing_Ord_eq nat_into_M
   151          trans_wfrec_abs [of _ _ _ _ "\<lambda>n g. nat_case(v, \<lambda>m. F(g`m), n)"])
   152 done
   153 
   154 
   155 lemma (in M_wfrank) iterates_closed [intro,simp]:
   156   "[| iterates_replacement(M,isF,v); relativize1(M,isF,F);
   157       n \<in> nat; M(v); \<forall>x[M]. M(F(x)) |] 
   158    ==> M(iterates(F,n,v))"
   159 apply (frule iterates_imp_wfrec_replacement, assumption+)
   160 apply (simp add: wf_Memrel trans_Memrel relation_Memrel nat_into_M
   161                  relativize2_def iterates_MH_abs 
   162                  iterates_nat_def recursor_def transrec_def 
   163                  eclose_sing_Ord_eq nat_into_M
   164          trans_wfrec_closed [of _ _ _ "\<lambda>n g. nat_case(v, \<lambda>m. F(g`m), n)"])
   165 done
   166 
   167 
   168 subsection {*lists without univ*}
   169 
   170 lemmas datatype_univs = Inl_in_univ Inr_in_univ 
   171                         Pair_in_univ nat_into_univ A_into_univ 
   172 
   173 lemma list_fun_bnd_mono: "bnd_mono(univ(A), \<lambda>X. {0} + A*X)"
   174 apply (rule bnd_monoI)
   175  apply (intro subset_refl zero_subset_univ A_subset_univ 
   176 	      sum_subset_univ Sigma_subset_univ) 
   177 apply (rule subset_refl sum_mono Sigma_mono | assumption)+
   178 done
   179 
   180 lemma list_fun_contin: "contin(\<lambda>X. {0} + A*X)"
   181 by (intro sum_contin prod_contin id_contin const_contin) 
   182 
   183 text{*Re-expresses lists using sum and product*}
   184 lemma list_eq_lfp2: "list(A) = lfp(univ(A), \<lambda>X. {0} + A*X)"
   185 apply (simp add: list_def) 
   186 apply (rule equalityI) 
   187  apply (rule lfp_lowerbound) 
   188   prefer 2 apply (rule lfp_subset)
   189  apply (clarify, subst lfp_unfold [OF list_fun_bnd_mono])
   190  apply (simp add: Nil_def Cons_def)
   191  apply blast 
   192 txt{*Opposite inclusion*}
   193 apply (rule lfp_lowerbound) 
   194  prefer 2 apply (rule lfp_subset) 
   195 apply (clarify, subst lfp_unfold [OF list.bnd_mono]) 
   196 apply (simp add: Nil_def Cons_def)
   197 apply (blast intro: datatype_univs
   198              dest: lfp_subset [THEN subsetD])
   199 done
   200 
   201 text{*Re-expresses lists using "iterates", no univ.*}
   202 lemma list_eq_Union:
   203      "list(A) = (\<Union>n\<in>nat. (\<lambda>X. {0} + A*X) ^ n (0))"
   204 by (simp add: list_eq_lfp2 lfp_eq_Union list_fun_bnd_mono list_fun_contin)
   205 
   206 
   207 constdefs
   208   is_list_functor :: "[i=>o,i,i,i] => o"
   209     "is_list_functor(M,A,X,Z) == 
   210         \<exists>n1[M]. \<exists>AX[M]. 
   211          number1(M,n1) & cartprod(M,A,X,AX) & is_sum(M,n1,AX,Z)"
   212 
   213 lemma (in M_axioms) list_functor_abs [simp]: 
   214      "[| M(A); M(X); M(Z) |] ==> is_list_functor(M,A,X,Z) <-> (Z = {0} + A*X)"
   215 by (simp add: is_list_functor_def singleton_0 nat_into_M)
   216 
   217 
   218 subsection {*formulas without univ*}
   219 
   220 lemma formula_fun_bnd_mono:
   221      "bnd_mono(univ(0), \<lambda>X. ((nat*nat) + (nat*nat)) + (X*X + X))"
   222 apply (rule bnd_monoI)
   223  apply (intro subset_refl zero_subset_univ A_subset_univ 
   224 	      sum_subset_univ Sigma_subset_univ nat_subset_univ) 
   225 apply (rule subset_refl sum_mono Sigma_mono | assumption)+
   226 done
   227 
   228 lemma formula_fun_contin:
   229      "contin(\<lambda>X. ((nat*nat) + (nat*nat)) + (X*X + X))"
   230 by (intro sum_contin prod_contin id_contin const_contin) 
   231 
   232 
   233 text{*Re-expresses formulas using sum and product*}
   234 lemma formula_eq_lfp2:
   235     "formula = lfp(univ(0), \<lambda>X. ((nat*nat) + (nat*nat)) + (X*X + X))"
   236 apply (simp add: formula_def) 
   237 apply (rule equalityI) 
   238  apply (rule lfp_lowerbound) 
   239   prefer 2 apply (rule lfp_subset)
   240  apply (clarify, subst lfp_unfold [OF formula_fun_bnd_mono])
   241  apply (simp add: Member_def Equal_def Nand_def Forall_def)
   242  apply blast 
   243 txt{*Opposite inclusion*}
   244 apply (rule lfp_lowerbound) 
   245  prefer 2 apply (rule lfp_subset, clarify) 
   246 apply (subst lfp_unfold [OF formula.bnd_mono, simplified]) 
   247 apply (simp add: Member_def Equal_def Nand_def Forall_def)  
   248 apply (elim sumE SigmaE, simp_all) 
   249 apply (blast intro: datatype_univs dest: lfp_subset [THEN subsetD])+  
   250 done
   251 
   252 text{*Re-expresses formulas using "iterates", no univ.*}
   253 lemma formula_eq_Union:
   254      "formula = 
   255       (\<Union>n\<in>nat. (\<lambda>X. ((nat*nat) + (nat*nat)) + (X*X + X)) ^ n (0))"
   256 by (simp add: formula_eq_lfp2 lfp_eq_Union formula_fun_bnd_mono 
   257               formula_fun_contin)
   258 
   259 
   260 constdefs
   261   is_formula_functor :: "[i=>o,i,i] => o"
   262     "is_formula_functor(M,X,Z) == 
   263         \<exists>nat'[M]. \<exists>natnat[M]. \<exists>natnatsum[M]. \<exists>XX[M]. \<exists>X3[M]. 
   264           omega(M,nat') & cartprod(M,nat',nat',natnat) & 
   265           is_sum(M,natnat,natnat,natnatsum) &
   266           cartprod(M,X,X,XX) & is_sum(M,XX,X,X3) & 
   267           is_sum(M,natnatsum,X3,Z)"
   268 
   269 lemma (in M_axioms) formula_functor_abs [simp]: 
   270      "[| M(X); M(Z) |] 
   271       ==> is_formula_functor(M,X,Z) <-> 
   272           Z = ((nat*nat) + (nat*nat)) + (X*X + X)"
   273 by (simp add: is_formula_functor_def) 
   274 
   275 
   276 subsection{*@{term M} Contains the List and Formula Datatypes*}
   277 
   278 constdefs
   279   list_N :: "[i,i] => i"
   280     "list_N(A,n) == (\<lambda>X. {0} + A * X)^n (0)"
   281 
   282 lemma Nil_in_list_N [simp]: "[] \<in> list_N(A,succ(n))"
   283 by (simp add: list_N_def Nil_def)
   284 
   285 lemma Cons_in_list_N [simp]:
   286      "Cons(a,l) \<in> list_N(A,succ(n)) <-> a\<in>A & l \<in> list_N(A,n)"
   287 by (simp add: list_N_def Cons_def) 
   288 
   289 text{*These two aren't simprules because they reveal the underlying
   290 list representation.*}
   291 lemma list_N_0: "list_N(A,0) = 0"
   292 by (simp add: list_N_def)
   293 
   294 lemma list_N_succ: "list_N(A,succ(n)) = {0} + A * (list_N(A,n))"
   295 by (simp add: list_N_def)
   296 
   297 lemma list_N_imp_list:
   298   "[| l \<in> list_N(A,n); n \<in> nat |] ==> l \<in> list(A)"
   299 by (force simp add: list_eq_Union list_N_def)
   300 
   301 lemma list_N_imp_length_lt [rule_format]:
   302      "n \<in> nat ==> \<forall>l \<in> list_N(A,n). length(l) < n"
   303 apply (induct_tac n)  
   304 apply (auto simp add: list_N_0 list_N_succ 
   305                       Nil_def [symmetric] Cons_def [symmetric]) 
   306 done
   307 
   308 lemma list_imp_list_N [rule_format]:
   309      "l \<in> list(A) ==> \<forall>n\<in>nat. length(l) < n --> l \<in> list_N(A, n)"
   310 apply (induct_tac l)
   311 apply (force elim: natE)+
   312 done
   313 
   314 lemma list_N_imp_eq_length:
   315       "[|n \<in> nat; l \<notin> list_N(A, n); l \<in> list_N(A, succ(n))|] 
   316        ==> n = length(l)"
   317 apply (rule le_anti_sym) 
   318  prefer 2 apply (simp add: list_N_imp_length_lt) 
   319 apply (frule list_N_imp_list, simp)
   320 apply (simp add: not_lt_iff_le [symmetric]) 
   321 apply (blast intro: list_imp_list_N) 
   322 done
   323   
   324 text{*Express @{term list_rec} without using @{term rank} or @{term Vset},
   325 neither of which is absolute.*}
   326 lemma (in M_triv_axioms) list_rec_eq:
   327   "l \<in> list(A) ==>
   328    list_rec(a,g,l) = 
   329    transrec (succ(length(l)),
   330       \<lambda>x h. Lambda (list(A),
   331                     list_case' (a, 
   332                            \<lambda>a l. g(a, l, h ` succ(length(l)) ` l)))) ` l"
   333 apply (induct_tac l) 
   334 apply (subst transrec, simp) 
   335 apply (subst transrec) 
   336 apply (simp add: list_imp_list_N) 
   337 done
   338 
   339 constdefs
   340   is_list_N :: "[i=>o,i,i,i] => o"
   341     "is_list_N(M,A,n,Z) == 
   342       \<exists>zero[M]. \<exists>sn[M]. \<exists>msn[M]. 
   343        empty(M,zero) & 
   344        successor(M,n,sn) & membership(M,sn,msn) &
   345        is_wfrec(M, iterates_MH(M, is_list_functor(M,A),zero), msn, n, Z)"
   346   
   347   mem_list :: "[i=>o,i,i] => o"
   348     "mem_list(M,A,l) == 
   349       \<exists>n[M]. \<exists>listn[M]. 
   350        finite_ordinal(M,n) & is_list_N(M,A,n,listn) & l \<in> listn"
   351 
   352   is_list :: "[i=>o,i,i] => o"
   353     "is_list(M,A,Z) == \<forall>l[M]. l \<in> Z <-> mem_list(M,A,l)"
   354 
   355 subsubsection{*Towards Absoluteness of @{term formula_rec}*}
   356 
   357 consts   depth :: "i=>i"
   358 primrec
   359   "depth(Member(x,y)) = 0"
   360   "depth(Equal(x,y))  = 0"
   361   "depth(Nand(p,q)) = succ(depth(p) \<union> depth(q))"
   362   "depth(Forall(p)) = succ(depth(p))"
   363 
   364 lemma depth_type [TC]: "p \<in> formula ==> depth(p) \<in> nat"
   365 by (induct_tac p, simp_all) 
   366 
   367 
   368 constdefs
   369   formula_N :: "i => i"
   370     "formula_N(n) == (\<lambda>X. ((nat*nat) + (nat*nat)) + (X*X + X)) ^ n (0)"
   371 
   372 lemma Member_in_formula_N [simp]:
   373      "Member(x,y) \<in> formula_N(succ(n)) <-> x \<in> nat & y \<in> nat"
   374 by (simp add: formula_N_def Member_def) 
   375 
   376 lemma Equal_in_formula_N [simp]:
   377      "Equal(x,y) \<in> formula_N(succ(n)) <-> x \<in> nat & y \<in> nat"
   378 by (simp add: formula_N_def Equal_def) 
   379 
   380 lemma Nand_in_formula_N [simp]:
   381      "Nand(x,y) \<in> formula_N(succ(n)) <-> x \<in> formula_N(n) & y \<in> formula_N(n)"
   382 by (simp add: formula_N_def Nand_def) 
   383 
   384 lemma Forall_in_formula_N [simp]:
   385      "Forall(x) \<in> formula_N(succ(n)) <-> x \<in> formula_N(n)"
   386 by (simp add: formula_N_def Forall_def) 
   387 
   388 text{*These two aren't simprules because they reveal the underlying
   389 formula representation.*}
   390 lemma formula_N_0: "formula_N(0) = 0"
   391 by (simp add: formula_N_def)
   392 
   393 lemma formula_N_succ:
   394      "formula_N(succ(n)) = 
   395       ((nat*nat) + (nat*nat)) + (formula_N(n) * formula_N(n) + formula_N(n))"
   396 by (simp add: formula_N_def)
   397 
   398 lemma formula_N_imp_formula:
   399   "[| p \<in> formula_N(n); n \<in> nat |] ==> p \<in> formula"
   400 by (force simp add: formula_eq_Union formula_N_def)
   401 
   402 lemma formula_N_imp_depth_lt [rule_format]:
   403      "n \<in> nat ==> \<forall>p \<in> formula_N(n). depth(p) < n"
   404 apply (induct_tac n)  
   405 apply (auto simp add: formula_N_0 formula_N_succ 
   406                       depth_type formula_N_imp_formula Un_least_lt_iff
   407                       Member_def [symmetric] Equal_def [symmetric]
   408                       Nand_def [symmetric] Forall_def [symmetric]) 
   409 done
   410 
   411 lemma formula_imp_formula_N [rule_format]:
   412      "p \<in> formula ==> \<forall>n\<in>nat. depth(p) < n --> p \<in> formula_N(n)"
   413 apply (induct_tac p)
   414 apply (simp_all add: succ_Un_distrib Un_least_lt_iff) 
   415 apply (force elim: natE)+
   416 done
   417 
   418 lemma formula_N_imp_eq_depth:
   419       "[|n \<in> nat; p \<notin> formula_N(n); p \<in> formula_N(succ(n))|] 
   420        ==> n = depth(p)"
   421 apply (rule le_anti_sym) 
   422  prefer 2 apply (simp add: formula_N_imp_depth_lt) 
   423 apply (frule formula_N_imp_formula, simp)
   424 apply (simp add: not_lt_iff_le [symmetric]) 
   425 apply (blast intro: formula_imp_formula_N) 
   426 done
   427 
   428 
   429 
   430 lemma formula_N_mono [rule_format]:
   431   "[| m \<in> nat; n \<in> nat |] ==> m\<le>n --> formula_N(m) \<subseteq> formula_N(n)"
   432 apply (rule_tac m = m and n = n in diff_induct)
   433 apply (simp_all add: formula_N_0 formula_N_succ, blast) 
   434 done
   435 
   436 lemma formula_N_distrib:
   437   "[| m \<in> nat; n \<in> nat |] ==> formula_N(m \<union> n) = formula_N(m) \<union> formula_N(n)"
   438 apply (rule_tac i = m and j = n in Ord_linear_le, auto) 
   439 apply (simp_all add: subset_Un_iff [THEN iffD1] subset_Un_iff2 [THEN iffD1] 
   440                      le_imp_subset formula_N_mono)
   441 done
   442 
   443 constdefs
   444   is_formula_N :: "[i=>o,i,i] => o"
   445     "is_formula_N(M,n,Z) == 
   446       \<exists>zero[M]. \<exists>sn[M]. \<exists>msn[M]. 
   447        empty(M,zero) & 
   448        successor(M,n,sn) & membership(M,sn,msn) &
   449        is_wfrec(M, iterates_MH(M, is_formula_functor(M),zero), msn, n, Z)"
   450   
   451 
   452 constdefs
   453   
   454   mem_formula :: "[i=>o,i] => o"
   455     "mem_formula(M,p) == 
   456       \<exists>n[M]. \<exists>formn[M]. 
   457        finite_ordinal(M,n) & is_formula_N(M,n,formn) & p \<in> formn"
   458 
   459   is_formula :: "[i=>o,i] => o"
   460     "is_formula(M,Z) == \<forall>p[M]. p \<in> Z <-> mem_formula(M,p)"
   461 
   462 locale M_datatypes = M_wfrank +
   463  assumes list_replacement1: 
   464    "M(A) ==> iterates_replacement(M, is_list_functor(M,A), 0)"
   465   and list_replacement2: 
   466    "M(A) ==> strong_replacement(M, 
   467          \<lambda>n y. n\<in>nat & 
   468                (\<exists>sn[M]. \<exists>msn[M]. successor(M,n,sn) & membership(M,sn,msn) &
   469                is_wfrec(M, iterates_MH(M,is_list_functor(M,A), 0), 
   470                         msn, n, y)))"
   471   and formula_replacement1: 
   472    "iterates_replacement(M, is_formula_functor(M), 0)"
   473   and formula_replacement2: 
   474    "strong_replacement(M, 
   475          \<lambda>n y. n\<in>nat & 
   476                (\<exists>sn[M]. \<exists>msn[M]. successor(M,n,sn) & membership(M,sn,msn) &
   477                is_wfrec(M, iterates_MH(M,is_formula_functor(M), 0), 
   478                         msn, n, y)))"
   479   and nth_replacement:
   480    "M(l) ==> iterates_replacement(M, %l t. is_tl(M,l,t), l)"
   481         
   482 
   483 subsubsection{*Absoluteness of the List Construction*}
   484 
   485 lemma (in M_datatypes) list_replacement2': 
   486   "M(A) ==> strong_replacement(M, \<lambda>n y. n\<in>nat & y = (\<lambda>X. {0} + A * X)^n (0))"
   487 apply (insert list_replacement2 [of A]) 
   488 apply (rule strong_replacement_cong [THEN iffD1])  
   489 apply (rule conj_cong [OF iff_refl iterates_abs [of "is_list_functor(M,A)"]]) 
   490 apply (simp_all add: list_replacement1 relativize1_def) 
   491 done
   492 
   493 lemma (in M_datatypes) list_closed [intro,simp]:
   494      "M(A) ==> M(list(A))"
   495 apply (insert list_replacement1)
   496 by  (simp add: RepFun_closed2 list_eq_Union 
   497                list_replacement2' relativize1_def
   498                iterates_closed [of "is_list_functor(M,A)"])
   499 
   500 text{*WARNING: use only with @{text "dest:"} or with variables fixed!*}
   501 lemmas (in M_datatypes) list_into_M = transM [OF _ list_closed]
   502 
   503 lemma (in M_datatypes) list_N_abs [simp]:
   504      "[|M(A); n\<in>nat; M(Z)|] 
   505       ==> is_list_N(M,A,n,Z) <-> Z = list_N(A,n)"
   506 apply (insert list_replacement1)
   507 apply (simp add: is_list_N_def list_N_def relativize1_def nat_into_M
   508                  iterates_abs [of "is_list_functor(M,A)" _ "\<lambda>X. {0} + A*X"])
   509 done
   510 
   511 lemma (in M_datatypes) list_N_closed [intro,simp]:
   512      "[|M(A); n\<in>nat|] ==> M(list_N(A,n))"
   513 apply (insert list_replacement1)
   514 apply (simp add: is_list_N_def list_N_def relativize1_def nat_into_M
   515                  iterates_closed [of "is_list_functor(M,A)"])
   516 done
   517 
   518 lemma (in M_datatypes) mem_list_abs [simp]:
   519      "M(A) ==> mem_list(M,A,l) <-> l \<in> list(A)"
   520 apply (insert list_replacement1)
   521 apply (simp add: mem_list_def list_N_def relativize1_def list_eq_Union
   522                  iterates_closed [of "is_list_functor(M,A)"]) 
   523 done
   524 
   525 lemma (in M_datatypes) list_abs [simp]:
   526      "[|M(A); M(Z)|] ==> is_list(M,A,Z) <-> Z = list(A)"
   527 apply (simp add: is_list_def, safe)
   528 apply (rule M_equalityI, simp_all)
   529 done
   530 
   531 subsubsection{*Absoluteness of Formulas*}
   532 
   533 lemma (in M_datatypes) formula_replacement2': 
   534   "strong_replacement(M, \<lambda>n y. n\<in>nat & y = (\<lambda>X. ((nat*nat) + (nat*nat)) + (X*X + X))^n (0))"
   535 apply (insert formula_replacement2) 
   536 apply (rule strong_replacement_cong [THEN iffD1])  
   537 apply (rule conj_cong [OF iff_refl iterates_abs [of "is_formula_functor(M)"]]) 
   538 apply (simp_all add: formula_replacement1 relativize1_def) 
   539 done
   540 
   541 lemma (in M_datatypes) formula_closed [intro,simp]:
   542      "M(formula)"
   543 apply (insert formula_replacement1)
   544 apply  (simp add: RepFun_closed2 formula_eq_Union 
   545                   formula_replacement2' relativize1_def
   546                   iterates_closed [of "is_formula_functor(M)"])
   547 done
   548 
   549 lemmas (in M_datatypes) formula_into_M = transM [OF _ formula_closed]
   550 
   551 lemma (in M_datatypes) formula_N_abs [simp]:
   552      "[|n\<in>nat; M(Z)|] 
   553       ==> is_formula_N(M,n,Z) <-> Z = formula_N(n)"
   554 apply (insert formula_replacement1)
   555 apply (simp add: is_formula_N_def formula_N_def relativize1_def nat_into_M
   556                  iterates_abs [of "is_formula_functor(M)" _ 
   557                                   "\<lambda>X. ((nat*nat) + (nat*nat)) + (X*X + X)"])
   558 done
   559 
   560 lemma (in M_datatypes) formula_N_closed [intro,simp]:
   561      "n\<in>nat ==> M(formula_N(n))"
   562 apply (insert formula_replacement1)
   563 apply (simp add: is_formula_N_def formula_N_def relativize1_def nat_into_M
   564                  iterates_closed [of "is_formula_functor(M)"])
   565 done
   566 
   567 lemma (in M_datatypes) mem_formula_abs [simp]:
   568      "mem_formula(M,l) <-> l \<in> formula"
   569 apply (insert formula_replacement1)
   570 apply (simp add: mem_formula_def relativize1_def formula_eq_Union formula_N_def
   571                  iterates_closed [of "is_formula_functor(M)"]) 
   572 done
   573 
   574 lemma (in M_datatypes) formula_abs [simp]:
   575      "[|M(Z)|] ==> is_formula(M,Z) <-> Z = formula"
   576 apply (simp add: is_formula_def, safe)
   577 apply (rule M_equalityI, simp_all)
   578 done
   579 
   580 
   581 subsection{*Absoluteness for Some List Operators*}
   582 
   583 subsection{*Absoluteness for @{text \<epsilon>}-Closure: the @{term eclose} Operator*}
   584 
   585 text{*Re-expresses eclose using "iterates"*}
   586 lemma eclose_eq_Union:
   587      "eclose(A) = (\<Union>n\<in>nat. Union^n (A))"
   588 apply (simp add: eclose_def) 
   589 apply (rule UN_cong) 
   590 apply (rule refl)
   591 apply (induct_tac n)
   592 apply (simp add: nat_rec_0)  
   593 apply (simp add: nat_rec_succ) 
   594 done
   595 
   596 constdefs
   597   is_eclose_n :: "[i=>o,i,i,i] => o"
   598     "is_eclose_n(M,A,n,Z) == 
   599       \<exists>sn[M]. \<exists>msn[M]. 
   600        successor(M,n,sn) & membership(M,sn,msn) &
   601        is_wfrec(M, iterates_MH(M, big_union(M), A), msn, n, Z)"
   602   
   603   mem_eclose :: "[i=>o,i,i] => o"
   604     "mem_eclose(M,A,l) == 
   605       \<exists>n[M]. \<exists>eclosen[M]. 
   606        finite_ordinal(M,n) & is_eclose_n(M,A,n,eclosen) & l \<in> eclosen"
   607 
   608   is_eclose :: "[i=>o,i,i] => o"
   609     "is_eclose(M,A,Z) == \<forall>u[M]. u \<in> Z <-> mem_eclose(M,A,u)"
   610 
   611 
   612 locale M_eclose = M_datatypes +
   613  assumes eclose_replacement1: 
   614    "M(A) ==> iterates_replacement(M, big_union(M), A)"
   615   and eclose_replacement2: 
   616    "M(A) ==> strong_replacement(M, 
   617          \<lambda>n y. n\<in>nat & 
   618                (\<exists>sn[M]. \<exists>msn[M]. successor(M,n,sn) & membership(M,sn,msn) &
   619                is_wfrec(M, iterates_MH(M,big_union(M), A), 
   620                         msn, n, y)))"
   621 
   622 lemma (in M_eclose) eclose_replacement2': 
   623   "M(A) ==> strong_replacement(M, \<lambda>n y. n\<in>nat & y = Union^n (A))"
   624 apply (insert eclose_replacement2 [of A]) 
   625 apply (rule strong_replacement_cong [THEN iffD1])  
   626 apply (rule conj_cong [OF iff_refl iterates_abs [of "big_union(M)"]]) 
   627 apply (simp_all add: eclose_replacement1 relativize1_def) 
   628 done
   629 
   630 lemma (in M_eclose) eclose_closed [intro,simp]:
   631      "M(A) ==> M(eclose(A))"
   632 apply (insert eclose_replacement1)
   633 by  (simp add: RepFun_closed2 eclose_eq_Union 
   634                eclose_replacement2' relativize1_def
   635                iterates_closed [of "big_union(M)"])
   636 
   637 lemma (in M_eclose) is_eclose_n_abs [simp]:
   638      "[|M(A); n\<in>nat; M(Z)|] ==> is_eclose_n(M,A,n,Z) <-> Z = Union^n (A)"
   639 apply (insert eclose_replacement1)
   640 apply (simp add: is_eclose_n_def relativize1_def nat_into_M
   641                  iterates_abs [of "big_union(M)" _ "Union"])
   642 done
   643 
   644 lemma (in M_eclose) mem_eclose_abs [simp]:
   645      "M(A) ==> mem_eclose(M,A,l) <-> l \<in> eclose(A)"
   646 apply (insert eclose_replacement1)
   647 apply (simp add: mem_eclose_def relativize1_def eclose_eq_Union
   648                  iterates_closed [of "big_union(M)"]) 
   649 done
   650 
   651 lemma (in M_eclose) eclose_abs [simp]:
   652      "[|M(A); M(Z)|] ==> is_eclose(M,A,Z) <-> Z = eclose(A)"
   653 apply (simp add: is_eclose_def, safe)
   654 apply (rule M_equalityI, simp_all)
   655 done
   656 
   657 
   658 
   659 
   660 subsection {*Absoluteness for @{term transrec}*}
   661 
   662 
   663 text{* @{term "transrec(a,H) \<equiv> wfrec(Memrel(eclose({a})), a, H)"} *}
   664 constdefs
   665 
   666   is_transrec :: "[i=>o, [i,i,i]=>o, i, i] => o"
   667    "is_transrec(M,MH,a,z) == 
   668       \<exists>sa[M]. \<exists>esa[M]. \<exists>mesa[M]. 
   669        upair(M,a,a,sa) & is_eclose(M,sa,esa) & membership(M,esa,mesa) &
   670        is_wfrec(M,MH,mesa,a,z)"
   671 
   672   transrec_replacement :: "[i=>o, [i,i,i]=>o, i] => o"
   673    "transrec_replacement(M,MH,a) ==
   674       \<exists>sa[M]. \<exists>esa[M]. \<exists>mesa[M]. 
   675        upair(M,a,a,sa) & is_eclose(M,sa,esa) & membership(M,esa,mesa) &
   676        wfrec_replacement(M,MH,mesa)"
   677 
   678 text{*The condition @{term "Ord(i)"} lets us use the simpler 
   679   @{text "trans_wfrec_abs"} rather than @{text "trans_wfrec_abs"},
   680   which I haven't even proved yet. *}
   681 theorem (in M_eclose) transrec_abs:
   682   "[|transrec_replacement(M,MH,i);  relativize2(M,MH,H);
   683      Ord(i);  M(i);  M(z);
   684      \<forall>x[M]. \<forall>g[M]. function(g) --> M(H(x,g))|] 
   685    ==> is_transrec(M,MH,i,z) <-> z = transrec(i,H)" 
   686 apply (rotate_tac 2) 
   687 apply (simp add: trans_wfrec_abs transrec_replacement_def is_transrec_def
   688        transrec_def eclose_sing_Ord_eq wf_Memrel trans_Memrel relation_Memrel)
   689 done
   690 
   691 
   692 theorem (in M_eclose) transrec_closed:
   693      "[|transrec_replacement(M,MH,i);  relativize2(M,MH,H);
   694 	Ord(i);  M(i);  
   695 	\<forall>x[M]. \<forall>g[M]. function(g) --> M(H(x,g))|] 
   696       ==> M(transrec(i,H))"
   697 apply (rotate_tac 2) 
   698 apply (simp add: trans_wfrec_closed transrec_replacement_def is_transrec_def
   699        transrec_def eclose_sing_Ord_eq wf_Memrel trans_Memrel relation_Memrel)
   700 done
   701 
   702 text{*Helps to prove instances of @{term transrec_replacement}*}
   703 lemma (in M_eclose) transrec_replacementI: 
   704    "[|M(a);
   705     strong_replacement (M, 
   706                   \<lambda>x z. \<exists>y[M]. pair(M, x, y, z) \<and> is_wfrec(M,MH,Memrel(eclose({a})),x,y))|]
   707     ==> transrec_replacement(M,MH,a)"
   708 by (simp add: transrec_replacement_def wfrec_replacement_def) 
   709 
   710 
   711 subsection{*Absoluteness for the List Operator @{term length}*}
   712 constdefs
   713 
   714   is_length :: "[i=>o,i,i,i] => o"
   715     "is_length(M,A,l,n) == 
   716        \<exists>sn[M]. \<exists>list_n[M]. \<exists>list_sn[M]. 
   717         is_list_N(M,A,n,list_n) & l \<notin> list_n &
   718         successor(M,n,sn) & is_list_N(M,A,sn,list_sn) & l \<in> list_sn"
   719 
   720 
   721 lemma (in M_datatypes) length_abs [simp]:
   722      "[|M(A); l \<in> list(A); n \<in> nat|] ==> is_length(M,A,l,n) <-> n = length(l)"
   723 apply (subgoal_tac "M(l) & M(n)")
   724  prefer 2 apply (blast dest: transM)  
   725 apply (simp add: is_length_def)
   726 apply (blast intro: list_imp_list_N nat_into_Ord list_N_imp_eq_length
   727              dest: list_N_imp_length_lt)
   728 done
   729 
   730 text{*Proof is trivial since @{term length} returns natural numbers.*}
   731 lemma (in M_triv_axioms) length_closed [intro,simp]:
   732      "l \<in> list(A) ==> M(length(l))"
   733 by (simp add: nat_into_M) 
   734 
   735 
   736 subsection {*Absoluteness for @{term nth}*}
   737 
   738 lemma nth_eq_hd_iterates_tl [rule_format]:
   739      "xs \<in> list(A) ==> \<forall>n \<in> nat. nth(n,xs) = hd' (tl'^n (xs))"
   740 apply (induct_tac xs) 
   741 apply (simp add: iterates_tl_Nil hd'_Nil, clarify) 
   742 apply (erule natE)
   743 apply (simp add: hd'_Cons) 
   744 apply (simp add: tl'_Cons iterates_commute) 
   745 done
   746 
   747 lemma (in M_axioms) iterates_tl'_closed:
   748      "[|n \<in> nat; M(x)|] ==> M(tl'^n (x))"
   749 apply (induct_tac n, simp) 
   750 apply (simp add: tl'_Cons tl'_closed) 
   751 done
   752 
   753 text{*Immediate by type-checking*}
   754 lemma (in M_datatypes) nth_closed [intro,simp]:
   755      "[|xs \<in> list(A); n \<in> nat; M(A)|] ==> M(nth(n,xs))" 
   756 apply (case_tac "n < length(xs)")
   757  apply (blast intro: nth_type transM)
   758 apply (simp add: not_lt_iff_le nth_eq_0)
   759 done
   760 
   761 constdefs
   762   is_nth :: "[i=>o,i,i,i] => o"
   763     "is_nth(M,n,l,Z) == 
   764       \<exists>X[M]. \<exists>sn[M]. \<exists>msn[M]. 
   765        successor(M,n,sn) & membership(M,sn,msn) &
   766        is_wfrec(M, iterates_MH(M, is_tl(M), l), msn, n, X) &
   767        is_hd(M,X,Z)"
   768  
   769 lemma (in M_datatypes) nth_abs [simp]:
   770      "[|M(A); n \<in> nat; l \<in> list(A); M(Z)|] 
   771       ==> is_nth(M,n,l,Z) <-> Z = nth(n,l)"
   772 apply (subgoal_tac "M(l)") 
   773  prefer 2 apply (blast intro: transM)
   774 apply (simp add: is_nth_def nth_eq_hd_iterates_tl nat_into_M
   775                  tl'_closed iterates_tl'_closed 
   776                  iterates_abs [OF _ relativize1_tl] nth_replacement)
   777 done
   778 
   779 
   780 subsection{*Relativization and Absoluteness for the @{term formula} Constructors*}
   781 
   782 constdefs
   783   is_Member :: "[i=>o,i,i,i] => o"
   784      --{* because @{term "Member(x,y) \<equiv> Inl(Inl(\<langle>x,y\<rangle>))"}*}
   785     "is_Member(M,x,y,Z) ==
   786 	\<exists>p[M]. \<exists>u[M]. pair(M,x,y,p) & is_Inl(M,p,u) & is_Inl(M,u,Z)"
   787 
   788 lemma (in M_triv_axioms) Member_abs [simp]:
   789      "[|M(x); M(y); M(Z)|] ==> is_Member(M,x,y,Z) <-> (Z = Member(x,y))"
   790 by (simp add: is_Member_def Member_def)
   791 
   792 lemma (in M_triv_axioms) Member_in_M_iff [iff]:
   793      "M(Member(x,y)) <-> M(x) & M(y)"
   794 by (simp add: Member_def) 
   795 
   796 constdefs
   797   is_Equal :: "[i=>o,i,i,i] => o"
   798      --{* because @{term "Equal(x,y) \<equiv> Inl(Inr(\<langle>x,y\<rangle>))"}*}
   799     "is_Equal(M,x,y,Z) ==
   800 	\<exists>p[M]. \<exists>u[M]. pair(M,x,y,p) & is_Inr(M,p,u) & is_Inl(M,u,Z)"
   801 
   802 lemma (in M_triv_axioms) Equal_abs [simp]:
   803      "[|M(x); M(y); M(Z)|] ==> is_Equal(M,x,y,Z) <-> (Z = Equal(x,y))"
   804 by (simp add: is_Equal_def Equal_def)
   805 
   806 lemma (in M_triv_axioms) Equal_in_M_iff [iff]: "M(Equal(x,y)) <-> M(x) & M(y)"
   807 by (simp add: Equal_def) 
   808 
   809 constdefs
   810   is_Nand :: "[i=>o,i,i,i] => o"
   811      --{* because @{term "Nand(x,y) \<equiv> Inr(Inl(\<langle>x,y\<rangle>))"}*}
   812     "is_Nand(M,x,y,Z) ==
   813 	\<exists>p[M]. \<exists>u[M]. pair(M,x,y,p) & is_Inl(M,p,u) & is_Inr(M,u,Z)"
   814 
   815 lemma (in M_triv_axioms) Nand_abs [simp]:
   816      "[|M(x); M(y); M(Z)|] ==> is_Nand(M,x,y,Z) <-> (Z = Nand(x,y))"
   817 by (simp add: is_Nand_def Nand_def)
   818 
   819 lemma (in M_triv_axioms) Nand_in_M_iff [iff]: "M(Nand(x,y)) <-> M(x) & M(y)"
   820 by (simp add: Nand_def) 
   821 
   822 constdefs
   823   is_Forall :: "[i=>o,i,i] => o"
   824      --{* because @{term "Forall(x) \<equiv> Inr(Inr(p))"}*}
   825     "is_Forall(M,p,Z) == \<exists>u[M]. is_Inr(M,p,u) & is_Inr(M,u,Z)"
   826 
   827 lemma (in M_triv_axioms) Forall_abs [simp]:
   828      "[|M(x); M(Z)|] ==> is_Forall(M,x,Z) <-> (Z = Forall(x))"
   829 by (simp add: is_Forall_def Forall_def)
   830 
   831 lemma (in M_triv_axioms) Forall_in_M_iff [iff]: "M(Forall(x)) <-> M(x)"
   832 by (simp add: Forall_def)
   833 
   834 
   835 subsection {*Absoluteness for @{term formula_rec}*}
   836 
   837 subsubsection{*@{term is_formula_case}: relativization of @{term formula_case}*}
   838 
   839 constdefs
   840 
   841  is_formula_case :: 
   842     "[i=>o, [i,i,i]=>o, [i,i,i]=>o, [i,i,i]=>o, [i,i]=>o, i, i] => o"
   843   --{*no constraint on non-formulas*}
   844   "is_formula_case(M, is_a, is_b, is_c, is_d, p, z) == 
   845       (\<forall>x[M]. \<forall>y[M]. finite_ordinal(M,x) --> finite_ordinal(M,y) --> 
   846                       is_Member(M,x,y,p) --> is_a(x,y,z)) &
   847       (\<forall>x[M]. \<forall>y[M]. finite_ordinal(M,x) --> finite_ordinal(M,y) --> 
   848                       is_Equal(M,x,y,p) --> is_b(x,y,z)) &
   849       (\<forall>x[M]. \<forall>y[M]. mem_formula(M,x) --> mem_formula(M,y) --> 
   850                      is_Nand(M,x,y,p) --> is_c(x,y,z)) &
   851       (\<forall>x[M]. mem_formula(M,x) --> is_Forall(M,x,p) --> is_d(x,z))"
   852 
   853 lemma (in M_datatypes) formula_case_abs [simp]: 
   854      "[| Relativize2(M,nat,nat,is_a,a); Relativize2(M,nat,nat,is_b,b); 
   855          Relativize2(M,formula,formula,is_c,c); Relativize1(M,formula,is_d,d); 
   856          p \<in> formula; M(z) |] 
   857       ==> is_formula_case(M,is_a,is_b,is_c,is_d,p,z) <-> 
   858           z = formula_case(a,b,c,d,p)"
   859 apply (simp add: formula_into_M is_formula_case_def)
   860 apply (erule formula.cases) 
   861    apply (simp_all add: Relativize1_def Relativize2_def) 
   862 done
   863 
   864 
   865 subsubsection{*@{term quasiformula}: For Case-Splitting with @{term formula_case'}*}
   866 
   867 constdefs
   868 
   869   quasiformula :: "i => o"
   870     "quasiformula(p) == 
   871 	(\<exists>x y. p = Member(x,y)) |
   872 	(\<exists>x y. p = Equal(x,y)) |
   873 	(\<exists>x y. p = Nand(x,y)) |
   874 	(\<exists>x. p = Forall(x))"
   875 
   876   is_quasiformula :: "[i=>o,i] => o"
   877     "is_quasiformula(M,p) == 
   878 	(\<exists>x[M]. \<exists>y[M]. is_Member(M,x,y,p)) |
   879 	(\<exists>x[M]. \<exists>y[M]. is_Equal(M,x,y,p)) |
   880 	(\<exists>x[M]. \<exists>y[M]. is_Nand(M,x,y,p)) |
   881 	(\<exists>x[M]. is_Forall(M,x,p))"
   882 
   883 lemma [iff]: "quasiformula(Member(x,y))"
   884 by (simp add: quasiformula_def)
   885 
   886 lemma [iff]: "quasiformula(Equal(x,y))"
   887 by (simp add: quasiformula_def)
   888 
   889 lemma [iff]: "quasiformula(Nand(x,y))"
   890 by (simp add: quasiformula_def)
   891 
   892 lemma [iff]: "quasiformula(Forall(x))"
   893 by (simp add: quasiformula_def)
   894 
   895 lemma formula_imp_quasiformula: "p \<in> formula ==> quasiformula(p)"
   896 by (erule formula.cases, simp_all)
   897 
   898 lemma (in M_triv_axioms) quasiformula_abs [simp]: 
   899      "M(z) ==> is_quasiformula(M,z) <-> quasiformula(z)"
   900 by (auto simp add: is_quasiformula_def quasiformula_def)
   901 
   902 constdefs
   903 
   904   formula_case' :: "[[i,i]=>i, [i,i]=>i, [i,i]=>i, i=>i, i] => i"
   905     --{*A version of @{term formula_case} that's always defined.*}
   906     "formula_case'(a,b,c,d,p) == 
   907        if quasiformula(p) then formula_case(a,b,c,d,p) else 0"  
   908 
   909   is_formula_case' :: 
   910       "[i=>o, [i,i,i]=>o, [i,i,i]=>o, [i,i,i]=>o, [i,i]=>o, i, i] => o"
   911     --{*Returns 0 for non-formulas*}
   912     "is_formula_case'(M, is_a, is_b, is_c, is_d, p, z) == 
   913 	(\<forall>x[M]. \<forall>y[M]. is_Member(M,x,y,p) --> is_a(x,y,z)) &
   914 	(\<forall>x[M]. \<forall>y[M]. is_Equal(M,x,y,p) --> is_b(x,y,z)) &
   915 	(\<forall>x[M]. \<forall>y[M]. is_Nand(M,x,y,p) --> is_c(x,y,z)) &
   916 	(\<forall>x[M]. is_Forall(M,x,p) --> is_d(x,z)) &
   917         (is_quasiformula(M,p) | empty(M,z))"
   918 
   919 subsubsection{*@{term formula_case'}, the Modified Version of @{term formula_case}*}
   920 
   921 lemma formula_case'_Member [simp]:
   922      "formula_case'(a,b,c,d,Member(x,y)) = a(x,y)"
   923 by (simp add: formula_case'_def)
   924 
   925 lemma formula_case'_Equal [simp]:
   926      "formula_case'(a,b,c,d,Equal(x,y)) = b(x,y)"
   927 by (simp add: formula_case'_def)
   928 
   929 lemma formula_case'_Nand [simp]:
   930      "formula_case'(a,b,c,d,Nand(x,y)) = c(x,y)"
   931 by (simp add: formula_case'_def)
   932 
   933 lemma formula_case'_Forall [simp]:
   934      "formula_case'(a,b,c,d,Forall(x)) = d(x)"
   935 by (simp add: formula_case'_def)
   936 
   937 lemma non_formula_case: "~ quasiformula(x) ==> formula_case'(a,b,c,d,x) = 0" 
   938 by (simp add: quasiformula_def formula_case'_def) 
   939 
   940 lemma formula_case'_eq_formula_case [simp]:
   941      "p \<in> formula ==>formula_case'(a,b,c,d,p) = formula_case(a,b,c,d,p)"
   942 by (erule formula.cases, simp_all)
   943 
   944 lemma (in M_axioms) formula_case'_closed [intro,simp]:
   945   "[|M(p); \<forall>x[M]. \<forall>y[M]. M(a(x,y)); 
   946            \<forall>x[M]. \<forall>y[M]. M(b(x,y)); 
   947            \<forall>x[M]. \<forall>y[M]. M(c(x,y)); 
   948            \<forall>x[M]. M(d(x))|] ==> M(formula_case'(a,b,c,d,p))"
   949 apply (case_tac "quasiformula(p)") 
   950  apply (simp add: quasiformula_def, force) 
   951 apply (simp add: non_formula_case) 
   952 done
   953 
   954 text{*Compared with @{text formula_case_closed'}, the premise on @{term p} is
   955       stronger while the other premises are weaker, incorporating typing 
   956       information.*}
   957 lemma (in M_datatypes) formula_case_closed [intro,simp]:
   958   "[|p \<in> formula; 
   959      \<forall>x[M]. \<forall>y[M]. x\<in>nat --> y\<in>nat --> M(a(x,y)); 
   960      \<forall>x[M]. \<forall>y[M]. x\<in>nat --> y\<in>nat --> M(b(x,y)); 
   961      \<forall>x[M]. \<forall>y[M]. x\<in>formula --> y\<in>formula --> M(c(x,y)); 
   962      \<forall>x[M]. x\<in>formula --> M(d(x))|] ==> M(formula_case(a,b,c,d,p))"
   963 by (erule formula.cases, simp_all) 
   964 
   965 lemma (in M_triv_axioms) formula_case'_abs [simp]: 
   966      "[| relativize2(M,is_a,a); relativize2(M,is_b,b); 
   967          relativize2(M,is_c,c); relativize1(M,is_d,d); M(p); M(z) |] 
   968       ==> is_formula_case'(M,is_a,is_b,is_c,is_d,p,z) <-> 
   969           z = formula_case'(a,b,c,d,p)"
   970 apply (case_tac "quasiformula(p)") 
   971  prefer 2 
   972  apply (simp add: is_formula_case'_def non_formula_case) 
   973  apply (force simp add: quasiformula_def) 
   974 apply (simp add: quasiformula_def is_formula_case'_def)
   975 apply (elim disjE exE) 
   976  apply (simp_all add: relativize1_def relativize2_def) 
   977 done
   978 
   979 
   980 text{*Express @{term formula_rec} without using @{term rank} or @{term Vset},
   981 neither of which is absolute.*}
   982 lemma (in M_triv_axioms) formula_rec_eq:
   983   "p \<in> formula ==>
   984    formula_rec(a,b,c,d,p) = 
   985    transrec (succ(depth(p)),
   986       \<lambda>x h. Lambda (formula,
   987              formula_case' (a, b,
   988                 \<lambda>u v. c(u, v, h ` succ(depth(u)) ` u, 
   989                               h ` succ(depth(v)) ` v),
   990                 \<lambda>u. d(u, h ` succ(depth(u)) ` u)))) 
   991    ` p"
   992 apply (induct_tac p)
   993    txt{*Base case for @{term Member}*}
   994    apply (subst transrec, simp add: formula.intros) 
   995   txt{*Base case for @{term Equal}*}
   996   apply (subst transrec, simp add: formula.intros)
   997  txt{*Inductive step for @{term Nand}*}
   998  apply (subst transrec) 
   999  apply (simp add: succ_Un_distrib formula.intros)
  1000 txt{*Inductive step for @{term Forall}*}
  1001 apply (subst transrec) 
  1002 apply (simp add: formula_imp_formula_N formula.intros) 
  1003 done
  1004 
  1005 
  1006 subsection{*Absoluteness for the Formula Operator @{term depth}*}
  1007 constdefs
  1008 
  1009   is_depth :: "[i=>o,i,i] => o"
  1010     "is_depth(M,p,n) == 
  1011        \<exists>sn[M]. \<exists>formula_n[M]. \<exists>formula_sn[M]. 
  1012         is_formula_N(M,n,formula_n) & p \<notin> formula_n &
  1013         successor(M,n,sn) & is_formula_N(M,sn,formula_sn) & p \<in> formula_sn"
  1014 
  1015 
  1016 lemma (in M_datatypes) depth_abs [simp]:
  1017      "[|p \<in> formula; n \<in> nat|] ==> is_depth(M,p,n) <-> n = depth(p)"
  1018 apply (subgoal_tac "M(p) & M(n)")
  1019  prefer 2 apply (blast dest: transM)  
  1020 apply (simp add: is_depth_def)
  1021 apply (blast intro: formula_imp_formula_N nat_into_Ord formula_N_imp_eq_depth
  1022              dest: formula_N_imp_depth_lt)
  1023 done
  1024 
  1025 text{*Proof is trivial since @{term depth} returns natural numbers.*}
  1026 lemma (in M_triv_axioms) depth_closed [intro,simp]:
  1027      "p \<in> formula ==> M(depth(p))"
  1028 by (simp add: nat_into_M) 
  1029 
  1030 
  1031 end