src/ZF/Constructible/L_axioms.thy
author paulson
Mon Jul 08 15:56:39 2002 +0200 (2002-07-08)
changeset 13314 84b9de3cbc91
parent 13309 a6adee8ea75a
child 13316 d16629fd0f95
permissions -rw-r--r--
Defining a meta-existential quantifier.
Using it to streamline reflection proofs.
     1 header {*The Class L Satisfies the ZF Axioms*}
     2 
     3 theory L_axioms = Formula + Relative + Reflection + MetaExists:
     4 
     5 
     6 text {* The class L satisfies the premises of locale @{text M_axioms} *}
     7 
     8 lemma transL: "[| y\<in>x; L(x) |] ==> L(y)"
     9 apply (insert Transset_Lset) 
    10 apply (simp add: Transset_def L_def, blast) 
    11 done
    12 
    13 lemma nonempty: "L(0)"
    14 apply (simp add: L_def) 
    15 apply (blast intro: zero_in_Lset) 
    16 done
    17 
    18 lemma upair_ax: "upair_ax(L)"
    19 apply (simp add: upair_ax_def upair_def, clarify)
    20 apply (rule_tac x="{x,y}" in rexI)  
    21 apply (simp_all add: doubleton_in_L) 
    22 done
    23 
    24 lemma Union_ax: "Union_ax(L)"
    25 apply (simp add: Union_ax_def big_union_def, clarify)
    26 apply (rule_tac x="Union(x)" in rexI)  
    27 apply (simp_all add: Union_in_L, auto) 
    28 apply (blast intro: transL) 
    29 done
    30 
    31 lemma power_ax: "power_ax(L)"
    32 apply (simp add: power_ax_def powerset_def Relative.subset_def, clarify)
    33 apply (rule_tac x="{y \<in> Pow(x). L(y)}" in rexI)  
    34 apply (simp_all add: LPow_in_L, auto)
    35 apply (blast intro: transL) 
    36 done
    37 
    38 subsubsection{*For L to satisfy Replacement *}
    39 
    40 (*Can't move these to Formula unless the definition of univalent is moved
    41 there too!*)
    42 
    43 lemma LReplace_in_Lset:
    44      "[|X \<in> Lset(i); univalent(L,X,Q); Ord(i)|] 
    45       ==> \<exists>j. Ord(j) & Replace(X, %x y. Q(x,y) & L(y)) \<subseteq> Lset(j)"
    46 apply (rule_tac x="\<Union>y \<in> Replace(X, %x y. Q(x,y) & L(y)). succ(lrank(y))" 
    47        in exI)
    48 apply simp
    49 apply clarify 
    50 apply (rule_tac a="x" in UN_I)  
    51  apply (simp_all add: Replace_iff univalent_def) 
    52 apply (blast dest: transL L_I) 
    53 done
    54 
    55 lemma LReplace_in_L: 
    56      "[|L(X); univalent(L,X,Q)|] 
    57       ==> \<exists>Y. L(Y) & Replace(X, %x y. Q(x,y) & L(y)) \<subseteq> Y"
    58 apply (drule L_D, clarify) 
    59 apply (drule LReplace_in_Lset, assumption+)
    60 apply (blast intro: L_I Lset_in_Lset_succ)
    61 done
    62 
    63 lemma replacement: "replacement(L,P)"
    64 apply (simp add: replacement_def, clarify)
    65 apply (frule LReplace_in_L, assumption+, clarify) 
    66 apply (rule_tac x=Y in rexI)   
    67 apply (simp_all add: Replace_iff univalent_def, blast) 
    68 done
    69 
    70 subsection{*Instantiation of the locale @{text M_triv_axioms}*}
    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 trivaxL 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", trivaxL (thm "M_triv_axioms.ball_abs"));
   100 bind_thm ("rall_abs", trivaxL (thm "M_triv_axioms.rall_abs"));
   101 bind_thm ("bex_abs", trivaxL (thm "M_triv_axioms.bex_abs"));
   102 bind_thm ("rex_abs", trivaxL (thm "M_triv_axioms.rex_abs"));
   103 bind_thm ("ball_iff_equiv", trivaxL (thm "M_triv_axioms.ball_iff_equiv"));
   104 bind_thm ("M_equalityI", trivaxL (thm "M_triv_axioms.M_equalityI"));
   105 bind_thm ("empty_abs", trivaxL (thm "M_triv_axioms.empty_abs"));
   106 bind_thm ("subset_abs", trivaxL (thm "M_triv_axioms.subset_abs"));
   107 bind_thm ("upair_abs", trivaxL (thm "M_triv_axioms.upair_abs"));
   108 bind_thm ("upair_in_M_iff", trivaxL (thm "M_triv_axioms.upair_in_M_iff"));
   109 bind_thm ("singleton_in_M_iff", trivaxL (thm "M_triv_axioms.singleton_in_M_iff"));
   110 bind_thm ("pair_abs", trivaxL (thm "M_triv_axioms.pair_abs"));
   111 bind_thm ("pair_in_M_iff", trivaxL (thm "M_triv_axioms.pair_in_M_iff"));
   112 bind_thm ("pair_components_in_M", trivaxL (thm "M_triv_axioms.pair_components_in_M"));
   113 bind_thm ("cartprod_abs", trivaxL (thm "M_triv_axioms.cartprod_abs"));
   114 bind_thm ("union_abs", trivaxL (thm "M_triv_axioms.union_abs"));
   115 bind_thm ("inter_abs", trivaxL (thm "M_triv_axioms.inter_abs"));
   116 bind_thm ("setdiff_abs", trivaxL (thm "M_triv_axioms.setdiff_abs"));
   117 bind_thm ("Union_abs", trivaxL (thm "M_triv_axioms.Union_abs"));
   118 bind_thm ("Union_closed", trivaxL (thm "M_triv_axioms.Union_closed"));
   119 bind_thm ("Un_closed", trivaxL (thm "M_triv_axioms.Un_closed"));
   120 bind_thm ("cons_closed", trivaxL (thm "M_triv_axioms.cons_closed"));
   121 bind_thm ("successor_abs", trivaxL (thm "M_triv_axioms.successor_abs"));
   122 bind_thm ("succ_in_M_iff", trivaxL (thm "M_triv_axioms.succ_in_M_iff"));
   123 bind_thm ("separation_closed", trivaxL (thm "M_triv_axioms.separation_closed"));
   124 bind_thm ("strong_replacementI", trivaxL (thm "M_triv_axioms.strong_replacementI"));
   125 bind_thm ("strong_replacement_closed", trivaxL (thm "M_triv_axioms.strong_replacement_closed"));
   126 bind_thm ("RepFun_closed", trivaxL (thm "M_triv_axioms.RepFun_closed"));
   127 bind_thm ("lam_closed", trivaxL (thm "M_triv_axioms.lam_closed"));
   128 bind_thm ("image_abs", trivaxL (thm "M_triv_axioms.image_abs"));
   129 bind_thm ("powerset_Pow", trivaxL (thm "M_triv_axioms.powerset_Pow"));
   130 bind_thm ("powerset_imp_subset_Pow", trivaxL (thm "M_triv_axioms.powerset_imp_subset_Pow"));
   131 bind_thm ("nat_into_M", trivaxL (thm "M_triv_axioms.nat_into_M"));
   132 bind_thm ("nat_case_closed", trivaxL (thm "M_triv_axioms.nat_case_closed"));
   133 bind_thm ("Inl_in_M_iff", trivaxL (thm "M_triv_axioms.Inl_in_M_iff"));
   134 bind_thm ("Inr_in_M_iff", trivaxL (thm "M_triv_axioms.Inr_in_M_iff"));
   135 bind_thm ("lt_closed", trivaxL (thm "M_triv_axioms.lt_closed"));
   136 bind_thm ("transitive_set_abs", trivaxL (thm "M_triv_axioms.transitive_set_abs"));
   137 bind_thm ("ordinal_abs", trivaxL (thm "M_triv_axioms.ordinal_abs"));
   138 bind_thm ("limit_ordinal_abs", trivaxL (thm "M_triv_axioms.limit_ordinal_abs"));
   139 bind_thm ("successor_ordinal_abs", trivaxL (thm "M_triv_axioms.successor_ordinal_abs"));
   140 bind_thm ("finite_ordinal_abs", trivaxL (thm "M_triv_axioms.finite_ordinal_abs"));
   141 bind_thm ("omega_abs", trivaxL (thm "M_triv_axioms.omega_abs"));
   142 bind_thm ("number1_abs", trivaxL (thm "M_triv_axioms.number1_abs"));
   143 bind_thm ("number1_abs", trivaxL (thm "M_triv_axioms.number1_abs"));
   144 bind_thm ("number3_abs", trivaxL (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_reflection = 
   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)
   313 apply blast 
   314 done
   315 
   316 lemma Collect_mem_eq: "{x\<in>A. x\<in>B} = A \<inter> B";
   317 by blast
   318 
   319 
   320 subsection{*Internalized formulas for some relativized ones*}
   321 
   322 lemmas setclass_simps = rall_setclass_is_ball rex_setclass_is_bex
   323 
   324 subsubsection{*Some numbers to help write de Bruijn indices*}
   325 
   326 syntax
   327     "3" :: i   ("3")
   328     "4" :: i   ("4")
   329     "5" :: i   ("5")
   330     "6" :: i   ("6")
   331     "7" :: i   ("7")
   332     "8" :: i   ("8")
   333     "9" :: i   ("9")
   334 
   335 translations
   336    "3"  == "succ(2)"
   337    "4"  == "succ(3)"
   338    "5"  == "succ(4)"
   339    "6"  == "succ(5)"
   340    "7"  == "succ(6)"
   341    "8"  == "succ(7)"
   342    "9"  == "succ(8)"
   343 
   344 subsubsection{*Unordered pairs*}
   345 
   346 constdefs upair_fm :: "[i,i,i]=>i"
   347     "upair_fm(x,y,z) == 
   348        And(Member(x,z), 
   349            And(Member(y,z),
   350                Forall(Implies(Member(0,succ(z)), 
   351                               Or(Equal(0,succ(x)), Equal(0,succ(y)))))))"
   352 
   353 lemma upair_type [TC]:
   354      "[| x \<in> nat; y \<in> nat; z \<in> nat |] ==> upair_fm(x,y,z) \<in> formula"
   355 by (simp add: upair_fm_def) 
   356 
   357 lemma arity_upair_fm [simp]:
   358      "[| x \<in> nat; y \<in> nat; z \<in> nat |] 
   359       ==> arity(upair_fm(x,y,z)) = succ(x) \<union> succ(y) \<union> succ(z)"
   360 by (simp add: upair_fm_def succ_Un_distrib [symmetric] Un_ac) 
   361 
   362 lemma sats_upair_fm [simp]:
   363    "[| x \<in> nat; y \<in> nat; z \<in> nat; env \<in> list(A)|]
   364     ==> sats(A, upair_fm(x,y,z), env) <-> 
   365             upair(**A, nth(x,env), nth(y,env), nth(z,env))"
   366 by (simp add: upair_fm_def upair_def)
   367 
   368 lemma upair_iff_sats:
   369       "[| nth(i,env) = x; nth(j,env) = y; nth(k,env) = z; 
   370           i \<in> nat; j \<in> nat; k \<in> nat; env \<in> list(A)|]
   371        ==> upair(**A, x, y, z) <-> sats(A, upair_fm(i,j,k), env)"
   372 by (simp add: sats_upair_fm)
   373 
   374 text{*Useful? At least it refers to "real" unordered pairs*}
   375 lemma sats_upair_fm2 [simp]:
   376    "[| x \<in> nat; y \<in> nat; z < length(env); env \<in> list(A); Transset(A)|]
   377     ==> sats(A, upair_fm(x,y,z), env) <-> 
   378         nth(z,env) = {nth(x,env), nth(y,env)}"
   379 apply (frule lt_length_in_nat, assumption)  
   380 apply (simp add: upair_fm_def Transset_def, auto) 
   381 apply (blast intro: nth_type) 
   382 done
   383 
   384 theorem upair_reflection:
   385      "REFLECTS[\<lambda>x. upair(L,f(x),g(x),h(x)), 
   386                \<lambda>i x. upair(**Lset(i),f(x),g(x),h(x))]" 
   387 apply (simp add: upair_def)
   388 apply (intro FOL_reflection)  
   389 done
   390 
   391 subsubsection{*Ordered pairs*}
   392 
   393 constdefs pair_fm :: "[i,i,i]=>i"
   394     "pair_fm(x,y,z) == 
   395        Exists(And(upair_fm(succ(x),succ(x),0),
   396               Exists(And(upair_fm(succ(succ(x)),succ(succ(y)),0),
   397                          upair_fm(1,0,succ(succ(z)))))))"
   398 
   399 lemma pair_type [TC]:
   400      "[| x \<in> nat; y \<in> nat; z \<in> nat |] ==> pair_fm(x,y,z) \<in> formula"
   401 by (simp add: pair_fm_def) 
   402 
   403 lemma arity_pair_fm [simp]:
   404      "[| x \<in> nat; y \<in> nat; z \<in> nat |] 
   405       ==> arity(pair_fm(x,y,z)) = succ(x) \<union> succ(y) \<union> succ(z)"
   406 by (simp add: pair_fm_def succ_Un_distrib [symmetric] Un_ac) 
   407 
   408 lemma sats_pair_fm [simp]:
   409    "[| x \<in> nat; y \<in> nat; z \<in> nat; env \<in> list(A)|]
   410     ==> sats(A, pair_fm(x,y,z), env) <-> 
   411         pair(**A, nth(x,env), nth(y,env), nth(z,env))"
   412 by (simp add: pair_fm_def pair_def)
   413 
   414 lemma pair_iff_sats:
   415       "[| nth(i,env) = x; nth(j,env) = y; nth(k,env) = z; 
   416           i \<in> nat; j \<in> nat; k \<in> nat; env \<in> list(A)|]
   417        ==> pair(**A, x, y, z) <-> sats(A, pair_fm(i,j,k), env)"
   418 by (simp add: sats_pair_fm)
   419 
   420 theorem pair_reflection:
   421      "REFLECTS[\<lambda>x. pair(L,f(x),g(x),h(x)), 
   422                \<lambda>i x. pair(**Lset(i),f(x),g(x),h(x))]"
   423 apply (simp only: pair_def setclass_simps)
   424 apply (intro FOL_reflection upair_reflection)  
   425 done
   426 
   427 
   428 subsubsection{*Binary Unions*}
   429 
   430 constdefs union_fm :: "[i,i,i]=>i"
   431     "union_fm(x,y,z) == 
   432        Forall(Iff(Member(0,succ(z)),
   433                   Or(Member(0,succ(x)),Member(0,succ(y)))))"
   434 
   435 lemma union_type [TC]:
   436      "[| x \<in> nat; y \<in> nat; z \<in> nat |] ==> union_fm(x,y,z) \<in> formula"
   437 by (simp add: union_fm_def) 
   438 
   439 lemma arity_union_fm [simp]:
   440      "[| x \<in> nat; y \<in> nat; z \<in> nat |] 
   441       ==> arity(union_fm(x,y,z)) = succ(x) \<union> succ(y) \<union> succ(z)"
   442 by (simp add: union_fm_def succ_Un_distrib [symmetric] Un_ac) 
   443 
   444 lemma sats_union_fm [simp]:
   445    "[| x \<in> nat; y \<in> nat; z \<in> nat; env \<in> list(A)|]
   446     ==> sats(A, union_fm(x,y,z), env) <-> 
   447         union(**A, nth(x,env), nth(y,env), nth(z,env))"
   448 by (simp add: union_fm_def union_def)
   449 
   450 lemma union_iff_sats:
   451       "[| nth(i,env) = x; nth(j,env) = y; nth(k,env) = z; 
   452           i \<in> nat; j \<in> nat; k \<in> nat; env \<in> list(A)|]
   453        ==> union(**A, x, y, z) <-> sats(A, union_fm(i,j,k), env)"
   454 by (simp add: sats_union_fm)
   455 
   456 theorem union_reflection:
   457      "REFLECTS[\<lambda>x. union(L,f(x),g(x),h(x)), 
   458                \<lambda>i x. union(**Lset(i),f(x),g(x),h(x))]"
   459 apply (simp only: union_def setclass_simps)
   460 apply (intro FOL_reflection)  
   461 done
   462 
   463 
   464 subsubsection{*`Cons' for sets*}
   465 
   466 constdefs cons_fm :: "[i,i,i]=>i"
   467     "cons_fm(x,y,z) == 
   468        Exists(And(upair_fm(succ(x),succ(x),0),
   469                   union_fm(0,succ(y),succ(z))))"
   470 
   471 
   472 lemma cons_type [TC]:
   473      "[| x \<in> nat; y \<in> nat; z \<in> nat |] ==> cons_fm(x,y,z) \<in> formula"
   474 by (simp add: cons_fm_def) 
   475 
   476 lemma arity_cons_fm [simp]:
   477      "[| x \<in> nat; y \<in> nat; z \<in> nat |] 
   478       ==> arity(cons_fm(x,y,z)) = succ(x) \<union> succ(y) \<union> succ(z)"
   479 by (simp add: cons_fm_def succ_Un_distrib [symmetric] Un_ac) 
   480 
   481 lemma sats_cons_fm [simp]:
   482    "[| x \<in> nat; y \<in> nat; z \<in> nat; env \<in> list(A)|]
   483     ==> sats(A, cons_fm(x,y,z), env) <-> 
   484         is_cons(**A, nth(x,env), nth(y,env), nth(z,env))"
   485 by (simp add: cons_fm_def is_cons_def)
   486 
   487 lemma cons_iff_sats:
   488       "[| nth(i,env) = x; nth(j,env) = y; nth(k,env) = z; 
   489           i \<in> nat; j \<in> nat; k \<in> nat; env \<in> list(A)|]
   490        ==> is_cons(**A, x, y, z) <-> sats(A, cons_fm(i,j,k), env)"
   491 by simp
   492 
   493 theorem cons_reflection:
   494      "REFLECTS[\<lambda>x. is_cons(L,f(x),g(x),h(x)), 
   495                \<lambda>i x. is_cons(**Lset(i),f(x),g(x),h(x))]"
   496 apply (simp only: is_cons_def setclass_simps)
   497 apply (intro FOL_reflection upair_reflection union_reflection)  
   498 done
   499 
   500 
   501 subsubsection{*Function Applications*}
   502 
   503 constdefs fun_apply_fm :: "[i,i,i]=>i"
   504     "fun_apply_fm(f,x,y) == 
   505        Forall(Iff(Exists(And(Member(0,succ(succ(f))),
   506                              pair_fm(succ(succ(x)), 1, 0))),
   507                   Equal(succ(y),0)))"
   508 
   509 lemma fun_apply_type [TC]:
   510      "[| x \<in> nat; y \<in> nat; z \<in> nat |] ==> fun_apply_fm(x,y,z) \<in> formula"
   511 by (simp add: fun_apply_fm_def) 
   512 
   513 lemma arity_fun_apply_fm [simp]:
   514      "[| x \<in> nat; y \<in> nat; z \<in> nat |] 
   515       ==> arity(fun_apply_fm(x,y,z)) = succ(x) \<union> succ(y) \<union> succ(z)"
   516 by (simp add: fun_apply_fm_def succ_Un_distrib [symmetric] Un_ac) 
   517 
   518 lemma sats_fun_apply_fm [simp]:
   519    "[| x \<in> nat; y \<in> nat; z \<in> nat; env \<in> list(A)|]
   520     ==> sats(A, fun_apply_fm(x,y,z), env) <-> 
   521         fun_apply(**A, nth(x,env), nth(y,env), nth(z,env))"
   522 by (simp add: fun_apply_fm_def fun_apply_def)
   523 
   524 lemma fun_apply_iff_sats:
   525       "[| nth(i,env) = x; nth(j,env) = y; nth(k,env) = z; 
   526           i \<in> nat; j \<in> nat; k \<in> nat; env \<in> list(A)|]
   527        ==> fun_apply(**A, x, y, z) <-> sats(A, fun_apply_fm(i,j,k), env)"
   528 by simp
   529 
   530 theorem fun_apply_reflection:
   531      "REFLECTS[\<lambda>x. fun_apply(L,f(x),g(x),h(x)), 
   532                \<lambda>i x. fun_apply(**Lset(i),f(x),g(x),h(x))]" 
   533 apply (simp only: fun_apply_def setclass_simps)
   534 apply (intro FOL_reflection pair_reflection)  
   535 done
   536 
   537 
   538 subsubsection{*Variants of Satisfaction Definitions for Ordinals, etc.*}
   539 
   540 text{*Differs from the one in Formula by using "ordinal" rather than "Ord"*}
   541 
   542 
   543 lemma sats_subset_fm':
   544    "[|x \<in> nat; y \<in> nat; env \<in> list(A)|]
   545     ==> sats(A, subset_fm(x,y), env) <-> subset(**A, nth(x,env), nth(y,env))" 
   546 by (simp add: subset_fm_def subset_def) 
   547 
   548 theorem subset_reflection:
   549      "REFLECTS[\<lambda>x. subset(L,f(x),g(x)), 
   550                \<lambda>i x. subset(**Lset(i),f(x),g(x))]" 
   551 apply (simp only: subset_def setclass_simps)
   552 apply (intro FOL_reflection)  
   553 done
   554 
   555 lemma sats_transset_fm':
   556    "[|x \<in> nat; env \<in> list(A)|]
   557     ==> sats(A, transset_fm(x), env) <-> transitive_set(**A, nth(x,env))"
   558 by (simp add: sats_subset_fm' transset_fm_def transitive_set_def) 
   559 
   560 theorem transitive_set_reflection:
   561      "REFLECTS[\<lambda>x. transitive_set(L,f(x)),
   562                \<lambda>i x. transitive_set(**Lset(i),f(x))]"
   563 apply (simp only: transitive_set_def setclass_simps)
   564 apply (intro FOL_reflection subset_reflection)  
   565 done
   566 
   567 lemma sats_ordinal_fm':
   568    "[|x \<in> nat; env \<in> list(A)|]
   569     ==> sats(A, ordinal_fm(x), env) <-> ordinal(**A,nth(x,env))"
   570 by (simp add: sats_transset_fm' ordinal_fm_def ordinal_def)
   571 
   572 lemma ordinal_iff_sats:
   573       "[| nth(i,env) = x;  i \<in> nat; env \<in> list(A)|]
   574        ==> ordinal(**A, x) <-> sats(A, ordinal_fm(i), env)"
   575 by (simp add: sats_ordinal_fm')
   576 
   577 theorem ordinal_reflection:
   578      "REFLECTS[\<lambda>x. ordinal(L,f(x)), \<lambda>i x. ordinal(**Lset(i),f(x))]"
   579 apply (simp only: ordinal_def setclass_simps)
   580 apply (intro FOL_reflection transitive_set_reflection)  
   581 done
   582 
   583 
   584 subsubsection{*Membership Relation*}
   585 
   586 constdefs Memrel_fm :: "[i,i]=>i"
   587     "Memrel_fm(A,r) == 
   588        Forall(Iff(Member(0,succ(r)),
   589                   Exists(And(Member(0,succ(succ(A))),
   590                              Exists(And(Member(0,succ(succ(succ(A)))),
   591                                         And(Member(1,0),
   592                                             pair_fm(1,0,2))))))))"
   593 
   594 lemma Memrel_type [TC]:
   595      "[| x \<in> nat; y \<in> nat |] ==> Memrel_fm(x,y) \<in> formula"
   596 by (simp add: Memrel_fm_def) 
   597 
   598 lemma arity_Memrel_fm [simp]:
   599      "[| x \<in> nat; y \<in> nat |] 
   600       ==> arity(Memrel_fm(x,y)) = succ(x) \<union> succ(y)"
   601 by (simp add: Memrel_fm_def succ_Un_distrib [symmetric] Un_ac) 
   602 
   603 lemma sats_Memrel_fm [simp]:
   604    "[| x \<in> nat; y \<in> nat; env \<in> list(A)|]
   605     ==> sats(A, Memrel_fm(x,y), env) <-> 
   606         membership(**A, nth(x,env), nth(y,env))"
   607 by (simp add: Memrel_fm_def membership_def)
   608 
   609 lemma Memrel_iff_sats:
   610       "[| nth(i,env) = x; nth(j,env) = y; 
   611           i \<in> nat; j \<in> nat; env \<in> list(A)|]
   612        ==> membership(**A, x, y) <-> sats(A, Memrel_fm(i,j), env)"
   613 by simp
   614 
   615 theorem membership_reflection:
   616      "REFLECTS[\<lambda>x. membership(L,f(x),g(x)), 
   617                \<lambda>i x. membership(**Lset(i),f(x),g(x))]"
   618 apply (simp only: membership_def setclass_simps)
   619 apply (intro FOL_reflection pair_reflection)  
   620 done
   621 
   622 subsubsection{*Predecessor Set*}
   623 
   624 constdefs pred_set_fm :: "[i,i,i,i]=>i"
   625     "pred_set_fm(A,x,r,B) == 
   626        Forall(Iff(Member(0,succ(B)),
   627                   Exists(And(Member(0,succ(succ(r))),
   628                              And(Member(1,succ(succ(A))),
   629                                  pair_fm(1,succ(succ(x)),0))))))"
   630 
   631 
   632 lemma pred_set_type [TC]:
   633      "[| A \<in> nat; x \<in> nat; r \<in> nat; B \<in> nat |] 
   634       ==> pred_set_fm(A,x,r,B) \<in> formula"
   635 by (simp add: pred_set_fm_def) 
   636 
   637 lemma arity_pred_set_fm [simp]:
   638    "[| A \<in> nat; x \<in> nat; r \<in> nat; B \<in> nat |] 
   639     ==> arity(pred_set_fm(A,x,r,B)) = succ(A) \<union> succ(x) \<union> succ(r) \<union> succ(B)"
   640 by (simp add: pred_set_fm_def succ_Un_distrib [symmetric] Un_ac) 
   641 
   642 lemma sats_pred_set_fm [simp]:
   643    "[| U \<in> nat; x \<in> nat; r \<in> nat; B \<in> nat; env \<in> list(A)|]
   644     ==> sats(A, pred_set_fm(U,x,r,B), env) <-> 
   645         pred_set(**A, nth(U,env), nth(x,env), nth(r,env), nth(B,env))"
   646 by (simp add: pred_set_fm_def pred_set_def)
   647 
   648 lemma pred_set_iff_sats:
   649       "[| nth(i,env) = U; nth(j,env) = x; nth(k,env) = r; nth(l,env) = B; 
   650           i \<in> nat; j \<in> nat; k \<in> nat; l \<in> nat; env \<in> list(A)|]
   651        ==> pred_set(**A,U,x,r,B) <-> sats(A, pred_set_fm(i,j,k,l), env)"
   652 by (simp add: sats_pred_set_fm)
   653 
   654 theorem pred_set_reflection:
   655      "REFLECTS[\<lambda>x. pred_set(L,f(x),g(x),h(x),b(x)), 
   656                \<lambda>i x. pred_set(**Lset(i),f(x),g(x),h(x),b(x))]" 
   657 apply (simp only: pred_set_def setclass_simps)
   658 apply (intro FOL_reflection pair_reflection)  
   659 done
   660 
   661 
   662 
   663 subsubsection{*Domain*}
   664 
   665 (* "is_domain(M,r,z) == 
   666 	\<forall>x[M]. (x \<in> z <-> (\<exists>w[M]. w\<in>r & (\<exists>y[M]. pair(M,x,y,w))))" *)
   667 constdefs domain_fm :: "[i,i]=>i"
   668     "domain_fm(r,z) == 
   669        Forall(Iff(Member(0,succ(z)),
   670                   Exists(And(Member(0,succ(succ(r))),
   671                              Exists(pair_fm(2,0,1))))))"
   672 
   673 lemma domain_type [TC]:
   674      "[| x \<in> nat; y \<in> nat |] ==> domain_fm(x,y) \<in> formula"
   675 by (simp add: domain_fm_def) 
   676 
   677 lemma arity_domain_fm [simp]:
   678      "[| x \<in> nat; y \<in> nat |] 
   679       ==> arity(domain_fm(x,y)) = succ(x) \<union> succ(y)"
   680 by (simp add: domain_fm_def succ_Un_distrib [symmetric] Un_ac) 
   681 
   682 lemma sats_domain_fm [simp]:
   683    "[| x \<in> nat; y \<in> nat; env \<in> list(A)|]
   684     ==> sats(A, domain_fm(x,y), env) <-> 
   685         is_domain(**A, nth(x,env), nth(y,env))"
   686 by (simp add: domain_fm_def is_domain_def)
   687 
   688 lemma domain_iff_sats:
   689       "[| nth(i,env) = x; nth(j,env) = y; 
   690           i \<in> nat; j \<in> nat; env \<in> list(A)|]
   691        ==> is_domain(**A, x, y) <-> sats(A, domain_fm(i,j), env)"
   692 by simp
   693 
   694 theorem domain_reflection:
   695      "REFLECTS[\<lambda>x. is_domain(L,f(x),g(x)), 
   696                \<lambda>i x. is_domain(**Lset(i),f(x),g(x))]"
   697 apply (simp only: is_domain_def setclass_simps)
   698 apply (intro FOL_reflection pair_reflection)  
   699 done
   700 
   701 
   702 subsubsection{*Range*}
   703 
   704 (* "is_range(M,r,z) == 
   705 	\<forall>y[M]. (y \<in> z <-> (\<exists>w[M]. w\<in>r & (\<exists>x[M]. pair(M,x,y,w))))" *)
   706 constdefs range_fm :: "[i,i]=>i"
   707     "range_fm(r,z) == 
   708        Forall(Iff(Member(0,succ(z)),
   709                   Exists(And(Member(0,succ(succ(r))),
   710                              Exists(pair_fm(0,2,1))))))"
   711 
   712 lemma range_type [TC]:
   713      "[| x \<in> nat; y \<in> nat |] ==> range_fm(x,y) \<in> formula"
   714 by (simp add: range_fm_def) 
   715 
   716 lemma arity_range_fm [simp]:
   717      "[| x \<in> nat; y \<in> nat |] 
   718       ==> arity(range_fm(x,y)) = succ(x) \<union> succ(y)"
   719 by (simp add: range_fm_def succ_Un_distrib [symmetric] Un_ac) 
   720 
   721 lemma sats_range_fm [simp]:
   722    "[| x \<in> nat; y \<in> nat; env \<in> list(A)|]
   723     ==> sats(A, range_fm(x,y), env) <-> 
   724         is_range(**A, nth(x,env), nth(y,env))"
   725 by (simp add: range_fm_def is_range_def)
   726 
   727 lemma range_iff_sats:
   728       "[| nth(i,env) = x; nth(j,env) = y; 
   729           i \<in> nat; j \<in> nat; env \<in> list(A)|]
   730        ==> is_range(**A, x, y) <-> sats(A, range_fm(i,j), env)"
   731 by simp
   732 
   733 theorem range_reflection:
   734      "REFLECTS[\<lambda>x. is_range(L,f(x),g(x)), 
   735                \<lambda>i x. is_range(**Lset(i),f(x),g(x))]"
   736 apply (simp only: is_range_def setclass_simps)
   737 apply (intro FOL_reflection pair_reflection)  
   738 done
   739 
   740  
   741 subsubsection{*Image*}
   742 
   743 (* "image(M,r,A,z) == 
   744         \<forall>y[M]. (y \<in> z <-> (\<exists>w[M]. w\<in>r & (\<exists>x[M]. x\<in>A & pair(M,x,y,w))))" *)
   745 constdefs image_fm :: "[i,i,i]=>i"
   746     "image_fm(r,A,z) == 
   747        Forall(Iff(Member(0,succ(z)),
   748                   Exists(And(Member(0,succ(succ(r))),
   749                              Exists(And(Member(0,succ(succ(succ(A)))),
   750 	 			        pair_fm(0,2,1)))))))"
   751 
   752 lemma image_type [TC]:
   753      "[| x \<in> nat; y \<in> nat; z \<in> nat |] ==> image_fm(x,y,z) \<in> formula"
   754 by (simp add: image_fm_def) 
   755 
   756 lemma arity_image_fm [simp]:
   757      "[| x \<in> nat; y \<in> nat; z \<in> nat |] 
   758       ==> arity(image_fm(x,y,z)) = succ(x) \<union> succ(y) \<union> succ(z)"
   759 by (simp add: image_fm_def succ_Un_distrib [symmetric] Un_ac) 
   760 
   761 lemma sats_image_fm [simp]:
   762    "[| x \<in> nat; y \<in> nat; z \<in> nat; env \<in> list(A)|]
   763     ==> sats(A, image_fm(x,y,z), env) <-> 
   764         image(**A, nth(x,env), nth(y,env), nth(z,env))"
   765 by (simp add: image_fm_def image_def)
   766 
   767 lemma image_iff_sats:
   768       "[| nth(i,env) = x; nth(j,env) = y; nth(k,env) = z; 
   769           i \<in> nat; j \<in> nat; k \<in> nat; env \<in> list(A)|]
   770        ==> image(**A, x, y, z) <-> sats(A, image_fm(i,j,k), env)"
   771 by (simp add: sats_image_fm)
   772 
   773 theorem image_reflection:
   774      "REFLECTS[\<lambda>x. image(L,f(x),g(x),h(x)), 
   775                \<lambda>i x. image(**Lset(i),f(x),g(x),h(x))]"
   776 apply (simp only: image_def setclass_simps)
   777 apply (intro FOL_reflection pair_reflection)  
   778 done
   779 
   780 
   781 subsubsection{*The Concept of Relation*}
   782 
   783 (* "is_relation(M,r) == 
   784         (\<forall>z[M]. z\<in>r --> (\<exists>x[M]. \<exists>y[M]. pair(M,x,y,z)))" *)
   785 constdefs relation_fm :: "i=>i"
   786     "relation_fm(r) == 
   787        Forall(Implies(Member(0,succ(r)), Exists(Exists(pair_fm(1,0,2)))))"
   788 
   789 lemma relation_type [TC]:
   790      "[| x \<in> nat |] ==> relation_fm(x) \<in> formula"
   791 by (simp add: relation_fm_def) 
   792 
   793 lemma arity_relation_fm [simp]:
   794      "x \<in> nat ==> arity(relation_fm(x)) = succ(x)"
   795 by (simp add: relation_fm_def succ_Un_distrib [symmetric] Un_ac) 
   796 
   797 lemma sats_relation_fm [simp]:
   798    "[| x \<in> nat; env \<in> list(A)|]
   799     ==> sats(A, relation_fm(x), env) <-> is_relation(**A, nth(x,env))"
   800 by (simp add: relation_fm_def is_relation_def)
   801 
   802 lemma relation_iff_sats:
   803       "[| nth(i,env) = x; nth(j,env) = y; 
   804           i \<in> nat; env \<in> list(A)|]
   805        ==> is_relation(**A, x) <-> sats(A, relation_fm(i), env)"
   806 by simp
   807 
   808 theorem is_relation_reflection:
   809      "REFLECTS[\<lambda>x. is_relation(L,f(x)), 
   810                \<lambda>i x. is_relation(**Lset(i),f(x))]"
   811 apply (simp only: is_relation_def setclass_simps)
   812 apply (intro FOL_reflection pair_reflection)  
   813 done
   814 
   815 
   816 subsubsection{*The Concept of Function*}
   817 
   818 (* "is_function(M,r) == 
   819 	\<forall>x[M]. \<forall>y[M]. \<forall>y'[M]. \<forall>p[M]. \<forall>p'[M]. 
   820            pair(M,x,y,p) --> pair(M,x,y',p') --> p\<in>r --> p'\<in>r --> y=y'" *)
   821 constdefs function_fm :: "i=>i"
   822     "function_fm(r) == 
   823        Forall(Forall(Forall(Forall(Forall(
   824          Implies(pair_fm(4,3,1),
   825                  Implies(pair_fm(4,2,0),
   826                          Implies(Member(1,r#+5),
   827                                  Implies(Member(0,r#+5), Equal(3,2))))))))))"
   828 
   829 lemma function_type [TC]:
   830      "[| x \<in> nat |] ==> function_fm(x) \<in> formula"
   831 by (simp add: function_fm_def) 
   832 
   833 lemma arity_function_fm [simp]:
   834      "x \<in> nat ==> arity(function_fm(x)) = succ(x)"
   835 by (simp add: function_fm_def succ_Un_distrib [symmetric] Un_ac) 
   836 
   837 lemma sats_function_fm [simp]:
   838    "[| x \<in> nat; env \<in> list(A)|]
   839     ==> sats(A, function_fm(x), env) <-> is_function(**A, nth(x,env))"
   840 by (simp add: function_fm_def is_function_def)
   841 
   842 lemma function_iff_sats:
   843       "[| nth(i,env) = x; nth(j,env) = y; 
   844           i \<in> nat; env \<in> list(A)|]
   845        ==> is_function(**A, x) <-> sats(A, function_fm(i), env)"
   846 by simp
   847 
   848 theorem is_function_reflection:
   849      "REFLECTS[\<lambda>x. is_function(L,f(x)), 
   850                \<lambda>i x. is_function(**Lset(i),f(x))]"
   851 apply (simp only: is_function_def setclass_simps)
   852 apply (intro FOL_reflection pair_reflection)  
   853 done
   854 
   855 
   856 subsubsection{*Typed Functions*}
   857 
   858 (* "typed_function(M,A,B,r) == 
   859         is_function(M,r) & is_relation(M,r) & is_domain(M,r,A) &
   860         (\<forall>u[M]. u\<in>r --> (\<forall>x[M]. \<forall>y[M]. pair(M,x,y,u) --> y\<in>B))" *)
   861 
   862 constdefs typed_function_fm :: "[i,i,i]=>i"
   863     "typed_function_fm(A,B,r) == 
   864        And(function_fm(r),
   865          And(relation_fm(r),
   866            And(domain_fm(r,A),
   867              Forall(Implies(Member(0,succ(r)),
   868                   Forall(Forall(Implies(pair_fm(1,0,2),Member(0,B#+3)))))))))"
   869 
   870 lemma typed_function_type [TC]:
   871      "[| x \<in> nat; y \<in> nat; z \<in> nat |] ==> typed_function_fm(x,y,z) \<in> formula"
   872 by (simp add: typed_function_fm_def) 
   873 
   874 lemma arity_typed_function_fm [simp]:
   875      "[| x \<in> nat; y \<in> nat; z \<in> nat |] 
   876       ==> arity(typed_function_fm(x,y,z)) = succ(x) \<union> succ(y) \<union> succ(z)"
   877 by (simp add: typed_function_fm_def succ_Un_distrib [symmetric] Un_ac) 
   878 
   879 lemma sats_typed_function_fm [simp]:
   880    "[| x \<in> nat; y \<in> nat; z \<in> nat; env \<in> list(A)|]
   881     ==> sats(A, typed_function_fm(x,y,z), env) <-> 
   882         typed_function(**A, nth(x,env), nth(y,env), nth(z,env))"
   883 by (simp add: typed_function_fm_def typed_function_def)
   884 
   885 lemma typed_function_iff_sats:
   886   "[| nth(i,env) = x; nth(j,env) = y; nth(k,env) = z; 
   887       i \<in> nat; j \<in> nat; k \<in> nat; env \<in> list(A)|]
   888    ==> typed_function(**A, x, y, z) <-> sats(A, typed_function_fm(i,j,k), env)"
   889 by simp
   890 
   891 lemmas function_reflection = 
   892         upair_reflection pair_reflection union_reflection
   893 	cons_reflection fun_apply_reflection subset_reflection
   894 	transitive_set_reflection ordinal_reflection membership_reflection
   895 	pred_set_reflection domain_reflection range_reflection image_reflection
   896 	is_relation_reflection is_function_reflection
   897 
   898 
   899 theorem typed_function_reflection:
   900      "REFLECTS[\<lambda>x. typed_function(L,f(x),g(x),h(x)), 
   901                \<lambda>i x. typed_function(**Lset(i),f(x),g(x),h(x))]"
   902 apply (simp only: typed_function_def setclass_simps)
   903 apply (intro FOL_reflection function_reflection)  
   904 done
   905 
   906 
   907 subsubsection{*Injections*}
   908 
   909 (* "injection(M,A,B,f) == 
   910 	typed_function(M,A,B,f) &
   911         (\<forall>x[M]. \<forall>x'[M]. \<forall>y[M]. \<forall>p[M]. \<forall>p'[M]. 
   912           pair(M,x,y,p) --> pair(M,x',y,p') --> p\<in>f --> p'\<in>f --> x=x')" *)
   913 constdefs injection_fm :: "[i,i,i]=>i"
   914  "injection_fm(A,B,f) == 
   915     And(typed_function_fm(A,B,f),
   916        Forall(Forall(Forall(Forall(Forall(
   917          Implies(pair_fm(4,2,1),
   918                  Implies(pair_fm(3,2,0),
   919                          Implies(Member(1,f#+5),
   920                                  Implies(Member(0,f#+5), Equal(4,3)))))))))))"
   921 
   922 
   923 lemma injection_type [TC]:
   924      "[| x \<in> nat; y \<in> nat; z \<in> nat |] ==> injection_fm(x,y,z) \<in> formula"
   925 by (simp add: injection_fm_def) 
   926 
   927 lemma arity_injection_fm [simp]:
   928      "[| x \<in> nat; y \<in> nat; z \<in> nat |] 
   929       ==> arity(injection_fm(x,y,z)) = succ(x) \<union> succ(y) \<union> succ(z)"
   930 by (simp add: injection_fm_def succ_Un_distrib [symmetric] Un_ac) 
   931 
   932 lemma sats_injection_fm [simp]:
   933    "[| x \<in> nat; y \<in> nat; z \<in> nat; env \<in> list(A)|]
   934     ==> sats(A, injection_fm(x,y,z), env) <-> 
   935         injection(**A, nth(x,env), nth(y,env), nth(z,env))"
   936 by (simp add: injection_fm_def injection_def)
   937 
   938 lemma injection_iff_sats:
   939   "[| nth(i,env) = x; nth(j,env) = y; nth(k,env) = z; 
   940       i \<in> nat; j \<in> nat; k \<in> nat; env \<in> list(A)|]
   941    ==> injection(**A, x, y, z) <-> sats(A, injection_fm(i,j,k), env)"
   942 by simp
   943 
   944 theorem injection_reflection:
   945      "REFLECTS[\<lambda>x. injection(L,f(x),g(x),h(x)), 
   946                \<lambda>i x. injection(**Lset(i),f(x),g(x),h(x))]"
   947 apply (simp only: injection_def setclass_simps)
   948 apply (intro FOL_reflection function_reflection typed_function_reflection)  
   949 done
   950 
   951 
   952 subsubsection{*Surjections*}
   953 
   954 (*  surjection :: "[i=>o,i,i,i] => o"
   955     "surjection(M,A,B,f) == 
   956         typed_function(M,A,B,f) &
   957         (\<forall>y[M]. y\<in>B --> (\<exists>x[M]. x\<in>A & fun_apply(M,f,x,y)))" *)
   958 constdefs surjection_fm :: "[i,i,i]=>i"
   959  "surjection_fm(A,B,f) == 
   960     And(typed_function_fm(A,B,f),
   961        Forall(Implies(Member(0,succ(B)),
   962                       Exists(And(Member(0,succ(succ(A))),
   963                                  fun_apply_fm(succ(succ(f)),0,1))))))"
   964 
   965 lemma surjection_type [TC]:
   966      "[| x \<in> nat; y \<in> nat; z \<in> nat |] ==> surjection_fm(x,y,z) \<in> formula"
   967 by (simp add: surjection_fm_def) 
   968 
   969 lemma arity_surjection_fm [simp]:
   970      "[| x \<in> nat; y \<in> nat; z \<in> nat |] 
   971       ==> arity(surjection_fm(x,y,z)) = succ(x) \<union> succ(y) \<union> succ(z)"
   972 by (simp add: surjection_fm_def succ_Un_distrib [symmetric] Un_ac) 
   973 
   974 lemma sats_surjection_fm [simp]:
   975    "[| x \<in> nat; y \<in> nat; z \<in> nat; env \<in> list(A)|]
   976     ==> sats(A, surjection_fm(x,y,z), env) <-> 
   977         surjection(**A, nth(x,env), nth(y,env), nth(z,env))"
   978 by (simp add: surjection_fm_def surjection_def)
   979 
   980 lemma surjection_iff_sats:
   981   "[| nth(i,env) = x; nth(j,env) = y; nth(k,env) = z; 
   982       i \<in> nat; j \<in> nat; k \<in> nat; env \<in> list(A)|]
   983    ==> surjection(**A, x, y, z) <-> sats(A, surjection_fm(i,j,k), env)"
   984 by simp
   985 
   986 theorem surjection_reflection:
   987      "REFLECTS[\<lambda>x. surjection(L,f(x),g(x),h(x)), 
   988                \<lambda>i x. surjection(**Lset(i),f(x),g(x),h(x))]"
   989 apply (simp only: surjection_def setclass_simps)
   990 apply (intro FOL_reflection function_reflection typed_function_reflection)  
   991 done
   992 
   993 
   994 
   995 subsubsection{*Bijections*}
   996 
   997 (*   bijection :: "[i=>o,i,i,i] => o"
   998     "bijection(M,A,B,f) == injection(M,A,B,f) & surjection(M,A,B,f)" *)
   999 constdefs bijection_fm :: "[i,i,i]=>i"
  1000  "bijection_fm(A,B,f) == And(injection_fm(A,B,f), surjection_fm(A,B,f))"
  1001 
  1002 lemma bijection_type [TC]:
  1003      "[| x \<in> nat; y \<in> nat; z \<in> nat |] ==> bijection_fm(x,y,z) \<in> formula"
  1004 by (simp add: bijection_fm_def) 
  1005 
  1006 lemma arity_bijection_fm [simp]:
  1007      "[| x \<in> nat; y \<in> nat; z \<in> nat |] 
  1008       ==> arity(bijection_fm(x,y,z)) = succ(x) \<union> succ(y) \<union> succ(z)"
  1009 by (simp add: bijection_fm_def succ_Un_distrib [symmetric] Un_ac) 
  1010 
  1011 lemma sats_bijection_fm [simp]:
  1012    "[| x \<in> nat; y \<in> nat; z \<in> nat; env \<in> list(A)|]
  1013     ==> sats(A, bijection_fm(x,y,z), env) <-> 
  1014         bijection(**A, nth(x,env), nth(y,env), nth(z,env))"
  1015 by (simp add: bijection_fm_def bijection_def)
  1016 
  1017 lemma bijection_iff_sats:
  1018   "[| nth(i,env) = x; nth(j,env) = y; nth(k,env) = z; 
  1019       i \<in> nat; j \<in> nat; k \<in> nat; env \<in> list(A)|]
  1020    ==> bijection(**A, x, y, z) <-> sats(A, bijection_fm(i,j,k), env)"
  1021 by simp
  1022 
  1023 theorem bijection_reflection:
  1024      "REFLECTS[\<lambda>x. bijection(L,f(x),g(x),h(x)), 
  1025                \<lambda>i x. bijection(**Lset(i),f(x),g(x),h(x))]"
  1026 apply (simp only: bijection_def setclass_simps)
  1027 apply (intro And_reflection injection_reflection surjection_reflection)  
  1028 done
  1029 
  1030 
  1031 subsubsection{*Order-Isomorphisms*}
  1032 
  1033 (*  order_isomorphism :: "[i=>o,i,i,i,i,i] => o"
  1034    "order_isomorphism(M,A,r,B,s,f) == 
  1035         bijection(M,A,B,f) & 
  1036         (\<forall>x[M]. x\<in>A --> (\<forall>y[M]. y\<in>A -->
  1037           (\<forall>p[M]. \<forall>fx[M]. \<forall>fy[M]. \<forall>q[M].
  1038             pair(M,x,y,p) --> fun_apply(M,f,x,fx) --> fun_apply(M,f,y,fy) --> 
  1039             pair(M,fx,fy,q) --> (p\<in>r <-> q\<in>s))))"
  1040   *)
  1041 
  1042 constdefs order_isomorphism_fm :: "[i,i,i,i,i]=>i"
  1043  "order_isomorphism_fm(A,r,B,s,f) == 
  1044    And(bijection_fm(A,B,f), 
  1045      Forall(Implies(Member(0,succ(A)),
  1046        Forall(Implies(Member(0,succ(succ(A))),
  1047          Forall(Forall(Forall(Forall(
  1048            Implies(pair_fm(5,4,3),
  1049              Implies(fun_apply_fm(f#+6,5,2),
  1050                Implies(fun_apply_fm(f#+6,4,1),
  1051                  Implies(pair_fm(2,1,0), 
  1052                    Iff(Member(3,r#+6), Member(0,s#+6)))))))))))))))"
  1053 
  1054 lemma order_isomorphism_type [TC]:
  1055      "[| A \<in> nat; r \<in> nat; B \<in> nat; s \<in> nat; f \<in> nat |]  
  1056       ==> order_isomorphism_fm(A,r,B,s,f) \<in> formula"
  1057 by (simp add: order_isomorphism_fm_def) 
  1058 
  1059 lemma arity_order_isomorphism_fm [simp]:
  1060      "[| A \<in> nat; r \<in> nat; B \<in> nat; s \<in> nat; f \<in> nat |] 
  1061       ==> arity(order_isomorphism_fm(A,r,B,s,f)) = 
  1062           succ(A) \<union> succ(r) \<union> succ(B) \<union> succ(s) \<union> succ(f)" 
  1063 by (simp add: order_isomorphism_fm_def succ_Un_distrib [symmetric] Un_ac) 
  1064 
  1065 lemma sats_order_isomorphism_fm [simp]:
  1066    "[| U \<in> nat; r \<in> nat; B \<in> nat; s \<in> nat; f \<in> nat; env \<in> list(A)|]
  1067     ==> sats(A, order_isomorphism_fm(U,r,B,s,f), env) <-> 
  1068         order_isomorphism(**A, nth(U,env), nth(r,env), nth(B,env), 
  1069                                nth(s,env), nth(f,env))"
  1070 by (simp add: order_isomorphism_fm_def order_isomorphism_def)
  1071 
  1072 lemma order_isomorphism_iff_sats:
  1073   "[| nth(i,env) = U; nth(j,env) = r; nth(k,env) = B; nth(j',env) = s; 
  1074       nth(k',env) = f; 
  1075       i \<in> nat; j \<in> nat; k \<in> nat; j' \<in> nat; k' \<in> nat; env \<in> list(A)|]
  1076    ==> order_isomorphism(**A,U,r,B,s,f) <-> 
  1077        sats(A, order_isomorphism_fm(i,j,k,j',k'), env)" 
  1078 by simp
  1079 
  1080 theorem order_isomorphism_reflection:
  1081      "REFLECTS[\<lambda>x. order_isomorphism(L,f(x),g(x),h(x),g'(x),h'(x)), 
  1082                \<lambda>i x. order_isomorphism(**Lset(i),f(x),g(x),h(x),g'(x),h'(x))]"
  1083 apply (simp only: order_isomorphism_def setclass_simps)
  1084 apply (intro FOL_reflection function_reflection bijection_reflection)  
  1085 done
  1086 
  1087 end