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