src/ZF/Constructible/Relative.thy
author paulson
Wed Oct 09 11:07:13 2002 +0200 (2002-10-09)
changeset 13634 99a593b49b04
parent 13628 87482b5e3f2e
child 13687 22dce9134953
permissions -rw-r--r--
Re-organization of Constructible theories
     1 (*  Title:      ZF/Constructible/Relative.thy
     2     ID:         $Id$
     3     Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
     4 *)
     5 
     6 header {*Relativization and Absoluteness*}
     7 
     8 theory Relative = Main:
     9 
    10 subsection{* Relativized versions of standard set-theoretic concepts *}
    11 
    12 constdefs
    13   empty :: "[i=>o,i] => o"
    14     "empty(M,z) == \<forall>x[M]. x \<notin> z"
    15 
    16   subset :: "[i=>o,i,i] => o"
    17     "subset(M,A,B) == \<forall>x[M]. x\<in>A --> x \<in> B"
    18 
    19   upair :: "[i=>o,i,i,i] => o"
    20     "upair(M,a,b,z) == a \<in> z & b \<in> z & (\<forall>x[M]. x\<in>z --> x = a | x = b)"
    21 
    22   pair :: "[i=>o,i,i,i] => o"
    23     "pair(M,a,b,z) == \<exists>x[M]. upair(M,a,a,x) &
    24                           (\<exists>y[M]. upair(M,a,b,y) & upair(M,x,y,z))"
    25 
    26 
    27   union :: "[i=>o,i,i,i] => o"
    28     "union(M,a,b,z) == \<forall>x[M]. x \<in> z <-> x \<in> a | x \<in> b"
    29 
    30   is_cons :: "[i=>o,i,i,i] => o"
    31     "is_cons(M,a,b,z) == \<exists>x[M]. upair(M,a,a,x) & union(M,x,b,z)"
    32 
    33   successor :: "[i=>o,i,i] => o"
    34     "successor(M,a,z) == is_cons(M,a,a,z)"
    35 
    36   number1 :: "[i=>o,i] => o"
    37     "number1(M,a) == \<exists>x[M]. empty(M,x) & successor(M,x,a)"
    38 
    39   number2 :: "[i=>o,i] => o"
    40     "number2(M,a) == \<exists>x[M]. number1(M,x) & successor(M,x,a)"
    41 
    42   number3 :: "[i=>o,i] => o"
    43     "number3(M,a) == \<exists>x[M]. number2(M,x) & successor(M,x,a)"
    44 
    45   powerset :: "[i=>o,i,i] => o"
    46     "powerset(M,A,z) == \<forall>x[M]. x \<in> z <-> subset(M,x,A)"
    47 
    48   is_Collect :: "[i=>o,i,i=>o,i] => o"
    49     "is_Collect(M,A,P,z) == \<forall>x[M]. x \<in> z <-> x \<in> A & P(x)"
    50 
    51   is_Replace :: "[i=>o,i,[i,i]=>o,i] => o"
    52     "is_Replace(M,A,P,z) == \<forall>u[M]. u \<in> z <-> (\<exists>x[M]. x\<in>A & P(x,u))"
    53 
    54   inter :: "[i=>o,i,i,i] => o"
    55     "inter(M,a,b,z) == \<forall>x[M]. x \<in> z <-> x \<in> a & x \<in> b"
    56 
    57   setdiff :: "[i=>o,i,i,i] => o"
    58     "setdiff(M,a,b,z) == \<forall>x[M]. x \<in> z <-> x \<in> a & x \<notin> b"
    59 
    60   big_union :: "[i=>o,i,i] => o"
    61     "big_union(M,A,z) == \<forall>x[M]. x \<in> z <-> (\<exists>y[M]. y\<in>A & x \<in> y)"
    62 
    63   big_inter :: "[i=>o,i,i] => o"
    64     "big_inter(M,A,z) ==
    65              (A=0 --> z=0) &
    66 	     (A\<noteq>0 --> (\<forall>x[M]. x \<in> z <-> (\<forall>y[M]. y\<in>A --> x \<in> y)))"
    67 
    68   cartprod :: "[i=>o,i,i,i] => o"
    69     "cartprod(M,A,B,z) ==
    70 	\<forall>u[M]. u \<in> z <-> (\<exists>x[M]. x\<in>A & (\<exists>y[M]. y\<in>B & pair(M,x,y,u)))"
    71 
    72   is_sum :: "[i=>o,i,i,i] => o"
    73     "is_sum(M,A,B,Z) ==
    74        \<exists>A0[M]. \<exists>n1[M]. \<exists>s1[M]. \<exists>B1[M].
    75        number1(M,n1) & cartprod(M,n1,A,A0) & upair(M,n1,n1,s1) &
    76        cartprod(M,s1,B,B1) & union(M,A0,B1,Z)"
    77 
    78   is_Inl :: "[i=>o,i,i] => o"
    79     "is_Inl(M,a,z) == \<exists>zero[M]. empty(M,zero) & pair(M,zero,a,z)"
    80 
    81   is_Inr :: "[i=>o,i,i] => o"
    82     "is_Inr(M,a,z) == \<exists>n1[M]. number1(M,n1) & pair(M,n1,a,z)"
    83 
    84   is_converse :: "[i=>o,i,i] => o"
    85     "is_converse(M,r,z) ==
    86 	\<forall>x[M]. x \<in> z <->
    87              (\<exists>w[M]. w\<in>r & (\<exists>u[M]. \<exists>v[M]. pair(M,u,v,w) & pair(M,v,u,x)))"
    88 
    89   pre_image :: "[i=>o,i,i,i] => o"
    90     "pre_image(M,r,A,z) ==
    91 	\<forall>x[M]. x \<in> z <-> (\<exists>w[M]. w\<in>r & (\<exists>y[M]. y\<in>A & pair(M,x,y,w)))"
    92 
    93   is_domain :: "[i=>o,i,i] => o"
    94     "is_domain(M,r,z) ==
    95 	\<forall>x[M]. x \<in> z <-> (\<exists>w[M]. w\<in>r & (\<exists>y[M]. pair(M,x,y,w)))"
    96 
    97   image :: "[i=>o,i,i,i] => o"
    98     "image(M,r,A,z) ==
    99         \<forall>y[M]. y \<in> z <-> (\<exists>w[M]. w\<in>r & (\<exists>x[M]. x\<in>A & pair(M,x,y,w)))"
   100 
   101   is_range :: "[i=>o,i,i] => o"
   102     --{*the cleaner
   103       @{term "\<exists>r'[M]. is_converse(M,r,r') & is_domain(M,r',z)"}
   104       unfortunately needs an instance of separation in order to prove
   105         @{term "M(converse(r))"}.*}
   106     "is_range(M,r,z) ==
   107 	\<forall>y[M]. y \<in> z <-> (\<exists>w[M]. w\<in>r & (\<exists>x[M]. pair(M,x,y,w)))"
   108 
   109   is_field :: "[i=>o,i,i] => o"
   110     "is_field(M,r,z) ==
   111 	\<exists>dr[M]. \<exists>rr[M]. is_domain(M,r,dr) & is_range(M,r,rr) &
   112                         union(M,dr,rr,z)"
   113 
   114   is_relation :: "[i=>o,i] => o"
   115     "is_relation(M,r) ==
   116         (\<forall>z[M]. z\<in>r --> (\<exists>x[M]. \<exists>y[M]. pair(M,x,y,z)))"
   117 
   118   is_function :: "[i=>o,i] => o"
   119     "is_function(M,r) ==
   120 	\<forall>x[M]. \<forall>y[M]. \<forall>y'[M]. \<forall>p[M]. \<forall>p'[M].
   121            pair(M,x,y,p) --> pair(M,x,y',p') --> p\<in>r --> p'\<in>r --> y=y'"
   122 
   123   fun_apply :: "[i=>o,i,i,i] => o"
   124     "fun_apply(M,f,x,y) ==
   125         (\<exists>xs[M]. \<exists>fxs[M].
   126          upair(M,x,x,xs) & image(M,f,xs,fxs) & big_union(M,fxs,y))"
   127 
   128   typed_function :: "[i=>o,i,i,i] => o"
   129     "typed_function(M,A,B,r) ==
   130         is_function(M,r) & is_relation(M,r) & is_domain(M,r,A) &
   131         (\<forall>u[M]. u\<in>r --> (\<forall>x[M]. \<forall>y[M]. pair(M,x,y,u) --> y\<in>B))"
   132 
   133   is_funspace :: "[i=>o,i,i,i] => o"
   134     "is_funspace(M,A,B,F) ==
   135         \<forall>f[M]. f \<in> F <-> typed_function(M,A,B,f)"
   136 
   137   composition :: "[i=>o,i,i,i] => o"
   138     "composition(M,r,s,t) ==
   139         \<forall>p[M]. p \<in> t <->
   140                (\<exists>x[M]. \<exists>y[M]. \<exists>z[M]. \<exists>xy[M]. \<exists>yz[M].
   141                 pair(M,x,z,p) & pair(M,x,y,xy) & pair(M,y,z,yz) &
   142                 xy \<in> s & yz \<in> r)"
   143 
   144   injection :: "[i=>o,i,i,i] => o"
   145     "injection(M,A,B,f) ==
   146 	typed_function(M,A,B,f) &
   147         (\<forall>x[M]. \<forall>x'[M]. \<forall>y[M]. \<forall>p[M]. \<forall>p'[M].
   148           pair(M,x,y,p) --> pair(M,x',y,p') --> p\<in>f --> p'\<in>f --> x=x')"
   149 
   150   surjection :: "[i=>o,i,i,i] => o"
   151     "surjection(M,A,B,f) ==
   152         typed_function(M,A,B,f) &
   153         (\<forall>y[M]. y\<in>B --> (\<exists>x[M]. x\<in>A & fun_apply(M,f,x,y)))"
   154 
   155   bijection :: "[i=>o,i,i,i] => o"
   156     "bijection(M,A,B,f) == injection(M,A,B,f) & surjection(M,A,B,f)"
   157 
   158   restriction :: "[i=>o,i,i,i] => o"
   159     "restriction(M,r,A,z) ==
   160 	\<forall>x[M]. x \<in> z <-> (x \<in> r & (\<exists>u[M]. u\<in>A & (\<exists>v[M]. pair(M,u,v,x))))"
   161 
   162   transitive_set :: "[i=>o,i] => o"
   163     "transitive_set(M,a) == \<forall>x[M]. x\<in>a --> subset(M,x,a)"
   164 
   165   ordinal :: "[i=>o,i] => o"
   166      --{*an ordinal is a transitive set of transitive sets*}
   167     "ordinal(M,a) == transitive_set(M,a) & (\<forall>x[M]. x\<in>a --> transitive_set(M,x))"
   168 
   169   limit_ordinal :: "[i=>o,i] => o"
   170     --{*a limit ordinal is a non-empty, successor-closed ordinal*}
   171     "limit_ordinal(M,a) ==
   172 	ordinal(M,a) & ~ empty(M,a) &
   173         (\<forall>x[M]. x\<in>a --> (\<exists>y[M]. y\<in>a & successor(M,x,y)))"
   174 
   175   successor_ordinal :: "[i=>o,i] => o"
   176     --{*a successor ordinal is any ordinal that is neither empty nor limit*}
   177     "successor_ordinal(M,a) ==
   178 	ordinal(M,a) & ~ empty(M,a) & ~ limit_ordinal(M,a)"
   179 
   180   finite_ordinal :: "[i=>o,i] => o"
   181     --{*an ordinal is finite if neither it nor any of its elements are limit*}
   182     "finite_ordinal(M,a) ==
   183 	ordinal(M,a) & ~ limit_ordinal(M,a) &
   184         (\<forall>x[M]. x\<in>a --> ~ limit_ordinal(M,x))"
   185 
   186   omega :: "[i=>o,i] => o"
   187     --{*omega is a limit ordinal none of whose elements are limit*}
   188     "omega(M,a) == limit_ordinal(M,a) & (\<forall>x[M]. x\<in>a --> ~ limit_ordinal(M,x))"
   189 
   190   is_quasinat :: "[i=>o,i] => o"
   191     "is_quasinat(M,z) == empty(M,z) | (\<exists>m[M]. successor(M,m,z))"
   192 
   193   is_nat_case :: "[i=>o, i, [i,i]=>o, i, i] => o"
   194     "is_nat_case(M, a, is_b, k, z) ==
   195        (empty(M,k) --> z=a) &
   196        (\<forall>m[M]. successor(M,m,k) --> is_b(m,z)) &
   197        (is_quasinat(M,k) | empty(M,z))"
   198 
   199   relation1 :: "[i=>o, [i,i]=>o, i=>i] => o"
   200     "relation1(M,is_f,f) == \<forall>x[M]. \<forall>y[M]. is_f(x,y) <-> y = f(x)"
   201 
   202   Relation1 :: "[i=>o, i, [i,i]=>o, i=>i] => o"
   203     --{*as above, but typed*}
   204     "Relation1(M,A,is_f,f) ==
   205         \<forall>x[M]. \<forall>y[M]. x\<in>A --> is_f(x,y) <-> y = f(x)"
   206 
   207   relation2 :: "[i=>o, [i,i,i]=>o, [i,i]=>i] => o"
   208     "relation2(M,is_f,f) == \<forall>x[M]. \<forall>y[M]. \<forall>z[M]. is_f(x,y,z) <-> z = f(x,y)"
   209 
   210   Relation2 :: "[i=>o, i, i, [i,i,i]=>o, [i,i]=>i] => o"
   211     "Relation2(M,A,B,is_f,f) ==
   212         \<forall>x[M]. \<forall>y[M]. \<forall>z[M]. x\<in>A --> y\<in>B --> is_f(x,y,z) <-> z = f(x,y)"
   213 
   214   relation3 :: "[i=>o, [i,i,i,i]=>o, [i,i,i]=>i] => o"
   215     "relation3(M,is_f,f) ==
   216        \<forall>x[M]. \<forall>y[M]. \<forall>z[M]. \<forall>u[M]. is_f(x,y,z,u) <-> u = f(x,y,z)"
   217 
   218   Relation3 :: "[i=>o, i, i, i, [i,i,i,i]=>o, [i,i,i]=>i] => o"
   219     "Relation3(M,A,B,C,is_f,f) ==
   220        \<forall>x[M]. \<forall>y[M]. \<forall>z[M]. \<forall>u[M].
   221          x\<in>A --> y\<in>B --> z\<in>C --> is_f(x,y,z,u) <-> u = f(x,y,z)"
   222 
   223   relation4 :: "[i=>o, [i,i,i,i,i]=>o, [i,i,i,i]=>i] => o"
   224     "relation4(M,is_f,f) ==
   225        \<forall>u[M]. \<forall>x[M]. \<forall>y[M]. \<forall>z[M]. \<forall>a[M]. is_f(u,x,y,z,a) <-> a = f(u,x,y,z)"
   226 
   227 
   228 text{*Useful when absoluteness reasoning has replaced the predicates by terms*}
   229 lemma triv_Relation1:
   230      "Relation1(M, A, \<lambda>x y. y = f(x), f)"
   231 by (simp add: Relation1_def)
   232 
   233 lemma triv_Relation2:
   234      "Relation2(M, A, B, \<lambda>x y a. a = f(x,y), f)"
   235 by (simp add: Relation2_def)
   236 
   237 
   238 subsection {*The relativized ZF axioms*}
   239 constdefs
   240 
   241   extensionality :: "(i=>o) => o"
   242     "extensionality(M) ==
   243 	\<forall>x[M]. \<forall>y[M]. (\<forall>z[M]. z \<in> x <-> z \<in> y) --> x=y"
   244 
   245   separation :: "[i=>o, i=>o] => o"
   246     --{*The formula @{text P} should only involve parameters
   247         belonging to @{text M} and all its quantifiers must be relativized
   248         to @{text M}.  We do not have separation as a scheme; every instance
   249         that we need must be assumed (and later proved) separately.*}
   250     "separation(M,P) ==
   251 	\<forall>z[M]. \<exists>y[M]. \<forall>x[M]. x \<in> y <-> x \<in> z & P(x)"
   252 
   253   upair_ax :: "(i=>o) => o"
   254     "upair_ax(M) == \<forall>x[M]. \<forall>y[M]. \<exists>z[M]. upair(M,x,y,z)"
   255 
   256   Union_ax :: "(i=>o) => o"
   257     "Union_ax(M) == \<forall>x[M]. \<exists>z[M]. big_union(M,x,z)"
   258 
   259   power_ax :: "(i=>o) => o"
   260     "power_ax(M) == \<forall>x[M]. \<exists>z[M]. powerset(M,x,z)"
   261 
   262   univalent :: "[i=>o, i, [i,i]=>o] => o"
   263     "univalent(M,A,P) ==
   264 	\<forall>x[M]. x\<in>A --> (\<forall>y[M]. \<forall>z[M]. P(x,y) & P(x,z) --> y=z)"
   265 
   266   replacement :: "[i=>o, [i,i]=>o] => o"
   267     "replacement(M,P) ==
   268       \<forall>A[M]. univalent(M,A,P) -->
   269       (\<exists>Y[M]. \<forall>b[M]. (\<exists>x[M]. x\<in>A & P(x,b)) --> b \<in> Y)"
   270 
   271   strong_replacement :: "[i=>o, [i,i]=>o] => o"
   272     "strong_replacement(M,P) ==
   273       \<forall>A[M]. univalent(M,A,P) -->
   274       (\<exists>Y[M]. \<forall>b[M]. b \<in> Y <-> (\<exists>x[M]. x\<in>A & P(x,b)))"
   275 
   276   foundation_ax :: "(i=>o) => o"
   277     "foundation_ax(M) ==
   278 	\<forall>x[M]. (\<exists>y[M]. y\<in>x) --> (\<exists>y[M]. y\<in>x & ~(\<exists>z[M]. z\<in>x & z \<in> y))"
   279 
   280 
   281 subsection{*A trivial consistency proof for $V_\omega$ *}
   282 
   283 text{*We prove that $V_\omega$
   284       (or @{text univ} in Isabelle) satisfies some ZF axioms.
   285      Kunen, Theorem IV 3.13, page 123.*}
   286 
   287 lemma univ0_downwards_mem: "[| y \<in> x; x \<in> univ(0) |] ==> y \<in> univ(0)"
   288 apply (insert Transset_univ [OF Transset_0])
   289 apply (simp add: Transset_def, blast)
   290 done
   291 
   292 lemma univ0_Ball_abs [simp]:
   293      "A \<in> univ(0) ==> (\<forall>x\<in>A. x \<in> univ(0) --> P(x)) <-> (\<forall>x\<in>A. P(x))"
   294 by (blast intro: univ0_downwards_mem)
   295 
   296 lemma univ0_Bex_abs [simp]:
   297      "A \<in> univ(0) ==> (\<exists>x\<in>A. x \<in> univ(0) & P(x)) <-> (\<exists>x\<in>A. P(x))"
   298 by (blast intro: univ0_downwards_mem)
   299 
   300 text{*Congruence rule for separation: can assume the variable is in @{text M}*}
   301 lemma separation_cong [cong]:
   302      "(!!x. M(x) ==> P(x) <-> P'(x))
   303       ==> separation(M, %x. P(x)) <-> separation(M, %x. P'(x))"
   304 by (simp add: separation_def)
   305 
   306 lemma univalent_cong [cong]:
   307      "[| A=A'; !!x y. [| x\<in>A; M(x); M(y) |] ==> P(x,y) <-> P'(x,y) |]
   308       ==> univalent(M, A, %x y. P(x,y)) <-> univalent(M, A', %x y. P'(x,y))"
   309 by (simp add: univalent_def)
   310 
   311 lemma univalent_triv [intro,simp]:
   312      "univalent(M, A, \<lambda>x y. y = f(x))"
   313 by (simp add: univalent_def)
   314 
   315 lemma univalent_conjI2 [intro,simp]:
   316      "univalent(M,A,Q) ==> univalent(M, A, \<lambda>x y. P(x,y) & Q(x,y))"
   317 by (simp add: univalent_def, blast)
   318 
   319 text{*Congruence rule for replacement*}
   320 lemma strong_replacement_cong [cong]:
   321      "[| !!x y. [| M(x); M(y) |] ==> P(x,y) <-> P'(x,y) |]
   322       ==> strong_replacement(M, %x y. P(x,y)) <->
   323           strong_replacement(M, %x y. P'(x,y))"
   324 by (simp add: strong_replacement_def)
   325 
   326 text{*The extensionality axiom*}
   327 lemma "extensionality(\<lambda>x. x \<in> univ(0))"
   328 apply (simp add: extensionality_def)
   329 apply (blast intro: univ0_downwards_mem)
   330 done
   331 
   332 text{*The separation axiom requires some lemmas*}
   333 lemma Collect_in_Vfrom:
   334      "[| X \<in> Vfrom(A,j);  Transset(A) |] ==> Collect(X,P) \<in> Vfrom(A, succ(j))"
   335 apply (drule Transset_Vfrom)
   336 apply (rule subset_mem_Vfrom)
   337 apply (unfold Transset_def, blast)
   338 done
   339 
   340 lemma Collect_in_VLimit:
   341      "[| X \<in> Vfrom(A,i);  Limit(i);  Transset(A) |]
   342       ==> Collect(X,P) \<in> Vfrom(A,i)"
   343 apply (rule Limit_VfromE, assumption+)
   344 apply (blast intro: Limit_has_succ VfromI Collect_in_Vfrom)
   345 done
   346 
   347 lemma Collect_in_univ:
   348      "[| X \<in> univ(A);  Transset(A) |] ==> Collect(X,P) \<in> univ(A)"
   349 by (simp add: univ_def Collect_in_VLimit Limit_nat)
   350 
   351 lemma "separation(\<lambda>x. x \<in> univ(0), P)"
   352 apply (simp add: separation_def, clarify)
   353 apply (rule_tac x = "Collect(z,P)" in bexI)
   354 apply (blast intro: Collect_in_univ Transset_0)+
   355 done
   356 
   357 text{*Unordered pairing axiom*}
   358 lemma "upair_ax(\<lambda>x. x \<in> univ(0))"
   359 apply (simp add: upair_ax_def upair_def)
   360 apply (blast intro: doubleton_in_univ)
   361 done
   362 
   363 text{*Union axiom*}
   364 lemma "Union_ax(\<lambda>x. x \<in> univ(0))"
   365 apply (simp add: Union_ax_def big_union_def, clarify)
   366 apply (rule_tac x="\<Union>x" in bexI)
   367  apply (blast intro: univ0_downwards_mem)
   368 apply (blast intro: Union_in_univ Transset_0)
   369 done
   370 
   371 text{*Powerset axiom*}
   372 
   373 lemma Pow_in_univ:
   374      "[| X \<in> univ(A);  Transset(A) |] ==> Pow(X) \<in> univ(A)"
   375 apply (simp add: univ_def Pow_in_VLimit Limit_nat)
   376 done
   377 
   378 lemma "power_ax(\<lambda>x. x \<in> univ(0))"
   379 apply (simp add: power_ax_def powerset_def subset_def, clarify)
   380 apply (rule_tac x="Pow(x)" in bexI)
   381  apply (blast intro: univ0_downwards_mem)
   382 apply (blast intro: Pow_in_univ Transset_0)
   383 done
   384 
   385 text{*Foundation axiom*}
   386 lemma "foundation_ax(\<lambda>x. x \<in> univ(0))"
   387 apply (simp add: foundation_ax_def, clarify)
   388 apply (cut_tac A=x in foundation)
   389 apply (blast intro: univ0_downwards_mem)
   390 done
   391 
   392 lemma "replacement(\<lambda>x. x \<in> univ(0), P)"
   393 apply (simp add: replacement_def, clarify)
   394 oops
   395 text{*no idea: maybe prove by induction on the rank of A?*}
   396 
   397 text{*Still missing: Replacement, Choice*}
   398 
   399 subsection{*Lemmas Needed to Reduce Some Set Constructions to Instances
   400       of Separation*}
   401 
   402 lemma image_iff_Collect: "r `` A = {y \<in> Union(Union(r)). \<exists>p\<in>r. \<exists>x\<in>A. p=<x,y>}"
   403 apply (rule equalityI, auto)
   404 apply (simp add: Pair_def, blast)
   405 done
   406 
   407 lemma vimage_iff_Collect:
   408      "r -`` A = {x \<in> Union(Union(r)). \<exists>p\<in>r. \<exists>y\<in>A. p=<x,y>}"
   409 apply (rule equalityI, auto)
   410 apply (simp add: Pair_def, blast)
   411 done
   412 
   413 text{*These two lemmas lets us prove @{text domain_closed} and
   414       @{text range_closed} without new instances of separation*}
   415 
   416 lemma domain_eq_vimage: "domain(r) = r -`` Union(Union(r))"
   417 apply (rule equalityI, auto)
   418 apply (rule vimageI, assumption)
   419 apply (simp add: Pair_def, blast)
   420 done
   421 
   422 lemma range_eq_image: "range(r) = r `` Union(Union(r))"
   423 apply (rule equalityI, auto)
   424 apply (rule imageI, assumption)
   425 apply (simp add: Pair_def, blast)
   426 done
   427 
   428 lemma replacementD:
   429     "[| replacement(M,P); M(A);  univalent(M,A,P) |]
   430      ==> \<exists>Y[M]. (\<forall>b[M]. ((\<exists>x[M]. x\<in>A & P(x,b)) --> b \<in> Y))"
   431 by (simp add: replacement_def)
   432 
   433 lemma strong_replacementD:
   434     "[| strong_replacement(M,P); M(A);  univalent(M,A,P) |]
   435      ==> \<exists>Y[M]. (\<forall>b[M]. (b \<in> Y <-> (\<exists>x[M]. x\<in>A & P(x,b))))"
   436 by (simp add: strong_replacement_def)
   437 
   438 lemma separationD:
   439     "[| separation(M,P); M(z) |] ==> \<exists>y[M]. \<forall>x[M]. x \<in> y <-> x \<in> z & P(x)"
   440 by (simp add: separation_def)
   441 
   442 
   443 text{*More constants, for order types*}
   444 constdefs
   445 
   446   order_isomorphism :: "[i=>o,i,i,i,i,i] => o"
   447     "order_isomorphism(M,A,r,B,s,f) ==
   448         bijection(M,A,B,f) &
   449         (\<forall>x[M]. x\<in>A --> (\<forall>y[M]. y\<in>A -->
   450           (\<forall>p[M]. \<forall>fx[M]. \<forall>fy[M]. \<forall>q[M].
   451             pair(M,x,y,p) --> fun_apply(M,f,x,fx) --> fun_apply(M,f,y,fy) -->
   452             pair(M,fx,fy,q) --> (p\<in>r <-> q\<in>s))))"
   453 
   454   pred_set :: "[i=>o,i,i,i,i] => o"
   455     "pred_set(M,A,x,r,B) ==
   456 	\<forall>y[M]. y \<in> B <-> (\<exists>p[M]. p\<in>r & y \<in> A & pair(M,y,x,p))"
   457 
   458   membership :: "[i=>o,i,i] => o" --{*membership relation*}
   459     "membership(M,A,r) ==
   460 	\<forall>p[M]. p \<in> r <-> (\<exists>x[M]. x\<in>A & (\<exists>y[M]. y\<in>A & x\<in>y & pair(M,x,y,p)))"
   461 
   462 
   463 subsection{*Introducing a Transitive Class Model*}
   464 
   465 text{*The class M is assumed to be transitive and to satisfy some
   466       relativized ZF axioms*}
   467 locale M_trivial =
   468   fixes M
   469   assumes transM:           "[| y\<in>x; M(x) |] ==> M(y)"
   470       and upair_ax:	    "upair_ax(M)"
   471       and Union_ax:	    "Union_ax(M)"
   472       and power_ax:         "power_ax(M)"
   473       and replacement:      "replacement(M,P)"
   474       and M_nat [iff]:      "M(nat)"           (*i.e. the axiom of infinity*)
   475 
   476 
   477 text{*Automatically discovers the proof using @{text transM}, @{text nat_0I}
   478 and @{text M_nat}.*}
   479 lemma (in M_trivial) nonempty [simp]: "M(0)"
   480 by (blast intro: transM)
   481 
   482 lemma (in M_trivial) rall_abs [simp]:
   483      "M(A) ==> (\<forall>x[M]. x\<in>A --> P(x)) <-> (\<forall>x\<in>A. P(x))"
   484 by (blast intro: transM)
   485 
   486 lemma (in M_trivial) rex_abs [simp]:
   487      "M(A) ==> (\<exists>x[M]. x\<in>A & P(x)) <-> (\<exists>x\<in>A. P(x))"
   488 by (blast intro: transM)
   489 
   490 lemma (in M_trivial) ball_iff_equiv:
   491      "M(A) ==> (\<forall>x[M]. (x\<in>A <-> P(x))) <->
   492                (\<forall>x\<in>A. P(x)) & (\<forall>x. P(x) --> M(x) --> x\<in>A)"
   493 by (blast intro: transM)
   494 
   495 text{*Simplifies proofs of equalities when there's an iff-equality
   496       available for rewriting, universally quantified over M. *}
   497 lemma (in M_trivial) M_equalityI:
   498      "[| !!x. M(x) ==> x\<in>A <-> x\<in>B; M(A); M(B) |] ==> A=B"
   499 by (blast intro!: equalityI dest: transM)
   500 
   501 
   502 subsubsection{*Trivial Absoluteness Proofs: Empty Set, Pairs, etc.*}
   503 
   504 lemma (in M_trivial) empty_abs [simp]:
   505      "M(z) ==> empty(M,z) <-> z=0"
   506 apply (simp add: empty_def)
   507 apply (blast intro: transM)
   508 done
   509 
   510 lemma (in M_trivial) subset_abs [simp]:
   511      "M(A) ==> subset(M,A,B) <-> A \<subseteq> B"
   512 apply (simp add: subset_def)
   513 apply (blast intro: transM)
   514 done
   515 
   516 lemma (in M_trivial) upair_abs [simp]:
   517      "M(z) ==> upair(M,a,b,z) <-> z={a,b}"
   518 apply (simp add: upair_def)
   519 apply (blast intro: transM)
   520 done
   521 
   522 lemma (in M_trivial) upair_in_M_iff [iff]:
   523      "M({a,b}) <-> M(a) & M(b)"
   524 apply (insert upair_ax, simp add: upair_ax_def)
   525 apply (blast intro: transM)
   526 done
   527 
   528 lemma (in M_trivial) singleton_in_M_iff [iff]:
   529      "M({a}) <-> M(a)"
   530 by (insert upair_in_M_iff [of a a], simp)
   531 
   532 lemma (in M_trivial) pair_abs [simp]:
   533      "M(z) ==> pair(M,a,b,z) <-> z=<a,b>"
   534 apply (simp add: pair_def ZF.Pair_def)
   535 apply (blast intro: transM)
   536 done
   537 
   538 lemma (in M_trivial) pair_in_M_iff [iff]:
   539      "M(<a,b>) <-> M(a) & M(b)"
   540 by (simp add: ZF.Pair_def)
   541 
   542 lemma (in M_trivial) pair_components_in_M:
   543      "[| <x,y> \<in> A; M(A) |] ==> M(x) & M(y)"
   544 apply (simp add: Pair_def)
   545 apply (blast dest: transM)
   546 done
   547 
   548 lemma (in M_trivial) cartprod_abs [simp]:
   549      "[| M(A); M(B); M(z) |] ==> cartprod(M,A,B,z) <-> z = A*B"
   550 apply (simp add: cartprod_def)
   551 apply (rule iffI)
   552  apply (blast intro!: equalityI intro: transM dest!: rspec)
   553 apply (blast dest: transM)
   554 done
   555 
   556 subsubsection{*Absoluteness for Unions and Intersections*}
   557 
   558 lemma (in M_trivial) union_abs [simp]:
   559      "[| M(a); M(b); M(z) |] ==> union(M,a,b,z) <-> z = a Un b"
   560 apply (simp add: union_def)
   561 apply (blast intro: transM)
   562 done
   563 
   564 lemma (in M_trivial) inter_abs [simp]:
   565      "[| M(a); M(b); M(z) |] ==> inter(M,a,b,z) <-> z = a Int b"
   566 apply (simp add: inter_def)
   567 apply (blast intro: transM)
   568 done
   569 
   570 lemma (in M_trivial) setdiff_abs [simp]:
   571      "[| M(a); M(b); M(z) |] ==> setdiff(M,a,b,z) <-> z = a-b"
   572 apply (simp add: setdiff_def)
   573 apply (blast intro: transM)
   574 done
   575 
   576 lemma (in M_trivial) Union_abs [simp]:
   577      "[| M(A); M(z) |] ==> big_union(M,A,z) <-> z = Union(A)"
   578 apply (simp add: big_union_def)
   579 apply (blast intro!: equalityI dest: transM)
   580 done
   581 
   582 lemma (in M_trivial) Union_closed [intro,simp]:
   583      "M(A) ==> M(Union(A))"
   584 by (insert Union_ax, simp add: Union_ax_def)
   585 
   586 lemma (in M_trivial) Un_closed [intro,simp]:
   587      "[| M(A); M(B) |] ==> M(A Un B)"
   588 by (simp only: Un_eq_Union, blast)
   589 
   590 lemma (in M_trivial) cons_closed [intro,simp]:
   591      "[| M(a); M(A) |] ==> M(cons(a,A))"
   592 by (subst cons_eq [symmetric], blast)
   593 
   594 lemma (in M_trivial) cons_abs [simp]:
   595      "[| M(b); M(z) |] ==> is_cons(M,a,b,z) <-> z = cons(a,b)"
   596 by (simp add: is_cons_def, blast intro: transM)
   597 
   598 lemma (in M_trivial) successor_abs [simp]:
   599      "[| M(a); M(z) |] ==> successor(M,a,z) <-> z = succ(a)"
   600 by (simp add: successor_def, blast)
   601 
   602 lemma (in M_trivial) succ_in_M_iff [iff]:
   603      "M(succ(a)) <-> M(a)"
   604 apply (simp add: succ_def)
   605 apply (blast intro: transM)
   606 done
   607 
   608 subsubsection{*Absoluteness for Separation and Replacement*}
   609 
   610 lemma (in M_trivial) separation_closed [intro,simp]:
   611      "[| separation(M,P); M(A) |] ==> M(Collect(A,P))"
   612 apply (insert separation, simp add: separation_def)
   613 apply (drule rspec, assumption, clarify)
   614 apply (subgoal_tac "y = Collect(A,P)", blast)
   615 apply (blast dest: transM)
   616 done
   617 
   618 lemma separation_iff:
   619      "separation(M,P) <-> (\<forall>z[M]. \<exists>y[M]. is_Collect(M,z,P,y))"
   620 by (simp add: separation_def is_Collect_def)
   621 
   622 lemma (in M_trivial) Collect_abs [simp]:
   623      "[| M(A); M(z) |] ==> is_Collect(M,A,P,z) <-> z = Collect(A,P)"
   624 apply (simp add: is_Collect_def)
   625 apply (blast intro!: equalityI dest: transM)
   626 done
   627 
   628 text{*Probably the premise and conclusion are equivalent*}
   629 lemma (in M_trivial) strong_replacementI [rule_format]:
   630     "[| \<forall>A[M]. separation(M, %u. \<exists>x[M]. x\<in>A & P(x,u)) |]
   631      ==> strong_replacement(M,P)"
   632 apply (simp add: strong_replacement_def, clarify)
   633 apply (frule replacementD [OF replacement], assumption, clarify)
   634 apply (drule_tac x=A in rspec, clarify)
   635 apply (drule_tac z=Y in separationD, assumption, clarify)
   636 apply (rule_tac x=y in rexI, force, assumption)
   637 done
   638 
   639 subsubsection{*The Operator @{term is_Replace}*}
   640 
   641 
   642 lemma is_Replace_cong [cong]:
   643      "[| A=A';
   644          !!x y. [| M(x); M(y) |] ==> P(x,y) <-> P'(x,y);
   645          z=z' |]
   646       ==> is_Replace(M, A, %x y. P(x,y), z) <->
   647           is_Replace(M, A', %x y. P'(x,y), z')"
   648 by (simp add: is_Replace_def)
   649 
   650 lemma (in M_trivial) univalent_Replace_iff:
   651      "[| M(A); univalent(M,A,P);
   652          !!x y. [| x\<in>A; P(x,y) |] ==> M(y) |]
   653       ==> u \<in> Replace(A,P) <-> (\<exists>x. x\<in>A & P(x,u))"
   654 apply (simp add: Replace_iff univalent_def)
   655 apply (blast dest: transM)
   656 done
   657 
   658 (*The last premise expresses that P takes M to M*)
   659 lemma (in M_trivial) strong_replacement_closed [intro,simp]:
   660      "[| strong_replacement(M,P); M(A); univalent(M,A,P);
   661          !!x y. [| x\<in>A; P(x,y) |] ==> M(y) |] ==> M(Replace(A,P))"
   662 apply (simp add: strong_replacement_def)
   663 apply (drule_tac x=A in rspec, safe)
   664 apply (subgoal_tac "Replace(A,P) = Y")
   665  apply simp
   666 apply (rule equality_iffI)
   667 apply (simp add: univalent_Replace_iff)
   668 apply (blast dest: transM)
   669 done
   670 
   671 lemma (in M_trivial) Replace_abs:
   672      "[| M(A); M(z); univalent(M,A,P); strong_replacement(M, P);
   673          !!x y. [| x\<in>A; P(x,y) |] ==> M(y)  |]
   674       ==> is_Replace(M,A,P,z) <-> z = Replace(A,P)"
   675 apply (simp add: is_Replace_def)
   676 apply (rule iffI)
   677 apply (rule M_equalityI)
   678 apply (simp_all add: univalent_Replace_iff, blast, blast)
   679 done
   680 
   681 (*The first premise can't simply be assumed as a schema.
   682   It is essential to take care when asserting instances of Replacement.
   683   Let K be a nonconstructible subset of nat and define
   684   f(x) = x if x:K and f(x)=0 otherwise.  Then RepFun(nat,f) = cons(0,K), a
   685   nonconstructible set.  So we cannot assume that M(X) implies M(RepFun(X,f))
   686   even for f : M -> M.
   687 *)
   688 lemma (in M_trivial) RepFun_closed:
   689      "[| strong_replacement(M, \<lambda>x y. y = f(x)); M(A); \<forall>x\<in>A. M(f(x)) |]
   690       ==> M(RepFun(A,f))"
   691 apply (simp add: RepFun_def)
   692 apply (rule strong_replacement_closed)
   693 apply (auto dest: transM  simp add: univalent_def)
   694 done
   695 
   696 lemma Replace_conj_eq: "{y . x \<in> A, x\<in>A & y=f(x)} = {y . x\<in>A, y=f(x)}"
   697 by simp
   698 
   699 text{*Better than @{text RepFun_closed} when having the formula @{term "x\<in>A"}
   700       makes relativization easier.*}
   701 lemma (in M_trivial) RepFun_closed2:
   702      "[| strong_replacement(M, \<lambda>x y. x\<in>A & y = f(x)); M(A); \<forall>x\<in>A. M(f(x)) |]
   703       ==> M(RepFun(A, %x. f(x)))"
   704 apply (simp add: RepFun_def)
   705 apply (frule strong_replacement_closed, assumption)
   706 apply (auto dest: transM  simp add: Replace_conj_eq univalent_def)
   707 done
   708 
   709 subsubsection {*Absoluteness for @{term Lambda}*}
   710 
   711 constdefs
   712  is_lambda :: "[i=>o, i, [i,i]=>o, i] => o"
   713     "is_lambda(M, A, is_b, z) ==
   714        \<forall>p[M]. p \<in> z <->
   715         (\<exists>u[M]. \<exists>v[M]. u\<in>A & pair(M,u,v,p) & is_b(u,v))"
   716 
   717 lemma (in M_trivial) lam_closed:
   718      "[| strong_replacement(M, \<lambda>x y. y = <x,b(x)>); M(A); \<forall>x\<in>A. M(b(x)) |]
   719       ==> M(\<lambda>x\<in>A. b(x))"
   720 by (simp add: lam_def, blast intro: RepFun_closed dest: transM)
   721 
   722 text{*Better than @{text lam_closed}: has the formula @{term "x\<in>A"}*}
   723 lemma (in M_trivial) lam_closed2:
   724   "[|strong_replacement(M, \<lambda>x y. x\<in>A & y = \<langle>x, b(x)\<rangle>);
   725      M(A); \<forall>m[M]. m\<in>A --> M(b(m))|] ==> M(Lambda(A,b))"
   726 apply (simp add: lam_def)
   727 apply (blast intro: RepFun_closed2 dest: transM)
   728 done
   729 
   730 lemma (in M_trivial) lambda_abs2 [simp]:
   731      "[| strong_replacement(M, \<lambda>x y. x\<in>A & y = \<langle>x, b(x)\<rangle>);
   732          Relation1(M,A,is_b,b); M(A); \<forall>m[M]. m\<in>A --> M(b(m)); M(z) |]
   733       ==> is_lambda(M,A,is_b,z) <-> z = Lambda(A,b)"
   734 apply (simp add: Relation1_def is_lambda_def)
   735 apply (rule iffI)
   736  prefer 2 apply (simp add: lam_def)
   737 apply (rule M_equalityI)
   738   apply (simp add: lam_def)
   739  apply (simp add: lam_closed2)+
   740 done
   741 
   742 lemma is_lambda_cong [cong]:
   743      "[| A=A';  z=z';
   744          !!x y. [| x\<in>A; M(x); M(y) |] ==> is_b(x,y) <-> is_b'(x,y) |]
   745       ==> is_lambda(M, A, %x y. is_b(x,y), z) <->
   746           is_lambda(M, A', %x y. is_b'(x,y), z')"
   747 by (simp add: is_lambda_def)
   748 
   749 lemma (in M_trivial) image_abs [simp]:
   750      "[| M(r); M(A); M(z) |] ==> image(M,r,A,z) <-> z = r``A"
   751 apply (simp add: image_def)
   752 apply (rule iffI)
   753  apply (blast intro!: equalityI dest: transM, blast)
   754 done
   755 
   756 text{*What about @{text Pow_abs}?  Powerset is NOT absolute!
   757       This result is one direction of absoluteness.*}
   758 
   759 lemma (in M_trivial) powerset_Pow:
   760      "powerset(M, x, Pow(x))"
   761 by (simp add: powerset_def)
   762 
   763 text{*But we can't prove that the powerset in @{text M} includes the
   764       real powerset.*}
   765 lemma (in M_trivial) powerset_imp_subset_Pow:
   766      "[| powerset(M,x,y); M(y) |] ==> y <= Pow(x)"
   767 apply (simp add: powerset_def)
   768 apply (blast dest: transM)
   769 done
   770 
   771 subsubsection{*Absoluteness for the Natural Numbers*}
   772 
   773 lemma (in M_trivial) nat_into_M [intro]:
   774      "n \<in> nat ==> M(n)"
   775 by (induct n rule: nat_induct, simp_all)
   776 
   777 lemma (in M_trivial) nat_case_closed [intro,simp]:
   778   "[|M(k); M(a); \<forall>m[M]. M(b(m))|] ==> M(nat_case(a,b,k))"
   779 apply (case_tac "k=0", simp)
   780 apply (case_tac "\<exists>m. k = succ(m)", force)
   781 apply (simp add: nat_case_def)
   782 done
   783 
   784 lemma (in M_trivial) quasinat_abs [simp]:
   785      "M(z) ==> is_quasinat(M,z) <-> quasinat(z)"
   786 by (auto simp add: is_quasinat_def quasinat_def)
   787 
   788 lemma (in M_trivial) nat_case_abs [simp]:
   789      "[| relation1(M,is_b,b); M(k); M(z) |]
   790       ==> is_nat_case(M,a,is_b,k,z) <-> z = nat_case(a,b,k)"
   791 apply (case_tac "quasinat(k)")
   792  prefer 2
   793  apply (simp add: is_nat_case_def non_nat_case)
   794  apply (force simp add: quasinat_def)
   795 apply (simp add: quasinat_def is_nat_case_def)
   796 apply (elim disjE exE)
   797  apply (simp_all add: relation1_def)
   798 done
   799 
   800 (*NOT for the simplifier.  The assumption M(z') is apparently necessary, but
   801   causes the error "Failed congruence proof!"  It may be better to replace
   802   is_nat_case by nat_case before attempting congruence reasoning.*)
   803 lemma is_nat_case_cong:
   804      "[| a = a'; k = k';  z = z';  M(z');
   805        !!x y. [| M(x); M(y) |] ==> is_b(x,y) <-> is_b'(x,y) |]
   806       ==> is_nat_case(M, a, is_b, k, z) <-> is_nat_case(M, a', is_b', k', z')"
   807 by (simp add: is_nat_case_def)
   808 
   809 
   810 subsection{*Absoluteness for Ordinals*}
   811 text{*These results constitute Theorem IV 5.1 of Kunen (page 126).*}
   812 
   813 lemma (in M_trivial) lt_closed:
   814      "[| j<i; M(i) |] ==> M(j)"
   815 by (blast dest: ltD intro: transM)
   816 
   817 lemma (in M_trivial) transitive_set_abs [simp]:
   818      "M(a) ==> transitive_set(M,a) <-> Transset(a)"
   819 by (simp add: transitive_set_def Transset_def)
   820 
   821 lemma (in M_trivial) ordinal_abs [simp]:
   822      "M(a) ==> ordinal(M,a) <-> Ord(a)"
   823 by (simp add: ordinal_def Ord_def)
   824 
   825 lemma (in M_trivial) limit_ordinal_abs [simp]:
   826      "M(a) ==> limit_ordinal(M,a) <-> Limit(a)"
   827 apply (unfold Limit_def limit_ordinal_def)
   828 apply (simp add: Ord_0_lt_iff)
   829 apply (simp add: lt_def, blast)
   830 done
   831 
   832 lemma (in M_trivial) successor_ordinal_abs [simp]:
   833      "M(a) ==> successor_ordinal(M,a) <-> Ord(a) & (\<exists>b[M]. a = succ(b))"
   834 apply (simp add: successor_ordinal_def, safe)
   835 apply (drule Ord_cases_disj, auto)
   836 done
   837 
   838 lemma finite_Ord_is_nat:
   839       "[| Ord(a); ~ Limit(a); \<forall>x\<in>a. ~ Limit(x) |] ==> a \<in> nat"
   840 by (induct a rule: trans_induct3, simp_all)
   841 
   842 lemma (in M_trivial) finite_ordinal_abs [simp]:
   843      "M(a) ==> finite_ordinal(M,a) <-> a \<in> nat"
   844 apply (simp add: finite_ordinal_def)
   845 apply (blast intro: finite_Ord_is_nat intro: nat_into_Ord
   846              dest: Ord_trans naturals_not_limit)
   847 done
   848 
   849 lemma Limit_non_Limit_implies_nat:
   850      "[| Limit(a); \<forall>x\<in>a. ~ Limit(x) |] ==> a = nat"
   851 apply (rule le_anti_sym)
   852 apply (rule all_lt_imp_le, blast, blast intro: Limit_is_Ord)
   853  apply (simp add: lt_def)
   854  apply (blast intro: Ord_in_Ord Ord_trans finite_Ord_is_nat)
   855 apply (erule nat_le_Limit)
   856 done
   857 
   858 lemma (in M_trivial) omega_abs [simp]:
   859      "M(a) ==> omega(M,a) <-> a = nat"
   860 apply (simp add: omega_def)
   861 apply (blast intro: Limit_non_Limit_implies_nat dest: naturals_not_limit)
   862 done
   863 
   864 lemma (in M_trivial) number1_abs [simp]:
   865      "M(a) ==> number1(M,a) <-> a = 1"
   866 by (simp add: number1_def)
   867 
   868 lemma (in M_trivial) number2_abs [simp]:
   869      "M(a) ==> number2(M,a) <-> a = succ(1)"
   870 by (simp add: number2_def)
   871 
   872 lemma (in M_trivial) number3_abs [simp]:
   873      "M(a) ==> number3(M,a) <-> a = succ(succ(1))"
   874 by (simp add: number3_def)
   875 
   876 text{*Kunen continued to 20...*}
   877 
   878 (*Could not get this to work.  The \<lambda>x\<in>nat is essential because everything
   879   but the recursion variable must stay unchanged.  But then the recursion
   880   equations only hold for x\<in>nat (or in some other set) and not for the
   881   whole of the class M.
   882   consts
   883     natnumber_aux :: "[i=>o,i] => i"
   884 
   885   primrec
   886       "natnumber_aux(M,0) = (\<lambda>x\<in>nat. if empty(M,x) then 1 else 0)"
   887       "natnumber_aux(M,succ(n)) =
   888 	   (\<lambda>x\<in>nat. if (\<exists>y[M]. natnumber_aux(M,n)`y=1 & successor(M,y,x))
   889 		     then 1 else 0)"
   890 
   891   constdefs
   892     natnumber :: "[i=>o,i,i] => o"
   893       "natnumber(M,n,x) == natnumber_aux(M,n)`x = 1"
   894 
   895   lemma (in M_trivial) [simp]:
   896        "natnumber(M,0,x) == x=0"
   897 *)
   898 
   899 subsection{*Some instances of separation and strong replacement*}
   900 
   901 locale M_basic = M_trivial +
   902 assumes Inter_separation:
   903      "M(A) ==> separation(M, \<lambda>x. \<forall>y[M]. y\<in>A --> x\<in>y)"
   904   and Diff_separation:
   905      "M(B) ==> separation(M, \<lambda>x. x \<notin> B)"
   906   and cartprod_separation:
   907      "[| M(A); M(B) |]
   908       ==> separation(M, \<lambda>z. \<exists>x[M]. x\<in>A & (\<exists>y[M]. y\<in>B & pair(M,x,y,z)))"
   909   and image_separation:
   910      "[| M(A); M(r) |]
   911       ==> separation(M, \<lambda>y. \<exists>p[M]. p\<in>r & (\<exists>x[M]. x\<in>A & pair(M,x,y,p)))"
   912   and converse_separation:
   913      "M(r) ==> separation(M,
   914          \<lambda>z. \<exists>p[M]. p\<in>r & (\<exists>x[M]. \<exists>y[M]. pair(M,x,y,p) & pair(M,y,x,z)))"
   915   and restrict_separation:
   916      "M(A) ==> separation(M, \<lambda>z. \<exists>x[M]. x\<in>A & (\<exists>y[M]. pair(M,x,y,z)))"
   917   and comp_separation:
   918      "[| M(r); M(s) |]
   919       ==> separation(M, \<lambda>xz. \<exists>x[M]. \<exists>y[M]. \<exists>z[M]. \<exists>xy[M]. \<exists>yz[M].
   920 		  pair(M,x,z,xz) & pair(M,x,y,xy) & pair(M,y,z,yz) &
   921                   xy\<in>s & yz\<in>r)"
   922   and pred_separation:
   923      "[| M(r); M(x) |] ==> separation(M, \<lambda>y. \<exists>p[M]. p\<in>r & pair(M,y,x,p))"
   924   and Memrel_separation:
   925      "separation(M, \<lambda>z. \<exists>x[M]. \<exists>y[M]. pair(M,x,y,z) & x \<in> y)"
   926   and funspace_succ_replacement:
   927      "M(n) ==>
   928       strong_replacement(M, \<lambda>p z. \<exists>f[M]. \<exists>b[M]. \<exists>nb[M]. \<exists>cnbf[M].
   929                 pair(M,f,b,p) & pair(M,n,b,nb) & is_cons(M,nb,f,cnbf) &
   930                 upair(M,cnbf,cnbf,z))"
   931   and is_recfun_separation:
   932      --{*for well-founded recursion: used to prove @{text is_recfun_equal}*}
   933      "[| M(r); M(f); M(g); M(a); M(b) |]
   934      ==> separation(M,
   935             \<lambda>x. \<exists>xa[M]. \<exists>xb[M].
   936                 pair(M,x,a,xa) & xa \<in> r & pair(M,x,b,xb) & xb \<in> r &
   937                 (\<exists>fx[M]. \<exists>gx[M]. fun_apply(M,f,x,fx) & fun_apply(M,g,x,gx) &
   938                                    fx \<noteq> gx))"
   939 
   940 lemma (in M_basic) cartprod_iff_lemma:
   941      "[| M(C);  \<forall>u[M]. u \<in> C <-> (\<exists>x\<in>A. \<exists>y\<in>B. u = {{x}, {x,y}});
   942          powerset(M, A \<union> B, p1); powerset(M, p1, p2);  M(p2) |]
   943        ==> C = {u \<in> p2 . \<exists>x\<in>A. \<exists>y\<in>B. u = {{x}, {x,y}}}"
   944 apply (simp add: powerset_def)
   945 apply (rule equalityI, clarify, simp)
   946  apply (frule transM, assumption)
   947  apply (frule transM, assumption, simp (no_asm_simp))
   948  apply blast
   949 apply clarify
   950 apply (frule transM, assumption, force)
   951 done
   952 
   953 lemma (in M_basic) cartprod_iff:
   954      "[| M(A); M(B); M(C) |]
   955       ==> cartprod(M,A,B,C) <->
   956           (\<exists>p1[M]. \<exists>p2[M]. powerset(M,A Un B,p1) & powerset(M,p1,p2) &
   957                    C = {z \<in> p2. \<exists>x\<in>A. \<exists>y\<in>B. z = <x,y>})"
   958 apply (simp add: Pair_def cartprod_def, safe)
   959 defer 1
   960   apply (simp add: powerset_def)
   961  apply blast
   962 txt{*Final, difficult case: the left-to-right direction of the theorem.*}
   963 apply (insert power_ax, simp add: power_ax_def)
   964 apply (frule_tac x="A Un B" and P="\<lambda>x. rex(M,?Q(x))" in rspec)
   965 apply (blast, clarify)
   966 apply (drule_tac x=z and P="\<lambda>x. rex(M,?Q(x))" in rspec)
   967 apply assumption
   968 apply (blast intro: cartprod_iff_lemma)
   969 done
   970 
   971 lemma (in M_basic) cartprod_closed_lemma:
   972      "[| M(A); M(B) |] ==> \<exists>C[M]. cartprod(M,A,B,C)"
   973 apply (simp del: cartprod_abs add: cartprod_iff)
   974 apply (insert power_ax, simp add: power_ax_def)
   975 apply (frule_tac x="A Un B" and P="\<lambda>x. rex(M,?Q(x))" in rspec)
   976 apply (blast, clarify)
   977 apply (drule_tac x=z and P="\<lambda>x. rex(M,?Q(x))" in rspec, auto)
   978 apply (intro rexI conjI, simp+)
   979 apply (insert cartprod_separation [of A B], simp)
   980 done
   981 
   982 text{*All the lemmas above are necessary because Powerset is not absolute.
   983       I should have used Replacement instead!*}
   984 lemma (in M_basic) cartprod_closed [intro,simp]:
   985      "[| M(A); M(B) |] ==> M(A*B)"
   986 by (frule cartprod_closed_lemma, assumption, force)
   987 
   988 lemma (in M_basic) sum_closed [intro,simp]:
   989      "[| M(A); M(B) |] ==> M(A+B)"
   990 by (simp add: sum_def)
   991 
   992 lemma (in M_basic) sum_abs [simp]:
   993      "[| M(A); M(B); M(Z) |] ==> is_sum(M,A,B,Z) <-> (Z = A+B)"
   994 by (simp add: is_sum_def sum_def singleton_0 nat_into_M)
   995 
   996 lemma (in M_trivial) Inl_in_M_iff [iff]:
   997      "M(Inl(a)) <-> M(a)"
   998 by (simp add: Inl_def)
   999 
  1000 lemma (in M_trivial) Inl_abs [simp]:
  1001      "M(Z) ==> is_Inl(M,a,Z) <-> (Z = Inl(a))"
  1002 by (simp add: is_Inl_def Inl_def)
  1003 
  1004 lemma (in M_trivial) Inr_in_M_iff [iff]:
  1005      "M(Inr(a)) <-> M(a)"
  1006 by (simp add: Inr_def)
  1007 
  1008 lemma (in M_trivial) Inr_abs [simp]:
  1009      "M(Z) ==> is_Inr(M,a,Z) <-> (Z = Inr(a))"
  1010 by (simp add: is_Inr_def Inr_def)
  1011 
  1012 
  1013 subsubsection {*converse of a relation*}
  1014 
  1015 lemma (in M_basic) M_converse_iff:
  1016      "M(r) ==>
  1017       converse(r) =
  1018       {z \<in> Union(Union(r)) * Union(Union(r)).
  1019        \<exists>p\<in>r. \<exists>x[M]. \<exists>y[M]. p = \<langle>x,y\<rangle> & z = \<langle>y,x\<rangle>}"
  1020 apply (rule equalityI)
  1021  prefer 2 apply (blast dest: transM, clarify, simp)
  1022 apply (simp add: Pair_def)
  1023 apply (blast dest: transM)
  1024 done
  1025 
  1026 lemma (in M_basic) converse_closed [intro,simp]:
  1027      "M(r) ==> M(converse(r))"
  1028 apply (simp add: M_converse_iff)
  1029 apply (insert converse_separation [of r], simp)
  1030 done
  1031 
  1032 lemma (in M_basic) converse_abs [simp]:
  1033      "[| M(r); M(z) |] ==> is_converse(M,r,z) <-> z = converse(r)"
  1034 apply (simp add: is_converse_def)
  1035 apply (rule iffI)
  1036  prefer 2 apply blast
  1037 apply (rule M_equalityI)
  1038   apply simp
  1039   apply (blast dest: transM)+
  1040 done
  1041 
  1042 
  1043 subsubsection {*image, preimage, domain, range*}
  1044 
  1045 lemma (in M_basic) image_closed [intro,simp]:
  1046      "[| M(A); M(r) |] ==> M(r``A)"
  1047 apply (simp add: image_iff_Collect)
  1048 apply (insert image_separation [of A r], simp)
  1049 done
  1050 
  1051 lemma (in M_basic) vimage_abs [simp]:
  1052      "[| M(r); M(A); M(z) |] ==> pre_image(M,r,A,z) <-> z = r-``A"
  1053 apply (simp add: pre_image_def)
  1054 apply (rule iffI)
  1055  apply (blast intro!: equalityI dest: transM, blast)
  1056 done
  1057 
  1058 lemma (in M_basic) vimage_closed [intro,simp]:
  1059      "[| M(A); M(r) |] ==> M(r-``A)"
  1060 by (simp add: vimage_def)
  1061 
  1062 
  1063 subsubsection{*Domain, range and field*}
  1064 
  1065 lemma (in M_basic) domain_abs [simp]:
  1066      "[| M(r); M(z) |] ==> is_domain(M,r,z) <-> z = domain(r)"
  1067 apply (simp add: is_domain_def)
  1068 apply (blast intro!: equalityI dest: transM)
  1069 done
  1070 
  1071 lemma (in M_basic) domain_closed [intro,simp]:
  1072      "M(r) ==> M(domain(r))"
  1073 apply (simp add: domain_eq_vimage)
  1074 done
  1075 
  1076 lemma (in M_basic) range_abs [simp]:
  1077      "[| M(r); M(z) |] ==> is_range(M,r,z) <-> z = range(r)"
  1078 apply (simp add: is_range_def)
  1079 apply (blast intro!: equalityI dest: transM)
  1080 done
  1081 
  1082 lemma (in M_basic) range_closed [intro,simp]:
  1083      "M(r) ==> M(range(r))"
  1084 apply (simp add: range_eq_image)
  1085 done
  1086 
  1087 lemma (in M_basic) field_abs [simp]:
  1088      "[| M(r); M(z) |] ==> is_field(M,r,z) <-> z = field(r)"
  1089 by (simp add: domain_closed range_closed is_field_def field_def)
  1090 
  1091 lemma (in M_basic) field_closed [intro,simp]:
  1092      "M(r) ==> M(field(r))"
  1093 by (simp add: domain_closed range_closed Un_closed field_def)
  1094 
  1095 
  1096 subsubsection{*Relations, functions and application*}
  1097 
  1098 lemma (in M_basic) relation_abs [simp]:
  1099      "M(r) ==> is_relation(M,r) <-> relation(r)"
  1100 apply (simp add: is_relation_def relation_def)
  1101 apply (blast dest!: bspec dest: pair_components_in_M)+
  1102 done
  1103 
  1104 lemma (in M_basic) function_abs [simp]:
  1105      "M(r) ==> is_function(M,r) <-> function(r)"
  1106 apply (simp add: is_function_def function_def, safe)
  1107    apply (frule transM, assumption)
  1108   apply (blast dest: pair_components_in_M)+
  1109 done
  1110 
  1111 lemma (in M_basic) apply_closed [intro,simp]:
  1112      "[|M(f); M(a)|] ==> M(f`a)"
  1113 by (simp add: apply_def)
  1114 
  1115 lemma (in M_basic) apply_abs [simp]:
  1116      "[| M(f); M(x); M(y) |] ==> fun_apply(M,f,x,y) <-> f`x = y"
  1117 apply (simp add: fun_apply_def apply_def, blast)
  1118 done
  1119 
  1120 lemma (in M_basic) typed_function_abs [simp]:
  1121      "[| M(A); M(f) |] ==> typed_function(M,A,B,f) <-> f \<in> A -> B"
  1122 apply (auto simp add: typed_function_def relation_def Pi_iff)
  1123 apply (blast dest: pair_components_in_M)+
  1124 done
  1125 
  1126 lemma (in M_basic) injection_abs [simp]:
  1127      "[| M(A); M(f) |] ==> injection(M,A,B,f) <-> f \<in> inj(A,B)"
  1128 apply (simp add: injection_def apply_iff inj_def apply_closed)
  1129 apply (blast dest: transM [of _ A])
  1130 done
  1131 
  1132 lemma (in M_basic) surjection_abs [simp]:
  1133      "[| M(A); M(B); M(f) |] ==> surjection(M,A,B,f) <-> f \<in> surj(A,B)"
  1134 by (simp add: surjection_def surj_def)
  1135 
  1136 lemma (in M_basic) bijection_abs [simp]:
  1137      "[| M(A); M(B); M(f) |] ==> bijection(M,A,B,f) <-> f \<in> bij(A,B)"
  1138 by (simp add: bijection_def bij_def)
  1139 
  1140 
  1141 subsubsection{*Composition of relations*}
  1142 
  1143 lemma (in M_basic) M_comp_iff:
  1144      "[| M(r); M(s) |]
  1145       ==> r O s =
  1146           {xz \<in> domain(s) * range(r).
  1147             \<exists>x[M]. \<exists>y[M]. \<exists>z[M]. xz = \<langle>x,z\<rangle> & \<langle>x,y\<rangle> \<in> s & \<langle>y,z\<rangle> \<in> r}"
  1148 apply (simp add: comp_def)
  1149 apply (rule equalityI)
  1150  apply clarify
  1151  apply simp
  1152  apply  (blast dest:  transM)+
  1153 done
  1154 
  1155 lemma (in M_basic) comp_closed [intro,simp]:
  1156      "[| M(r); M(s) |] ==> M(r O s)"
  1157 apply (simp add: M_comp_iff)
  1158 apply (insert comp_separation [of r s], simp)
  1159 done
  1160 
  1161 lemma (in M_basic) composition_abs [simp]:
  1162      "[| M(r); M(s); M(t) |]
  1163       ==> composition(M,r,s,t) <-> t = r O s"
  1164 apply safe
  1165  txt{*Proving @{term "composition(M, r, s, r O s)"}*}
  1166  prefer 2
  1167  apply (simp add: composition_def comp_def)
  1168  apply (blast dest: transM)
  1169 txt{*Opposite implication*}
  1170 apply (rule M_equalityI)
  1171   apply (simp add: composition_def comp_def)
  1172   apply (blast del: allE dest: transM)+
  1173 done
  1174 
  1175 text{*no longer needed*}
  1176 lemma (in M_basic) restriction_is_function:
  1177      "[| restriction(M,f,A,z); function(f); M(f); M(A); M(z) |]
  1178       ==> function(z)"
  1179 apply (simp add: restriction_def ball_iff_equiv)
  1180 apply (unfold function_def, blast)
  1181 done
  1182 
  1183 lemma (in M_basic) restriction_abs [simp]:
  1184      "[| M(f); M(A); M(z) |]
  1185       ==> restriction(M,f,A,z) <-> z = restrict(f,A)"
  1186 apply (simp add: ball_iff_equiv restriction_def restrict_def)
  1187 apply (blast intro!: equalityI dest: transM)
  1188 done
  1189 
  1190 
  1191 lemma (in M_basic) M_restrict_iff:
  1192      "M(r) ==> restrict(r,A) = {z \<in> r . \<exists>x\<in>A. \<exists>y[M]. z = \<langle>x, y\<rangle>}"
  1193 by (simp add: restrict_def, blast dest: transM)
  1194 
  1195 lemma (in M_basic) restrict_closed [intro,simp]:
  1196      "[| M(A); M(r) |] ==> M(restrict(r,A))"
  1197 apply (simp add: M_restrict_iff)
  1198 apply (insert restrict_separation [of A], simp)
  1199 done
  1200 
  1201 lemma (in M_basic) Inter_abs [simp]:
  1202      "[| M(A); M(z) |] ==> big_inter(M,A,z) <-> z = Inter(A)"
  1203 apply (simp add: big_inter_def Inter_def)
  1204 apply (blast intro!: equalityI dest: transM)
  1205 done
  1206 
  1207 lemma (in M_basic) Inter_closed [intro,simp]:
  1208      "M(A) ==> M(Inter(A))"
  1209 by (insert Inter_separation, simp add: Inter_def)
  1210 
  1211 lemma (in M_basic) Int_closed [intro,simp]:
  1212      "[| M(A); M(B) |] ==> M(A Int B)"
  1213 apply (subgoal_tac "M({A,B})")
  1214 apply (frule Inter_closed, force+)
  1215 done
  1216 
  1217 lemma (in M_basic) Diff_closed [intro,simp]:
  1218      "[|M(A); M(B)|] ==> M(A-B)"
  1219 by (insert Diff_separation, simp add: Diff_def)
  1220 
  1221 subsubsection{*Some Facts About Separation Axioms*}
  1222 
  1223 lemma (in M_basic) separation_conj:
  1224      "[|separation(M,P); separation(M,Q)|] ==> separation(M, \<lambda>z. P(z) & Q(z))"
  1225 by (simp del: separation_closed
  1226          add: separation_iff Collect_Int_Collect_eq [symmetric])
  1227 
  1228 (*???equalities*)
  1229 lemma Collect_Un_Collect_eq:
  1230      "Collect(A,P) Un Collect(A,Q) = Collect(A, %x. P(x) | Q(x))"
  1231 by blast
  1232 
  1233 lemma Diff_Collect_eq:
  1234      "A - Collect(A,P) = Collect(A, %x. ~ P(x))"
  1235 by blast
  1236 
  1237 lemma (in M_trivial) Collect_rall_eq:
  1238      "M(Y) ==> Collect(A, %x. \<forall>y[M]. y\<in>Y --> P(x,y)) =
  1239                (if Y=0 then A else (\<Inter>y \<in> Y. {x \<in> A. P(x,y)}))"
  1240 apply simp
  1241 apply (blast intro!: equalityI dest: transM)
  1242 done
  1243 
  1244 lemma (in M_basic) separation_disj:
  1245      "[|separation(M,P); separation(M,Q)|] ==> separation(M, \<lambda>z. P(z) | Q(z))"
  1246 by (simp del: separation_closed
  1247          add: separation_iff Collect_Un_Collect_eq [symmetric])
  1248 
  1249 lemma (in M_basic) separation_neg:
  1250      "separation(M,P) ==> separation(M, \<lambda>z. ~P(z))"
  1251 by (simp del: separation_closed
  1252          add: separation_iff Diff_Collect_eq [symmetric])
  1253 
  1254 lemma (in M_basic) separation_imp:
  1255      "[|separation(M,P); separation(M,Q)|]
  1256       ==> separation(M, \<lambda>z. P(z) --> Q(z))"
  1257 by (simp add: separation_neg separation_disj not_disj_iff_imp [symmetric])
  1258 
  1259 text{*This result is a hint of how little can be done without the Reflection
  1260   Theorem.  The quantifier has to be bounded by a set.  We also need another
  1261   instance of Separation!*}
  1262 lemma (in M_basic) separation_rall:
  1263      "[|M(Y); \<forall>y[M]. separation(M, \<lambda>x. P(x,y));
  1264         \<forall>z[M]. strong_replacement(M, \<lambda>x y. y = {u \<in> z . P(u,x)})|]
  1265       ==> separation(M, \<lambda>x. \<forall>y[M]. y\<in>Y --> P(x,y))"
  1266 apply (simp del: separation_closed rall_abs
  1267          add: separation_iff Collect_rall_eq)
  1268 apply (blast intro!: Inter_closed RepFun_closed dest: transM)
  1269 done
  1270 
  1271 
  1272 subsubsection{*Functions and function space*}
  1273 
  1274 text{*The assumption @{term "M(A->B)"} is unusual, but essential: in
  1275 all but trivial cases, A->B cannot be expected to belong to @{term M}.*}
  1276 lemma (in M_basic) is_funspace_abs [simp]:
  1277      "[|M(A); M(B); M(F); M(A->B)|] ==> is_funspace(M,A,B,F) <-> F = A->B";
  1278 apply (simp add: is_funspace_def)
  1279 apply (rule iffI)
  1280  prefer 2 apply blast
  1281 apply (rule M_equalityI)
  1282   apply simp_all
  1283 done
  1284 
  1285 lemma (in M_basic) succ_fun_eq2:
  1286      "[|M(B); M(n->B)|] ==>
  1287       succ(n) -> B =
  1288       \<Union>{z. p \<in> (n->B)*B, \<exists>f[M]. \<exists>b[M]. p = <f,b> & z = {cons(<n,b>, f)}}"
  1289 apply (simp add: succ_fun_eq)
  1290 apply (blast dest: transM)
  1291 done
  1292 
  1293 lemma (in M_basic) funspace_succ:
  1294      "[|M(n); M(B); M(n->B) |] ==> M(succ(n) -> B)"
  1295 apply (insert funspace_succ_replacement [of n], simp)
  1296 apply (force simp add: succ_fun_eq2 univalent_def)
  1297 done
  1298 
  1299 text{*@{term M} contains all finite function spaces.  Needed to prove the
  1300 absoluteness of transitive closure.  See the definition of
  1301 @{text rtrancl_alt} in in @{text WF_absolute.thy}.*}
  1302 lemma (in M_basic) finite_funspace_closed [intro,simp]:
  1303      "[|n\<in>nat; M(B)|] ==> M(n->B)"
  1304 apply (induct_tac n, simp)
  1305 apply (simp add: funspace_succ nat_into_M)
  1306 done
  1307 
  1308 
  1309 subsection{*Relativization and Absoluteness for Boolean Operators*}
  1310 
  1311 constdefs
  1312   is_bool_of_o :: "[i=>o, o, i] => o"
  1313    "is_bool_of_o(M,P,z) == (P & number1(M,z)) | (~P & empty(M,z))"
  1314 
  1315   is_not :: "[i=>o, i, i] => o"
  1316    "is_not(M,a,z) == (number1(M,a)  & empty(M,z)) |
  1317                      (~number1(M,a) & number1(M,z))"
  1318 
  1319   is_and :: "[i=>o, i, i, i] => o"
  1320    "is_and(M,a,b,z) == (number1(M,a)  & z=b) |
  1321                        (~number1(M,a) & empty(M,z))"
  1322 
  1323   is_or :: "[i=>o, i, i, i] => o"
  1324    "is_or(M,a,b,z) == (number1(M,a)  & number1(M,z)) |
  1325                       (~number1(M,a) & z=b)"
  1326 
  1327 lemma (in M_trivial) bool_of_o_abs [simp]:
  1328      "M(z) ==> is_bool_of_o(M,P,z) <-> z = bool_of_o(P)"
  1329 by (simp add: is_bool_of_o_def bool_of_o_def)
  1330 
  1331 
  1332 lemma (in M_trivial) not_abs [simp]:
  1333      "[| M(a); M(z)|] ==> is_not(M,a,z) <-> z = not(a)"
  1334 by (simp add: Bool.not_def cond_def is_not_def)
  1335 
  1336 lemma (in M_trivial) and_abs [simp]:
  1337      "[| M(a); M(b); M(z)|] ==> is_and(M,a,b,z) <-> z = a and b"
  1338 by (simp add: Bool.and_def cond_def is_and_def)
  1339 
  1340 lemma (in M_trivial) or_abs [simp]:
  1341      "[| M(a); M(b); M(z)|] ==> is_or(M,a,b,z) <-> z = a or b"
  1342 by (simp add: Bool.or_def cond_def is_or_def)
  1343 
  1344 
  1345 lemma (in M_trivial) bool_of_o_closed [intro,simp]:
  1346      "M(bool_of_o(P))"
  1347 by (simp add: bool_of_o_def)
  1348 
  1349 lemma (in M_trivial) and_closed [intro,simp]:
  1350      "[| M(p); M(q) |] ==> M(p and q)"
  1351 by (simp add: and_def cond_def)
  1352 
  1353 lemma (in M_trivial) or_closed [intro,simp]:
  1354      "[| M(p); M(q) |] ==> M(p or q)"
  1355 by (simp add: or_def cond_def)
  1356 
  1357 lemma (in M_trivial) not_closed [intro,simp]:
  1358      "M(p) ==> M(not(p))"
  1359 by (simp add: Bool.not_def cond_def)
  1360 
  1361 
  1362 subsection{*Relativization and Absoluteness for List Operators*}
  1363 
  1364 constdefs
  1365 
  1366   is_Nil :: "[i=>o, i] => o"
  1367      --{* because @{term "[] \<equiv> Inl(0)"}*}
  1368     "is_Nil(M,xs) == \<exists>zero[M]. empty(M,zero) & is_Inl(M,zero,xs)"
  1369 
  1370   is_Cons :: "[i=>o,i,i,i] => o"
  1371      --{* because @{term "Cons(a, l) \<equiv> Inr(\<langle>a,l\<rangle>)"}*}
  1372     "is_Cons(M,a,l,Z) == \<exists>p[M]. pair(M,a,l,p) & is_Inr(M,p,Z)"
  1373 
  1374 
  1375 lemma (in M_trivial) Nil_in_M [intro,simp]: "M(Nil)"
  1376 by (simp add: Nil_def)
  1377 
  1378 lemma (in M_trivial) Nil_abs [simp]: "M(Z) ==> is_Nil(M,Z) <-> (Z = Nil)"
  1379 by (simp add: is_Nil_def Nil_def)
  1380 
  1381 lemma (in M_trivial) Cons_in_M_iff [iff]: "M(Cons(a,l)) <-> M(a) & M(l)"
  1382 by (simp add: Cons_def)
  1383 
  1384 lemma (in M_trivial) Cons_abs [simp]:
  1385      "[|M(a); M(l); M(Z)|] ==> is_Cons(M,a,l,Z) <-> (Z = Cons(a,l))"
  1386 by (simp add: is_Cons_def Cons_def)
  1387 
  1388 
  1389 constdefs
  1390 
  1391   quasilist :: "i => o"
  1392     "quasilist(xs) == xs=Nil | (\<exists>x l. xs = Cons(x,l))"
  1393 
  1394   is_quasilist :: "[i=>o,i] => o"
  1395     "is_quasilist(M,z) == is_Nil(M,z) | (\<exists>x[M]. \<exists>l[M]. is_Cons(M,x,l,z))"
  1396 
  1397   list_case' :: "[i, [i,i]=>i, i] => i"
  1398     --{*A version of @{term list_case} that's always defined.*}
  1399     "list_case'(a,b,xs) ==
  1400        if quasilist(xs) then list_case(a,b,xs) else 0"
  1401 
  1402   is_list_case :: "[i=>o, i, [i,i,i]=>o, i, i] => o"
  1403     --{*Returns 0 for non-lists*}
  1404     "is_list_case(M, a, is_b, xs, z) ==
  1405        (is_Nil(M,xs) --> z=a) &
  1406        (\<forall>x[M]. \<forall>l[M]. is_Cons(M,x,l,xs) --> is_b(x,l,z)) &
  1407        (is_quasilist(M,xs) | empty(M,z))"
  1408 
  1409   hd' :: "i => i"
  1410     --{*A version of @{term hd} that's always defined.*}
  1411     "hd'(xs) == if quasilist(xs) then hd(xs) else 0"
  1412 
  1413   tl' :: "i => i"
  1414     --{*A version of @{term tl} that's always defined.*}
  1415     "tl'(xs) == if quasilist(xs) then tl(xs) else 0"
  1416 
  1417   is_hd :: "[i=>o,i,i] => o"
  1418      --{* @{term "hd([]) = 0"} no constraints if not a list.
  1419           Avoiding implication prevents the simplifier's looping.*}
  1420     "is_hd(M,xs,H) ==
  1421        (is_Nil(M,xs) --> empty(M,H)) &
  1422        (\<forall>x[M]. \<forall>l[M]. ~ is_Cons(M,x,l,xs) | H=x) &
  1423        (is_quasilist(M,xs) | empty(M,H))"
  1424 
  1425   is_tl :: "[i=>o,i,i] => o"
  1426      --{* @{term "tl([]) = []"}; see comments about @{term is_hd}*}
  1427     "is_tl(M,xs,T) ==
  1428        (is_Nil(M,xs) --> T=xs) &
  1429        (\<forall>x[M]. \<forall>l[M]. ~ is_Cons(M,x,l,xs) | T=l) &
  1430        (is_quasilist(M,xs) | empty(M,T))"
  1431 
  1432 subsubsection{*@{term quasilist}: For Case-Splitting with @{term list_case'}*}
  1433 
  1434 lemma [iff]: "quasilist(Nil)"
  1435 by (simp add: quasilist_def)
  1436 
  1437 lemma [iff]: "quasilist(Cons(x,l))"
  1438 by (simp add: quasilist_def)
  1439 
  1440 lemma list_imp_quasilist: "l \<in> list(A) ==> quasilist(l)"
  1441 by (erule list.cases, simp_all)
  1442 
  1443 subsubsection{*@{term list_case'}, the Modified Version of @{term list_case}*}
  1444 
  1445 lemma list_case'_Nil [simp]: "list_case'(a,b,Nil) = a"
  1446 by (simp add: list_case'_def quasilist_def)
  1447 
  1448 lemma list_case'_Cons [simp]: "list_case'(a,b,Cons(x,l)) = b(x,l)"
  1449 by (simp add: list_case'_def quasilist_def)
  1450 
  1451 lemma non_list_case: "~ quasilist(x) ==> list_case'(a,b,x) = 0"
  1452 by (simp add: quasilist_def list_case'_def)
  1453 
  1454 lemma list_case'_eq_list_case [simp]:
  1455      "xs \<in> list(A) ==>list_case'(a,b,xs) = list_case(a,b,xs)"
  1456 by (erule list.cases, simp_all)
  1457 
  1458 lemma (in M_basic) list_case'_closed [intro,simp]:
  1459   "[|M(k); M(a); \<forall>x[M]. \<forall>y[M]. M(b(x,y))|] ==> M(list_case'(a,b,k))"
  1460 apply (case_tac "quasilist(k)")
  1461  apply (simp add: quasilist_def, force)
  1462 apply (simp add: non_list_case)
  1463 done
  1464 
  1465 lemma (in M_trivial) quasilist_abs [simp]:
  1466      "M(z) ==> is_quasilist(M,z) <-> quasilist(z)"
  1467 by (auto simp add: is_quasilist_def quasilist_def)
  1468 
  1469 lemma (in M_trivial) list_case_abs [simp]:
  1470      "[| relation2(M,is_b,b); M(k); M(z) |]
  1471       ==> is_list_case(M,a,is_b,k,z) <-> z = list_case'(a,b,k)"
  1472 apply (case_tac "quasilist(k)")
  1473  prefer 2
  1474  apply (simp add: is_list_case_def non_list_case)
  1475  apply (force simp add: quasilist_def)
  1476 apply (simp add: quasilist_def is_list_case_def)
  1477 apply (elim disjE exE)
  1478  apply (simp_all add: relation2_def)
  1479 done
  1480 
  1481 
  1482 subsubsection{*The Modified Operators @{term hd'} and @{term tl'}*}
  1483 
  1484 lemma (in M_trivial) is_hd_Nil: "is_hd(M,[],Z) <-> empty(M,Z)"
  1485 by (simp add: is_hd_def)
  1486 
  1487 lemma (in M_trivial) is_hd_Cons:
  1488      "[|M(a); M(l)|] ==> is_hd(M,Cons(a,l),Z) <-> Z = a"
  1489 by (force simp add: is_hd_def)
  1490 
  1491 lemma (in M_trivial) hd_abs [simp]:
  1492      "[|M(x); M(y)|] ==> is_hd(M,x,y) <-> y = hd'(x)"
  1493 apply (simp add: hd'_def)
  1494 apply (intro impI conjI)
  1495  prefer 2 apply (force simp add: is_hd_def)
  1496 apply (simp add: quasilist_def is_hd_def)
  1497 apply (elim disjE exE, auto)
  1498 done
  1499 
  1500 lemma (in M_trivial) is_tl_Nil: "is_tl(M,[],Z) <-> Z = []"
  1501 by (simp add: is_tl_def)
  1502 
  1503 lemma (in M_trivial) is_tl_Cons:
  1504      "[|M(a); M(l)|] ==> is_tl(M,Cons(a,l),Z) <-> Z = l"
  1505 by (force simp add: is_tl_def)
  1506 
  1507 lemma (in M_trivial) tl_abs [simp]:
  1508      "[|M(x); M(y)|] ==> is_tl(M,x,y) <-> y = tl'(x)"
  1509 apply (simp add: tl'_def)
  1510 apply (intro impI conjI)
  1511  prefer 2 apply (force simp add: is_tl_def)
  1512 apply (simp add: quasilist_def is_tl_def)
  1513 apply (elim disjE exE, auto)
  1514 done
  1515 
  1516 lemma (in M_trivial) relation1_tl: "relation1(M, is_tl(M), tl')"
  1517 by (simp add: relation1_def)
  1518 
  1519 lemma hd'_Nil: "hd'([]) = 0"
  1520 by (simp add: hd'_def)
  1521 
  1522 lemma hd'_Cons: "hd'(Cons(a,l)) = a"
  1523 by (simp add: hd'_def)
  1524 
  1525 lemma tl'_Nil: "tl'([]) = []"
  1526 by (simp add: tl'_def)
  1527 
  1528 lemma tl'_Cons: "tl'(Cons(a,l)) = l"
  1529 by (simp add: tl'_def)
  1530 
  1531 lemma iterates_tl_Nil: "n \<in> nat ==> tl'^n ([]) = []"
  1532 apply (induct_tac n)
  1533 apply (simp_all add: tl'_Nil)
  1534 done
  1535 
  1536 lemma (in M_basic) tl'_closed: "M(x) ==> M(tl'(x))"
  1537 apply (simp add: tl'_def)
  1538 apply (force simp add: quasilist_def)
  1539 done
  1540 
  1541 
  1542 end