src/ZF/Constructible/Formula.thy
author paulson
Wed Oct 09 11:07:13 2002 +0200 (2002-10-09)
changeset 13634 99a593b49b04
parent 13535 007559e981c7
child 13647 7f6f0ffc45c3
permissions -rw-r--r--
Re-organization of Constructible theories
     1 (*  Title:      ZF/Constructible/Formula.thy
     2     ID: $Id$
     3     Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
     4 *)
     5 
     6 header {* First-Order Formulas and the Definition of the Class L *}
     7 
     8 theory Formula = Main:
     9 
    10 subsection{*Internalized formulas of FOL*}
    11 
    12 text{*De Bruijn representation.
    13   Unbound variables get their denotations from an environment.*}
    14 
    15 consts   formula :: i
    16 datatype
    17   "formula" = Member ("x: nat", "y: nat")
    18             | Equal  ("x: nat", "y: nat")
    19             | Nand ("p: formula", "q: formula")
    20             | Forall ("p: formula")
    21 
    22 declare formula.intros [TC]
    23 
    24 constdefs Neg :: "i=>i"
    25     "Neg(p) == Nand(p,p)"
    26 
    27 constdefs And :: "[i,i]=>i"
    28     "And(p,q) == Neg(Nand(p,q))"
    29 
    30 constdefs Or :: "[i,i]=>i"
    31     "Or(p,q) == Nand(Neg(p),Neg(q))"
    32 
    33 constdefs Implies :: "[i,i]=>i"
    34     "Implies(p,q) == Nand(p,Neg(q))"
    35 
    36 constdefs Iff :: "[i,i]=>i"
    37     "Iff(p,q) == And(Implies(p,q), Implies(q,p))"
    38 
    39 constdefs Exists :: "i=>i"
    40     "Exists(p) == Neg(Forall(Neg(p)))";
    41 
    42 lemma Neg_type [TC]: "p \<in> formula ==> Neg(p) \<in> formula"
    43 by (simp add: Neg_def) 
    44 
    45 lemma And_type [TC]: "[| p \<in> formula; q \<in> formula |] ==> And(p,q) \<in> formula"
    46 by (simp add: And_def) 
    47 
    48 lemma Or_type [TC]: "[| p \<in> formula; q \<in> formula |] ==> Or(p,q) \<in> formula"
    49 by (simp add: Or_def) 
    50 
    51 lemma Implies_type [TC]:
    52      "[| p \<in> formula; q \<in> formula |] ==> Implies(p,q) \<in> formula"
    53 by (simp add: Implies_def) 
    54 
    55 lemma Iff_type [TC]:
    56      "[| p \<in> formula; q \<in> formula |] ==> Iff(p,q) \<in> formula"
    57 by (simp add: Iff_def) 
    58 
    59 lemma Exists_type [TC]: "p \<in> formula ==> Exists(p) \<in> formula"
    60 by (simp add: Exists_def) 
    61 
    62 
    63 consts   satisfies :: "[i,i]=>i"
    64 primrec (*explicit lambda is required because the environment varies*)
    65   "satisfies(A,Member(x,y)) = 
    66       (\<lambda>env \<in> list(A). bool_of_o (nth(x,env) \<in> nth(y,env)))"
    67 
    68   "satisfies(A,Equal(x,y)) = 
    69       (\<lambda>env \<in> list(A). bool_of_o (nth(x,env) = nth(y,env)))"
    70 
    71   "satisfies(A,Nand(p,q)) =
    72       (\<lambda>env \<in> list(A). not ((satisfies(A,p)`env) and (satisfies(A,q)`env)))"
    73 
    74   "satisfies(A,Forall(p)) = 
    75       (\<lambda>env \<in> list(A). bool_of_o (\<forall>x\<in>A. satisfies(A,p) ` (Cons(x,env)) = 1))"
    76 
    77 
    78 lemma "p \<in> formula ==> satisfies(A,p) \<in> list(A) -> bool"
    79 by (induct_tac p, simp_all) 
    80 
    81 syntax sats :: "[i,i,i] => o"
    82 translations "sats(A,p,env)" == "satisfies(A,p)`env = 1"
    83 
    84 lemma [simp]:
    85   "env \<in> list(A) 
    86    ==> sats(A, Member(x,y), env) <-> nth(x,env) \<in> nth(y,env)"
    87 by simp
    88 
    89 lemma [simp]:
    90   "env \<in> list(A) 
    91    ==> sats(A, Equal(x,y), env) <-> nth(x,env) = nth(y,env)"
    92 by simp
    93 
    94 lemma sats_Nand_iff [simp]:
    95   "env \<in> list(A) 
    96    ==> (sats(A, Nand(p,q), env)) <-> ~ (sats(A,p,env) & sats(A,q,env))" 
    97 by (simp add: Bool.and_def Bool.not_def cond_def) 
    98 
    99 lemma sats_Forall_iff [simp]:
   100   "env \<in> list(A) 
   101    ==> sats(A, Forall(p), env) <-> (\<forall>x\<in>A. sats(A, p, Cons(x,env)))"
   102 by simp
   103 
   104 declare satisfies.simps [simp del]; 
   105 
   106 subsection{*Dividing line between primitive and derived connectives*}
   107 
   108 lemma sats_Neg_iff [simp]:
   109   "env \<in> list(A) 
   110    ==> sats(A, Neg(p), env) <-> ~ sats(A,p,env)"
   111 by (simp add: Neg_def) 
   112 
   113 lemma sats_And_iff [simp]:
   114   "env \<in> list(A) 
   115    ==> (sats(A, And(p,q), env)) <-> sats(A,p,env) & sats(A,q,env)"
   116 by (simp add: And_def) 
   117 
   118 lemma sats_Or_iff [simp]:
   119   "env \<in> list(A) 
   120    ==> (sats(A, Or(p,q), env)) <-> sats(A,p,env) | sats(A,q,env)"
   121 by (simp add: Or_def)
   122 
   123 lemma sats_Implies_iff [simp]:
   124   "env \<in> list(A) 
   125    ==> (sats(A, Implies(p,q), env)) <-> (sats(A,p,env) --> sats(A,q,env))"
   126 by (simp add: Implies_def, blast) 
   127 
   128 lemma sats_Iff_iff [simp]:
   129   "env \<in> list(A) 
   130    ==> (sats(A, Iff(p,q), env)) <-> (sats(A,p,env) <-> sats(A,q,env))"
   131 by (simp add: Iff_def, blast) 
   132 
   133 lemma sats_Exists_iff [simp]:
   134   "env \<in> list(A) 
   135    ==> sats(A, Exists(p), env) <-> (\<exists>x\<in>A. sats(A, p, Cons(x,env)))"
   136 by (simp add: Exists_def)
   137 
   138 
   139 subsubsection{*Derived rules to help build up formulas*}
   140 
   141 lemma mem_iff_sats:
   142       "[| nth(i,env) = x; nth(j,env) = y; env \<in> list(A)|]
   143        ==> (x\<in>y) <-> sats(A, Member(i,j), env)" 
   144 by (simp add: satisfies.simps)
   145 
   146 lemma equal_iff_sats:
   147       "[| nth(i,env) = x; nth(j,env) = y; env \<in> list(A)|]
   148        ==> (x=y) <-> sats(A, Equal(i,j), env)" 
   149 by (simp add: satisfies.simps)
   150 
   151 lemma not_iff_sats:
   152       "[| P <-> sats(A,p,env); env \<in> list(A)|]
   153        ==> (~P) <-> sats(A, Neg(p), env)"
   154 by simp
   155 
   156 lemma conj_iff_sats:
   157       "[| P <-> sats(A,p,env); Q <-> sats(A,q,env); env \<in> list(A)|]
   158        ==> (P & Q) <-> sats(A, And(p,q), env)"
   159 by (simp add: sats_And_iff)
   160 
   161 lemma disj_iff_sats:
   162       "[| P <-> sats(A,p,env); Q <-> sats(A,q,env); env \<in> list(A)|]
   163        ==> (P | Q) <-> sats(A, Or(p,q), env)"
   164 by (simp add: sats_Or_iff)
   165 
   166 lemma iff_iff_sats:
   167       "[| P <-> sats(A,p,env); Q <-> sats(A,q,env); env \<in> list(A)|]
   168        ==> (P <-> Q) <-> sats(A, Iff(p,q), env)"
   169 by (simp add: sats_Forall_iff) 
   170 
   171 lemma imp_iff_sats:
   172       "[| P <-> sats(A,p,env); Q <-> sats(A,q,env); env \<in> list(A)|]
   173        ==> (P --> Q) <-> sats(A, Implies(p,q), env)"
   174 by (simp add: sats_Forall_iff) 
   175 
   176 lemma ball_iff_sats:
   177       "[| !!x. x\<in>A ==> P(x) <-> sats(A, p, Cons(x, env)); env \<in> list(A)|]
   178        ==> (\<forall>x\<in>A. P(x)) <-> sats(A, Forall(p), env)"
   179 by (simp add: sats_Forall_iff) 
   180 
   181 lemma bex_iff_sats:
   182       "[| !!x. x\<in>A ==> P(x) <-> sats(A, p, Cons(x, env)); env \<in> list(A)|]
   183        ==> (\<exists>x\<in>A. P(x)) <-> sats(A, Exists(p), env)"
   184 by (simp add: sats_Exists_iff) 
   185 
   186 lemmas FOL_iff_sats = 
   187         mem_iff_sats equal_iff_sats not_iff_sats conj_iff_sats
   188         disj_iff_sats imp_iff_sats iff_iff_sats imp_iff_sats ball_iff_sats
   189         bex_iff_sats
   190 
   191 constdefs incr_var :: "[i,i]=>i"
   192     "incr_var(x,lev) == if x<lev then x else succ(x)"
   193 
   194 lemma incr_var_lt: "x<lev ==> incr_var(x,lev) = x"
   195 by (simp add: incr_var_def)
   196 
   197 lemma incr_var_le: "lev\<le>x ==> incr_var(x,lev) = succ(x)"
   198 apply (simp add: incr_var_def) 
   199 apply (blast dest: lt_trans1) 
   200 done
   201 
   202 consts   incr_bv :: "i=>i"
   203 primrec
   204   "incr_bv(Member(x,y)) = 
   205       (\<lambda>lev \<in> nat. Member (incr_var(x,lev), incr_var(y,lev)))"
   206 
   207   "incr_bv(Equal(x,y)) = 
   208       (\<lambda>lev \<in> nat. Equal (incr_var(x,lev), incr_var(y,lev)))"
   209 
   210   "incr_bv(Nand(p,q)) =
   211       (\<lambda>lev \<in> nat. Nand (incr_bv(p)`lev, incr_bv(q)`lev))"
   212 
   213   "incr_bv(Forall(p)) = 
   214       (\<lambda>lev \<in> nat. Forall (incr_bv(p) ` succ(lev)))"
   215 
   216 
   217 constdefs incr_boundvars :: "i => i"
   218     "incr_boundvars(p) == incr_bv(p)`0"
   219 
   220 
   221 lemma [TC]: "x \<in> nat ==> incr_var(x,lev) \<in> nat"
   222 by (simp add: incr_var_def) 
   223 
   224 lemma incr_bv_type [TC]: "p \<in> formula ==> incr_bv(p) \<in> nat -> formula"
   225 by (induct_tac p, simp_all) 
   226 
   227 lemma incr_boundvars_type [TC]: "p \<in> formula ==> incr_boundvars(p) \<in> formula"
   228 by (simp add: incr_boundvars_def) 
   229 
   230 (*Obviously DPow is closed under complements and finite intersections and
   231 unions.  Needs an inductive lemma to allow two lists of parameters to 
   232 be combined.*)
   233 
   234 lemma sats_incr_bv_iff [rule_format]:
   235   "[| p \<in> formula; env \<in> list(A); x \<in> A |]
   236    ==> \<forall>bvs \<in> list(A). 
   237            sats(A, incr_bv(p) ` length(bvs), bvs @ Cons(x,env)) <-> 
   238            sats(A, p, bvs@env)"
   239 apply (induct_tac p)
   240 apply (simp_all add: incr_var_def nth_append succ_lt_iff length_type)
   241 apply (auto simp add: diff_succ not_lt_iff_le)
   242 done
   243 
   244 (*UNUSED*)
   245 lemma sats_incr_boundvars_iff:
   246   "[| p \<in> formula; env \<in> list(A); x \<in> A |]
   247    ==> sats(A, incr_boundvars(p), Cons(x,env)) <-> sats(A, p, env)"
   248 apply (insert sats_incr_bv_iff [of p env A x Nil])
   249 apply (simp add: incr_boundvars_def) 
   250 done
   251 
   252 (*UNUSED
   253 lemma formula_add_params [rule_format]:
   254   "[| p \<in> formula; n \<in> nat |]
   255    ==> \<forall>bvs \<in> list(A). \<forall>env \<in> list(A). 
   256          length(bvs) = n --> 
   257          sats(A, iterates(incr_boundvars,n,p), bvs@env) <-> sats(A, p, env)"
   258 apply (induct_tac n, simp, clarify) 
   259 apply (erule list.cases)
   260 apply (auto simp add: sats_incr_boundvars_iff)  
   261 done
   262 *)
   263 
   264 consts   arity :: "i=>i"
   265 primrec
   266   "arity(Member(x,y)) = succ(x) \<union> succ(y)"
   267 
   268   "arity(Equal(x,y)) = succ(x) \<union> succ(y)"
   269 
   270   "arity(Nand(p,q)) = arity(p) \<union> arity(q)"
   271 
   272   "arity(Forall(p)) = nat_case(0, %x. x, arity(p))"
   273 
   274 
   275 lemma arity_type [TC]: "p \<in> formula ==> arity(p) \<in> nat"
   276 by (induct_tac p, simp_all) 
   277 
   278 lemma arity_Neg [simp]: "arity(Neg(p)) = arity(p)"
   279 by (simp add: Neg_def) 
   280 
   281 lemma arity_And [simp]: "arity(And(p,q)) = arity(p) \<union> arity(q)"
   282 by (simp add: And_def) 
   283 
   284 lemma arity_Or [simp]: "arity(Or(p,q)) = arity(p) \<union> arity(q)"
   285 by (simp add: Or_def) 
   286 
   287 lemma arity_Implies [simp]: "arity(Implies(p,q)) = arity(p) \<union> arity(q)"
   288 by (simp add: Implies_def) 
   289 
   290 lemma arity_Iff [simp]: "arity(Iff(p,q)) = arity(p) \<union> arity(q)"
   291 by (simp add: Iff_def, blast)
   292 
   293 lemma arity_Exists [simp]: "arity(Exists(p)) = nat_case(0, %x. x, arity(p))"
   294 by (simp add: Exists_def) 
   295 
   296 
   297 lemma arity_sats_iff [rule_format]:
   298   "[| p \<in> formula; extra \<in> list(A) |]
   299    ==> \<forall>env \<in> list(A). 
   300            arity(p) \<le> length(env) --> 
   301            sats(A, p, env @ extra) <-> sats(A, p, env)"
   302 apply (induct_tac p)
   303 apply (simp_all add: nth_append Un_least_lt_iff arity_type nat_imp_quasinat
   304                 split: split_nat_case, auto) 
   305 done
   306 
   307 lemma arity_sats1_iff:
   308   "[| arity(p) \<le> succ(length(env)); p \<in> formula; x \<in> A; env \<in> list(A); 
   309     extra \<in> list(A) |]
   310    ==> sats(A, p, Cons(x, env @ extra)) <-> sats(A, p, Cons(x, env))"
   311 apply (insert arity_sats_iff [of p extra A "Cons(x,env)"])
   312 apply simp 
   313 done
   314 
   315 (*the following two lemmas prevent huge case splits in arity_incr_bv_lemma*)
   316 lemma incr_var_lemma:
   317      "[| x \<in> nat; y \<in> nat; lev \<le> x |]
   318       ==> succ(x) \<union> incr_var(y,lev) = succ(x \<union> y)"
   319 apply (simp add: incr_var_def Ord_Un_if, auto)
   320   apply (blast intro: leI)
   321  apply (simp add: not_lt_iff_le)  
   322  apply (blast intro: le_anti_sym) 
   323 apply (blast dest: lt_trans2) 
   324 done
   325 
   326 lemma incr_And_lemma:
   327      "y < x ==> y \<union> succ(x) = succ(x \<union> y)"
   328 apply (simp add: Ord_Un_if lt_Ord lt_Ord2 succ_lt_iff) 
   329 apply (blast dest: lt_asym) 
   330 done
   331 
   332 lemma arity_incr_bv_lemma [rule_format]:
   333   "p \<in> formula 
   334    ==> \<forall>n \<in> nat. arity (incr_bv(p) ` n) = 
   335                  (if n < arity(p) then succ(arity(p)) else arity(p))"
   336 apply (induct_tac p) 
   337 apply (simp_all add: imp_disj not_lt_iff_le Un_least_lt_iff lt_Un_iff le_Un_iff
   338                      succ_Un_distrib [symmetric] incr_var_lt incr_var_le
   339                      Un_commute incr_var_lemma arity_type nat_imp_quasinat
   340             split: split_nat_case) 
   341  txt{*the Forall case reduces to linear arithmetic*}
   342  prefer 2
   343  apply clarify 
   344  apply (blast dest: lt_trans1) 
   345 txt{*left with the And case*}
   346 apply safe
   347  apply (blast intro: incr_And_lemma lt_trans1) 
   348 apply (subst incr_And_lemma)
   349  apply (blast intro: lt_trans1) 
   350 apply (simp add: Un_commute)
   351 done
   352 
   353 lemma arity_incr_boundvars_eq:
   354   "p \<in> formula
   355    ==> arity(incr_boundvars(p)) =
   356         (if 0 < arity(p) then succ(arity(p)) else arity(p))"
   357 apply (insert arity_incr_bv_lemma [of p 0])
   358 apply (simp add: incr_boundvars_def) 
   359 done
   360 
   361 lemma arity_iterates_incr_boundvars_eq:
   362   "[| p \<in> formula; n \<in> nat |]
   363    ==> arity(incr_boundvars^n(p)) =
   364          (if 0 < arity(p) then n #+ arity(p) else arity(p))"
   365 apply (induct_tac n) 
   366 apply (simp_all add: arity_incr_boundvars_eq not_lt_iff_le) 
   367 done
   368 
   369 
   370 subsection{*Renaming all but the first bound variable*}
   371 
   372 constdefs incr_bv1 :: "i => i"
   373     "incr_bv1(p) == incr_bv(p)`1"
   374 
   375 
   376 lemma incr_bv1_type [TC]: "p \<in> formula ==> incr_bv1(p) \<in> formula"
   377 by (simp add: incr_bv1_def) 
   378 
   379 (*For renaming all but the bound variable at level 0*)
   380 lemma sats_incr_bv1_iff [rule_format]:
   381   "[| p \<in> formula; env \<in> list(A); x \<in> A; y \<in> A |]
   382    ==> sats(A, incr_bv1(p), Cons(x, Cons(y, env))) <-> 
   383        sats(A, p, Cons(x,env))"
   384 apply (insert sats_incr_bv_iff [of p env A y "Cons(x,Nil)"])
   385 apply (simp add: incr_bv1_def) 
   386 done
   387 
   388 lemma formula_add_params1 [rule_format]:
   389   "[| p \<in> formula; n \<in> nat; x \<in> A |]
   390    ==> \<forall>bvs \<in> list(A). \<forall>env \<in> list(A). 
   391           length(bvs) = n --> 
   392           sats(A, iterates(incr_bv1, n, p), Cons(x, bvs@env)) <-> 
   393           sats(A, p, Cons(x,env))"
   394 apply (induct_tac n, simp, clarify) 
   395 apply (erule list.cases)
   396 apply (simp_all add: sats_incr_bv1_iff) 
   397 done
   398 
   399 
   400 lemma arity_incr_bv1_eq:
   401   "p \<in> formula
   402    ==> arity(incr_bv1(p)) =
   403         (if 1 < arity(p) then succ(arity(p)) else arity(p))"
   404 apply (insert arity_incr_bv_lemma [of p 1])
   405 apply (simp add: incr_bv1_def) 
   406 done
   407 
   408 lemma arity_iterates_incr_bv1_eq:
   409   "[| p \<in> formula; n \<in> nat |]
   410    ==> arity(incr_bv1^n(p)) =
   411          (if 1 < arity(p) then n #+ arity(p) else arity(p))"
   412 apply (induct_tac n) 
   413 apply (simp_all add: arity_incr_bv1_eq)
   414 apply (simp add: not_lt_iff_le)
   415 apply (blast intro: le_trans add_le_self2 arity_type) 
   416 done
   417 
   418 
   419 (*Definable powerset operation: Kunen's definition 1.1, page 165.*)
   420 constdefs DPow :: "i => i"
   421   "DPow(A) == {X \<in> Pow(A). 
   422                \<exists>env \<in> list(A). \<exists>p \<in> formula. 
   423                  arity(p) \<le> succ(length(env)) & 
   424                  X = {x\<in>A. sats(A, p, Cons(x,env))}}"
   425 
   426 lemma DPowI:
   427   "[|env \<in> list(A);  p \<in> formula;  arity(p) \<le> succ(length(env))|]
   428    ==> {x\<in>A. sats(A, p, Cons(x,env))} \<in> DPow(A)"
   429 by (simp add: DPow_def, blast) 
   430 
   431 text{*With this rule we can specify @{term p} later.*}
   432 lemma DPowI2 [rule_format]:
   433   "[|\<forall>x\<in>A. P(x) <-> sats(A, p, Cons(x,env));
   434      env \<in> list(A);  p \<in> formula;  arity(p) \<le> succ(length(env))|]
   435    ==> {x\<in>A. P(x)} \<in> DPow(A)"
   436 by (simp add: DPow_def, blast) 
   437 
   438 lemma DPowD:
   439   "X \<in> DPow(A) 
   440    ==> X <= A &
   441        (\<exists>env \<in> list(A). 
   442         \<exists>p \<in> formula. arity(p) \<le> succ(length(env)) & 
   443                       X = {x\<in>A. sats(A, p, Cons(x,env))})"
   444 by (simp add: DPow_def) 
   445 
   446 lemmas DPow_imp_subset = DPowD [THEN conjunct1]
   447 
   448 (*Lemma 1.2*)
   449 lemma "[| p \<in> formula; env \<in> list(A); arity(p) \<le> succ(length(env)) |] 
   450        ==> {x\<in>A. sats(A, p, Cons(x,env))} \<in> DPow(A)"
   451 by (blast intro: DPowI)
   452 
   453 lemma DPow_subset_Pow: "DPow(A) <= Pow(A)"
   454 by (simp add: DPow_def, blast)
   455 
   456 lemma empty_in_DPow: "0 \<in> DPow(A)"
   457 apply (simp add: DPow_def)
   458 apply (rule_tac x=Nil in bexI) 
   459  apply (rule_tac x="Neg(Equal(0,0))" in bexI) 
   460   apply (auto simp add: Un_least_lt_iff) 
   461 done
   462 
   463 lemma Compl_in_DPow: "X \<in> DPow(A) ==> (A-X) \<in> DPow(A)"
   464 apply (simp add: DPow_def, clarify, auto) 
   465 apply (rule bexI) 
   466  apply (rule_tac x="Neg(p)" in bexI) 
   467   apply auto 
   468 done
   469 
   470 lemma Int_in_DPow: "[| X \<in> DPow(A); Y \<in> DPow(A) |] ==> X Int Y \<in> DPow(A)"
   471 apply (simp add: DPow_def, auto) 
   472 apply (rename_tac envp p envq q) 
   473 apply (rule_tac x="envp@envq" in bexI) 
   474  apply (rule_tac x="And(p, iterates(incr_bv1,length(envp),q))" in bexI)
   475   apply typecheck
   476 apply (rule conjI) 
   477 (*finally check the arity!*)
   478  apply (simp add: arity_iterates_incr_bv1_eq length_app Un_least_lt_iff)
   479  apply (force intro: add_le_self le_trans) 
   480 apply (simp add: arity_sats1_iff formula_add_params1, blast) 
   481 done
   482 
   483 lemma Un_in_DPow: "[| X \<in> DPow(A); Y \<in> DPow(A) |] ==> X Un Y \<in> DPow(A)"
   484 apply (subgoal_tac "X Un Y = A - ((A-X) Int (A-Y))") 
   485 apply (simp add: Int_in_DPow Compl_in_DPow) 
   486 apply (simp add: DPow_def, blast) 
   487 done
   488 
   489 lemma singleton_in_DPow: "x \<in> A ==> {x} \<in> DPow(A)"
   490 apply (simp add: DPow_def)
   491 apply (rule_tac x="Cons(x,Nil)" in bexI) 
   492  apply (rule_tac x="Equal(0,1)" in bexI) 
   493   apply typecheck
   494 apply (force simp add: succ_Un_distrib [symmetric])  
   495 done
   496 
   497 lemma cons_in_DPow: "[| a \<in> A; X \<in> DPow(A) |] ==> cons(a,X) \<in> DPow(A)"
   498 apply (rule cons_eq [THEN subst]) 
   499 apply (blast intro: singleton_in_DPow Un_in_DPow) 
   500 done
   501 
   502 (*Part of Lemma 1.3*)
   503 lemma Fin_into_DPow: "X \<in> Fin(A) ==> X \<in> DPow(A)"
   504 apply (erule Fin.induct) 
   505  apply (rule empty_in_DPow) 
   506 apply (blast intro: cons_in_DPow) 
   507 done
   508 
   509 (*DPow is not monotonic.  For example, let A be some non-constructible set
   510   of natural numbers, and let B be nat.  Then A<=B and obviously A : DPow(A)
   511   but A ~: DPow(B).*)
   512 lemma DPow_mono: "A : DPow(B) ==> DPow(A) <= DPow(B)"
   513 apply (simp add: DPow_def, auto) 
   514 (*must use the formula defining A in B to relativize the new formula...*)
   515 oops
   516 
   517 lemma DPow_0: "DPow(0) = {0}" 
   518 by (blast intro: empty_in_DPow dest: DPow_imp_subset)
   519 
   520 lemma Finite_Pow_subset_Pow: "Finite(A) ==> Pow(A) <= DPow(A)" 
   521 by (blast intro: Fin_into_DPow Finite_into_Fin Fin_subset)
   522 
   523 lemma Finite_DPow_eq_Pow: "Finite(A) ==> DPow(A) = Pow(A)"
   524 apply (rule equalityI) 
   525 apply (rule DPow_subset_Pow) 
   526 apply (erule Finite_Pow_subset_Pow) 
   527 done
   528 
   529 (*This may be true but the proof looks difficult, requiring relativization 
   530 lemma DPow_insert: "DPow (cons(a,A)) = DPow(A) Un {cons(a,X) . X: DPow(A)}"
   531 apply (rule equalityI, safe)
   532 oops
   533 *)
   534 
   535 
   536 subsection{*Internalized formulas for basic concepts*}
   537 
   538 subsubsection{*The subset relation*}
   539 
   540 constdefs subset_fm :: "[i,i]=>i"
   541     "subset_fm(x,y) == Forall(Implies(Member(0,succ(x)), Member(0,succ(y))))"
   542 
   543 lemma subset_type [TC]: "[| x \<in> nat; y \<in> nat |] ==> subset_fm(x,y) \<in> formula"
   544 by (simp add: subset_fm_def) 
   545 
   546 lemma arity_subset_fm [simp]:
   547      "[| x \<in> nat; y \<in> nat |] ==> arity(subset_fm(x,y)) = succ(x) \<union> succ(y)"
   548 by (simp add: subset_fm_def succ_Un_distrib [symmetric]) 
   549 
   550 lemma sats_subset_fm [simp]:
   551    "[|x < length(env); y \<in> nat; env \<in> list(A); Transset(A)|]
   552     ==> sats(A, subset_fm(x,y), env) <-> nth(x,env) \<subseteq> nth(y,env)"
   553 apply (frule lt_length_in_nat, assumption)  
   554 apply (simp add: subset_fm_def Transset_def) 
   555 apply (blast intro: nth_type) 
   556 done
   557 
   558 subsubsection{*Transitive sets*}
   559 
   560 constdefs transset_fm :: "i=>i"
   561    "transset_fm(x) == Forall(Implies(Member(0,succ(x)), subset_fm(0,succ(x))))"
   562 
   563 lemma transset_type [TC]: "x \<in> nat ==> transset_fm(x) \<in> formula"
   564 by (simp add: transset_fm_def) 
   565 
   566 lemma arity_transset_fm [simp]:
   567      "x \<in> nat ==> arity(transset_fm(x)) = succ(x)"
   568 by (simp add: transset_fm_def succ_Un_distrib [symmetric]) 
   569 
   570 lemma sats_transset_fm [simp]:
   571    "[|x < length(env); env \<in> list(A); Transset(A)|]
   572     ==> sats(A, transset_fm(x), env) <-> Transset(nth(x,env))"
   573 apply (frule lt_nat_in_nat, erule length_type) 
   574 apply (simp add: transset_fm_def Transset_def) 
   575 apply (blast intro: nth_type) 
   576 done
   577 
   578 subsubsection{*Ordinals*}
   579 
   580 constdefs ordinal_fm :: "i=>i"
   581    "ordinal_fm(x) == 
   582       And(transset_fm(x), Forall(Implies(Member(0,succ(x)), transset_fm(0))))"
   583 
   584 lemma ordinal_type [TC]: "x \<in> nat ==> ordinal_fm(x) \<in> formula"
   585 by (simp add: ordinal_fm_def) 
   586 
   587 lemma arity_ordinal_fm [simp]:
   588      "x \<in> nat ==> arity(ordinal_fm(x)) = succ(x)"
   589 by (simp add: ordinal_fm_def succ_Un_distrib [symmetric]) 
   590 
   591 lemma sats_ordinal_fm:
   592    "[|x < length(env); env \<in> list(A); Transset(A)|]
   593     ==> sats(A, ordinal_fm(x), env) <-> Ord(nth(x,env))"
   594 apply (frule lt_nat_in_nat, erule length_type) 
   595 apply (simp add: ordinal_fm_def Ord_def Transset_def)
   596 apply (blast intro: nth_type) 
   597 done
   598 
   599 
   600 subsection{* Constant Lset: Levels of the Constructible Universe *}
   601 
   602 constdefs Lset :: "i=>i"
   603     "Lset(i) == transrec(i, %x f. \<Union>y\<in>x. DPow(f`y))"
   604 
   605 text{*NOT SUITABLE FOR REWRITING -- RECURSIVE!*}
   606 lemma Lset: "Lset(i) = (UN j:i. DPow(Lset(j)))"
   607 by (subst Lset_def [THEN def_transrec], simp)
   608 
   609 lemma LsetI: "[|y\<in>x; A \<in> DPow(Lset(y))|] ==> A \<in> Lset(x)";
   610 by (subst Lset, blast)
   611 
   612 lemma LsetD: "A \<in> Lset(x) ==> \<exists>y\<in>x. A \<in> DPow(Lset(y))";
   613 apply (insert Lset [of x]) 
   614 apply (blast intro: elim: equalityE) 
   615 done
   616 
   617 subsubsection{* Transitivity *}
   618 
   619 lemma elem_subset_in_DPow: "[|X \<in> A; X \<subseteq> A|] ==> X \<in> DPow(A)"
   620 apply (simp add: Transset_def DPow_def)
   621 apply (rule_tac x="[X]" in bexI) 
   622  apply (rule_tac x="Member(0,1)" in bexI) 
   623   apply (auto simp add: Un_least_lt_iff) 
   624 done
   625 
   626 lemma Transset_subset_DPow: "Transset(A) ==> A <= DPow(A)"
   627 apply clarify  
   628 apply (simp add: Transset_def)
   629 apply (blast intro: elem_subset_in_DPow) 
   630 done
   631 
   632 lemma Transset_DPow: "Transset(A) ==> Transset(DPow(A))"
   633 apply (simp add: Transset_def) 
   634 apply (blast intro: elem_subset_in_DPow dest: DPowD) 
   635 done
   636 
   637 text{*Kunen's VI, 1.6 (a)*}
   638 lemma Transset_Lset: "Transset(Lset(i))"
   639 apply (rule_tac a=i in eps_induct)
   640 apply (subst Lset)
   641 apply (blast intro!: Transset_Union_family Transset_Un Transset_DPow)
   642 done
   643 
   644 lemma mem_Lset_imp_subset_Lset: "a \<in> Lset(i) ==> a \<subseteq> Lset(i)"
   645 apply (insert Transset_Lset) 
   646 apply (simp add: Transset_def) 
   647 done
   648 
   649 subsubsection{* Monotonicity *}
   650 
   651 text{*Kunen's VI, 1.6 (b)*}
   652 lemma Lset_mono [rule_format]:
   653      "ALL j. i<=j --> Lset(i) <= Lset(j)"
   654 apply (rule_tac a=i in eps_induct)
   655 apply (rule impI [THEN allI])
   656 apply (subst Lset)
   657 apply (subst Lset, blast) 
   658 done
   659 
   660 text{*This version lets us remove the premise @{term "Ord(i)"} sometimes.*}
   661 lemma Lset_mono_mem [rule_format]:
   662      "ALL j. i:j --> Lset(i) <= Lset(j)"
   663 apply (rule_tac a=i in eps_induct)
   664 apply (rule impI [THEN allI])
   665 apply (subst Lset, auto) 
   666 apply (rule rev_bexI, assumption)
   667 apply (blast intro: elem_subset_in_DPow dest: LsetD DPowD) 
   668 done
   669 
   670 text{*Useful with Reflection to bump up the ordinal*}
   671 lemma subset_Lset_ltD: "[|A \<subseteq> Lset(i); i < j|] ==> A \<subseteq> Lset(j)"
   672 by (blast dest: ltD [THEN Lset_mono_mem]) 
   673 
   674 subsubsection{* 0, successor and limit equations fof Lset *}
   675 
   676 lemma Lset_0 [simp]: "Lset(0) = 0"
   677 by (subst Lset, blast)
   678 
   679 lemma Lset_succ_subset1: "DPow(Lset(i)) <= Lset(succ(i))"
   680 by (subst Lset, rule succI1 [THEN RepFunI, THEN Union_upper])
   681 
   682 lemma Lset_succ_subset2: "Lset(succ(i)) <= DPow(Lset(i))"
   683 apply (subst Lset, rule UN_least)
   684 apply (erule succE) 
   685  apply blast 
   686 apply clarify
   687 apply (rule elem_subset_in_DPow)
   688  apply (subst Lset)
   689  apply blast 
   690 apply (blast intro: dest: DPowD Lset_mono_mem) 
   691 done
   692 
   693 lemma Lset_succ: "Lset(succ(i)) = DPow(Lset(i))"
   694 by (intro equalityI Lset_succ_subset1 Lset_succ_subset2) 
   695 
   696 lemma Lset_Union [simp]: "Lset(\<Union>(X)) = (\<Union>y\<in>X. Lset(y))"
   697 apply (subst Lset)
   698 apply (rule equalityI)
   699  txt{*first inclusion*}
   700  apply (rule UN_least)
   701  apply (erule UnionE)
   702  apply (rule subset_trans)
   703   apply (erule_tac [2] UN_upper, subst Lset, erule UN_upper)
   704 txt{*opposite inclusion*}
   705 apply (rule UN_least)
   706 apply (subst Lset, blast)
   707 done
   708 
   709 subsubsection{* Lset applied to Limit ordinals *}
   710 
   711 lemma Limit_Lset_eq:
   712     "Limit(i) ==> Lset(i) = (\<Union>y\<in>i. Lset(y))"
   713 by (simp add: Lset_Union [symmetric] Limit_Union_eq)
   714 
   715 lemma lt_LsetI: "[| a: Lset(j);  j<i |] ==> a : Lset(i)"
   716 by (blast dest: Lset_mono [OF le_imp_subset [OF leI]])
   717 
   718 lemma Limit_LsetE:
   719     "[| a: Lset(i);  ~R ==> Limit(i);
   720         !!x. [| x<i;  a: Lset(x) |] ==> R
   721      |] ==> R"
   722 apply (rule classical)
   723 apply (rule Limit_Lset_eq [THEN equalityD1, THEN subsetD, THEN UN_E])
   724   prefer 2 apply assumption
   725  apply blast 
   726 apply (blast intro: ltI  Limit_is_Ord)
   727 done
   728 
   729 subsubsection{* Basic closure properties *}
   730 
   731 lemma zero_in_Lset: "y:x ==> 0 : Lset(x)"
   732 by (subst Lset, blast intro: empty_in_DPow)
   733 
   734 lemma notin_Lset: "x \<notin> Lset(x)"
   735 apply (rule_tac a=x in eps_induct)
   736 apply (subst Lset)
   737 apply (blast dest: DPowD)  
   738 done
   739 
   740 
   741 subsection{*Constructible Ordinals: Kunen's VI, 1.9 (b)*}
   742 
   743 text{*The subset consisting of the ordinals is definable.*}
   744 lemma Ords_in_DPow: "Transset(A) ==> {x \<in> A. Ord(x)} \<in> DPow(A)"
   745 apply (simp add: DPow_def Collect_subset) 
   746 apply (rule_tac x=Nil in bexI) 
   747  apply (rule_tac x="ordinal_fm(0)" in bexI) 
   748 apply (simp_all add: sats_ordinal_fm)
   749 done 
   750 
   751 lemma Ords_of_Lset_eq: "Ord(i) ==> {x\<in>Lset(i). Ord(x)} = i"
   752 apply (erule trans_induct3)
   753   apply (simp_all add: Lset_succ Limit_Lset_eq Limit_Union_eq)
   754 txt{*The successor case remains.*} 
   755 apply (rule equalityI)
   756 txt{*First inclusion*}
   757  apply clarify  
   758  apply (erule Ord_linear_lt, assumption) 
   759    apply (blast dest: DPow_imp_subset ltD notE [OF notin_Lset]) 
   760   apply blast 
   761  apply (blast dest: ltD)
   762 txt{*Opposite inclusion, @{term "succ(x) \<subseteq> DPow(Lset(x)) \<inter> ON"}*}
   763 apply auto
   764 txt{*Key case: *}
   765   apply (erule subst, rule Ords_in_DPow [OF Transset_Lset]) 
   766  apply (blast intro: elem_subset_in_DPow dest: OrdmemD elim: equalityE) 
   767 apply (blast intro: Ord_in_Ord) 
   768 done
   769 
   770 
   771 lemma Ord_subset_Lset: "Ord(i) ==> i \<subseteq> Lset(i)"
   772 by (subst Ords_of_Lset_eq [symmetric], assumption, fast)
   773 
   774 lemma Ord_in_Lset: "Ord(i) ==> i \<in> Lset(succ(i))"
   775 apply (simp add: Lset_succ)
   776 apply (subst Ords_of_Lset_eq [symmetric], assumption, 
   777        rule Ords_in_DPow [OF Transset_Lset]) 
   778 done
   779 
   780 subsubsection{* Unions *}
   781 
   782 lemma Union_in_Lset:
   783      "X \<in> Lset(j) ==> Union(X) \<in> Lset(succ(j))"
   784 apply (insert Transset_Lset)
   785 apply (rule LsetI [OF succI1])
   786 apply (simp add: Transset_def DPow_def) 
   787 apply (intro conjI, blast)
   788 txt{*Now to create the formula @{term "\<exists>y. y \<in> X \<and> x \<in> y"} *}
   789 apply (rule_tac x="Cons(X,Nil)" in bexI) 
   790  apply (rule_tac x="Exists(And(Member(0,2), Member(1,0)))" in bexI) 
   791   apply typecheck
   792 apply (simp add: succ_Un_distrib [symmetric], blast) 
   793 done
   794 
   795 lemma Union_in_LLimit:
   796      "[| X: Lset(i);  Limit(i) |] ==> Union(X) : Lset(i)"
   797 apply (rule Limit_LsetE, assumption+)
   798 apply (blast intro: Limit_has_succ lt_LsetI Union_in_Lset)
   799 done
   800 
   801 subsubsection{* Finite sets and ordered pairs *}
   802 
   803 lemma singleton_in_Lset: "a: Lset(i) ==> {a} : Lset(succ(i))"
   804 by (simp add: Lset_succ singleton_in_DPow) 
   805 
   806 lemma doubleton_in_Lset:
   807      "[| a: Lset(i);  b: Lset(i) |] ==> {a,b} : Lset(succ(i))"
   808 by (simp add: Lset_succ empty_in_DPow cons_in_DPow) 
   809 
   810 lemma Pair_in_Lset:
   811     "[| a: Lset(i);  b: Lset(i); Ord(i) |] ==> <a,b> : Lset(succ(succ(i)))"
   812 apply (unfold Pair_def)
   813 apply (blast intro: doubleton_in_Lset) 
   814 done
   815 
   816 lemma singleton_in_LLimit:
   817     "[| a: Lset(i);  Limit(i) |] ==> {a} : Lset(i)"
   818 apply (erule Limit_LsetE, assumption)
   819 apply (erule singleton_in_Lset [THEN lt_LsetI])
   820 apply (blast intro: Limit_has_succ) 
   821 done
   822 
   823 lemmas Lset_UnI1 = Un_upper1 [THEN Lset_mono [THEN subsetD], standard]
   824 lemmas Lset_UnI2 = Un_upper2 [THEN Lset_mono [THEN subsetD], standard]
   825 
   826 text{*Hard work is finding a single j:i such that {a,b}<=Lset(j)*}
   827 lemma doubleton_in_LLimit:
   828     "[| a: Lset(i);  b: Lset(i);  Limit(i) |] ==> {a,b} : Lset(i)"
   829 apply (erule Limit_LsetE, assumption)
   830 apply (erule Limit_LsetE, assumption)
   831 apply (blast intro: lt_LsetI [OF doubleton_in_Lset]
   832                     Lset_UnI1 Lset_UnI2 Limit_has_succ Un_least_lt)
   833 done
   834 
   835 lemma Pair_in_LLimit:
   836     "[| a: Lset(i);  b: Lset(i);  Limit(i) |] ==> <a,b> : Lset(i)"
   837 txt{*Infer that a, b occur at ordinals x,xa < i.*}
   838 apply (erule Limit_LsetE, assumption)
   839 apply (erule Limit_LsetE, assumption)
   840 txt{*Infer that succ(succ(x Un xa)) < i *}
   841 apply (blast intro: lt_Ord lt_LsetI [OF Pair_in_Lset]
   842                     Lset_UnI1 Lset_UnI2 Limit_has_succ Un_least_lt)
   843 done
   844 
   845 lemma product_LLimit: "Limit(i) ==> Lset(i) * Lset(i) <= Lset(i)"
   846 by (blast intro: Pair_in_LLimit)
   847 
   848 lemmas Sigma_subset_LLimit = subset_trans [OF Sigma_mono product_LLimit]
   849 
   850 lemma nat_subset_LLimit: "Limit(i) ==> nat \<subseteq> Lset(i)"
   851 by (blast dest: Ord_subset_Lset nat_le_Limit le_imp_subset Limit_is_Ord)
   852 
   853 lemma nat_into_LLimit: "[| n: nat;  Limit(i) |] ==> n : Lset(i)"
   854 by (blast intro: nat_subset_LLimit [THEN subsetD])
   855 
   856 
   857 subsubsection{* Closure under disjoint union *}
   858 
   859 lemmas zero_in_LLimit = Limit_has_0 [THEN ltD, THEN zero_in_Lset, standard]
   860 
   861 lemma one_in_LLimit: "Limit(i) ==> 1 : Lset(i)"
   862 by (blast intro: nat_into_LLimit)
   863 
   864 lemma Inl_in_LLimit:
   865     "[| a: Lset(i); Limit(i) |] ==> Inl(a) : Lset(i)"
   866 apply (unfold Inl_def)
   867 apply (blast intro: zero_in_LLimit Pair_in_LLimit)
   868 done
   869 
   870 lemma Inr_in_LLimit:
   871     "[| b: Lset(i); Limit(i) |] ==> Inr(b) : Lset(i)"
   872 apply (unfold Inr_def)
   873 apply (blast intro: one_in_LLimit Pair_in_LLimit)
   874 done
   875 
   876 lemma sum_LLimit: "Limit(i) ==> Lset(i) + Lset(i) <= Lset(i)"
   877 by (blast intro!: Inl_in_LLimit Inr_in_LLimit)
   878 
   879 lemmas sum_subset_LLimit = subset_trans [OF sum_mono sum_LLimit]
   880 
   881 
   882 text{*The constructible universe and its rank function*}
   883 constdefs
   884   L :: "i=>o" --{*Kunen's definition VI, 1.5, page 167*}
   885     "L(x) == \<exists>i. Ord(i) & x \<in> Lset(i)"
   886   
   887   lrank :: "i=>i" --{*Kunen's definition VI, 1.7*}
   888     "lrank(x) == \<mu>i. x \<in> Lset(succ(i))"
   889 
   890 lemma L_I: "[|x \<in> Lset(i); Ord(i)|] ==> L(x)"
   891 by (simp add: L_def, blast)
   892 
   893 lemma L_D: "L(x) ==> \<exists>i. Ord(i) & x \<in> Lset(i)"
   894 by (simp add: L_def)
   895 
   896 lemma Ord_lrank [simp]: "Ord(lrank(a))"
   897 by (simp add: lrank_def)
   898 
   899 lemma Lset_lrank_lt [rule_format]: "Ord(i) ==> x \<in> Lset(i) --> lrank(x) < i"
   900 apply (erule trans_induct3)
   901   apply simp   
   902  apply (simp only: lrank_def) 
   903  apply (blast intro: Least_le) 
   904 apply (simp_all add: Limit_Lset_eq) 
   905 apply (blast intro: ltI Limit_is_Ord lt_trans) 
   906 done
   907 
   908 text{*Kunen's VI, 1.8, and the proof is much less trivial than the text
   909 would suggest.  For a start it need the previous lemma, proved by induction.*}
   910 lemma Lset_iff_lrank_lt: "Ord(i) ==> x \<in> Lset(i) <-> L(x) & lrank(x) < i"
   911 apply (simp add: L_def, auto) 
   912  apply (blast intro: Lset_lrank_lt) 
   913  apply (unfold lrank_def) 
   914 apply (drule succI1 [THEN Lset_mono_mem, THEN subsetD]) 
   915 apply (drule_tac P="\<lambda>i. x \<in> Lset(succ(i))" in LeastI, assumption) 
   916 apply (blast intro!: le_imp_subset Lset_mono [THEN subsetD]) 
   917 done
   918 
   919 lemma Lset_succ_lrank_iff [simp]: "x \<in> Lset(succ(lrank(x))) <-> L(x)"
   920 by (simp add: Lset_iff_lrank_lt)
   921 
   922 text{*Kunen's VI, 1.9 (a)*}
   923 lemma lrank_of_Ord: "Ord(i) ==> lrank(i) = i"
   924 apply (unfold lrank_def) 
   925 apply (rule Least_equality) 
   926   apply (erule Ord_in_Lset) 
   927  apply assumption
   928 apply (insert notin_Lset [of i]) 
   929 apply (blast intro!: le_imp_subset Lset_mono [THEN subsetD]) 
   930 done
   931 
   932 
   933 lemma Ord_in_L: "Ord(i) ==> L(i)"
   934 by (blast intro: Ord_in_Lset L_I)
   935 
   936 text{*This is lrank(lrank(a)) = lrank(a) *}
   937 declare Ord_lrank [THEN lrank_of_Ord, simp]
   938 
   939 text{*Kunen's VI, 1.10 *}
   940 lemma Lset_in_Lset_succ: "Lset(i) \<in> Lset(succ(i))";
   941 apply (simp add: Lset_succ DPow_def) 
   942 apply (rule_tac x=Nil in bexI) 
   943  apply (rule_tac x="Equal(0,0)" in bexI) 
   944 apply auto 
   945 done
   946 
   947 lemma lrank_Lset: "Ord(i) ==> lrank(Lset(i)) = i"
   948 apply (unfold lrank_def) 
   949 apply (rule Least_equality) 
   950   apply (rule Lset_in_Lset_succ) 
   951  apply assumption
   952 apply clarify 
   953 apply (subgoal_tac "Lset(succ(ia)) <= Lset(i)")
   954  apply (blast dest: mem_irrefl) 
   955 apply (blast intro!: le_imp_subset Lset_mono) 
   956 done
   957 
   958 text{*Kunen's VI, 1.11 *}
   959 lemma Lset_subset_Vset: "Ord(i) ==> Lset(i) <= Vset(i)";
   960 apply (erule trans_induct)
   961 apply (subst Lset) 
   962 apply (subst Vset) 
   963 apply (rule UN_mono [OF subset_refl]) 
   964 apply (rule subset_trans [OF DPow_subset_Pow]) 
   965 apply (rule Pow_mono, blast) 
   966 done
   967 
   968 text{*Kunen's VI, 1.12 *}
   969 lemma Lset_subset_Vset': "i \<in> nat ==> Lset(i) = Vset(i)";
   970 apply (erule nat_induct)
   971  apply (simp add: Vfrom_0) 
   972 apply (simp add: Lset_succ Vset_succ Finite_Vset Finite_DPow_eq_Pow) 
   973 done
   974 
   975 text{*Every set of constructible sets is included in some @{term Lset}*} 
   976 lemma subset_Lset:
   977      "(\<forall>x\<in>A. L(x)) ==> \<exists>i. Ord(i) & A \<subseteq> Lset(i)"
   978 by (rule_tac x = "\<Union>x\<in>A. succ(lrank(x))" in exI, force)
   979 
   980 lemma subset_LsetE:
   981      "[|\<forall>x\<in>A. L(x);
   982         !!i. [|Ord(i); A \<subseteq> Lset(i)|] ==> P|]
   983       ==> P"
   984 by (blast dest: subset_Lset) 
   985 
   986 subsection{*For L to satisfy the ZF axioms*}
   987 
   988 theorem Union_in_L: "L(X) ==> L(Union(X))"
   989 apply (simp add: L_def, clarify) 
   990 apply (drule Ord_imp_greater_Limit) 
   991 apply (blast intro: lt_LsetI Union_in_LLimit Limit_is_Ord) 
   992 done
   993 
   994 theorem doubleton_in_L: "[| L(a); L(b) |] ==> L({a, b})"
   995 apply (simp add: L_def, clarify) 
   996 apply (drule Ord2_imp_greater_Limit, assumption) 
   997 apply (blast intro: lt_LsetI doubleton_in_LLimit Limit_is_Ord) 
   998 done
   999 
  1000 subsubsection{*For L to satisfy Powerset *}
  1001 
  1002 lemma LPow_env_typing:
  1003     "[| y : Lset(i); Ord(i); y \<subseteq> X |] 
  1004      ==> \<exists>z \<in> Pow(X). y \<in> Lset(succ(lrank(z)))"
  1005 by (auto intro: L_I iff: Lset_succ_lrank_iff) 
  1006 
  1007 lemma LPow_in_Lset:
  1008      "[|X \<in> Lset(i); Ord(i)|] ==> \<exists>j. Ord(j) & {y \<in> Pow(X). L(y)} \<in> Lset(j)"
  1009 apply (rule_tac x="succ(\<Union>y \<in> Pow(X). succ(lrank(y)))" in exI)
  1010 apply simp 
  1011 apply (rule LsetI [OF succI1])
  1012 apply (simp add: DPow_def) 
  1013 apply (intro conjI, clarify) 
  1014  apply (rule_tac a=x in UN_I, simp+)  
  1015 txt{*Now to create the formula @{term "y \<subseteq> X"} *}
  1016 apply (rule_tac x="Cons(X,Nil)" in bexI) 
  1017  apply (rule_tac x="subset_fm(0,1)" in bexI) 
  1018   apply typecheck
  1019  apply (rule conjI) 
  1020 apply (simp add: succ_Un_distrib [symmetric]) 
  1021 apply (rule equality_iffI) 
  1022 apply (simp add: Transset_UN [OF Transset_Lset] LPow_env_typing)
  1023 apply (auto intro: L_I iff: Lset_succ_lrank_iff) 
  1024 done
  1025 
  1026 theorem LPow_in_L: "L(X) ==> L({y \<in> Pow(X). L(y)})"
  1027 by (blast intro: L_I dest: L_D LPow_in_Lset)
  1028 
  1029 
  1030 subsection{*Eliminating @{term arity} from the Definition of @{term Lset}*}
  1031 
  1032 
  1033 lemma nth_zero_eq_0: "n \<in> nat ==> nth(n,[0]) = 0"
  1034 by (induct_tac n, auto)
  1035 
  1036 lemma sats_app_0_iff [rule_format]:
  1037   "[| p \<in> formula; 0 \<in> A |]
  1038    ==> \<forall>env \<in> list(A). sats(A,p, env@[0]) <-> sats(A,p,env)"
  1039 apply (induct_tac p)
  1040 apply (simp_all del: app_Cons add: app_Cons [symmetric]
  1041 		add: nth_zero_eq_0 nth_append not_lt_iff_le nth_eq_0)
  1042 done
  1043 
  1044 lemma sats_app_zeroes_iff:
  1045   "[| p \<in> formula; 0 \<in> A; env \<in> list(A); n \<in> nat |]
  1046    ==> sats(A,p,env @ repeat(0,n)) <-> sats(A,p,env)"
  1047 apply (induct_tac n, simp) 
  1048 apply (simp del: repeat.simps
  1049             add: repeat_succ_app sats_app_0_iff app_assoc [symmetric]) 
  1050 done
  1051 
  1052 lemma exists_bigger_env:
  1053   "[| p \<in> formula; 0 \<in> A; env \<in> list(A) |]
  1054    ==> \<exists>env' \<in> list(A). arity(p) \<le> succ(length(env')) & 
  1055               (\<forall>a\<in>A. sats(A,p,Cons(a,env')) <-> sats(A,p,Cons(a,env)))"
  1056 apply (rule_tac x="env @ repeat(0,arity(p))" in bexI) 
  1057 apply (simp del: app_Cons add: app_Cons [symmetric]
  1058 	    add: length_repeat sats_app_zeroes_iff, typecheck)
  1059 done
  1060 
  1061 
  1062 text{*A simpler version of @{term DPow}: no arity check!*}
  1063 constdefs DPow' :: "i => i"
  1064   "DPow'(A) == {X \<in> Pow(A). 
  1065                 \<exists>env \<in> list(A). \<exists>p \<in> formula. 
  1066                     X = {x\<in>A. sats(A, p, Cons(x,env))}}"
  1067 
  1068 lemma DPow_subset_DPow': "DPow(A) <= DPow'(A)";
  1069 by (simp add: DPow_def DPow'_def, blast)
  1070 
  1071 lemma DPow'_0: "DPow'(0) = {0}"
  1072 by (auto simp add: DPow'_def)
  1073 
  1074 lemma DPow'_subset_DPow: "0 \<in> A ==> DPow'(A) \<subseteq> DPow(A)"
  1075 apply (auto simp add: DPow'_def DPow_def) 
  1076 apply (frule exists_bigger_env, assumption+, force)  
  1077 done
  1078 
  1079 lemma DPow_eq_DPow': "Transset(A) ==> DPow(A) = DPow'(A)"
  1080 apply (drule Transset_0_disj) 
  1081 apply (erule disjE) 
  1082  apply (simp add: DPow'_0 DPow_0) 
  1083 apply (rule equalityI)
  1084  apply (rule DPow_subset_DPow') 
  1085 apply (erule DPow'_subset_DPow) 
  1086 done
  1087 
  1088 text{*And thus we can relativize @{term Lset} without bothering with
  1089       @{term arity} and @{term length}*}
  1090 lemma Lset_eq_transrec_DPow': "Lset(i) = transrec(i, %x f. \<Union>y\<in>x. DPow'(f`y))"
  1091 apply (rule_tac a=i in eps_induct)
  1092 apply (subst Lset)
  1093 apply (subst transrec)
  1094 apply (simp only: DPow_eq_DPow' [OF Transset_Lset], simp) 
  1095 done
  1096 
  1097 text{*With this rule we can specify @{term p} later and don't worry about
  1098       arities at all!*}
  1099 lemma DPow_LsetI [rule_format]:
  1100   "[|\<forall>x\<in>Lset(i). P(x) <-> sats(Lset(i), p, Cons(x,env));
  1101      env \<in> list(Lset(i));  p \<in> formula|]
  1102    ==> {x\<in>Lset(i). P(x)} \<in> DPow(Lset(i))"
  1103 by (simp add: DPow_eq_DPow' [OF Transset_Lset] DPow'_def, blast) 
  1104 
  1105 end