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