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