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