src/ZF/Constructible/L_axioms.thy
author paulson
Tue Jul 16 16:29:36 2002 +0200 (2002-07-16)
changeset 13363 c26eeb000470
parent 13352 3cd767f8d78b
child 13385 31df66ca0780
permissions -rw-r--r--
instantiation of locales M_trancl and M_wfrank;
proofs of list_replacement{1,2}
     1 header {*The ZF Axioms (Except Separation) in L*}
     2 
     3 theory L_axioms = Formula + Relative + Reflection + MetaExists:
     4 
     5 text {* The class L satisfies the premises of locale @{text M_triv_axioms} *}
     6 
     7 lemma transL: "[| y\<in>x; L(x) |] ==> L(y)"
     8 apply (insert Transset_Lset) 
     9 apply (simp add: Transset_def L_def, blast) 
    10 done
    11 
    12 lemma nonempty: "L(0)"
    13 apply (simp add: L_def) 
    14 apply (blast intro: zero_in_Lset) 
    15 done
    16 
    17 lemma upair_ax: "upair_ax(L)"
    18 apply (simp add: upair_ax_def upair_def, clarify)
    19 apply (rule_tac x="{x,y}" in rexI)  
    20 apply (simp_all add: doubleton_in_L) 
    21 done
    22 
    23 lemma Union_ax: "Union_ax(L)"
    24 apply (simp add: Union_ax_def big_union_def, clarify)
    25 apply (rule_tac x="Union(x)" in rexI)  
    26 apply (simp_all add: Union_in_L, auto) 
    27 apply (blast intro: transL) 
    28 done
    29 
    30 lemma power_ax: "power_ax(L)"
    31 apply (simp add: power_ax_def powerset_def Relative.subset_def, clarify)
    32 apply (rule_tac x="{y \<in> Pow(x). L(y)}" in rexI)  
    33 apply (simp_all add: LPow_in_L, auto)
    34 apply (blast intro: transL) 
    35 done
    36 
    37 subsubsection{*For L to satisfy Replacement *}
    38 
    39 (*Can't move these to Formula unless the definition of univalent is moved
    40 there too!*)
    41 
    42 lemma LReplace_in_Lset:
    43      "[|X \<in> Lset(i); univalent(L,X,Q); Ord(i)|] 
    44       ==> \<exists>j. Ord(j) & Replace(X, %x y. Q(x,y) & L(y)) \<subseteq> Lset(j)"
    45 apply (rule_tac x="\<Union>y \<in> Replace(X, %x y. Q(x,y) & L(y)). succ(lrank(y))" 
    46        in exI)
    47 apply simp
    48 apply clarify 
    49 apply (rule_tac a=x in UN_I)  
    50  apply (simp_all add: Replace_iff univalent_def) 
    51 apply (blast dest: transL L_I) 
    52 done
    53 
    54 lemma LReplace_in_L: 
    55      "[|L(X); univalent(L,X,Q)|] 
    56       ==> \<exists>Y. L(Y) & Replace(X, %x y. Q(x,y) & L(y)) \<subseteq> Y"
    57 apply (drule L_D, clarify) 
    58 apply (drule LReplace_in_Lset, assumption+)
    59 apply (blast intro: L_I Lset_in_Lset_succ)
    60 done
    61 
    62 lemma replacement: "replacement(L,P)"
    63 apply (simp add: replacement_def, clarify)
    64 apply (frule LReplace_in_L, assumption+, clarify) 
    65 apply (rule_tac x=Y in rexI)   
    66 apply (simp_all add: Replace_iff univalent_def, blast) 
    67 done
    68 
    69 subsection{*Instantiating the locale @{text M_triv_axioms}*}
    70 text{*No instances of Separation yet.*}
    71 
    72 lemma Lset_mono_le: "mono_le_subset(Lset)"
    73 by (simp add: mono_le_subset_def le_imp_subset Lset_mono) 
    74 
    75 lemma Lset_cont: "cont_Ord(Lset)"
    76 by (simp add: cont_Ord_def Limit_Lset_eq OUnion_def Limit_is_Ord) 
    77 
    78 lemmas Pair_in_Lset = Formula.Pair_in_LLimit;
    79 
    80 lemmas L_nat = Ord_in_L [OF Ord_nat];
    81 
    82 ML
    83 {*
    84 val transL = thm "transL";
    85 val nonempty = thm "nonempty";
    86 val upair_ax = thm "upair_ax";
    87 val Union_ax = thm "Union_ax";
    88 val power_ax = thm "power_ax";
    89 val replacement = thm "replacement";
    90 val L_nat = thm "L_nat";
    91 
    92 fun kill_flex_triv_prems st = Seq.hd ((REPEAT_FIRST assume_tac) st);
    93 
    94 fun triv_axioms_L th =
    95     kill_flex_triv_prems 
    96        ([transL, nonempty, upair_ax, Union_ax, power_ax, replacement, L_nat] 
    97         MRS (inst "M" "L" th));
    98 
    99 bind_thm ("ball_abs", triv_axioms_L (thm "M_triv_axioms.ball_abs"));
   100 bind_thm ("rall_abs", triv_axioms_L (thm "M_triv_axioms.rall_abs"));
   101 bind_thm ("bex_abs", triv_axioms_L (thm "M_triv_axioms.bex_abs"));
   102 bind_thm ("rex_abs", triv_axioms_L (thm "M_triv_axioms.rex_abs"));
   103 bind_thm ("ball_iff_equiv", triv_axioms_L (thm "M_triv_axioms.ball_iff_equiv"));
   104 bind_thm ("M_equalityI", triv_axioms_L (thm "M_triv_axioms.M_equalityI"));
   105 bind_thm ("empty_abs", triv_axioms_L (thm "M_triv_axioms.empty_abs"));
   106 bind_thm ("subset_abs", triv_axioms_L (thm "M_triv_axioms.subset_abs"));
   107 bind_thm ("upair_abs", triv_axioms_L (thm "M_triv_axioms.upair_abs"));
   108 bind_thm ("upair_in_M_iff", triv_axioms_L (thm "M_triv_axioms.upair_in_M_iff"));
   109 bind_thm ("singleton_in_M_iff", triv_axioms_L (thm "M_triv_axioms.singleton_in_M_iff"));
   110 bind_thm ("pair_abs", triv_axioms_L (thm "M_triv_axioms.pair_abs"));
   111 bind_thm ("pair_in_M_iff", triv_axioms_L (thm "M_triv_axioms.pair_in_M_iff"));
   112 bind_thm ("pair_components_in_M", triv_axioms_L (thm "M_triv_axioms.pair_components_in_M"));
   113 bind_thm ("cartprod_abs", triv_axioms_L (thm "M_triv_axioms.cartprod_abs"));
   114 bind_thm ("union_abs", triv_axioms_L (thm "M_triv_axioms.union_abs"));
   115 bind_thm ("inter_abs", triv_axioms_L (thm "M_triv_axioms.inter_abs"));
   116 bind_thm ("setdiff_abs", triv_axioms_L (thm "M_triv_axioms.setdiff_abs"));
   117 bind_thm ("Union_abs", triv_axioms_L (thm "M_triv_axioms.Union_abs"));
   118 bind_thm ("Union_closed", triv_axioms_L (thm "M_triv_axioms.Union_closed"));
   119 bind_thm ("Un_closed", triv_axioms_L (thm "M_triv_axioms.Un_closed"));
   120 bind_thm ("cons_closed", triv_axioms_L (thm "M_triv_axioms.cons_closed"));
   121 bind_thm ("successor_abs", triv_axioms_L (thm "M_triv_axioms.successor_abs"));
   122 bind_thm ("succ_in_M_iff", triv_axioms_L (thm "M_triv_axioms.succ_in_M_iff"));
   123 bind_thm ("separation_closed", triv_axioms_L (thm "M_triv_axioms.separation_closed"));
   124 bind_thm ("strong_replacementI", triv_axioms_L (thm "M_triv_axioms.strong_replacementI"));
   125 bind_thm ("strong_replacement_closed", triv_axioms_L (thm "M_triv_axioms.strong_replacement_closed"));
   126 bind_thm ("RepFun_closed", triv_axioms_L (thm "M_triv_axioms.RepFun_closed"));
   127 bind_thm ("lam_closed", triv_axioms_L (thm "M_triv_axioms.lam_closed"));
   128 bind_thm ("image_abs", triv_axioms_L (thm "M_triv_axioms.image_abs"));
   129 bind_thm ("powerset_Pow", triv_axioms_L (thm "M_triv_axioms.powerset_Pow"));
   130 bind_thm ("powerset_imp_subset_Pow", triv_axioms_L (thm "M_triv_axioms.powerset_imp_subset_Pow"));
   131 bind_thm ("nat_into_M", triv_axioms_L (thm "M_triv_axioms.nat_into_M"));
   132 bind_thm ("nat_case_closed", triv_axioms_L (thm "M_triv_axioms.nat_case_closed"));
   133 bind_thm ("Inl_in_M_iff", triv_axioms_L (thm "M_triv_axioms.Inl_in_M_iff"));
   134 bind_thm ("Inr_in_M_iff", triv_axioms_L (thm "M_triv_axioms.Inr_in_M_iff"));
   135 bind_thm ("lt_closed", triv_axioms_L (thm "M_triv_axioms.lt_closed"));
   136 bind_thm ("transitive_set_abs", triv_axioms_L (thm "M_triv_axioms.transitive_set_abs"));
   137 bind_thm ("ordinal_abs", triv_axioms_L (thm "M_triv_axioms.ordinal_abs"));
   138 bind_thm ("limit_ordinal_abs", triv_axioms_L (thm "M_triv_axioms.limit_ordinal_abs"));
   139 bind_thm ("successor_ordinal_abs", triv_axioms_L (thm "M_triv_axioms.successor_ordinal_abs"));
   140 bind_thm ("finite_ordinal_abs", triv_axioms_L (thm "M_triv_axioms.finite_ordinal_abs"));
   141 bind_thm ("omega_abs", triv_axioms_L (thm "M_triv_axioms.omega_abs"));
   142 bind_thm ("number1_abs", triv_axioms_L (thm "M_triv_axioms.number1_abs"));
   143 bind_thm ("number1_abs", triv_axioms_L (thm "M_triv_axioms.number1_abs"));
   144 bind_thm ("number3_abs", triv_axioms_L (thm "M_triv_axioms.number3_abs"));
   145 *}
   146 
   147 declare ball_abs [simp] 
   148 declare rall_abs [simp] 
   149 declare bex_abs [simp] 
   150 declare rex_abs [simp] 
   151 declare empty_abs [simp] 
   152 declare subset_abs [simp] 
   153 declare upair_abs [simp] 
   154 declare upair_in_M_iff [iff]
   155 declare singleton_in_M_iff [iff]
   156 declare pair_abs [simp] 
   157 declare pair_in_M_iff [iff]
   158 declare cartprod_abs [simp] 
   159 declare union_abs [simp] 
   160 declare inter_abs [simp] 
   161 declare setdiff_abs [simp] 
   162 declare Union_abs [simp] 
   163 declare Union_closed [intro,simp]
   164 declare Un_closed [intro,simp]
   165 declare cons_closed [intro,simp]
   166 declare successor_abs [simp] 
   167 declare succ_in_M_iff [iff]
   168 declare separation_closed [intro,simp]
   169 declare strong_replacementI
   170 declare strong_replacement_closed [intro,simp]
   171 declare RepFun_closed [intro,simp]
   172 declare lam_closed [intro,simp]
   173 declare image_abs [simp] 
   174 declare nat_into_M [intro]
   175 declare Inl_in_M_iff [iff]
   176 declare Inr_in_M_iff [iff]
   177 declare transitive_set_abs [simp] 
   178 declare ordinal_abs [simp] 
   179 declare limit_ordinal_abs [simp] 
   180 declare successor_ordinal_abs [simp] 
   181 declare finite_ordinal_abs [simp] 
   182 declare omega_abs [simp] 
   183 declare number1_abs [simp] 
   184 declare number1_abs [simp] 
   185 declare number3_abs [simp]
   186 
   187 
   188 subsection{*Instantiation of the locale @{text reflection}*}
   189 
   190 text{*instances of locale constants*}
   191 constdefs
   192   L_F0 :: "[i=>o,i] => i"
   193     "L_F0(P,y) == \<mu>b. (\<exists>z. L(z) \<and> P(<y,z>)) --> (\<exists>z\<in>Lset(b). P(<y,z>))"
   194 
   195   L_FF :: "[i=>o,i] => i"
   196     "L_FF(P)   == \<lambda>a. \<Union>y\<in>Lset(a). L_F0(P,y)"
   197 
   198   L_ClEx :: "[i=>o,i] => o"
   199     "L_ClEx(P) == \<lambda>a. Limit(a) \<and> normalize(L_FF(P),a) = a"
   200 
   201 
   202 text{*We must use the meta-existential quantifier; otherwise the reflection
   203       terms become enormous!*} 
   204 constdefs
   205   L_Reflects :: "[i=>o,[i,i]=>o] => prop"      ("(3REFLECTS/ [_,/ _])")
   206     "REFLECTS[P,Q] == (??Cl. Closed_Unbounded(Cl) &
   207                            (\<forall>a. Cl(a) --> (\<forall>x \<in> Lset(a). P(x) <-> Q(a,x))))"
   208 
   209 
   210 theorem Triv_reflection:
   211      "REFLECTS[P, \<lambda>a x. P(x)]"
   212 apply (simp add: L_Reflects_def) 
   213 apply (rule meta_exI) 
   214 apply (rule Closed_Unbounded_Ord) 
   215 done
   216 
   217 theorem Not_reflection:
   218      "REFLECTS[P,Q] ==> REFLECTS[\<lambda>x. ~P(x), \<lambda>a x. ~Q(a,x)]"
   219 apply (unfold L_Reflects_def) 
   220 apply (erule meta_exE) 
   221 apply (rule_tac x=Cl in meta_exI, simp) 
   222 done
   223 
   224 theorem And_reflection:
   225      "[| REFLECTS[P,Q]; REFLECTS[P',Q'] |] 
   226       ==> REFLECTS[\<lambda>x. P(x) \<and> P'(x), \<lambda>a x. Q(a,x) \<and> Q'(a,x)]"
   227 apply (unfold L_Reflects_def) 
   228 apply (elim meta_exE) 
   229 apply (rule_tac x="\<lambda>a. Cl(a) \<and> Cla(a)" in meta_exI) 
   230 apply (simp add: Closed_Unbounded_Int, blast) 
   231 done
   232 
   233 theorem Or_reflection:
   234      "[| REFLECTS[P,Q]; REFLECTS[P',Q'] |] 
   235       ==> REFLECTS[\<lambda>x. P(x) \<or> P'(x), \<lambda>a x. Q(a,x) \<or> Q'(a,x)]"
   236 apply (unfold L_Reflects_def) 
   237 apply (elim meta_exE) 
   238 apply (rule_tac x="\<lambda>a. Cl(a) \<and> Cla(a)" in meta_exI) 
   239 apply (simp add: Closed_Unbounded_Int, blast) 
   240 done
   241 
   242 theorem Imp_reflection:
   243      "[| REFLECTS[P,Q]; REFLECTS[P',Q'] |] 
   244       ==> REFLECTS[\<lambda>x. P(x) --> P'(x), \<lambda>a x. Q(a,x) --> Q'(a,x)]"
   245 apply (unfold L_Reflects_def) 
   246 apply (elim meta_exE) 
   247 apply (rule_tac x="\<lambda>a. Cl(a) \<and> Cla(a)" in meta_exI) 
   248 apply (simp add: Closed_Unbounded_Int, blast) 
   249 done
   250 
   251 theorem Iff_reflection:
   252      "[| REFLECTS[P,Q]; REFLECTS[P',Q'] |] 
   253       ==> REFLECTS[\<lambda>x. P(x) <-> P'(x), \<lambda>a x. Q(a,x) <-> Q'(a,x)]"
   254 apply (unfold L_Reflects_def) 
   255 apply (elim meta_exE) 
   256 apply (rule_tac x="\<lambda>a. Cl(a) \<and> Cla(a)" in meta_exI) 
   257 apply (simp add: Closed_Unbounded_Int, blast) 
   258 done
   259 
   260 
   261 theorem Ex_reflection:
   262      "REFLECTS[\<lambda>x. P(fst(x),snd(x)), \<lambda>a x. Q(a,fst(x),snd(x))]
   263       ==> REFLECTS[\<lambda>x. \<exists>z. L(z) \<and> P(x,z), \<lambda>a x. \<exists>z\<in>Lset(a). Q(a,x,z)]"
   264 apply (unfold L_Reflects_def L_ClEx_def L_FF_def L_F0_def L_def) 
   265 apply (elim meta_exE) 
   266 apply (rule meta_exI)
   267 apply (rule reflection.Ex_reflection [OF Lset_mono_le Lset_cont Pair_in_Lset],
   268        assumption+)
   269 done
   270 
   271 theorem All_reflection:
   272      "REFLECTS[\<lambda>x. P(fst(x),snd(x)), \<lambda>a x. Q(a,fst(x),snd(x))]
   273       ==> REFLECTS[\<lambda>x. \<forall>z. L(z) --> P(x,z), \<lambda>a x. \<forall>z\<in>Lset(a). Q(a,x,z)]" 
   274 apply (unfold L_Reflects_def L_ClEx_def L_FF_def L_F0_def L_def) 
   275 apply (elim meta_exE) 
   276 apply (rule meta_exI)
   277 apply (rule reflection.All_reflection [OF Lset_mono_le Lset_cont Pair_in_Lset],
   278        assumption+)
   279 done
   280 
   281 theorem Rex_reflection:
   282      "REFLECTS[ \<lambda>x. P(fst(x),snd(x)), \<lambda>a x. Q(a,fst(x),snd(x))]
   283       ==> REFLECTS[\<lambda>x. \<exists>z[L]. P(x,z), \<lambda>a x. \<exists>z\<in>Lset(a). Q(a,x,z)]"
   284 apply (unfold rex_def) 
   285 apply (intro And_reflection Ex_reflection, assumption)
   286 done
   287 
   288 theorem Rall_reflection:
   289      "REFLECTS[\<lambda>x. P(fst(x),snd(x)), \<lambda>a x. Q(a,fst(x),snd(x))]
   290       ==> REFLECTS[\<lambda>x. \<forall>z[L]. P(x,z), \<lambda>a x. \<forall>z\<in>Lset(a). Q(a,x,z)]" 
   291 apply (unfold rall_def) 
   292 apply (intro Imp_reflection All_reflection, assumption)
   293 done
   294 
   295 lemmas FOL_reflections = 
   296         Triv_reflection Not_reflection And_reflection Or_reflection
   297         Imp_reflection Iff_reflection Ex_reflection All_reflection
   298         Rex_reflection Rall_reflection
   299 
   300 lemma ReflectsD:
   301      "[|REFLECTS[P,Q]; Ord(i)|] 
   302       ==> \<exists>j. i<j & (\<forall>x \<in> Lset(j). P(x) <-> Q(j,x))"
   303 apply (unfold L_Reflects_def Closed_Unbounded_def) 
   304 apply (elim meta_exE, clarify) 
   305 apply (blast dest!: UnboundedD) 
   306 done
   307 
   308 lemma ReflectsE:
   309      "[| REFLECTS[P,Q]; Ord(i);
   310          !!j. [|i<j;  \<forall>x \<in> Lset(j). P(x) <-> Q(j,x)|] ==> R |]
   311       ==> R"
   312 apply (drule ReflectsD, assumption, blast) 
   313 done
   314 
   315 lemma Collect_mem_eq: "{x\<in>A. x\<in>B} = A \<inter> B";
   316 by blast
   317 
   318 
   319 subsection{*Internalized Formulas for some Set-Theoretic Concepts*}
   320 
   321 lemmas setclass_simps = rall_setclass_is_ball rex_setclass_is_bex
   322 
   323 subsubsection{*Some numbers to help write de Bruijn indices*}
   324 
   325 syntax
   326     "3" :: i   ("3")
   327     "4" :: i   ("4")
   328     "5" :: i   ("5")
   329     "6" :: i   ("6")
   330     "7" :: i   ("7")
   331     "8" :: i   ("8")
   332     "9" :: i   ("9")
   333 
   334 translations
   335    "3"  == "succ(2)"
   336    "4"  == "succ(3)"
   337    "5"  == "succ(4)"
   338    "6"  == "succ(5)"
   339    "7"  == "succ(6)"
   340    "8"  == "succ(7)"
   341    "9"  == "succ(8)"
   342 
   343 
   344 subsubsection{*The Empty Set, Internalized*}
   345 
   346 constdefs empty_fm :: "i=>i"
   347     "empty_fm(x) == Forall(Neg(Member(0,succ(x))))"
   348 
   349 lemma empty_type [TC]:
   350      "x \<in> nat ==> empty_fm(x) \<in> formula"
   351 by (simp add: empty_fm_def) 
   352 
   353 lemma arity_empty_fm [simp]:
   354      "x \<in> nat ==> arity(empty_fm(x)) = succ(x)"
   355 by (simp add: empty_fm_def succ_Un_distrib [symmetric] Un_ac) 
   356 
   357 lemma sats_empty_fm [simp]:
   358    "[| x \<in> nat; env \<in> list(A)|]
   359     ==> sats(A, empty_fm(x), env) <-> empty(**A, nth(x,env))"
   360 by (simp add: empty_fm_def empty_def)
   361 
   362 lemma empty_iff_sats:
   363       "[| nth(i,env) = x; nth(j,env) = y; 
   364           i \<in> nat; env \<in> list(A)|]
   365        ==> empty(**A, x) <-> sats(A, empty_fm(i), env)"
   366 by simp
   367 
   368 theorem empty_reflection:
   369      "REFLECTS[\<lambda>x. empty(L,f(x)), 
   370                \<lambda>i x. empty(**Lset(i),f(x))]"
   371 apply (simp only: empty_def setclass_simps)
   372 apply (intro FOL_reflections)  
   373 done
   374 
   375 
   376 subsubsection{*Unordered Pairs, Internalized*}
   377 
   378 constdefs upair_fm :: "[i,i,i]=>i"
   379     "upair_fm(x,y,z) == 
   380        And(Member(x,z), 
   381            And(Member(y,z),
   382                Forall(Implies(Member(0,succ(z)), 
   383                               Or(Equal(0,succ(x)), Equal(0,succ(y)))))))"
   384 
   385 lemma upair_type [TC]:
   386      "[| x \<in> nat; y \<in> nat; z \<in> nat |] ==> upair_fm(x,y,z) \<in> formula"
   387 by (simp add: upair_fm_def) 
   388 
   389 lemma arity_upair_fm [simp]:
   390      "[| x \<in> nat; y \<in> nat; z \<in> nat |] 
   391       ==> arity(upair_fm(x,y,z)) = succ(x) \<union> succ(y) \<union> succ(z)"
   392 by (simp add: upair_fm_def succ_Un_distrib [symmetric] Un_ac) 
   393 
   394 lemma sats_upair_fm [simp]:
   395    "[| x \<in> nat; y \<in> nat; z \<in> nat; env \<in> list(A)|]
   396     ==> sats(A, upair_fm(x,y,z), env) <-> 
   397             upair(**A, nth(x,env), nth(y,env), nth(z,env))"
   398 by (simp add: upair_fm_def upair_def)
   399 
   400 lemma upair_iff_sats:
   401       "[| nth(i,env) = x; nth(j,env) = y; nth(k,env) = z; 
   402           i \<in> nat; j \<in> nat; k \<in> nat; env \<in> list(A)|]
   403        ==> upair(**A, x, y, z) <-> sats(A, upair_fm(i,j,k), env)"
   404 by (simp add: sats_upair_fm)
   405 
   406 text{*Useful? At least it refers to "real" unordered pairs*}
   407 lemma sats_upair_fm2 [simp]:
   408    "[| x \<in> nat; y \<in> nat; z < length(env); env \<in> list(A); Transset(A)|]
   409     ==> sats(A, upair_fm(x,y,z), env) <-> 
   410         nth(z,env) = {nth(x,env), nth(y,env)}"
   411 apply (frule lt_length_in_nat, assumption)  
   412 apply (simp add: upair_fm_def Transset_def, auto) 
   413 apply (blast intro: nth_type) 
   414 done
   415 
   416 theorem upair_reflection:
   417      "REFLECTS[\<lambda>x. upair(L,f(x),g(x),h(x)), 
   418                \<lambda>i x. upair(**Lset(i),f(x),g(x),h(x))]" 
   419 apply (simp add: upair_def)
   420 apply (intro FOL_reflections)  
   421 done
   422 
   423 subsubsection{*Ordered pairs, Internalized*}
   424 
   425 constdefs pair_fm :: "[i,i,i]=>i"
   426     "pair_fm(x,y,z) == 
   427        Exists(And(upair_fm(succ(x),succ(x),0),
   428               Exists(And(upair_fm(succ(succ(x)),succ(succ(y)),0),
   429                          upair_fm(1,0,succ(succ(z)))))))"
   430 
   431 lemma pair_type [TC]:
   432      "[| x \<in> nat; y \<in> nat; z \<in> nat |] ==> pair_fm(x,y,z) \<in> formula"
   433 by (simp add: pair_fm_def) 
   434 
   435 lemma arity_pair_fm [simp]:
   436      "[| x \<in> nat; y \<in> nat; z \<in> nat |] 
   437       ==> arity(pair_fm(x,y,z)) = succ(x) \<union> succ(y) \<union> succ(z)"
   438 by (simp add: pair_fm_def succ_Un_distrib [symmetric] Un_ac) 
   439 
   440 lemma sats_pair_fm [simp]:
   441    "[| x \<in> nat; y \<in> nat; z \<in> nat; env \<in> list(A)|]
   442     ==> sats(A, pair_fm(x,y,z), env) <-> 
   443         pair(**A, nth(x,env), nth(y,env), nth(z,env))"
   444 by (simp add: pair_fm_def pair_def)
   445 
   446 lemma pair_iff_sats:
   447       "[| nth(i,env) = x; nth(j,env) = y; nth(k,env) = z; 
   448           i \<in> nat; j \<in> nat; k \<in> nat; env \<in> list(A)|]
   449        ==> pair(**A, x, y, z) <-> sats(A, pair_fm(i,j,k), env)"
   450 by (simp add: sats_pair_fm)
   451 
   452 theorem pair_reflection:
   453      "REFLECTS[\<lambda>x. pair(L,f(x),g(x),h(x)), 
   454                \<lambda>i x. pair(**Lset(i),f(x),g(x),h(x))]"
   455 apply (simp only: pair_def setclass_simps)
   456 apply (intro FOL_reflections upair_reflection)  
   457 done
   458 
   459 
   460 subsubsection{*Binary Unions, Internalized*}
   461 
   462 constdefs union_fm :: "[i,i,i]=>i"
   463     "union_fm(x,y,z) == 
   464        Forall(Iff(Member(0,succ(z)),
   465                   Or(Member(0,succ(x)),Member(0,succ(y)))))"
   466 
   467 lemma union_type [TC]:
   468      "[| x \<in> nat; y \<in> nat; z \<in> nat |] ==> union_fm(x,y,z) \<in> formula"
   469 by (simp add: union_fm_def) 
   470 
   471 lemma arity_union_fm [simp]:
   472      "[| x \<in> nat; y \<in> nat; z \<in> nat |] 
   473       ==> arity(union_fm(x,y,z)) = succ(x) \<union> succ(y) \<union> succ(z)"
   474 by (simp add: union_fm_def succ_Un_distrib [symmetric] Un_ac) 
   475 
   476 lemma sats_union_fm [simp]:
   477    "[| x \<in> nat; y \<in> nat; z \<in> nat; env \<in> list(A)|]
   478     ==> sats(A, union_fm(x,y,z), env) <-> 
   479         union(**A, nth(x,env), nth(y,env), nth(z,env))"
   480 by (simp add: union_fm_def union_def)
   481 
   482 lemma union_iff_sats:
   483       "[| nth(i,env) = x; nth(j,env) = y; nth(k,env) = z; 
   484           i \<in> nat; j \<in> nat; k \<in> nat; env \<in> list(A)|]
   485        ==> union(**A, x, y, z) <-> sats(A, union_fm(i,j,k), env)"
   486 by (simp add: sats_union_fm)
   487 
   488 theorem union_reflection:
   489      "REFLECTS[\<lambda>x. union(L,f(x),g(x),h(x)), 
   490                \<lambda>i x. union(**Lset(i),f(x),g(x),h(x))]"
   491 apply (simp only: union_def setclass_simps)
   492 apply (intro FOL_reflections)  
   493 done
   494 
   495 
   496 subsubsection{*Set ``Cons,'' Internalized*}
   497 
   498 constdefs cons_fm :: "[i,i,i]=>i"
   499     "cons_fm(x,y,z) == 
   500        Exists(And(upair_fm(succ(x),succ(x),0),
   501                   union_fm(0,succ(y),succ(z))))"
   502 
   503 
   504 lemma cons_type [TC]:
   505      "[| x \<in> nat; y \<in> nat; z \<in> nat |] ==> cons_fm(x,y,z) \<in> formula"
   506 by (simp add: cons_fm_def) 
   507 
   508 lemma arity_cons_fm [simp]:
   509      "[| x \<in> nat; y \<in> nat; z \<in> nat |] 
   510       ==> arity(cons_fm(x,y,z)) = succ(x) \<union> succ(y) \<union> succ(z)"
   511 by (simp add: cons_fm_def succ_Un_distrib [symmetric] Un_ac) 
   512 
   513 lemma sats_cons_fm [simp]:
   514    "[| x \<in> nat; y \<in> nat; z \<in> nat; env \<in> list(A)|]
   515     ==> sats(A, cons_fm(x,y,z), env) <-> 
   516         is_cons(**A, nth(x,env), nth(y,env), nth(z,env))"
   517 by (simp add: cons_fm_def is_cons_def)
   518 
   519 lemma cons_iff_sats:
   520       "[| nth(i,env) = x; nth(j,env) = y; nth(k,env) = z; 
   521           i \<in> nat; j \<in> nat; k \<in> nat; env \<in> list(A)|]
   522        ==> is_cons(**A, x, y, z) <-> sats(A, cons_fm(i,j,k), env)"
   523 by simp
   524 
   525 theorem cons_reflection:
   526      "REFLECTS[\<lambda>x. is_cons(L,f(x),g(x),h(x)), 
   527                \<lambda>i x. is_cons(**Lset(i),f(x),g(x),h(x))]"
   528 apply (simp only: is_cons_def setclass_simps)
   529 apply (intro FOL_reflections upair_reflection union_reflection)  
   530 done
   531 
   532 
   533 subsubsection{*Successor Function, Internalized*}
   534 
   535 constdefs succ_fm :: "[i,i]=>i"
   536     "succ_fm(x,y) == cons_fm(x,x,y)"
   537 
   538 lemma succ_type [TC]:
   539      "[| x \<in> nat; y \<in> nat |] ==> succ_fm(x,y) \<in> formula"
   540 by (simp add: succ_fm_def) 
   541 
   542 lemma arity_succ_fm [simp]:
   543      "[| x \<in> nat; y \<in> nat |] 
   544       ==> arity(succ_fm(x,y)) = succ(x) \<union> succ(y)"
   545 by (simp add: succ_fm_def)
   546 
   547 lemma sats_succ_fm [simp]:
   548    "[| x \<in> nat; y \<in> nat; env \<in> list(A)|]
   549     ==> sats(A, succ_fm(x,y), env) <-> 
   550         successor(**A, nth(x,env), nth(y,env))"
   551 by (simp add: succ_fm_def successor_def)
   552 
   553 lemma successor_iff_sats:
   554       "[| nth(i,env) = x; nth(j,env) = y; 
   555           i \<in> nat; j \<in> nat; env \<in> list(A)|]
   556        ==> successor(**A, x, y) <-> sats(A, succ_fm(i,j), env)"
   557 by simp
   558 
   559 theorem successor_reflection:
   560      "REFLECTS[\<lambda>x. successor(L,f(x),g(x)), 
   561                \<lambda>i x. successor(**Lset(i),f(x),g(x))]"
   562 apply (simp only: successor_def setclass_simps)
   563 apply (intro cons_reflection)  
   564 done
   565 
   566 
   567 subsubsection{*The Number 1, Internalized*}
   568 
   569 (* "number1(M,a) == (\<exists>x[M]. empty(M,x) & successor(M,x,a))" *)
   570 constdefs number1_fm :: "i=>i"
   571     "number1_fm(a) == Exists(And(empty_fm(0), succ_fm(0,succ(a))))"
   572 
   573 lemma number1_type [TC]:
   574      "x \<in> nat ==> number1_fm(x) \<in> formula"
   575 by (simp add: number1_fm_def) 
   576 
   577 lemma arity_number1_fm [simp]:
   578      "x \<in> nat ==> arity(number1_fm(x)) = succ(x)"
   579 by (simp add: number1_fm_def succ_Un_distrib [symmetric] Un_ac) 
   580 
   581 lemma sats_number1_fm [simp]:
   582    "[| x \<in> nat; env \<in> list(A)|]
   583     ==> sats(A, number1_fm(x), env) <-> number1(**A, nth(x,env))"
   584 by (simp add: number1_fm_def number1_def)
   585 
   586 lemma number1_iff_sats:
   587       "[| nth(i,env) = x; nth(j,env) = y; 
   588           i \<in> nat; env \<in> list(A)|]
   589        ==> number1(**A, x) <-> sats(A, number1_fm(i), env)"
   590 by simp
   591 
   592 theorem number1_reflection:
   593      "REFLECTS[\<lambda>x. number1(L,f(x)), 
   594                \<lambda>i x. number1(**Lset(i),f(x))]"
   595 apply (simp only: number1_def setclass_simps)
   596 apply (intro FOL_reflections empty_reflection successor_reflection)
   597 done
   598 
   599 
   600 subsubsection{*Big Union, Internalized*}
   601 
   602 (*  "big_union(M,A,z) == \<forall>x[M]. x \<in> z <-> (\<exists>y[M]. y\<in>A & x \<in> y)" *)
   603 constdefs big_union_fm :: "[i,i]=>i"
   604     "big_union_fm(A,z) == 
   605        Forall(Iff(Member(0,succ(z)),
   606                   Exists(And(Member(0,succ(succ(A))), Member(1,0)))))"
   607 
   608 lemma big_union_type [TC]:
   609      "[| x \<in> nat; y \<in> nat |] ==> big_union_fm(x,y) \<in> formula"
   610 by (simp add: big_union_fm_def) 
   611 
   612 lemma arity_big_union_fm [simp]:
   613      "[| x \<in> nat; y \<in> nat |] 
   614       ==> arity(big_union_fm(x,y)) = succ(x) \<union> succ(y)"
   615 by (simp add: big_union_fm_def succ_Un_distrib [symmetric] Un_ac)
   616 
   617 lemma sats_big_union_fm [simp]:
   618    "[| x \<in> nat; y \<in> nat; env \<in> list(A)|]
   619     ==> sats(A, big_union_fm(x,y), env) <-> 
   620         big_union(**A, nth(x,env), nth(y,env))"
   621 by (simp add: big_union_fm_def big_union_def)
   622 
   623 lemma big_union_iff_sats:
   624       "[| nth(i,env) = x; nth(j,env) = y; 
   625           i \<in> nat; j \<in> nat; env \<in> list(A)|]
   626        ==> big_union(**A, x, y) <-> sats(A, big_union_fm(i,j), env)"
   627 by simp
   628 
   629 theorem big_union_reflection:
   630      "REFLECTS[\<lambda>x. big_union(L,f(x),g(x)), 
   631                \<lambda>i x. big_union(**Lset(i),f(x),g(x))]"
   632 apply (simp only: big_union_def setclass_simps)
   633 apply (intro FOL_reflections)  
   634 done
   635 
   636 
   637 subsubsection{*Variants of Satisfaction Definitions for Ordinals, etc.*}
   638 
   639 text{*Differs from the one in Formula by using "ordinal" rather than "Ord"*}
   640 
   641 
   642 lemma sats_subset_fm':
   643    "[|x \<in> nat; y \<in> nat; env \<in> list(A)|]
   644     ==> sats(A, subset_fm(x,y), env) <-> subset(**A, nth(x,env), nth(y,env))" 
   645 by (simp add: subset_fm_def Relative.subset_def) 
   646 
   647 theorem subset_reflection:
   648      "REFLECTS[\<lambda>x. subset(L,f(x),g(x)), 
   649                \<lambda>i x. subset(**Lset(i),f(x),g(x))]" 
   650 apply (simp only: Relative.subset_def setclass_simps)
   651 apply (intro FOL_reflections)  
   652 done
   653 
   654 lemma sats_transset_fm':
   655    "[|x \<in> nat; env \<in> list(A)|]
   656     ==> sats(A, transset_fm(x), env) <-> transitive_set(**A, nth(x,env))"
   657 by (simp add: sats_subset_fm' transset_fm_def transitive_set_def) 
   658 
   659 theorem transitive_set_reflection:
   660      "REFLECTS[\<lambda>x. transitive_set(L,f(x)),
   661                \<lambda>i x. transitive_set(**Lset(i),f(x))]"
   662 apply (simp only: transitive_set_def setclass_simps)
   663 apply (intro FOL_reflections subset_reflection)  
   664 done
   665 
   666 lemma sats_ordinal_fm':
   667    "[|x \<in> nat; env \<in> list(A)|]
   668     ==> sats(A, ordinal_fm(x), env) <-> ordinal(**A,nth(x,env))"
   669 by (simp add: sats_transset_fm' ordinal_fm_def ordinal_def)
   670 
   671 lemma ordinal_iff_sats:
   672       "[| nth(i,env) = x;  i \<in> nat; env \<in> list(A)|]
   673        ==> ordinal(**A, x) <-> sats(A, ordinal_fm(i), env)"
   674 by (simp add: sats_ordinal_fm')
   675 
   676 theorem ordinal_reflection:
   677      "REFLECTS[\<lambda>x. ordinal(L,f(x)), \<lambda>i x. ordinal(**Lset(i),f(x))]"
   678 apply (simp only: ordinal_def setclass_simps)
   679 apply (intro FOL_reflections transitive_set_reflection)  
   680 done
   681 
   682 
   683 subsubsection{*Membership Relation, Internalized*}
   684 
   685 constdefs Memrel_fm :: "[i,i]=>i"
   686     "Memrel_fm(A,r) == 
   687        Forall(Iff(Member(0,succ(r)),
   688                   Exists(And(Member(0,succ(succ(A))),
   689                              Exists(And(Member(0,succ(succ(succ(A)))),
   690                                         And(Member(1,0),
   691                                             pair_fm(1,0,2))))))))"
   692 
   693 lemma Memrel_type [TC]:
   694      "[| x \<in> nat; y \<in> nat |] ==> Memrel_fm(x,y) \<in> formula"
   695 by (simp add: Memrel_fm_def) 
   696 
   697 lemma arity_Memrel_fm [simp]:
   698      "[| x \<in> nat; y \<in> nat |] 
   699       ==> arity(Memrel_fm(x,y)) = succ(x) \<union> succ(y)"
   700 by (simp add: Memrel_fm_def succ_Un_distrib [symmetric] Un_ac) 
   701 
   702 lemma sats_Memrel_fm [simp]:
   703    "[| x \<in> nat; y \<in> nat; env \<in> list(A)|]
   704     ==> sats(A, Memrel_fm(x,y), env) <-> 
   705         membership(**A, nth(x,env), nth(y,env))"
   706 by (simp add: Memrel_fm_def membership_def)
   707 
   708 lemma Memrel_iff_sats:
   709       "[| nth(i,env) = x; nth(j,env) = y; 
   710           i \<in> nat; j \<in> nat; env \<in> list(A)|]
   711        ==> membership(**A, x, y) <-> sats(A, Memrel_fm(i,j), env)"
   712 by simp
   713 
   714 theorem membership_reflection:
   715      "REFLECTS[\<lambda>x. membership(L,f(x),g(x)), 
   716                \<lambda>i x. membership(**Lset(i),f(x),g(x))]"
   717 apply (simp only: membership_def setclass_simps)
   718 apply (intro FOL_reflections pair_reflection)  
   719 done
   720 
   721 subsubsection{*Predecessor Set, Internalized*}
   722 
   723 constdefs pred_set_fm :: "[i,i,i,i]=>i"
   724     "pred_set_fm(A,x,r,B) == 
   725        Forall(Iff(Member(0,succ(B)),
   726                   Exists(And(Member(0,succ(succ(r))),
   727                              And(Member(1,succ(succ(A))),
   728                                  pair_fm(1,succ(succ(x)),0))))))"
   729 
   730 
   731 lemma pred_set_type [TC]:
   732      "[| A \<in> nat; x \<in> nat; r \<in> nat; B \<in> nat |] 
   733       ==> pred_set_fm(A,x,r,B) \<in> formula"
   734 by (simp add: pred_set_fm_def) 
   735 
   736 lemma arity_pred_set_fm [simp]:
   737    "[| A \<in> nat; x \<in> nat; r \<in> nat; B \<in> nat |] 
   738     ==> arity(pred_set_fm(A,x,r,B)) = succ(A) \<union> succ(x) \<union> succ(r) \<union> succ(B)"
   739 by (simp add: pred_set_fm_def succ_Un_distrib [symmetric] Un_ac) 
   740 
   741 lemma sats_pred_set_fm [simp]:
   742    "[| U \<in> nat; x \<in> nat; r \<in> nat; B \<in> nat; env \<in> list(A)|]
   743     ==> sats(A, pred_set_fm(U,x,r,B), env) <-> 
   744         pred_set(**A, nth(U,env), nth(x,env), nth(r,env), nth(B,env))"
   745 by (simp add: pred_set_fm_def pred_set_def)
   746 
   747 lemma pred_set_iff_sats:
   748       "[| nth(i,env) = U; nth(j,env) = x; nth(k,env) = r; nth(l,env) = B; 
   749           i \<in> nat; j \<in> nat; k \<in> nat; l \<in> nat; env \<in> list(A)|]
   750        ==> pred_set(**A,U,x,r,B) <-> sats(A, pred_set_fm(i,j,k,l), env)"
   751 by (simp add: sats_pred_set_fm)
   752 
   753 theorem pred_set_reflection:
   754      "REFLECTS[\<lambda>x. pred_set(L,f(x),g(x),h(x),b(x)), 
   755                \<lambda>i x. pred_set(**Lset(i),f(x),g(x),h(x),b(x))]" 
   756 apply (simp only: pred_set_def setclass_simps)
   757 apply (intro FOL_reflections pair_reflection)  
   758 done
   759 
   760 
   761 
   762 subsubsection{*Domain of a Relation, Internalized*}
   763 
   764 (* "is_domain(M,r,z) == 
   765 	\<forall>x[M]. (x \<in> z <-> (\<exists>w[M]. w\<in>r & (\<exists>y[M]. pair(M,x,y,w))))" *)
   766 constdefs domain_fm :: "[i,i]=>i"
   767     "domain_fm(r,z) == 
   768        Forall(Iff(Member(0,succ(z)),
   769                   Exists(And(Member(0,succ(succ(r))),
   770                              Exists(pair_fm(2,0,1))))))"
   771 
   772 lemma domain_type [TC]:
   773      "[| x \<in> nat; y \<in> nat |] ==> domain_fm(x,y) \<in> formula"
   774 by (simp add: domain_fm_def) 
   775 
   776 lemma arity_domain_fm [simp]:
   777      "[| x \<in> nat; y \<in> nat |] 
   778       ==> arity(domain_fm(x,y)) = succ(x) \<union> succ(y)"
   779 by (simp add: domain_fm_def succ_Un_distrib [symmetric] Un_ac) 
   780 
   781 lemma sats_domain_fm [simp]:
   782    "[| x \<in> nat; y \<in> nat; env \<in> list(A)|]
   783     ==> sats(A, domain_fm(x,y), env) <-> 
   784         is_domain(**A, nth(x,env), nth(y,env))"
   785 by (simp add: domain_fm_def is_domain_def)
   786 
   787 lemma domain_iff_sats:
   788       "[| nth(i,env) = x; nth(j,env) = y; 
   789           i \<in> nat; j \<in> nat; env \<in> list(A)|]
   790        ==> is_domain(**A, x, y) <-> sats(A, domain_fm(i,j), env)"
   791 by simp
   792 
   793 theorem domain_reflection:
   794      "REFLECTS[\<lambda>x. is_domain(L,f(x),g(x)), 
   795                \<lambda>i x. is_domain(**Lset(i),f(x),g(x))]"
   796 apply (simp only: is_domain_def setclass_simps)
   797 apply (intro FOL_reflections pair_reflection)  
   798 done
   799 
   800 
   801 subsubsection{*Range of a Relation, Internalized*}
   802 
   803 (* "is_range(M,r,z) == 
   804 	\<forall>y[M]. (y \<in> z <-> (\<exists>w[M]. w\<in>r & (\<exists>x[M]. pair(M,x,y,w))))" *)
   805 constdefs range_fm :: "[i,i]=>i"
   806     "range_fm(r,z) == 
   807        Forall(Iff(Member(0,succ(z)),
   808                   Exists(And(Member(0,succ(succ(r))),
   809                              Exists(pair_fm(0,2,1))))))"
   810 
   811 lemma range_type [TC]:
   812      "[| x \<in> nat; y \<in> nat |] ==> range_fm(x,y) \<in> formula"
   813 by (simp add: range_fm_def) 
   814 
   815 lemma arity_range_fm [simp]:
   816      "[| x \<in> nat; y \<in> nat |] 
   817       ==> arity(range_fm(x,y)) = succ(x) \<union> succ(y)"
   818 by (simp add: range_fm_def succ_Un_distrib [symmetric] Un_ac) 
   819 
   820 lemma sats_range_fm [simp]:
   821    "[| x \<in> nat; y \<in> nat; env \<in> list(A)|]
   822     ==> sats(A, range_fm(x,y), env) <-> 
   823         is_range(**A, nth(x,env), nth(y,env))"
   824 by (simp add: range_fm_def is_range_def)
   825 
   826 lemma range_iff_sats:
   827       "[| nth(i,env) = x; nth(j,env) = y; 
   828           i \<in> nat; j \<in> nat; env \<in> list(A)|]
   829        ==> is_range(**A, x, y) <-> sats(A, range_fm(i,j), env)"
   830 by simp
   831 
   832 theorem range_reflection:
   833      "REFLECTS[\<lambda>x. is_range(L,f(x),g(x)), 
   834                \<lambda>i x. is_range(**Lset(i),f(x),g(x))]"
   835 apply (simp only: is_range_def setclass_simps)
   836 apply (intro FOL_reflections pair_reflection)  
   837 done
   838 
   839  
   840 subsubsection{*Field of a Relation, Internalized*}
   841 
   842 (* "is_field(M,r,z) == 
   843 	\<exists>dr[M]. is_domain(M,r,dr) & 
   844             (\<exists>rr[M]. is_range(M,r,rr) & union(M,dr,rr,z))" *)
   845 constdefs field_fm :: "[i,i]=>i"
   846     "field_fm(r,z) == 
   847        Exists(And(domain_fm(succ(r),0), 
   848               Exists(And(range_fm(succ(succ(r)),0), 
   849                          union_fm(1,0,succ(succ(z)))))))"
   850 
   851 lemma field_type [TC]:
   852      "[| x \<in> nat; y \<in> nat |] ==> field_fm(x,y) \<in> formula"
   853 by (simp add: field_fm_def) 
   854 
   855 lemma arity_field_fm [simp]:
   856      "[| x \<in> nat; y \<in> nat |] 
   857       ==> arity(field_fm(x,y)) = succ(x) \<union> succ(y)"
   858 by (simp add: field_fm_def succ_Un_distrib [symmetric] Un_ac) 
   859 
   860 lemma sats_field_fm [simp]:
   861    "[| x \<in> nat; y \<in> nat; env \<in> list(A)|]
   862     ==> sats(A, field_fm(x,y), env) <-> 
   863         is_field(**A, nth(x,env), nth(y,env))"
   864 by (simp add: field_fm_def is_field_def)
   865 
   866 lemma field_iff_sats:
   867       "[| nth(i,env) = x; nth(j,env) = y; 
   868           i \<in> nat; j \<in> nat; env \<in> list(A)|]
   869        ==> is_field(**A, x, y) <-> sats(A, field_fm(i,j), env)"
   870 by simp
   871 
   872 theorem field_reflection:
   873      "REFLECTS[\<lambda>x. is_field(L,f(x),g(x)), 
   874                \<lambda>i x. is_field(**Lset(i),f(x),g(x))]"
   875 apply (simp only: is_field_def setclass_simps)
   876 apply (intro FOL_reflections domain_reflection range_reflection
   877              union_reflection)
   878 done
   879 
   880 
   881 subsubsection{*Image under a Relation, Internalized*}
   882 
   883 (* "image(M,r,A,z) == 
   884         \<forall>y[M]. (y \<in> z <-> (\<exists>w[M]. w\<in>r & (\<exists>x[M]. x\<in>A & pair(M,x,y,w))))" *)
   885 constdefs image_fm :: "[i,i,i]=>i"
   886     "image_fm(r,A,z) == 
   887        Forall(Iff(Member(0,succ(z)),
   888                   Exists(And(Member(0,succ(succ(r))),
   889                              Exists(And(Member(0,succ(succ(succ(A)))),
   890 	 			        pair_fm(0,2,1)))))))"
   891 
   892 lemma image_type [TC]:
   893      "[| x \<in> nat; y \<in> nat; z \<in> nat |] ==> image_fm(x,y,z) \<in> formula"
   894 by (simp add: image_fm_def) 
   895 
   896 lemma arity_image_fm [simp]:
   897      "[| x \<in> nat; y \<in> nat; z \<in> nat |] 
   898       ==> arity(image_fm(x,y,z)) = succ(x) \<union> succ(y) \<union> succ(z)"
   899 by (simp add: image_fm_def succ_Un_distrib [symmetric] Un_ac) 
   900 
   901 lemma sats_image_fm [simp]:
   902    "[| x \<in> nat; y \<in> nat; z \<in> nat; env \<in> list(A)|]
   903     ==> sats(A, image_fm(x,y,z), env) <-> 
   904         image(**A, nth(x,env), nth(y,env), nth(z,env))"
   905 by (simp add: image_fm_def Relative.image_def)
   906 
   907 lemma image_iff_sats:
   908       "[| nth(i,env) = x; nth(j,env) = y; nth(k,env) = z; 
   909           i \<in> nat; j \<in> nat; k \<in> nat; env \<in> list(A)|]
   910        ==> image(**A, x, y, z) <-> sats(A, image_fm(i,j,k), env)"
   911 by (simp add: sats_image_fm)
   912 
   913 theorem image_reflection:
   914      "REFLECTS[\<lambda>x. image(L,f(x),g(x),h(x)), 
   915                \<lambda>i x. image(**Lset(i),f(x),g(x),h(x))]"
   916 apply (simp only: Relative.image_def setclass_simps)
   917 apply (intro FOL_reflections pair_reflection)  
   918 done
   919 
   920 
   921 subsubsection{*Pre-Image under a Relation, Internalized*}
   922 
   923 (* "pre_image(M,r,A,z) == 
   924 	\<forall>x[M]. x \<in> z <-> (\<exists>w[M]. w\<in>r & (\<exists>y[M]. y\<in>A & pair(M,x,y,w)))" *)
   925 constdefs pre_image_fm :: "[i,i,i]=>i"
   926     "pre_image_fm(r,A,z) == 
   927        Forall(Iff(Member(0,succ(z)),
   928                   Exists(And(Member(0,succ(succ(r))),
   929                              Exists(And(Member(0,succ(succ(succ(A)))),
   930 	 			        pair_fm(2,0,1)))))))"
   931 
   932 lemma pre_image_type [TC]:
   933      "[| x \<in> nat; y \<in> nat; z \<in> nat |] ==> pre_image_fm(x,y,z) \<in> formula"
   934 by (simp add: pre_image_fm_def) 
   935 
   936 lemma arity_pre_image_fm [simp]:
   937      "[| x \<in> nat; y \<in> nat; z \<in> nat |] 
   938       ==> arity(pre_image_fm(x,y,z)) = succ(x) \<union> succ(y) \<union> succ(z)"
   939 by (simp add: pre_image_fm_def succ_Un_distrib [symmetric] Un_ac) 
   940 
   941 lemma sats_pre_image_fm [simp]:
   942    "[| x \<in> nat; y \<in> nat; z \<in> nat; env \<in> list(A)|]
   943     ==> sats(A, pre_image_fm(x,y,z), env) <-> 
   944         pre_image(**A, nth(x,env), nth(y,env), nth(z,env))"
   945 by (simp add: pre_image_fm_def Relative.pre_image_def)
   946 
   947 lemma pre_image_iff_sats:
   948       "[| nth(i,env) = x; nth(j,env) = y; nth(k,env) = z; 
   949           i \<in> nat; j \<in> nat; k \<in> nat; env \<in> list(A)|]
   950        ==> pre_image(**A, x, y, z) <-> sats(A, pre_image_fm(i,j,k), env)"
   951 by (simp add: sats_pre_image_fm)
   952 
   953 theorem pre_image_reflection:
   954      "REFLECTS[\<lambda>x. pre_image(L,f(x),g(x),h(x)), 
   955                \<lambda>i x. pre_image(**Lset(i),f(x),g(x),h(x))]"
   956 apply (simp only: Relative.pre_image_def setclass_simps)
   957 apply (intro FOL_reflections pair_reflection)  
   958 done
   959 
   960 
   961 subsubsection{*Function Application, Internalized*}
   962 
   963 (* "fun_apply(M,f,x,y) == 
   964         (\<exists>xs[M]. \<exists>fxs[M]. 
   965          upair(M,x,x,xs) & image(M,f,xs,fxs) & big_union(M,fxs,y))" *)
   966 constdefs fun_apply_fm :: "[i,i,i]=>i"
   967     "fun_apply_fm(f,x,y) == 
   968        Exists(Exists(And(upair_fm(succ(succ(x)), succ(succ(x)), 1),
   969                          And(image_fm(succ(succ(f)), 1, 0), 
   970                              big_union_fm(0,succ(succ(y)))))))"
   971 
   972 lemma fun_apply_type [TC]:
   973      "[| x \<in> nat; y \<in> nat; z \<in> nat |] ==> fun_apply_fm(x,y,z) \<in> formula"
   974 by (simp add: fun_apply_fm_def) 
   975 
   976 lemma arity_fun_apply_fm [simp]:
   977      "[| x \<in> nat; y \<in> nat; z \<in> nat |] 
   978       ==> arity(fun_apply_fm(x,y,z)) = succ(x) \<union> succ(y) \<union> succ(z)"
   979 by (simp add: fun_apply_fm_def succ_Un_distrib [symmetric] Un_ac) 
   980 
   981 lemma sats_fun_apply_fm [simp]:
   982    "[| x \<in> nat; y \<in> nat; z \<in> nat; env \<in> list(A)|]
   983     ==> sats(A, fun_apply_fm(x,y,z), env) <-> 
   984         fun_apply(**A, nth(x,env), nth(y,env), nth(z,env))"
   985 by (simp add: fun_apply_fm_def fun_apply_def)
   986 
   987 lemma fun_apply_iff_sats:
   988       "[| nth(i,env) = x; nth(j,env) = y; nth(k,env) = z; 
   989           i \<in> nat; j \<in> nat; k \<in> nat; env \<in> list(A)|]
   990        ==> fun_apply(**A, x, y, z) <-> sats(A, fun_apply_fm(i,j,k), env)"
   991 by simp
   992 
   993 theorem fun_apply_reflection:
   994      "REFLECTS[\<lambda>x. fun_apply(L,f(x),g(x),h(x)), 
   995                \<lambda>i x. fun_apply(**Lset(i),f(x),g(x),h(x))]" 
   996 apply (simp only: fun_apply_def setclass_simps)
   997 apply (intro FOL_reflections upair_reflection image_reflection
   998              big_union_reflection)  
   999 done
  1000 
  1001 
  1002 subsubsection{*The Concept of Relation, Internalized*}
  1003 
  1004 (* "is_relation(M,r) == 
  1005         (\<forall>z[M]. z\<in>r --> (\<exists>x[M]. \<exists>y[M]. pair(M,x,y,z)))" *)
  1006 constdefs relation_fm :: "i=>i"
  1007     "relation_fm(r) == 
  1008        Forall(Implies(Member(0,succ(r)), Exists(Exists(pair_fm(1,0,2)))))"
  1009 
  1010 lemma relation_type [TC]:
  1011      "[| x \<in> nat |] ==> relation_fm(x) \<in> formula"
  1012 by (simp add: relation_fm_def) 
  1013 
  1014 lemma arity_relation_fm [simp]:
  1015      "x \<in> nat ==> arity(relation_fm(x)) = succ(x)"
  1016 by (simp add: relation_fm_def succ_Un_distrib [symmetric] Un_ac) 
  1017 
  1018 lemma sats_relation_fm [simp]:
  1019    "[| x \<in> nat; env \<in> list(A)|]
  1020     ==> sats(A, relation_fm(x), env) <-> is_relation(**A, nth(x,env))"
  1021 by (simp add: relation_fm_def is_relation_def)
  1022 
  1023 lemma relation_iff_sats:
  1024       "[| nth(i,env) = x; nth(j,env) = y; 
  1025           i \<in> nat; env \<in> list(A)|]
  1026        ==> is_relation(**A, x) <-> sats(A, relation_fm(i), env)"
  1027 by simp
  1028 
  1029 theorem is_relation_reflection:
  1030      "REFLECTS[\<lambda>x. is_relation(L,f(x)), 
  1031                \<lambda>i x. is_relation(**Lset(i),f(x))]"
  1032 apply (simp only: is_relation_def setclass_simps)
  1033 apply (intro FOL_reflections pair_reflection)  
  1034 done
  1035 
  1036 
  1037 subsubsection{*The Concept of Function, Internalized*}
  1038 
  1039 (* "is_function(M,r) == 
  1040 	\<forall>x[M]. \<forall>y[M]. \<forall>y'[M]. \<forall>p[M]. \<forall>p'[M]. 
  1041            pair(M,x,y,p) --> pair(M,x,y',p') --> p\<in>r --> p'\<in>r --> y=y'" *)
  1042 constdefs function_fm :: "i=>i"
  1043     "function_fm(r) == 
  1044        Forall(Forall(Forall(Forall(Forall(
  1045          Implies(pair_fm(4,3,1),
  1046                  Implies(pair_fm(4,2,0),
  1047                          Implies(Member(1,r#+5),
  1048                                  Implies(Member(0,r#+5), Equal(3,2))))))))))"
  1049 
  1050 lemma function_type [TC]:
  1051      "[| x \<in> nat |] ==> function_fm(x) \<in> formula"
  1052 by (simp add: function_fm_def) 
  1053 
  1054 lemma arity_function_fm [simp]:
  1055      "x \<in> nat ==> arity(function_fm(x)) = succ(x)"
  1056 by (simp add: function_fm_def succ_Un_distrib [symmetric] Un_ac) 
  1057 
  1058 lemma sats_function_fm [simp]:
  1059    "[| x \<in> nat; env \<in> list(A)|]
  1060     ==> sats(A, function_fm(x), env) <-> is_function(**A, nth(x,env))"
  1061 by (simp add: function_fm_def is_function_def)
  1062 
  1063 lemma function_iff_sats:
  1064       "[| nth(i,env) = x; nth(j,env) = y; 
  1065           i \<in> nat; env \<in> list(A)|]
  1066        ==> is_function(**A, x) <-> sats(A, function_fm(i), env)"
  1067 by simp
  1068 
  1069 theorem is_function_reflection:
  1070      "REFLECTS[\<lambda>x. is_function(L,f(x)), 
  1071                \<lambda>i x. is_function(**Lset(i),f(x))]"
  1072 apply (simp only: is_function_def setclass_simps)
  1073 apply (intro FOL_reflections pair_reflection)  
  1074 done
  1075 
  1076 
  1077 subsubsection{*Typed Functions, Internalized*}
  1078 
  1079 (* "typed_function(M,A,B,r) == 
  1080         is_function(M,r) & is_relation(M,r) & is_domain(M,r,A) &
  1081         (\<forall>u[M]. u\<in>r --> (\<forall>x[M]. \<forall>y[M]. pair(M,x,y,u) --> y\<in>B))" *)
  1082 
  1083 constdefs typed_function_fm :: "[i,i,i]=>i"
  1084     "typed_function_fm(A,B,r) == 
  1085        And(function_fm(r),
  1086          And(relation_fm(r),
  1087            And(domain_fm(r,A),
  1088              Forall(Implies(Member(0,succ(r)),
  1089                   Forall(Forall(Implies(pair_fm(1,0,2),Member(0,B#+3)))))))))"
  1090 
  1091 lemma typed_function_type [TC]:
  1092      "[| x \<in> nat; y \<in> nat; z \<in> nat |] ==> typed_function_fm(x,y,z) \<in> formula"
  1093 by (simp add: typed_function_fm_def) 
  1094 
  1095 lemma arity_typed_function_fm [simp]:
  1096      "[| x \<in> nat; y \<in> nat; z \<in> nat |] 
  1097       ==> arity(typed_function_fm(x,y,z)) = succ(x) \<union> succ(y) \<union> succ(z)"
  1098 by (simp add: typed_function_fm_def succ_Un_distrib [symmetric] Un_ac) 
  1099 
  1100 lemma sats_typed_function_fm [simp]:
  1101    "[| x \<in> nat; y \<in> nat; z \<in> nat; env \<in> list(A)|]
  1102     ==> sats(A, typed_function_fm(x,y,z), env) <-> 
  1103         typed_function(**A, nth(x,env), nth(y,env), nth(z,env))"
  1104 by (simp add: typed_function_fm_def typed_function_def)
  1105 
  1106 lemma typed_function_iff_sats:
  1107   "[| nth(i,env) = x; nth(j,env) = y; nth(k,env) = z; 
  1108       i \<in> nat; j \<in> nat; k \<in> nat; env \<in> list(A)|]
  1109    ==> typed_function(**A, x, y, z) <-> sats(A, typed_function_fm(i,j,k), env)"
  1110 by simp
  1111 
  1112 lemmas function_reflections = 
  1113         empty_reflection number1_reflection
  1114 	upair_reflection pair_reflection union_reflection
  1115 	big_union_reflection cons_reflection successor_reflection 
  1116         fun_apply_reflection subset_reflection
  1117 	transitive_set_reflection membership_reflection
  1118 	pred_set_reflection domain_reflection range_reflection field_reflection
  1119         image_reflection pre_image_reflection
  1120 	is_relation_reflection is_function_reflection
  1121 
  1122 lemmas function_iff_sats = 
  1123         empty_iff_sats number1_iff_sats 
  1124 	upair_iff_sats pair_iff_sats union_iff_sats
  1125 	cons_iff_sats successor_iff_sats
  1126         fun_apply_iff_sats  Memrel_iff_sats
  1127 	pred_set_iff_sats domain_iff_sats range_iff_sats field_iff_sats
  1128         image_iff_sats pre_image_iff_sats 
  1129 	relation_iff_sats function_iff_sats
  1130 
  1131 
  1132 theorem typed_function_reflection:
  1133      "REFLECTS[\<lambda>x. typed_function(L,f(x),g(x),h(x)), 
  1134                \<lambda>i x. typed_function(**Lset(i),f(x),g(x),h(x))]"
  1135 apply (simp only: typed_function_def setclass_simps)
  1136 apply (intro FOL_reflections function_reflections)  
  1137 done
  1138 
  1139 
  1140 subsubsection{*Composition of Relations, Internalized*}
  1141 
  1142 (* "composition(M,r,s,t) == 
  1143         \<forall>p[M]. p \<in> t <-> 
  1144                (\<exists>x[M]. \<exists>y[M]. \<exists>z[M]. \<exists>xy[M]. \<exists>yz[M]. 
  1145                 pair(M,x,z,p) & pair(M,x,y,xy) & pair(M,y,z,yz) & 
  1146                 xy \<in> s & yz \<in> r)" *)
  1147 constdefs composition_fm :: "[i,i,i]=>i"
  1148   "composition_fm(r,s,t) == 
  1149      Forall(Iff(Member(0,succ(t)),
  1150              Exists(Exists(Exists(Exists(Exists( 
  1151               And(pair_fm(4,2,5),
  1152                And(pair_fm(4,3,1),
  1153                 And(pair_fm(3,2,0),
  1154                  And(Member(1,s#+6), Member(0,r#+6))))))))))))"
  1155 
  1156 lemma composition_type [TC]:
  1157      "[| x \<in> nat; y \<in> nat; z \<in> nat |] ==> composition_fm(x,y,z) \<in> formula"
  1158 by (simp add: composition_fm_def) 
  1159 
  1160 lemma arity_composition_fm [simp]:
  1161      "[| x \<in> nat; y \<in> nat; z \<in> nat |] 
  1162       ==> arity(composition_fm(x,y,z)) = succ(x) \<union> succ(y) \<union> succ(z)"
  1163 by (simp add: composition_fm_def succ_Un_distrib [symmetric] Un_ac) 
  1164 
  1165 lemma sats_composition_fm [simp]:
  1166    "[| x \<in> nat; y \<in> nat; z \<in> nat; env \<in> list(A)|]
  1167     ==> sats(A, composition_fm(x,y,z), env) <-> 
  1168         composition(**A, nth(x,env), nth(y,env), nth(z,env))"
  1169 by (simp add: composition_fm_def composition_def)
  1170 
  1171 lemma composition_iff_sats:
  1172       "[| nth(i,env) = x; nth(j,env) = y; nth(k,env) = z; 
  1173           i \<in> nat; j \<in> nat; k \<in> nat; env \<in> list(A)|]
  1174        ==> composition(**A, x, y, z) <-> sats(A, composition_fm(i,j,k), env)"
  1175 by simp
  1176 
  1177 theorem composition_reflection:
  1178      "REFLECTS[\<lambda>x. composition(L,f(x),g(x),h(x)), 
  1179                \<lambda>i x. composition(**Lset(i),f(x),g(x),h(x))]"
  1180 apply (simp only: composition_def setclass_simps)
  1181 apply (intro FOL_reflections pair_reflection)  
  1182 done
  1183 
  1184 
  1185 subsubsection{*Injections, Internalized*}
  1186 
  1187 (* "injection(M,A,B,f) == 
  1188 	typed_function(M,A,B,f) &
  1189         (\<forall>x[M]. \<forall>x'[M]. \<forall>y[M]. \<forall>p[M]. \<forall>p'[M]. 
  1190           pair(M,x,y,p) --> pair(M,x',y,p') --> p\<in>f --> p'\<in>f --> x=x')" *)
  1191 constdefs injection_fm :: "[i,i,i]=>i"
  1192  "injection_fm(A,B,f) == 
  1193     And(typed_function_fm(A,B,f),
  1194        Forall(Forall(Forall(Forall(Forall(
  1195          Implies(pair_fm(4,2,1),
  1196                  Implies(pair_fm(3,2,0),
  1197                          Implies(Member(1,f#+5),
  1198                                  Implies(Member(0,f#+5), Equal(4,3)))))))))))"
  1199 
  1200 
  1201 lemma injection_type [TC]:
  1202      "[| x \<in> nat; y \<in> nat; z \<in> nat |] ==> injection_fm(x,y,z) \<in> formula"
  1203 by (simp add: injection_fm_def) 
  1204 
  1205 lemma arity_injection_fm [simp]:
  1206      "[| x \<in> nat; y \<in> nat; z \<in> nat |] 
  1207       ==> arity(injection_fm(x,y,z)) = succ(x) \<union> succ(y) \<union> succ(z)"
  1208 by (simp add: injection_fm_def succ_Un_distrib [symmetric] Un_ac) 
  1209 
  1210 lemma sats_injection_fm [simp]:
  1211    "[| x \<in> nat; y \<in> nat; z \<in> nat; env \<in> list(A)|]
  1212     ==> sats(A, injection_fm(x,y,z), env) <-> 
  1213         injection(**A, nth(x,env), nth(y,env), nth(z,env))"
  1214 by (simp add: injection_fm_def injection_def)
  1215 
  1216 lemma injection_iff_sats:
  1217   "[| nth(i,env) = x; nth(j,env) = y; nth(k,env) = z; 
  1218       i \<in> nat; j \<in> nat; k \<in> nat; env \<in> list(A)|]
  1219    ==> injection(**A, x, y, z) <-> sats(A, injection_fm(i,j,k), env)"
  1220 by simp
  1221 
  1222 theorem injection_reflection:
  1223      "REFLECTS[\<lambda>x. injection(L,f(x),g(x),h(x)), 
  1224                \<lambda>i x. injection(**Lset(i),f(x),g(x),h(x))]"
  1225 apply (simp only: injection_def setclass_simps)
  1226 apply (intro FOL_reflections function_reflections typed_function_reflection)  
  1227 done
  1228 
  1229 
  1230 subsubsection{*Surjections, Internalized*}
  1231 
  1232 (*  surjection :: "[i=>o,i,i,i] => o"
  1233     "surjection(M,A,B,f) == 
  1234         typed_function(M,A,B,f) &
  1235         (\<forall>y[M]. y\<in>B --> (\<exists>x[M]. x\<in>A & fun_apply(M,f,x,y)))" *)
  1236 constdefs surjection_fm :: "[i,i,i]=>i"
  1237  "surjection_fm(A,B,f) == 
  1238     And(typed_function_fm(A,B,f),
  1239        Forall(Implies(Member(0,succ(B)),
  1240                       Exists(And(Member(0,succ(succ(A))),
  1241                                  fun_apply_fm(succ(succ(f)),0,1))))))"
  1242 
  1243 lemma surjection_type [TC]:
  1244      "[| x \<in> nat; y \<in> nat; z \<in> nat |] ==> surjection_fm(x,y,z) \<in> formula"
  1245 by (simp add: surjection_fm_def) 
  1246 
  1247 lemma arity_surjection_fm [simp]:
  1248      "[| x \<in> nat; y \<in> nat; z \<in> nat |] 
  1249       ==> arity(surjection_fm(x,y,z)) = succ(x) \<union> succ(y) \<union> succ(z)"
  1250 by (simp add: surjection_fm_def succ_Un_distrib [symmetric] Un_ac) 
  1251 
  1252 lemma sats_surjection_fm [simp]:
  1253    "[| x \<in> nat; y \<in> nat; z \<in> nat; env \<in> list(A)|]
  1254     ==> sats(A, surjection_fm(x,y,z), env) <-> 
  1255         surjection(**A, nth(x,env), nth(y,env), nth(z,env))"
  1256 by (simp add: surjection_fm_def surjection_def)
  1257 
  1258 lemma surjection_iff_sats:
  1259   "[| nth(i,env) = x; nth(j,env) = y; nth(k,env) = z; 
  1260       i \<in> nat; j \<in> nat; k \<in> nat; env \<in> list(A)|]
  1261    ==> surjection(**A, x, y, z) <-> sats(A, surjection_fm(i,j,k), env)"
  1262 by simp
  1263 
  1264 theorem surjection_reflection:
  1265      "REFLECTS[\<lambda>x. surjection(L,f(x),g(x),h(x)), 
  1266                \<lambda>i x. surjection(**Lset(i),f(x),g(x),h(x))]"
  1267 apply (simp only: surjection_def setclass_simps)
  1268 apply (intro FOL_reflections function_reflections typed_function_reflection)  
  1269 done
  1270 
  1271 
  1272 
  1273 subsubsection{*Bijections, Internalized*}
  1274 
  1275 (*   bijection :: "[i=>o,i,i,i] => o"
  1276     "bijection(M,A,B,f) == injection(M,A,B,f) & surjection(M,A,B,f)" *)
  1277 constdefs bijection_fm :: "[i,i,i]=>i"
  1278  "bijection_fm(A,B,f) == And(injection_fm(A,B,f), surjection_fm(A,B,f))"
  1279 
  1280 lemma bijection_type [TC]:
  1281      "[| x \<in> nat; y \<in> nat; z \<in> nat |] ==> bijection_fm(x,y,z) \<in> formula"
  1282 by (simp add: bijection_fm_def) 
  1283 
  1284 lemma arity_bijection_fm [simp]:
  1285      "[| x \<in> nat; y \<in> nat; z \<in> nat |] 
  1286       ==> arity(bijection_fm(x,y,z)) = succ(x) \<union> succ(y) \<union> succ(z)"
  1287 by (simp add: bijection_fm_def succ_Un_distrib [symmetric] Un_ac) 
  1288 
  1289 lemma sats_bijection_fm [simp]:
  1290    "[| x \<in> nat; y \<in> nat; z \<in> nat; env \<in> list(A)|]
  1291     ==> sats(A, bijection_fm(x,y,z), env) <-> 
  1292         bijection(**A, nth(x,env), nth(y,env), nth(z,env))"
  1293 by (simp add: bijection_fm_def bijection_def)
  1294 
  1295 lemma bijection_iff_sats:
  1296   "[| nth(i,env) = x; nth(j,env) = y; nth(k,env) = z; 
  1297       i \<in> nat; j \<in> nat; k \<in> nat; env \<in> list(A)|]
  1298    ==> bijection(**A, x, y, z) <-> sats(A, bijection_fm(i,j,k), env)"
  1299 by simp
  1300 
  1301 theorem bijection_reflection:
  1302      "REFLECTS[\<lambda>x. bijection(L,f(x),g(x),h(x)), 
  1303                \<lambda>i x. bijection(**Lset(i),f(x),g(x),h(x))]"
  1304 apply (simp only: bijection_def setclass_simps)
  1305 apply (intro And_reflection injection_reflection surjection_reflection)  
  1306 done
  1307 
  1308 
  1309 subsubsection{*Restriction of a Relation, Internalized*}
  1310 
  1311 
  1312 (* "restriction(M,r,A,z) == 
  1313 	\<forall>x[M]. x \<in> z <-> (x \<in> r & (\<exists>u[M]. u\<in>A & (\<exists>v[M]. pair(M,u,v,x))))" *)
  1314 constdefs restriction_fm :: "[i,i,i]=>i"
  1315     "restriction_fm(r,A,z) == 
  1316        Forall(Iff(Member(0,succ(z)),
  1317                   And(Member(0,succ(r)),
  1318                       Exists(And(Member(0,succ(succ(A))),
  1319                                  Exists(pair_fm(1,0,2)))))))"
  1320 
  1321 lemma restriction_type [TC]:
  1322      "[| x \<in> nat; y \<in> nat; z \<in> nat |] ==> restriction_fm(x,y,z) \<in> formula"
  1323 by (simp add: restriction_fm_def) 
  1324 
  1325 lemma arity_restriction_fm [simp]:
  1326      "[| x \<in> nat; y \<in> nat; z \<in> nat |] 
  1327       ==> arity(restriction_fm(x,y,z)) = succ(x) \<union> succ(y) \<union> succ(z)"
  1328 by (simp add: restriction_fm_def succ_Un_distrib [symmetric] Un_ac) 
  1329 
  1330 lemma sats_restriction_fm [simp]:
  1331    "[| x \<in> nat; y \<in> nat; z \<in> nat; env \<in> list(A)|]
  1332     ==> sats(A, restriction_fm(x,y,z), env) <-> 
  1333         restriction(**A, nth(x,env), nth(y,env), nth(z,env))"
  1334 by (simp add: restriction_fm_def restriction_def)
  1335 
  1336 lemma restriction_iff_sats:
  1337       "[| nth(i,env) = x; nth(j,env) = y; nth(k,env) = z; 
  1338           i \<in> nat; j \<in> nat; k \<in> nat; env \<in> list(A)|]
  1339        ==> restriction(**A, x, y, z) <-> sats(A, restriction_fm(i,j,k), env)"
  1340 by simp
  1341 
  1342 theorem restriction_reflection:
  1343      "REFLECTS[\<lambda>x. restriction(L,f(x),g(x),h(x)), 
  1344                \<lambda>i x. restriction(**Lset(i),f(x),g(x),h(x))]"
  1345 apply (simp only: restriction_def setclass_simps)
  1346 apply (intro FOL_reflections pair_reflection)  
  1347 done
  1348 
  1349 subsubsection{*Order-Isomorphisms, Internalized*}
  1350 
  1351 (*  order_isomorphism :: "[i=>o,i,i,i,i,i] => o"
  1352    "order_isomorphism(M,A,r,B,s,f) == 
  1353         bijection(M,A,B,f) & 
  1354         (\<forall>x[M]. x\<in>A --> (\<forall>y[M]. y\<in>A -->
  1355           (\<forall>p[M]. \<forall>fx[M]. \<forall>fy[M]. \<forall>q[M].
  1356             pair(M,x,y,p) --> fun_apply(M,f,x,fx) --> fun_apply(M,f,y,fy) --> 
  1357             pair(M,fx,fy,q) --> (p\<in>r <-> q\<in>s))))"
  1358   *)
  1359 
  1360 constdefs order_isomorphism_fm :: "[i,i,i,i,i]=>i"
  1361  "order_isomorphism_fm(A,r,B,s,f) == 
  1362    And(bijection_fm(A,B,f), 
  1363      Forall(Implies(Member(0,succ(A)),
  1364        Forall(Implies(Member(0,succ(succ(A))),
  1365          Forall(Forall(Forall(Forall(
  1366            Implies(pair_fm(5,4,3),
  1367              Implies(fun_apply_fm(f#+6,5,2),
  1368                Implies(fun_apply_fm(f#+6,4,1),
  1369                  Implies(pair_fm(2,1,0), 
  1370                    Iff(Member(3,r#+6), Member(0,s#+6)))))))))))))))"
  1371 
  1372 lemma order_isomorphism_type [TC]:
  1373      "[| A \<in> nat; r \<in> nat; B \<in> nat; s \<in> nat; f \<in> nat |]  
  1374       ==> order_isomorphism_fm(A,r,B,s,f) \<in> formula"
  1375 by (simp add: order_isomorphism_fm_def) 
  1376 
  1377 lemma arity_order_isomorphism_fm [simp]:
  1378      "[| A \<in> nat; r \<in> nat; B \<in> nat; s \<in> nat; f \<in> nat |] 
  1379       ==> arity(order_isomorphism_fm(A,r,B,s,f)) = 
  1380           succ(A) \<union> succ(r) \<union> succ(B) \<union> succ(s) \<union> succ(f)" 
  1381 by (simp add: order_isomorphism_fm_def succ_Un_distrib [symmetric] Un_ac) 
  1382 
  1383 lemma sats_order_isomorphism_fm [simp]:
  1384    "[| U \<in> nat; r \<in> nat; B \<in> nat; s \<in> nat; f \<in> nat; env \<in> list(A)|]
  1385     ==> sats(A, order_isomorphism_fm(U,r,B,s,f), env) <-> 
  1386         order_isomorphism(**A, nth(U,env), nth(r,env), nth(B,env), 
  1387                                nth(s,env), nth(f,env))"
  1388 by (simp add: order_isomorphism_fm_def order_isomorphism_def)
  1389 
  1390 lemma order_isomorphism_iff_sats:
  1391   "[| nth(i,env) = U; nth(j,env) = r; nth(k,env) = B; nth(j',env) = s; 
  1392       nth(k',env) = f; 
  1393       i \<in> nat; j \<in> nat; k \<in> nat; j' \<in> nat; k' \<in> nat; env \<in> list(A)|]
  1394    ==> order_isomorphism(**A,U,r,B,s,f) <-> 
  1395        sats(A, order_isomorphism_fm(i,j,k,j',k'), env)" 
  1396 by simp
  1397 
  1398 theorem order_isomorphism_reflection:
  1399      "REFLECTS[\<lambda>x. order_isomorphism(L,f(x),g(x),h(x),g'(x),h'(x)), 
  1400                \<lambda>i x. order_isomorphism(**Lset(i),f(x),g(x),h(x),g'(x),h'(x))]"
  1401 apply (simp only: order_isomorphism_def setclass_simps)
  1402 apply (intro FOL_reflections function_reflections bijection_reflection)  
  1403 done
  1404 
  1405 subsubsection{*Limit Ordinals, Internalized*}
  1406 
  1407 text{*A limit ordinal is a non-empty, successor-closed ordinal*}
  1408 
  1409 (* "limit_ordinal(M,a) == 
  1410 	ordinal(M,a) & ~ empty(M,a) & 
  1411         (\<forall>x[M]. x\<in>a --> (\<exists>y[M]. y\<in>a & successor(M,x,y)))" *)
  1412 
  1413 constdefs limit_ordinal_fm :: "i=>i"
  1414     "limit_ordinal_fm(x) == 
  1415         And(ordinal_fm(x),
  1416             And(Neg(empty_fm(x)),
  1417 	        Forall(Implies(Member(0,succ(x)),
  1418                                Exists(And(Member(0,succ(succ(x))),
  1419                                           succ_fm(1,0)))))))"
  1420 
  1421 lemma limit_ordinal_type [TC]:
  1422      "x \<in> nat ==> limit_ordinal_fm(x) \<in> formula"
  1423 by (simp add: limit_ordinal_fm_def) 
  1424 
  1425 lemma arity_limit_ordinal_fm [simp]:
  1426      "x \<in> nat ==> arity(limit_ordinal_fm(x)) = succ(x)"
  1427 by (simp add: limit_ordinal_fm_def succ_Un_distrib [symmetric] Un_ac) 
  1428 
  1429 lemma sats_limit_ordinal_fm [simp]:
  1430    "[| x \<in> nat; env \<in> list(A)|]
  1431     ==> sats(A, limit_ordinal_fm(x), env) <-> limit_ordinal(**A, nth(x,env))"
  1432 by (simp add: limit_ordinal_fm_def limit_ordinal_def sats_ordinal_fm')
  1433 
  1434 lemma limit_ordinal_iff_sats:
  1435       "[| nth(i,env) = x; nth(j,env) = y; 
  1436           i \<in> nat; env \<in> list(A)|]
  1437        ==> limit_ordinal(**A, x) <-> sats(A, limit_ordinal_fm(i), env)"
  1438 by simp
  1439 
  1440 theorem limit_ordinal_reflection:
  1441      "REFLECTS[\<lambda>x. limit_ordinal(L,f(x)), 
  1442                \<lambda>i x. limit_ordinal(**Lset(i),f(x))]"
  1443 apply (simp only: limit_ordinal_def setclass_simps)
  1444 apply (intro FOL_reflections ordinal_reflection 
  1445              empty_reflection successor_reflection)  
  1446 done
  1447 
  1448 subsubsection{*Omega: The Set of Natural Numbers*}
  1449 
  1450 (* omega(M,a) == limit_ordinal(M,a) & (\<forall>x[M]. x\<in>a --> ~ limit_ordinal(M,x)) *)
  1451 constdefs omega_fm :: "i=>i"
  1452     "omega_fm(x) == 
  1453        And(limit_ordinal_fm(x),
  1454            Forall(Implies(Member(0,succ(x)),
  1455                           Neg(limit_ordinal_fm(0)))))"
  1456 
  1457 lemma omega_type [TC]:
  1458      "x \<in> nat ==> omega_fm(x) \<in> formula"
  1459 by (simp add: omega_fm_def) 
  1460 
  1461 lemma arity_omega_fm [simp]:
  1462      "x \<in> nat ==> arity(omega_fm(x)) = succ(x)"
  1463 by (simp add: omega_fm_def succ_Un_distrib [symmetric] Un_ac) 
  1464 
  1465 lemma sats_omega_fm [simp]:
  1466    "[| x \<in> nat; env \<in> list(A)|]
  1467     ==> sats(A, omega_fm(x), env) <-> omega(**A, nth(x,env))"
  1468 by (simp add: omega_fm_def omega_def)
  1469 
  1470 lemma omega_iff_sats:
  1471       "[| nth(i,env) = x; nth(j,env) = y; 
  1472           i \<in> nat; env \<in> list(A)|]
  1473        ==> omega(**A, x) <-> sats(A, omega_fm(i), env)"
  1474 by simp
  1475 
  1476 theorem omega_reflection:
  1477      "REFLECTS[\<lambda>x. omega(L,f(x)), 
  1478                \<lambda>i x. omega(**Lset(i),f(x))]"
  1479 apply (simp only: omega_def setclass_simps)
  1480 apply (intro FOL_reflections limit_ordinal_reflection)  
  1481 done
  1482 
  1483 
  1484 lemmas fun_plus_reflections =
  1485         typed_function_reflection composition_reflection
  1486         injection_reflection surjection_reflection
  1487         bijection_reflection restriction_reflection
  1488         order_isomorphism_reflection
  1489         ordinal_reflection limit_ordinal_reflection omega_reflection
  1490 
  1491 lemmas fun_plus_iff_sats = 
  1492 	typed_function_iff_sats composition_iff_sats
  1493         injection_iff_sats surjection_iff_sats 
  1494         bijection_iff_sats restriction_iff_sats 
  1495         order_isomorphism_iff_sats
  1496         ordinal_iff_sats limit_ordinal_iff_sats omega_iff_sats
  1497 
  1498 end