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