src/ZF/Constructible/Datatype_absolute.thy
 author paulson Tue Oct 01 13:26:10 2002 +0200 (2002-10-01) changeset 13615 449a70d88b38 parent 13564 1500a2e48d44 child 13634 99a593b49b04 permissions -rw-r--r--
Numerous cosmetic changes, prompted by the new simplifier
```     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_basic) 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_basic) 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_basic) 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_basic) 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_trivial) 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 by (simp add: trans_wfrec_abs transrec_replacement_def is_transrec_def
```
```   687        transrec_def eclose_sing_Ord_eq wf_Memrel trans_Memrel relation_Memrel)
```
```   688
```
```   689
```
```   690 theorem (in M_eclose) transrec_closed:
```
```   691      "[|transrec_replacement(M,MH,i);  relativize2(M,MH,H);
```
```   692 	Ord(i);  M(i);
```
```   693 	\<forall>x[M]. \<forall>g[M]. function(g) --> M(H(x,g))|]
```
```   694       ==> M(transrec(i,H))"
```
```   695 by (simp add: trans_wfrec_closed transrec_replacement_def is_transrec_def
```
```   696         transrec_def eclose_sing_Ord_eq wf_Memrel trans_Memrel relation_Memrel)
```
```   697
```
```   698
```
```   699 text{*Helps to prove instances of @{term transrec_replacement}*}
```
```   700 lemma (in M_eclose) transrec_replacementI:
```
```   701    "[|M(a);
```
```   702     strong_replacement (M,
```
```   703                   \<lambda>x z. \<exists>y[M]. pair(M, x, y, z) \<and> is_wfrec(M,MH,Memrel(eclose({a})),x,y))|]
```
```   704     ==> transrec_replacement(M,MH,a)"
```
```   705 by (simp add: transrec_replacement_def wfrec_replacement_def)
```
```   706
```
```   707
```
```   708 subsection{*Absoluteness for the List Operator @{term length}*}
```
```   709 constdefs
```
```   710
```
```   711   is_length :: "[i=>o,i,i,i] => o"
```
```   712     "is_length(M,A,l,n) ==
```
```   713        \<exists>sn[M]. \<exists>list_n[M]. \<exists>list_sn[M].
```
```   714         is_list_N(M,A,n,list_n) & l \<notin> list_n &
```
```   715         successor(M,n,sn) & is_list_N(M,A,sn,list_sn) & l \<in> list_sn"
```
```   716
```
```   717
```
```   718 lemma (in M_datatypes) length_abs [simp]:
```
```   719      "[|M(A); l \<in> list(A); n \<in> nat|] ==> is_length(M,A,l,n) <-> n = length(l)"
```
```   720 apply (subgoal_tac "M(l) & M(n)")
```
```   721  prefer 2 apply (blast dest: transM)
```
```   722 apply (simp add: is_length_def)
```
```   723 apply (blast intro: list_imp_list_N nat_into_Ord list_N_imp_eq_length
```
```   724              dest: list_N_imp_length_lt)
```
```   725 done
```
```   726
```
```   727 text{*Proof is trivial since @{term length} returns natural numbers.*}
```
```   728 lemma (in M_trivial) length_closed [intro,simp]:
```
```   729      "l \<in> list(A) ==> M(length(l))"
```
```   730 by (simp add: nat_into_M)
```
```   731
```
```   732
```
```   733 subsection {*Absoluteness for @{term nth}*}
```
```   734
```
```   735 lemma nth_eq_hd_iterates_tl [rule_format]:
```
```   736      "xs \<in> list(A) ==> \<forall>n \<in> nat. nth(n,xs) = hd' (tl'^n (xs))"
```
```   737 apply (induct_tac xs)
```
```   738 apply (simp add: iterates_tl_Nil hd'_Nil, clarify)
```
```   739 apply (erule natE)
```
```   740 apply (simp add: hd'_Cons)
```
```   741 apply (simp add: tl'_Cons iterates_commute)
```
```   742 done
```
```   743
```
```   744 lemma (in M_basic) iterates_tl'_closed:
```
```   745      "[|n \<in> nat; M(x)|] ==> M(tl'^n (x))"
```
```   746 apply (induct_tac n, simp)
```
```   747 apply (simp add: tl'_Cons tl'_closed)
```
```   748 done
```
```   749
```
```   750 text{*Immediate by type-checking*}
```
```   751 lemma (in M_datatypes) nth_closed [intro,simp]:
```
```   752      "[|xs \<in> list(A); n \<in> nat; M(A)|] ==> M(nth(n,xs))"
```
```   753 apply (case_tac "n < length(xs)")
```
```   754  apply (blast intro: nth_type transM)
```
```   755 apply (simp add: not_lt_iff_le nth_eq_0)
```
```   756 done
```
```   757
```
```   758 constdefs
```
```   759   is_nth :: "[i=>o,i,i,i] => o"
```
```   760     "is_nth(M,n,l,Z) ==
```
```   761       \<exists>X[M]. \<exists>sn[M]. \<exists>msn[M].
```
```   762        successor(M,n,sn) & membership(M,sn,msn) &
```
```   763        is_wfrec(M, iterates_MH(M, is_tl(M), l), msn, n, X) &
```
```   764        is_hd(M,X,Z)"
```
```   765
```
```   766 lemma (in M_datatypes) nth_abs [simp]:
```
```   767      "[|M(A); n \<in> nat; l \<in> list(A); M(Z)|]
```
```   768       ==> is_nth(M,n,l,Z) <-> Z = nth(n,l)"
```
```   769 apply (subgoal_tac "M(l)")
```
```   770  prefer 2 apply (blast intro: transM)
```
```   771 apply (simp add: is_nth_def nth_eq_hd_iterates_tl nat_into_M
```
```   772                  tl'_closed iterates_tl'_closed
```
```   773                  iterates_abs [OF _ relativize1_tl] nth_replacement)
```
```   774 done
```
```   775
```
```   776
```
```   777 subsection{*Relativization and Absoluteness for the @{term formula} Constructors*}
```
```   778
```
```   779 constdefs
```
```   780   is_Member :: "[i=>o,i,i,i] => o"
```
```   781      --{* because @{term "Member(x,y) \<equiv> Inl(Inl(\<langle>x,y\<rangle>))"}*}
```
```   782     "is_Member(M,x,y,Z) ==
```
```   783 	\<exists>p[M]. \<exists>u[M]. pair(M,x,y,p) & is_Inl(M,p,u) & is_Inl(M,u,Z)"
```
```   784
```
```   785 lemma (in M_trivial) Member_abs [simp]:
```
```   786      "[|M(x); M(y); M(Z)|] ==> is_Member(M,x,y,Z) <-> (Z = Member(x,y))"
```
```   787 by (simp add: is_Member_def Member_def)
```
```   788
```
```   789 lemma (in M_trivial) Member_in_M_iff [iff]:
```
```   790      "M(Member(x,y)) <-> M(x) & M(y)"
```
```   791 by (simp add: Member_def)
```
```   792
```
```   793 constdefs
```
```   794   is_Equal :: "[i=>o,i,i,i] => o"
```
```   795      --{* because @{term "Equal(x,y) \<equiv> Inl(Inr(\<langle>x,y\<rangle>))"}*}
```
```   796     "is_Equal(M,x,y,Z) ==
```
```   797 	\<exists>p[M]. \<exists>u[M]. pair(M,x,y,p) & is_Inr(M,p,u) & is_Inl(M,u,Z)"
```
```   798
```
```   799 lemma (in M_trivial) Equal_abs [simp]:
```
```   800      "[|M(x); M(y); M(Z)|] ==> is_Equal(M,x,y,Z) <-> (Z = Equal(x,y))"
```
```   801 by (simp add: is_Equal_def Equal_def)
```
```   802
```
```   803 lemma (in M_trivial) Equal_in_M_iff [iff]: "M(Equal(x,y)) <-> M(x) & M(y)"
```
```   804 by (simp add: Equal_def)
```
```   805
```
```   806 constdefs
```
```   807   is_Nand :: "[i=>o,i,i,i] => o"
```
```   808      --{* because @{term "Nand(x,y) \<equiv> Inr(Inl(\<langle>x,y\<rangle>))"}*}
```
```   809     "is_Nand(M,x,y,Z) ==
```
```   810 	\<exists>p[M]. \<exists>u[M]. pair(M,x,y,p) & is_Inl(M,p,u) & is_Inr(M,u,Z)"
```
```   811
```
```   812 lemma (in M_trivial) Nand_abs [simp]:
```
```   813      "[|M(x); M(y); M(Z)|] ==> is_Nand(M,x,y,Z) <-> (Z = Nand(x,y))"
```
```   814 by (simp add: is_Nand_def Nand_def)
```
```   815
```
```   816 lemma (in M_trivial) Nand_in_M_iff [iff]: "M(Nand(x,y)) <-> M(x) & M(y)"
```
```   817 by (simp add: Nand_def)
```
```   818
```
```   819 constdefs
```
```   820   is_Forall :: "[i=>o,i,i] => o"
```
```   821      --{* because @{term "Forall(x) \<equiv> Inr(Inr(p))"}*}
```
```   822     "is_Forall(M,p,Z) == \<exists>u[M]. is_Inr(M,p,u) & is_Inr(M,u,Z)"
```
```   823
```
```   824 lemma (in M_trivial) Forall_abs [simp]:
```
```   825      "[|M(x); M(Z)|] ==> is_Forall(M,x,Z) <-> (Z = Forall(x))"
```
```   826 by (simp add: is_Forall_def Forall_def)
```
```   827
```
```   828 lemma (in M_trivial) Forall_in_M_iff [iff]: "M(Forall(x)) <-> M(x)"
```
```   829 by (simp add: Forall_def)
```
```   830
```
```   831
```
```   832 subsection {*Absoluteness for @{term formula_rec}*}
```
```   833
```
```   834 subsubsection{*@{term is_formula_case}: relativization of @{term formula_case}*}
```
```   835
```
```   836 constdefs
```
```   837
```
```   838  is_formula_case ::
```
```   839     "[i=>o, [i,i,i]=>o, [i,i,i]=>o, [i,i,i]=>o, [i,i]=>o, i, i] => o"
```
```   840   --{*no constraint on non-formulas*}
```
```   841   "is_formula_case(M, is_a, is_b, is_c, is_d, p, z) ==
```
```   842       (\<forall>x[M]. \<forall>y[M]. finite_ordinal(M,x) --> finite_ordinal(M,y) -->
```
```   843                       is_Member(M,x,y,p) --> is_a(x,y,z)) &
```
```   844       (\<forall>x[M]. \<forall>y[M]. finite_ordinal(M,x) --> finite_ordinal(M,y) -->
```
```   845                       is_Equal(M,x,y,p) --> is_b(x,y,z)) &
```
```   846       (\<forall>x[M]. \<forall>y[M]. mem_formula(M,x) --> mem_formula(M,y) -->
```
```   847                      is_Nand(M,x,y,p) --> is_c(x,y,z)) &
```
```   848       (\<forall>x[M]. mem_formula(M,x) --> is_Forall(M,x,p) --> is_d(x,z))"
```
```   849
```
```   850 lemma (in M_datatypes) formula_case_abs [simp]:
```
```   851      "[| Relativize2(M,nat,nat,is_a,a); Relativize2(M,nat,nat,is_b,b);
```
```   852          Relativize2(M,formula,formula,is_c,c); Relativize1(M,formula,is_d,d);
```
```   853          p \<in> formula; M(z) |]
```
```   854       ==> is_formula_case(M,is_a,is_b,is_c,is_d,p,z) <->
```
```   855           z = formula_case(a,b,c,d,p)"
```
```   856 apply (simp add: formula_into_M is_formula_case_def)
```
```   857 apply (erule formula.cases)
```
```   858    apply (simp_all add: Relativize1_def Relativize2_def)
```
```   859 done
```
```   860
```
```   861 lemma (in M_datatypes) formula_case_closed [intro,simp]:
```
```   862   "[|p \<in> formula;
```
```   863      \<forall>x[M]. \<forall>y[M]. x\<in>nat --> y\<in>nat --> M(a(x,y));
```
```   864      \<forall>x[M]. \<forall>y[M]. x\<in>nat --> y\<in>nat --> M(b(x,y));
```
```   865      \<forall>x[M]. \<forall>y[M]. x\<in>formula --> y\<in>formula --> M(c(x,y));
```
```   866      \<forall>x[M]. x\<in>formula --> M(d(x))|] ==> M(formula_case(a,b,c,d,p))"
```
```   867 by (erule formula.cases, simp_all)
```
```   868
```
```   869
```
```   870 subsection{*Absoluteness for the Formula Operator @{term depth}*}
```
```   871 constdefs
```
```   872
```
```   873   is_depth :: "[i=>o,i,i] => o"
```
```   874     "is_depth(M,p,n) ==
```
```   875        \<exists>sn[M]. \<exists>formula_n[M]. \<exists>formula_sn[M].
```
```   876         is_formula_N(M,n,formula_n) & p \<notin> formula_n &
```
```   877         successor(M,n,sn) & is_formula_N(M,sn,formula_sn) & p \<in> formula_sn"
```
```   878
```
```   879
```
```   880 lemma (in M_datatypes) depth_abs [simp]:
```
```   881      "[|p \<in> formula; n \<in> nat|] ==> is_depth(M,p,n) <-> n = depth(p)"
```
```   882 apply (subgoal_tac "M(p) & M(n)")
```
```   883  prefer 2 apply (blast dest: transM)
```
```   884 apply (simp add: is_depth_def)
```
```   885 apply (blast intro: formula_imp_formula_N nat_into_Ord formula_N_imp_eq_depth
```
```   886              dest: formula_N_imp_depth_lt)
```
```   887 done
```
```   888
```
```   889 text{*Proof is trivial since @{term depth} returns natural numbers.*}
```
```   890 lemma (in M_trivial) depth_closed [intro,simp]:
```
```   891      "p \<in> formula ==> M(depth(p))"
```
```   892 by (simp add: nat_into_M)
```
```   893
```
```   894
```
```   895 subsection {*Absoluteness for @{term formula_rec}*}
```
```   896
```
```   897 constdefs
```
```   898
```
```   899   formula_rec_case :: "[[i,i]=>i, [i,i]=>i, [i,i,i,i]=>i, [i,i]=>i, i, i] => i"
```
```   900     --{* the instance of @{term formula_case} in @{term formula_rec}*}
```
```   901    "formula_rec_case(a,b,c,d,h) ==
```
```   902         formula_case (a, b,
```
```   903                 \<lambda>u v. c(u, v, h ` succ(depth(u)) ` u,
```
```   904                               h ` succ(depth(v)) ` v),
```
```   905                 \<lambda>u. d(u, h ` succ(depth(u)) ` u))"
```
```   906
```
```   907   is_formula_rec :: "[i=>o, [i,i,i]=>o, i, i] => o"
```
```   908     --{* predicate to relativize the functional @{term formula_rec}*}
```
```   909    "is_formula_rec(M,MH,p,z)  ==
```
```   910       \<exists>dp[M]. \<exists>i[M]. \<exists>f[M]. finite_ordinal(M,dp) & is_depth(M,p,dp) &
```
```   911              successor(M,dp,i) & fun_apply(M,f,p,z) & is_transrec(M,MH,i,f)"
```
```   912
```
```   913 text{*Unfold @{term formula_rec} to @{term formula_rec_case}.
```
```   914      Express @{term formula_rec} without using @{term rank} or @{term Vset},
```
```   915 neither of which is absolute.*}
```
```   916 lemma (in M_trivial) formula_rec_eq:
```
```   917   "p \<in> formula ==>
```
```   918    formula_rec(a,b,c,d,p) =
```
```   919    transrec (succ(depth(p)),
```
```   920              \<lambda>x h. Lambda (formula, formula_rec_case(a,b,c,d,h))) ` p"
```
```   921 apply (simp add: formula_rec_case_def)
```
```   922 apply (induct_tac p)
```
```   923    txt{*Base case for @{term Member}*}
```
```   924    apply (subst transrec, simp add: formula.intros)
```
```   925   txt{*Base case for @{term Equal}*}
```
```   926   apply (subst transrec, simp add: formula.intros)
```
```   927  txt{*Inductive step for @{term Nand}*}
```
```   928  apply (subst transrec)
```
```   929  apply (simp add: succ_Un_distrib formula.intros)
```
```   930 txt{*Inductive step for @{term Forall}*}
```
```   931 apply (subst transrec)
```
```   932 apply (simp add: formula_imp_formula_N formula.intros)
```
```   933 done
```
```   934
```
```   935
```
```   936 text{*Sufficient conditions to relative the instance of @{term formula_case}
```
```   937       in @{term formula_rec}*}
```
```   938 lemma (in M_datatypes) Relativize1_formula_rec_case:
```
```   939      "[|Relativize2(M, nat, nat, is_a, a);
```
```   940         Relativize2(M, nat, nat, is_b, b);
```
```   941         Relativize2 (M, formula, formula,
```
```   942            is_c, \<lambda>u v. c(u, v, h`succ(depth(u))`u, h`succ(depth(v))`v));
```
```   943         Relativize1(M, formula,
```
```   944            is_d, \<lambda>u. d(u, h ` succ(depth(u)) ` u));
```
```   945  	M(h) |]
```
```   946       ==> Relativize1(M, formula,
```
```   947                          is_formula_case (M, is_a, is_b, is_c, is_d),
```
```   948                          formula_rec_case(a, b, c, d, h))"
```
```   949 apply (simp (no_asm) add: formula_rec_case_def Relativize1_def)
```
```   950 apply (simp add: formula_case_abs)
```
```   951 done
```
```   952
```
```   953
```
```   954 text{*This locale packages the premises of the following theorems,
```
```   955       which is the normal purpose of locales.  It doesn't accumulate
```
```   956       constraints on the class @{term M}, as in most of this deveopment.*}
```
```   957 locale Formula_Rec = M_eclose +
```
```   958   fixes a and is_a and b and is_b and c and is_c and d and is_d and MH
```
```   959   defines
```
```   960       "MH(u::i,f,z) ==
```
```   961 	\<forall>fml[M]. is_formula(M,fml) -->
```
```   962              is_lambda
```
```   963 	 (M, fml, is_formula_case (M, is_a, is_b, is_c(f), is_d(f)), z)"
```
```   964
```
```   965   assumes a_closed: "[|x\<in>nat; y\<in>nat|] ==> M(a(x,y))"
```
```   966       and a_rel:    "Relativize2(M, nat, nat, is_a, a)"
```
```   967       and b_closed: "[|x\<in>nat; y\<in>nat|] ==> M(b(x,y))"
```
```   968       and b_rel:    "Relativize2(M, nat, nat, is_b, b)"
```
```   969       and c_closed: "[|x \<in> formula; y \<in> formula; M(gx); M(gy)|]
```
```   970                      ==> M(c(x, y, gx, gy))"
```
```   971       and c_rel:
```
```   972          "M(f) ==>
```
```   973           Relativize2 (M, formula, formula, is_c(f),
```
```   974              \<lambda>u v. c(u, v, f ` succ(depth(u)) ` u, f ` succ(depth(v)) ` v))"
```
```   975       and d_closed: "[|x \<in> formula; M(gx)|] ==> M(d(x, gx))"
```
```   976       and d_rel:
```
```   977          "M(f) ==>
```
```   978           Relativize1(M, formula, is_d(f), \<lambda>u. d(u, f ` succ(depth(u)) ` u))"
```
```   979       and fr_replace: "n \<in> nat ==> transrec_replacement(M,MH,n)"
```
```   980       and fr_lam_replace:
```
```   981            "M(g) ==>
```
```   982             strong_replacement
```
```   983 	      (M, \<lambda>x y. x \<in> formula &
```
```   984 		  y = \<langle>x, formula_rec_case(a,b,c,d,g,x)\<rangle>)";
```
```   985
```
```   986 lemma (in Formula_Rec) formula_rec_case_closed:
```
```   987     "[|M(g); p \<in> formula|] ==> M(formula_rec_case(a, b, c, d, g, p))"
```
```   988 by (simp add: formula_rec_case_def a_closed b_closed c_closed d_closed)
```
```   989
```
```   990 lemma (in Formula_Rec) formula_rec_lam_closed:
```
```   991     "M(g) ==> M(Lambda (formula, formula_rec_case(a,b,c,d,g)))"
```
```   992 by (simp add: lam_closed2 fr_lam_replace formula_rec_case_closed)
```
```   993
```
```   994 lemma (in Formula_Rec) MH_rel2:
```
```   995      "relativize2 (M, MH,
```
```   996              \<lambda>x h. Lambda (formula, formula_rec_case(a,b,c,d,h)))"
```
```   997 apply (simp add: relativize2_def MH_def, clarify)
```
```   998 apply (rule lambda_abs2)
```
```   999 apply (rule fr_lam_replace, assumption)
```
```  1000 apply (rule Relativize1_formula_rec_case)
```
```  1001 apply (simp_all add: a_rel b_rel c_rel d_rel formula_rec_case_closed)
```
```  1002 done
```
```  1003
```
```  1004 lemma (in Formula_Rec) fr_transrec_closed:
```
```  1005     "n \<in> nat
```
```  1006      ==> M(transrec
```
```  1007           (n, \<lambda>x h. Lambda(formula, formula_rec_case(a, b, c, d, h))))"
```
```  1008 by (simp add: transrec_closed [OF fr_replace MH_rel2]
```
```  1009               nat_into_M formula_rec_lam_closed)
```
```  1010
```
```  1011 text{*The main two results: @{term formula_rec} is absolute for @{term M}.*}
```
```  1012 theorem (in Formula_Rec) formula_rec_closed:
```
```  1013     "p \<in> formula ==> M(formula_rec(a,b,c,d,p))"
```
```  1014 by (simp add: formula_rec_eq fr_transrec_closed
```
```  1015               transM [OF _ formula_closed])
```
```  1016
```
```  1017 theorem (in Formula_Rec) formula_rec_abs:
```
```  1018   "[| p \<in> formula; M(z)|]
```
```  1019    ==> is_formula_rec(M,MH,p,z) <-> z = formula_rec(a,b,c,d,p)"
```
```  1020 by (simp add: is_formula_rec_def formula_rec_eq transM [OF _ formula_closed]
```
```  1021               transrec_abs [OF fr_replace MH_rel2] depth_type
```
```  1022               fr_transrec_closed formula_rec_lam_closed eq_commute)
```
```  1023
```
```  1024
```
```  1025 end
```