src/ZF/Constructible/Relative.thy
author wenzelm
Tue Nov 07 19:40:13 2006 +0100 (2006-11-07)
changeset 21233 5a5c8ea5f66a
parent 16417 9bc16273c2d4
child 21404 eb85850d3eb7
permissions -rw-r--r--
tuned specifications;
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
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*}
wenzelm@21233
   239
definition
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*}
wenzelm@21233
   444
definition
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@13702
   496
      available for rewriting, universally quantified over M.  
paulson@13702
   497
      But it's not the only way to prove such equalities: its
paulson@13702
   498
      premises @{term "M(A)"} and  @{term "M(B)"} can be too strong.*}
paulson@13628
   499
lemma (in M_trivial) M_equalityI:
paulson@13290
   500
     "[| !!x. M(x) ==> x\<in>A <-> x\<in>B; M(A); M(B) |] ==> A=B"
paulson@13628
   501
by (blast intro!: equalityI dest: transM)
paulson@13290
   502
paulson@13418
   503
paulson@13418
   504
subsubsection{*Trivial Absoluteness Proofs: Empty Set, Pairs, etc.*}
paulson@13418
   505
paulson@13628
   506
lemma (in M_trivial) empty_abs [simp]:
paulson@13290
   507
     "M(z) ==> empty(M,z) <-> z=0"
paulson@13290
   508
apply (simp add: empty_def)
paulson@13628
   509
apply (blast intro: transM)
paulson@13290
   510
done
paulson@13290
   511
paulson@13628
   512
lemma (in M_trivial) subset_abs [simp]:
paulson@13290
   513
     "M(A) ==> subset(M,A,B) <-> A \<subseteq> B"
paulson@13628
   514
apply (simp add: subset_def)
paulson@13628
   515
apply (blast intro: transM)
paulson@13290
   516
done
paulson@13290
   517
paulson@13628
   518
lemma (in M_trivial) upair_abs [simp]:
paulson@13290
   519
     "M(z) ==> upair(M,a,b,z) <-> z={a,b}"
paulson@13628
   520
apply (simp add: upair_def)
paulson@13628
   521
apply (blast intro: transM)
paulson@13290
   522
done
paulson@13290
   523
paulson@13564
   524
lemma (in M_trivial) upair_in_M_iff [iff]:
paulson@13290
   525
     "M({a,b}) <-> M(a) & M(b)"
paulson@13628
   526
apply (insert upair_ax, simp add: upair_ax_def)
paulson@13628
   527
apply (blast intro: transM)
paulson@13290
   528
done
paulson@13290
   529
paulson@13564
   530
lemma (in M_trivial) singleton_in_M_iff [iff]:
paulson@13290
   531
     "M({a}) <-> M(a)"
paulson@13628
   532
by (insert upair_in_M_iff [of a a], simp)
paulson@13290
   533
paulson@13628
   534
lemma (in M_trivial) pair_abs [simp]:
paulson@13290
   535
     "M(z) ==> pair(M,a,b,z) <-> z=<a,b>"
paulson@13290
   536
apply (simp add: pair_def ZF.Pair_def)
paulson@13628
   537
apply (blast intro: transM)
paulson@13290
   538
done
paulson@13290
   539
paulson@13564
   540
lemma (in M_trivial) pair_in_M_iff [iff]:
paulson@13290
   541
     "M(<a,b>) <-> M(a) & M(b)"
paulson@13290
   542
by (simp add: ZF.Pair_def)
paulson@13290
   543
paulson@13564
   544
lemma (in M_trivial) pair_components_in_M:
paulson@13290
   545
     "[| <x,y> \<in> A; M(A) |] ==> M(x) & M(y)"
paulson@13290
   546
apply (simp add: Pair_def)
paulson@13628
   547
apply (blast dest: transM)
paulson@13290
   548
done
paulson@13290
   549
paulson@13628
   550
lemma (in M_trivial) cartprod_abs [simp]:
paulson@13290
   551
     "[| M(A); M(B); M(z) |] ==> cartprod(M,A,B,z) <-> z = A*B"
paulson@13290
   552
apply (simp add: cartprod_def)
paulson@13628
   553
apply (rule iffI)
paulson@13628
   554
 apply (blast intro!: equalityI intro: transM dest!: rspec)
paulson@13628
   555
apply (blast dest: transM)
paulson@13290
   556
done
paulson@13290
   557
paulson@13418
   558
subsubsection{*Absoluteness for Unions and Intersections*}
paulson@13418
   559
paulson@13628
   560
lemma (in M_trivial) union_abs [simp]:
paulson@13290
   561
     "[| M(a); M(b); M(z) |] ==> union(M,a,b,z) <-> z = a Un b"
paulson@13628
   562
apply (simp add: union_def)
paulson@13628
   563
apply (blast intro: transM)
paulson@13290
   564
done
paulson@13290
   565
paulson@13628
   566
lemma (in M_trivial) inter_abs [simp]:
paulson@13290
   567
     "[| M(a); M(b); M(z) |] ==> inter(M,a,b,z) <-> z = a Int b"
paulson@13628
   568
apply (simp add: inter_def)
paulson@13628
   569
apply (blast intro: transM)
paulson@13290
   570
done
paulson@13290
   571
paulson@13628
   572
lemma (in M_trivial) setdiff_abs [simp]:
paulson@13290
   573
     "[| M(a); M(b); M(z) |] ==> setdiff(M,a,b,z) <-> z = a-b"
paulson@13628
   574
apply (simp add: setdiff_def)
paulson@13628
   575
apply (blast intro: transM)
paulson@13290
   576
done
paulson@13290
   577
paulson@13628
   578
lemma (in M_trivial) Union_abs [simp]:
paulson@13290
   579
     "[| M(A); M(z) |] ==> big_union(M,A,z) <-> z = Union(A)"
paulson@13628
   580
apply (simp add: big_union_def)
paulson@13628
   581
apply (blast intro!: equalityI dest: transM)
paulson@13290
   582
done
paulson@13290
   583
paulson@13564
   584
lemma (in M_trivial) Union_closed [intro,simp]:
paulson@13290
   585
     "M(A) ==> M(Union(A))"
paulson@13628
   586
by (insert Union_ax, simp add: Union_ax_def)
paulson@13290
   587
paulson@13564
   588
lemma (in M_trivial) Un_closed [intro,simp]:
paulson@13290
   589
     "[| M(A); M(B) |] ==> M(A Un B)"
paulson@13628
   590
by (simp only: Un_eq_Union, blast)
paulson@13290
   591
paulson@13564
   592
lemma (in M_trivial) cons_closed [intro,simp]:
paulson@13290
   593
     "[| M(a); M(A) |] ==> M(cons(a,A))"
paulson@13628
   594
by (subst cons_eq [symmetric], blast)
paulson@13290
   595
paulson@13628
   596
lemma (in M_trivial) cons_abs [simp]:
paulson@13306
   597
     "[| M(b); M(z) |] ==> is_cons(M,a,b,z) <-> z = cons(a,b)"
paulson@13628
   598
by (simp add: is_cons_def, blast intro: transM)
paulson@13306
   599
paulson@13628
   600
lemma (in M_trivial) successor_abs [simp]:
paulson@13306
   601
     "[| M(a); M(z) |] ==> successor(M,a,z) <-> z = succ(a)"
paulson@13628
   602
by (simp add: successor_def, blast)
paulson@13290
   603
paulson@13564
   604
lemma (in M_trivial) succ_in_M_iff [iff]:
paulson@13290
   605
     "M(succ(a)) <-> M(a)"
paulson@13628
   606
apply (simp add: succ_def)
paulson@13628
   607
apply (blast intro: transM)
paulson@13290
   608
done
paulson@13290
   609
paulson@13418
   610
subsubsection{*Absoluteness for Separation and Replacement*}
paulson@13418
   611
paulson@13564
   612
lemma (in M_trivial) separation_closed [intro,simp]:
paulson@13290
   613
     "[| separation(M,P); M(A) |] ==> M(Collect(A,P))"
paulson@13628
   614
apply (insert separation, simp add: separation_def)
paulson@13628
   615
apply (drule rspec, assumption, clarify)
paulson@13290
   616
apply (subgoal_tac "y = Collect(A,P)", blast)
paulson@13628
   617
apply (blast dest: transM)
paulson@13290
   618
done
paulson@13290
   619
paulson@13436
   620
lemma separation_iff:
paulson@13436
   621
     "separation(M,P) <-> (\<forall>z[M]. \<exists>y[M]. is_Collect(M,z,P,y))"
paulson@13628
   622
by (simp add: separation_def is_Collect_def)
paulson@13436
   623
paulson@13628
   624
lemma (in M_trivial) Collect_abs [simp]:
paulson@13436
   625
     "[| M(A); M(z) |] ==> is_Collect(M,A,P,z) <-> z = Collect(A,P)"
paulson@13436
   626
apply (simp add: is_Collect_def)
paulson@13436
   627
apply (blast intro!: equalityI dest: transM)
paulson@13436
   628
done
paulson@13436
   629
paulson@13290
   630
text{*Probably the premise and conclusion are equivalent*}
paulson@13564
   631
lemma (in M_trivial) strong_replacementI [rule_format]:
paulson@13687
   632
    "[| \<forall>B[M]. separation(M, %u. \<exists>x[M]. x\<in>B & P(x,u)) |]
paulson@13290
   633
     ==> strong_replacement(M,P)"
paulson@13628
   634
apply (simp add: strong_replacement_def, clarify)
paulson@13628
   635
apply (frule replacementD [OF replacement], assumption, clarify)
paulson@13628
   636
apply (drule_tac x=A in rspec, clarify)
paulson@13628
   637
apply (drule_tac z=Y in separationD, assumption, clarify)
paulson@13628
   638
apply (rule_tac x=y in rexI, force, assumption)
paulson@13290
   639
done
paulson@13290
   640
paulson@13505
   641
subsubsection{*The Operator @{term is_Replace}*}
paulson@13505
   642
paulson@13505
   643
paulson@13505
   644
lemma is_Replace_cong [cong]:
paulson@13628
   645
     "[| A=A';
paulson@13505
   646
         !!x y. [| M(x); M(y) |] ==> P(x,y) <-> P'(x,y);
paulson@13628
   647
         z=z' |]
paulson@13628
   648
      ==> is_Replace(M, A, %x y. P(x,y), z) <->
paulson@13628
   649
          is_Replace(M, A', %x y. P'(x,y), z')"
paulson@13628
   650
by (simp add: is_Replace_def)
paulson@13505
   651
paulson@13628
   652
lemma (in M_trivial) univalent_Replace_iff:
paulson@13505
   653
     "[| M(A); univalent(M,A,P);
paulson@13628
   654
         !!x y. [| x\<in>A; P(x,y) |] ==> M(y) |]
paulson@13505
   655
      ==> u \<in> Replace(A,P) <-> (\<exists>x. x\<in>A & P(x,u))"
paulson@13628
   656
apply (simp add: Replace_iff univalent_def)
paulson@13505
   657
apply (blast dest: transM)
paulson@13505
   658
done
paulson@13505
   659
paulson@13290
   660
(*The last premise expresses that P takes M to M*)
paulson@13564
   661
lemma (in M_trivial) strong_replacement_closed [intro,simp]:
paulson@13628
   662
     "[| strong_replacement(M,P); M(A); univalent(M,A,P);
paulson@13505
   663
         !!x y. [| x\<in>A; P(x,y) |] ==> M(y) |] ==> M(Replace(A,P))"
paulson@13628
   664
apply (simp add: strong_replacement_def)
paulson@13628
   665
apply (drule_tac x=A in rspec, safe)
paulson@13290
   666
apply (subgoal_tac "Replace(A,P) = Y")
paulson@13628
   667
 apply simp
paulson@13505
   668
apply (rule equality_iffI)
paulson@13505
   669
apply (simp add: univalent_Replace_iff)
paulson@13628
   670
apply (blast dest: transM)
paulson@13505
   671
done
paulson@13505
   672
paulson@13628
   673
lemma (in M_trivial) Replace_abs:
paulson@13702
   674
     "[| M(A); M(z); univalent(M,A,P); 
paulson@13628
   675
         !!x y. [| x\<in>A; P(x,y) |] ==> M(y)  |]
paulson@13505
   676
      ==> is_Replace(M,A,P,z) <-> z = Replace(A,P)"
paulson@13505
   677
apply (simp add: is_Replace_def)
paulson@13628
   678
apply (rule iffI)
paulson@13702
   679
 apply (rule equality_iffI)
paulson@13702
   680
 apply (simp_all add: univalent_Replace_iff) 
paulson@13702
   681
 apply (blast dest: transM)+
paulson@13290
   682
done
paulson@13290
   683
paulson@13702
   684
paulson@13290
   685
(*The first premise can't simply be assumed as a schema.
paulson@13290
   686
  It is essential to take care when asserting instances of Replacement.
paulson@13290
   687
  Let K be a nonconstructible subset of nat and define
paulson@13628
   688
  f(x) = x if x:K and f(x)=0 otherwise.  Then RepFun(nat,f) = cons(0,K), a
paulson@13290
   689
  nonconstructible set.  So we cannot assume that M(X) implies M(RepFun(X,f))
paulson@13290
   690
  even for f : M -> M.
paulson@13290
   691
*)
paulson@13564
   692
lemma (in M_trivial) RepFun_closed:
paulson@13290
   693
     "[| strong_replacement(M, \<lambda>x y. y = f(x)); M(A); \<forall>x\<in>A. M(f(x)) |]
paulson@13290
   694
      ==> M(RepFun(A,f))"
paulson@13628
   695
apply (simp add: RepFun_def)
paulson@13628
   696
apply (rule strong_replacement_closed)
paulson@13628
   697
apply (auto dest: transM  simp add: univalent_def)
paulson@13290
   698
done
paulson@13290
   699
paulson@13353
   700
lemma Replace_conj_eq: "{y . x \<in> A, x\<in>A & y=f(x)} = {y . x\<in>A, y=f(x)}"
paulson@13353
   701
by simp
paulson@13353
   702
paulson@13353
   703
text{*Better than @{text RepFun_closed} when having the formula @{term "x\<in>A"}
paulson@13353
   704
      makes relativization easier.*}
paulson@13564
   705
lemma (in M_trivial) RepFun_closed2:
paulson@13353
   706
     "[| strong_replacement(M, \<lambda>x y. x\<in>A & y = f(x)); M(A); \<forall>x\<in>A. M(f(x)) |]
paulson@13353
   707
      ==> M(RepFun(A, %x. f(x)))"
paulson@13353
   708
apply (simp add: RepFun_def)
paulson@13353
   709
apply (frule strong_replacement_closed, assumption)
paulson@13628
   710
apply (auto dest: transM  simp add: Replace_conj_eq univalent_def)
paulson@13353
   711
done
paulson@13353
   712
paulson@13418
   713
subsubsection {*Absoluteness for @{term Lambda}*}
paulson@13418
   714
wenzelm@21233
   715
definition
paulson@13418
   716
 is_lambda :: "[i=>o, i, [i,i]=>o, i] => o"
paulson@13628
   717
    "is_lambda(M, A, is_b, z) ==
paulson@13418
   718
       \<forall>p[M]. p \<in> z <->
paulson@13418
   719
        (\<exists>u[M]. \<exists>v[M]. u\<in>A & pair(M,u,v,p) & is_b(u,v))"
paulson@13418
   720
paulson@13564
   721
lemma (in M_trivial) lam_closed:
paulson@13290
   722
     "[| strong_replacement(M, \<lambda>x y. y = <x,b(x)>); M(A); \<forall>x\<in>A. M(b(x)) |]
paulson@13290
   723
      ==> M(\<lambda>x\<in>A. b(x))"
paulson@13628
   724
by (simp add: lam_def, blast intro: RepFun_closed dest: transM)
paulson@13290
   725
paulson@13418
   726
text{*Better than @{text lam_closed}: has the formula @{term "x\<in>A"}*}
paulson@13564
   727
lemma (in M_trivial) lam_closed2:
paulson@13418
   728
  "[|strong_replacement(M, \<lambda>x y. x\<in>A & y = \<langle>x, b(x)\<rangle>);
paulson@13418
   729
     M(A); \<forall>m[M]. m\<in>A --> M(b(m))|] ==> M(Lambda(A,b))"
paulson@13418
   730
apply (simp add: lam_def)
paulson@13628
   731
apply (blast intro: RepFun_closed2 dest: transM)
paulson@13418
   732
done
paulson@13418
   733
paulson@13702
   734
lemma (in M_trivial) lambda_abs2:
paulson@13702
   735
     "[| Relation1(M,A,is_b,b); M(A); \<forall>m[M]. m\<in>A --> M(b(m)); M(z) |]
paulson@13418
   736
      ==> is_lambda(M,A,is_b,z) <-> z = Lambda(A,b)"
paulson@13634
   737
apply (simp add: Relation1_def is_lambda_def)
paulson@13418
   738
apply (rule iffI)
paulson@13628
   739
 prefer 2 apply (simp add: lam_def)
paulson@13702
   740
apply (rule equality_iffI)
paulson@13702
   741
apply (simp add: lam_def) 
paulson@13702
   742
apply (rule iffI) 
paulson@13702
   743
 apply (blast dest: transM) 
paulson@13702
   744
apply (auto simp add: transM [of _ A]) 
paulson@13418
   745
done
paulson@13418
   746
paulson@13423
   747
lemma is_lambda_cong [cong]:
paulson@13628
   748
     "[| A=A';  z=z';
paulson@13628
   749
         !!x y. [| x\<in>A; M(x); M(y) |] ==> is_b(x,y) <-> is_b'(x,y) |]
paulson@13628
   750
      ==> is_lambda(M, A, %x y. is_b(x,y), z) <->
paulson@13628
   751
          is_lambda(M, A', %x y. is_b'(x,y), z')"
paulson@13628
   752
by (simp add: is_lambda_def)
paulson@13423
   753
paulson@13628
   754
lemma (in M_trivial) image_abs [simp]:
paulson@13290
   755
     "[| M(r); M(A); M(z) |] ==> image(M,r,A,z) <-> z = r``A"
paulson@13290
   756
apply (simp add: image_def)
paulson@13628
   757
apply (rule iffI)
paulson@13628
   758
 apply (blast intro!: equalityI dest: transM, blast)
paulson@13290
   759
done
paulson@13290
   760
paulson@13290
   761
text{*What about @{text Pow_abs}?  Powerset is NOT absolute!
paulson@13290
   762
      This result is one direction of absoluteness.*}
paulson@13290
   763
paulson@13628
   764
lemma (in M_trivial) powerset_Pow:
paulson@13290
   765
     "powerset(M, x, Pow(x))"
paulson@13290
   766
by (simp add: powerset_def)
paulson@13290
   767
paulson@13290
   768
text{*But we can't prove that the powerset in @{text M} includes the
paulson@13290
   769
      real powerset.*}
paulson@13628
   770
lemma (in M_trivial) powerset_imp_subset_Pow:
paulson@13290
   771
     "[| powerset(M,x,y); M(y) |] ==> y <= Pow(x)"
paulson@13628
   772
apply (simp add: powerset_def)
paulson@13628
   773
apply (blast dest: transM)
paulson@13290
   774
done
paulson@13290
   775
paulson@13418
   776
subsubsection{*Absoluteness for the Natural Numbers*}
paulson@13418
   777
paulson@13564
   778
lemma (in M_trivial) nat_into_M [intro]:
paulson@13290
   779
     "n \<in> nat ==> M(n)"
paulson@13290
   780
by (induct n rule: nat_induct, simp_all)
paulson@13290
   781
paulson@13564
   782
lemma (in M_trivial) nat_case_closed [intro,simp]:
paulson@13290
   783
  "[|M(k); M(a); \<forall>m[M]. M(b(m))|] ==> M(nat_case(a,b,k))"
paulson@13628
   784
apply (case_tac "k=0", simp)
paulson@13290
   785
apply (case_tac "\<exists>m. k = succ(m)", force)
paulson@13628
   786
apply (simp add: nat_case_def)
paulson@13290
   787
done
paulson@13290
   788
paulson@13628
   789
lemma (in M_trivial) quasinat_abs [simp]:
paulson@13350
   790
     "M(z) ==> is_quasinat(M,z) <-> quasinat(z)"
paulson@13350
   791
by (auto simp add: is_quasinat_def quasinat_def)
paulson@13350
   792
paulson@13628
   793
lemma (in M_trivial) nat_case_abs [simp]:
paulson@13634
   794
     "[| relation1(M,is_b,b); M(k); M(z) |]
paulson@13353
   795
      ==> is_nat_case(M,a,is_b,k,z) <-> z = nat_case(a,b,k)"
paulson@13628
   796
apply (case_tac "quasinat(k)")
paulson@13628
   797
 prefer 2
paulson@13628
   798
 apply (simp add: is_nat_case_def non_nat_case)
paulson@13628
   799
 apply (force simp add: quasinat_def)
paulson@13350
   800
apply (simp add: quasinat_def is_nat_case_def)
paulson@13628
   801
apply (elim disjE exE)
paulson@13634
   802
 apply (simp_all add: relation1_def)
paulson@13350
   803
done
paulson@13350
   804
paulson@13628
   805
(*NOT for the simplifier.  The assumption M(z') is apparently necessary, but
paulson@13363
   806
  causes the error "Failed congruence proof!"  It may be better to replace
paulson@13363
   807
  is_nat_case by nat_case before attempting congruence reasoning.*)
paulson@13434
   808
lemma is_nat_case_cong:
paulson@13352
   809
     "[| a = a'; k = k';  z = z';  M(z');
paulson@13352
   810
       !!x y. [| M(x); M(y) |] ==> is_b(x,y) <-> is_b'(x,y) |]
paulson@13352
   811
      ==> is_nat_case(M, a, is_b, k, z) <-> is_nat_case(M, a', is_b', k', z')"
paulson@13628
   812
by (simp add: is_nat_case_def)
paulson@13352
   813
paulson@13290
   814
paulson@13418
   815
subsection{*Absoluteness for Ordinals*}
paulson@13290
   816
text{*These results constitute Theorem IV 5.1 of Kunen (page 126).*}
paulson@13290
   817
paulson@13564
   818
lemma (in M_trivial) lt_closed:
paulson@13628
   819
     "[| j<i; M(i) |] ==> M(j)"
paulson@13628
   820
by (blast dest: ltD intro: transM)
paulson@13290
   821
paulson@13628
   822
lemma (in M_trivial) transitive_set_abs [simp]:
paulson@13290
   823
     "M(a) ==> transitive_set(M,a) <-> Transset(a)"
paulson@13290
   824
by (simp add: transitive_set_def Transset_def)
paulson@13290
   825
paulson@13628
   826
lemma (in M_trivial) ordinal_abs [simp]:
paulson@13290
   827
     "M(a) ==> ordinal(M,a) <-> Ord(a)"
paulson@13290
   828
by (simp add: ordinal_def Ord_def)
paulson@13290
   829
paulson@13628
   830
lemma (in M_trivial) limit_ordinal_abs [simp]:
paulson@13628
   831
     "M(a) ==> limit_ordinal(M,a) <-> Limit(a)"
paulson@13628
   832
apply (unfold Limit_def limit_ordinal_def)
paulson@13628
   833
apply (simp add: Ord_0_lt_iff)
paulson@13628
   834
apply (simp add: lt_def, blast)
paulson@13290
   835
done
paulson@13290
   836
paulson@13628
   837
lemma (in M_trivial) successor_ordinal_abs [simp]:
paulson@13299
   838
     "M(a) ==> successor_ordinal(M,a) <-> Ord(a) & (\<exists>b[M]. a = succ(b))"
paulson@13290
   839
apply (simp add: successor_ordinal_def, safe)
paulson@13628
   840
apply (drule Ord_cases_disj, auto)
paulson@13290
   841
done
paulson@13290
   842
paulson@13290
   843
lemma finite_Ord_is_nat:
paulson@13290
   844
      "[| Ord(a); ~ Limit(a); \<forall>x\<in>a. ~ Limit(x) |] ==> a \<in> nat"
paulson@13290
   845
by (induct a rule: trans_induct3, simp_all)
paulson@13290
   846
paulson@13628
   847
lemma (in M_trivial) finite_ordinal_abs [simp]:
paulson@13290
   848
     "M(a) ==> finite_ordinal(M,a) <-> a \<in> nat"
paulson@13290
   849
apply (simp add: finite_ordinal_def)
paulson@13628
   850
apply (blast intro: finite_Ord_is_nat intro: nat_into_Ord
paulson@13290
   851
             dest: Ord_trans naturals_not_limit)
paulson@13290
   852
done
paulson@13290
   853
paulson@13290
   854
lemma Limit_non_Limit_implies_nat:
paulson@13290
   855
     "[| Limit(a); \<forall>x\<in>a. ~ Limit(x) |] ==> a = nat"
paulson@13628
   856
apply (rule le_anti_sym)
paulson@13628
   857
apply (rule all_lt_imp_le, blast, blast intro: Limit_is_Ord)
paulson@13628
   858
 apply (simp add: lt_def)
paulson@13628
   859
 apply (blast intro: Ord_in_Ord Ord_trans finite_Ord_is_nat)
paulson@13290
   860
apply (erule nat_le_Limit)
paulson@13290
   861
done
paulson@13290
   862
paulson@13628
   863
lemma (in M_trivial) omega_abs [simp]:
paulson@13290
   864
     "M(a) ==> omega(M,a) <-> a = nat"
paulson@13628
   865
apply (simp add: omega_def)
paulson@13290
   866
apply (blast intro: Limit_non_Limit_implies_nat dest: naturals_not_limit)
paulson@13290
   867
done
paulson@13290
   868
paulson@13628
   869
lemma (in M_trivial) number1_abs [simp]:
paulson@13290
   870
     "M(a) ==> number1(M,a) <-> a = 1"
paulson@13628
   871
by (simp add: number1_def)
paulson@13290
   872
paulson@13628
   873
lemma (in M_trivial) number2_abs [simp]:
paulson@13290
   874
     "M(a) ==> number2(M,a) <-> a = succ(1)"
paulson@13628
   875
by (simp add: number2_def)
paulson@13290
   876
paulson@13628
   877
lemma (in M_trivial) number3_abs [simp]:
paulson@13290
   878
     "M(a) ==> number3(M,a) <-> a = succ(succ(1))"
paulson@13628
   879
by (simp add: number3_def)
paulson@13290
   880
paulson@13290
   881
text{*Kunen continued to 20...*}
paulson@13290
   882
paulson@13628
   883
(*Could not get this to work.  The \<lambda>x\<in>nat is essential because everything
paulson@13290
   884
  but the recursion variable must stay unchanged.  But then the recursion
paulson@13628
   885
  equations only hold for x\<in>nat (or in some other set) and not for the
paulson@13290
   886
  whole of the class M.
paulson@13290
   887
  consts
paulson@13290
   888
    natnumber_aux :: "[i=>o,i] => i"
paulson@13290
   889
paulson@13290
   890
  primrec
paulson@13290
   891
      "natnumber_aux(M,0) = (\<lambda>x\<in>nat. if empty(M,x) then 1 else 0)"
paulson@13628
   892
      "natnumber_aux(M,succ(n)) =
paulson@13628
   893
	   (\<lambda>x\<in>nat. if (\<exists>y[M]. natnumber_aux(M,n)`y=1 & successor(M,y,x))
paulson@13290
   894
		     then 1 else 0)"
paulson@13290
   895
wenzelm@21233
   896
  definition
paulson@13290
   897
    natnumber :: "[i=>o,i,i] => o"
paulson@13290
   898
      "natnumber(M,n,x) == natnumber_aux(M,n)`x = 1"
paulson@13290
   899
paulson@13628
   900
  lemma (in M_trivial) [simp]:
paulson@13290
   901
       "natnumber(M,0,x) == x=0"
paulson@13290
   902
*)
paulson@13290
   903
paulson@13290
   904
subsection{*Some instances of separation and strong replacement*}
paulson@13290
   905
paulson@13564
   906
locale M_basic = M_trivial +
paulson@13290
   907
assumes Inter_separation:
paulson@13268
   908
     "M(A) ==> separation(M, \<lambda>x. \<forall>y[M]. y\<in>A --> x\<in>y)"
paulson@13436
   909
  and Diff_separation:
paulson@13436
   910
     "M(B) ==> separation(M, \<lambda>x. x \<notin> B)"
paulson@13223
   911
  and cartprod_separation:
paulson@13628
   912
     "[| M(A); M(B) |]
paulson@13298
   913
      ==> separation(M, \<lambda>z. \<exists>x[M]. x\<in>A & (\<exists>y[M]. y\<in>B & pair(M,x,y,z)))"
paulson@13223
   914
  and image_separation:
paulson@13628
   915
     "[| M(A); M(r) |]
paulson@13268
   916
      ==> separation(M, \<lambda>y. \<exists>p[M]. p\<in>r & (\<exists>x[M]. x\<in>A & pair(M,x,y,p)))"
paulson@13223
   917
  and converse_separation:
paulson@13628
   918
     "M(r) ==> separation(M,
paulson@13298
   919
         \<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
   920
  and restrict_separation:
paulson@13268
   921
     "M(A) ==> separation(M, \<lambda>z. \<exists>x[M]. x\<in>A & (\<exists>y[M]. pair(M,x,y,z)))"
paulson@13223
   922
  and comp_separation:
paulson@13223
   923
     "[| M(r); M(s) |]
paulson@13628
   924
      ==> separation(M, \<lambda>xz. \<exists>x[M]. \<exists>y[M]. \<exists>z[M]. \<exists>xy[M]. \<exists>yz[M].
paulson@13628
   925
		  pair(M,x,z,xz) & pair(M,x,y,xy) & pair(M,y,z,yz) &
paulson@13268
   926
                  xy\<in>s & yz\<in>r)"
paulson@13223
   927
  and pred_separation:
paulson@13298
   928
     "[| M(r); M(x) |] ==> separation(M, \<lambda>y. \<exists>p[M]. p\<in>r & pair(M,y,x,p))"
paulson@13223
   929
  and Memrel_separation:
paulson@13298
   930
     "separation(M, \<lambda>z. \<exists>x[M]. \<exists>y[M]. pair(M,x,y,z) & x \<in> y)"
paulson@13268
   931
  and funspace_succ_replacement:
paulson@13628
   932
     "M(n) ==>
paulson@13628
   933
      strong_replacement(M, \<lambda>p z. \<exists>f[M]. \<exists>b[M]. \<exists>nb[M]. \<exists>cnbf[M].
paulson@13306
   934
                pair(M,f,b,p) & pair(M,n,b,nb) & is_cons(M,nb,f,cnbf) &
paulson@13306
   935
                upair(M,cnbf,cnbf,z))"
paulson@13223
   936
  and is_recfun_separation:
paulson@13634
   937
     --{*for well-founded recursion: used to prove @{text is_recfun_equal}*}
paulson@13628
   938
     "[| M(r); M(f); M(g); M(a); M(b) |]
paulson@13628
   939
     ==> separation(M,
paulson@13628
   940
            \<lambda>x. \<exists>xa[M]. \<exists>xb[M].
paulson@13628
   941
                pair(M,x,a,xa) & xa \<in> r & pair(M,x,b,xb) & xb \<in> r &
paulson@13628
   942
                (\<exists>fx[M]. \<exists>gx[M]. fun_apply(M,f,x,fx) & fun_apply(M,g,x,gx) &
paulson@13319
   943
                                   fx \<noteq> gx))"
paulson@13223
   944
paulson@13564
   945
lemma (in M_basic) cartprod_iff_lemma:
paulson@13628
   946
     "[| M(C);  \<forall>u[M]. u \<in> C <-> (\<exists>x\<in>A. \<exists>y\<in>B. u = {{x}, {x,y}});
paulson@13254
   947
         powerset(M, A \<union> B, p1); powerset(M, p1, p2);  M(p2) |]
paulson@13223
   948
       ==> C = {u \<in> p2 . \<exists>x\<in>A. \<exists>y\<in>B. u = {{x}, {x,y}}}"
paulson@13628
   949
apply (simp add: powerset_def)
paulson@13254
   950
apply (rule equalityI, clarify, simp)
paulson@13628
   951
 apply (frule transM, assumption)
berghofe@13611
   952
 apply (frule transM, assumption, simp (no_asm_simp))
paulson@13628
   953
 apply blast
paulson@13223
   954
apply clarify
paulson@13628
   955
apply (frule transM, assumption, force)
paulson@13223
   956
done
paulson@13223
   957
paulson@13564
   958
lemma (in M_basic) cartprod_iff:
paulson@13628
   959
     "[| M(A); M(B); M(C) |]
paulson@13628
   960
      ==> cartprod(M,A,B,C) <->
paulson@13628
   961
          (\<exists>p1[M]. \<exists>p2[M]. powerset(M,A Un B,p1) & powerset(M,p1,p2) &
paulson@13223
   962
                   C = {z \<in> p2. \<exists>x\<in>A. \<exists>y\<in>B. z = <x,y>})"
paulson@13223
   963
apply (simp add: Pair_def cartprod_def, safe)
paulson@13628
   964
defer 1
paulson@13628
   965
  apply (simp add: powerset_def)
paulson@13628
   966
 apply blast
paulson@13223
   967
txt{*Final, difficult case: the left-to-right direction of the theorem.*}
paulson@13628
   968
apply (insert power_ax, simp add: power_ax_def)
paulson@13628
   969
apply (frule_tac x="A Un B" and P="\<lambda>x. rex(M,?Q(x))" in rspec)
paulson@13628
   970
apply (blast, clarify)
paulson@13299
   971
apply (drule_tac x=z and P="\<lambda>x. rex(M,?Q(x))" in rspec)
paulson@13299
   972
apply assumption
paulson@13628
   973
apply (blast intro: cartprod_iff_lemma)
paulson@13223
   974
done
paulson@13223
   975
paulson@13564
   976
lemma (in M_basic) cartprod_closed_lemma:
paulson@13299
   977
     "[| M(A); M(B) |] ==> \<exists>C[M]. cartprod(M,A,B,C)"
paulson@13223
   978
apply (simp del: cartprod_abs add: cartprod_iff)
paulson@13628
   979
apply (insert power_ax, simp add: power_ax_def)
paulson@13628
   980
apply (frule_tac x="A Un B" and P="\<lambda>x. rex(M,?Q(x))" in rspec)
paulson@13299
   981
apply (blast, clarify)
paulson@13628
   982
apply (drule_tac x=z and P="\<lambda>x. rex(M,?Q(x))" in rspec, auto)
paulson@13628
   983
apply (intro rexI conjI, simp+)
paulson@13628
   984
apply (insert cartprod_separation [of A B], simp)
paulson@13223
   985
done
paulson@13223
   986
paulson@13223
   987
text{*All the lemmas above are necessary because Powerset is not absolute.
paulson@13223
   988
      I should have used Replacement instead!*}
paulson@13628
   989
lemma (in M_basic) cartprod_closed [intro,simp]:
paulson@13223
   990
     "[| M(A); M(B) |] ==> M(A*B)"
paulson@13223
   991
by (frule cartprod_closed_lemma, assumption, force)
paulson@13223
   992
paulson@13628
   993
lemma (in M_basic) sum_closed [intro,simp]:
paulson@13268
   994
     "[| M(A); M(B) |] ==> M(A+B)"
paulson@13268
   995
by (simp add: sum_def)
paulson@13268
   996
paulson@13564
   997
lemma (in M_basic) sum_abs [simp]:
paulson@13350
   998
     "[| M(A); M(B); M(Z) |] ==> is_sum(M,A,B,Z) <-> (Z = A+B)"
paulson@13350
   999
by (simp add: is_sum_def sum_def singleton_0 nat_into_M)
paulson@13350
  1000
paulson@13564
  1001
lemma (in M_trivial) Inl_in_M_iff [iff]:
paulson@13397
  1002
     "M(Inl(a)) <-> M(a)"
paulson@13628
  1003
by (simp add: Inl_def)
paulson@13397
  1004
paulson@13564
  1005
lemma (in M_trivial) Inl_abs [simp]:
paulson@13397
  1006
     "M(Z) ==> is_Inl(M,a,Z) <-> (Z = Inl(a))"
paulson@13397
  1007
by (simp add: is_Inl_def Inl_def)
paulson@13397
  1008
paulson@13564
  1009
lemma (in M_trivial) Inr_in_M_iff [iff]:
paulson@13397
  1010
     "M(Inr(a)) <-> M(a)"
paulson@13628
  1011
by (simp add: Inr_def)
paulson@13397
  1012
paulson@13564
  1013
lemma (in M_trivial) Inr_abs [simp]:
paulson@13397
  1014
     "M(Z) ==> is_Inr(M,a,Z) <-> (Z = Inr(a))"
paulson@13397
  1015
by (simp add: is_Inr_def Inr_def)
paulson@13397
  1016
paulson@13290
  1017
paulson@13290
  1018
subsubsection {*converse of a relation*}
paulson@13290
  1019
paulson@13564
  1020
lemma (in M_basic) M_converse_iff:
paulson@13628
  1021
     "M(r) ==>
paulson@13628
  1022
      converse(r) =
paulson@13628
  1023
      {z \<in> Union(Union(r)) * Union(Union(r)).
paulson@13290
  1024
       \<exists>p\<in>r. \<exists>x[M]. \<exists>y[M]. p = \<langle>x,y\<rangle> & z = \<langle>y,x\<rangle>}"
paulson@13290
  1025
apply (rule equalityI)
paulson@13628
  1026
 prefer 2 apply (blast dest: transM, clarify, simp)
paulson@13628
  1027
apply (simp add: Pair_def)
paulson@13628
  1028
apply (blast dest: transM)
paulson@13290
  1029
done
paulson@13290
  1030
paulson@13628
  1031
lemma (in M_basic) converse_closed [intro,simp]:
paulson@13290
  1032
     "M(r) ==> M(converse(r))"
paulson@13290
  1033
apply (simp add: M_converse_iff)
paulson@13290
  1034
apply (insert converse_separation [of r], simp)
paulson@13290
  1035
done
paulson@13290
  1036
paulson@13628
  1037
lemma (in M_basic) converse_abs [simp]:
paulson@13290
  1038
     "[| M(r); M(z) |] ==> is_converse(M,r,z) <-> z = converse(r)"
paulson@13290
  1039
apply (simp add: is_converse_def)
paulson@13290
  1040
apply (rule iffI)
paulson@13628
  1041
 prefer 2 apply blast
paulson@13290
  1042
apply (rule M_equalityI)
paulson@13290
  1043
  apply simp
paulson@13290
  1044
  apply (blast dest: transM)+
paulson@13290
  1045
done
paulson@13290
  1046
paulson@13290
  1047
paulson@13290
  1048
subsubsection {*image, preimage, domain, range*}
paulson@13290
  1049
paulson@13628
  1050
lemma (in M_basic) image_closed [intro,simp]:
paulson@13223
  1051
     "[| M(A); M(r) |] ==> M(r``A)"
paulson@13223
  1052
apply (simp add: image_iff_Collect)
paulson@13628
  1053
apply (insert image_separation [of A r], simp)
paulson@13223
  1054
done
paulson@13223
  1055
paulson@13628
  1056
lemma (in M_basic) vimage_abs [simp]:
paulson@13223
  1057
     "[| M(r); M(A); M(z) |] ==> pre_image(M,r,A,z) <-> z = r-``A"
paulson@13223
  1058
apply (simp add: pre_image_def)
paulson@13628
  1059
apply (rule iffI)
paulson@13628
  1060
 apply (blast intro!: equalityI dest: transM, blast)
paulson@13223
  1061
done
paulson@13223
  1062
paulson@13628
  1063
lemma (in M_basic) vimage_closed [intro,simp]:
paulson@13223
  1064
     "[| M(A); M(r) |] ==> M(r-``A)"
paulson@13290
  1065
by (simp add: vimage_def)
paulson@13290
  1066
paulson@13290
  1067
paulson@13290
  1068
subsubsection{*Domain, range and field*}
paulson@13223
  1069
paulson@13628
  1070
lemma (in M_basic) domain_abs [simp]:
paulson@13223
  1071
     "[| M(r); M(z) |] ==> is_domain(M,r,z) <-> z = domain(r)"
paulson@13628
  1072
apply (simp add: is_domain_def)
paulson@13628
  1073
apply (blast intro!: equalityI dest: transM)
paulson@13223
  1074
done
paulson@13223
  1075
paulson@13628
  1076
lemma (in M_basic) domain_closed [intro,simp]:
paulson@13223
  1077
     "M(r) ==> M(domain(r))"
paulson@13223
  1078
apply (simp add: domain_eq_vimage)
paulson@13223
  1079
done
paulson@13223
  1080
paulson@13628
  1081
lemma (in M_basic) range_abs [simp]:
paulson@13223
  1082
     "[| M(r); M(z) |] ==> is_range(M,r,z) <-> z = range(r)"
paulson@13223
  1083
apply (simp add: is_range_def)
paulson@13223
  1084
apply (blast intro!: equalityI dest: transM)
paulson@13223
  1085
done
paulson@13223
  1086
paulson@13628
  1087
lemma (in M_basic) range_closed [intro,simp]:
paulson@13223
  1088
     "M(r) ==> M(range(r))"
paulson@13223
  1089
apply (simp add: range_eq_image)
paulson@13223
  1090
done
paulson@13223
  1091
paulson@13628
  1092
lemma (in M_basic) field_abs [simp]:
paulson@13245
  1093
     "[| M(r); M(z) |] ==> is_field(M,r,z) <-> z = field(r)"
paulson@13245
  1094
by (simp add: domain_closed range_closed is_field_def field_def)
paulson@13245
  1095
paulson@13628
  1096
lemma (in M_basic) field_closed [intro,simp]:
paulson@13245
  1097
     "M(r) ==> M(field(r))"
paulson@13628
  1098
by (simp add: domain_closed range_closed Un_closed field_def)
paulson@13245
  1099
paulson@13245
  1100
paulson@13290
  1101
subsubsection{*Relations, functions and application*}
paulson@13254
  1102
paulson@13628
  1103
lemma (in M_basic) relation_abs [simp]:
paulson@13223
  1104
     "M(r) ==> is_relation(M,r) <-> relation(r)"
paulson@13628
  1105
apply (simp add: is_relation_def relation_def)
paulson@13223
  1106
apply (blast dest!: bspec dest: pair_components_in_M)+
paulson@13223
  1107
done
paulson@13223
  1108
paulson@13628
  1109
lemma (in M_basic) function_abs [simp]:
paulson@13223
  1110
     "M(r) ==> is_function(M,r) <-> function(r)"
paulson@13628
  1111
apply (simp add: is_function_def function_def, safe)
paulson@13628
  1112
   apply (frule transM, assumption)
paulson@13223
  1113
  apply (blast dest: pair_components_in_M)+
paulson@13223
  1114
done
paulson@13223
  1115
paulson@13628
  1116
lemma (in M_basic) apply_closed [intro,simp]:
paulson@13223
  1117
     "[|M(f); M(a)|] ==> M(f`a)"
paulson@13290
  1118
by (simp add: apply_def)
paulson@13223
  1119
paulson@13628
  1120
lemma (in M_basic) apply_abs [simp]:
paulson@13352
  1121
     "[| M(f); M(x); M(y) |] ==> fun_apply(M,f,x,y) <-> f`x = y"
paulson@13628
  1122
apply (simp add: fun_apply_def apply_def, blast)
paulson@13223
  1123
done
paulson@13223
  1124
paulson@13628
  1125
lemma (in M_basic) typed_function_abs [simp]:
paulson@13223
  1126
     "[| M(A); M(f) |] ==> typed_function(M,A,B,f) <-> f \<in> A -> B"
paulson@13628
  1127
apply (auto simp add: typed_function_def relation_def Pi_iff)
paulson@13223
  1128
apply (blast dest: pair_components_in_M)+
paulson@13223
  1129
done
paulson@13223
  1130
paulson@13628
  1131
lemma (in M_basic) injection_abs [simp]:
paulson@13223
  1132
     "[| M(A); M(f) |] ==> injection(M,A,B,f) <-> f \<in> inj(A,B)"
paulson@13223
  1133
apply (simp add: injection_def apply_iff inj_def apply_closed)
paulson@13628
  1134
apply (blast dest: transM [of _ A])
paulson@13223
  1135
done
paulson@13223
  1136
paulson@13628
  1137
lemma (in M_basic) surjection_abs [simp]:
paulson@13223
  1138
     "[| M(A); M(B); M(f) |] ==> surjection(M,A,B,f) <-> f \<in> surj(A,B)"
paulson@13352
  1139
by (simp add: surjection_def surj_def)
paulson@13223
  1140
paulson@13628
  1141
lemma (in M_basic) bijection_abs [simp]:
paulson@13223
  1142
     "[| M(A); M(B); M(f) |] ==> bijection(M,A,B,f) <-> f \<in> bij(A,B)"
paulson@13223
  1143
by (simp add: bijection_def bij_def)
paulson@13223
  1144
paulson@13223
  1145
paulson@13290
  1146
subsubsection{*Composition of relations*}
paulson@13223
  1147
paulson@13564
  1148
lemma (in M_basic) M_comp_iff:
paulson@13628
  1149
     "[| M(r); M(s) |]
paulson@13628
  1150
      ==> r O s =
paulson@13628
  1151
          {xz \<in> domain(s) * range(r).
paulson@13268
  1152
            \<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
  1153
apply (simp add: comp_def)
paulson@13628
  1154
apply (rule equalityI)
paulson@13628
  1155
 apply clarify
paulson@13628
  1156
 apply simp
paulson@13223
  1157
 apply  (blast dest:  transM)+
paulson@13223
  1158
done
paulson@13223
  1159
paulson@13628
  1160
lemma (in M_basic) comp_closed [intro,simp]:
paulson@13223
  1161
     "[| M(r); M(s) |] ==> M(r O s)"
paulson@13223
  1162
apply (simp add: M_comp_iff)
paulson@13628
  1163
apply (insert comp_separation [of r s], simp)
paulson@13245
  1164
done
paulson@13245
  1165
paulson@13628
  1166
lemma (in M_basic) composition_abs [simp]:
paulson@13702
  1167
     "[| M(r); M(s); M(t) |] ==> composition(M,r,s,t) <-> t = r O s"
paulson@13247
  1168
apply safe
paulson@13245
  1169
 txt{*Proving @{term "composition(M, r, s, r O s)"}*}
paulson@13628
  1170
 prefer 2
paulson@13245
  1171
 apply (simp add: composition_def comp_def)
paulson@13628
  1172
 apply (blast dest: transM)
paulson@13245
  1173
txt{*Opposite implication*}
paulson@13245
  1174
apply (rule M_equalityI)
paulson@13245
  1175
  apply (simp add: composition_def comp_def)
paulson@13245
  1176
  apply (blast del: allE dest: transM)+
paulson@13223
  1177
done
paulson@13223
  1178
paulson@13290
  1179
text{*no longer needed*}
paulson@13628
  1180
lemma (in M_basic) restriction_is_function:
paulson@13628
  1181
     "[| restriction(M,f,A,z); function(f); M(f); M(A); M(z) |]
paulson@13290
  1182
      ==> function(z)"
paulson@13628
  1183
apply (simp add: restriction_def ball_iff_equiv)
paulson@13628
  1184
apply (unfold function_def, blast)
paulson@13269
  1185
done
paulson@13269
  1186
paulson@13628
  1187
lemma (in M_basic) restriction_abs [simp]:
paulson@13628
  1188
     "[| M(f); M(A); M(z) |]
paulson@13290
  1189
      ==> restriction(M,f,A,z) <-> z = restrict(f,A)"
paulson@13290
  1190
apply (simp add: ball_iff_equiv restriction_def restrict_def)
paulson@13628
  1191
apply (blast intro!: equalityI dest: transM)
paulson@13290
  1192
done
paulson@13290
  1193
paulson@13223
  1194
paulson@13564
  1195
lemma (in M_basic) M_restrict_iff:
paulson@13290
  1196
     "M(r) ==> restrict(r,A) = {z \<in> r . \<exists>x\<in>A. \<exists>y[M]. z = \<langle>x, y\<rangle>}"
paulson@13290
  1197
by (simp add: restrict_def, blast dest: transM)
paulson@13290
  1198
paulson@13628
  1199
lemma (in M_basic) restrict_closed [intro,simp]:
paulson@13290
  1200
     "[| M(A); M(r) |] ==> M(restrict(r,A))"
paulson@13290
  1201
apply (simp add: M_restrict_iff)
paulson@13628
  1202
apply (insert restrict_separation [of A], simp)
paulson@13290
  1203
done
paulson@13223
  1204
paulson@13628
  1205
lemma (in M_basic) Inter_abs [simp]:
paulson@13223
  1206
     "[| M(A); M(z) |] ==> big_inter(M,A,z) <-> z = Inter(A)"
paulson@13628
  1207
apply (simp add: big_inter_def Inter_def)
paulson@13628
  1208
apply (blast intro!: equalityI dest: transM)
paulson@13223
  1209
done
paulson@13223
  1210
paulson@13564
  1211
lemma (in M_basic) Inter_closed [intro,simp]:
paulson@13223
  1212
     "M(A) ==> M(Inter(A))"
paulson@13245
  1213
by (insert Inter_separation, simp add: Inter_def)
paulson@13223
  1214
paulson@13564
  1215
lemma (in M_basic) Int_closed [intro,simp]:
paulson@13223
  1216
     "[| M(A); M(B) |] ==> M(A Int B)"
paulson@13223
  1217
apply (subgoal_tac "M({A,B})")
paulson@13628
  1218
apply (frule Inter_closed, force+)
paulson@13223
  1219
done
paulson@13223
  1220
paulson@13564
  1221
lemma (in M_basic) Diff_closed [intro,simp]:
paulson@13436
  1222
     "[|M(A); M(B)|] ==> M(A-B)"
paulson@13436
  1223
by (insert Diff_separation, simp add: Diff_def)
paulson@13436
  1224
paulson@13436
  1225
subsubsection{*Some Facts About Separation Axioms*}
paulson@13436
  1226
paulson@13564
  1227
lemma (in M_basic) separation_conj:
paulson@13436
  1228
     "[|separation(M,P); separation(M,Q)|] ==> separation(M, \<lambda>z. P(z) & Q(z))"
paulson@13436
  1229
by (simp del: separation_closed
paulson@13628
  1230
         add: separation_iff Collect_Int_Collect_eq [symmetric])
paulson@13436
  1231
paulson@13436
  1232
(*???equalities*)
paulson@13436
  1233
lemma Collect_Un_Collect_eq:
paulson@13436
  1234
     "Collect(A,P) Un Collect(A,Q) = Collect(A, %x. P(x) | Q(x))"
paulson@13436
  1235
by blast
paulson@13436
  1236
paulson@13436
  1237
lemma Diff_Collect_eq:
paulson@13436
  1238
     "A - Collect(A,P) = Collect(A, %x. ~ P(x))"
paulson@13436
  1239
by blast
paulson@13436
  1240
paulson@13564
  1241
lemma (in M_trivial) Collect_rall_eq:
paulson@13628
  1242
     "M(Y) ==> Collect(A, %x. \<forall>y[M]. y\<in>Y --> P(x,y)) =
paulson@13436
  1243
               (if Y=0 then A else (\<Inter>y \<in> Y. {x \<in> A. P(x,y)}))"
paulson@13628
  1244
apply simp
paulson@13628
  1245
apply (blast intro!: equalityI dest: transM)
paulson@13436
  1246
done
paulson@13436
  1247
paulson@13564
  1248
lemma (in M_basic) separation_disj:
paulson@13436
  1249
     "[|separation(M,P); separation(M,Q)|] ==> separation(M, \<lambda>z. P(z) | Q(z))"
paulson@13436
  1250
by (simp del: separation_closed
paulson@13628
  1251
         add: separation_iff Collect_Un_Collect_eq [symmetric])
paulson@13436
  1252
paulson@13564
  1253
lemma (in M_basic) separation_neg:
paulson@13436
  1254
     "separation(M,P) ==> separation(M, \<lambda>z. ~P(z))"
paulson@13436
  1255
by (simp del: separation_closed
paulson@13628
  1256
         add: separation_iff Diff_Collect_eq [symmetric])
paulson@13436
  1257
paulson@13564
  1258
lemma (in M_basic) separation_imp:
paulson@13628
  1259
     "[|separation(M,P); separation(M,Q)|]
paulson@13436
  1260
      ==> separation(M, \<lambda>z. P(z) --> Q(z))"
paulson@13628
  1261
by (simp add: separation_neg separation_disj not_disj_iff_imp [symmetric])
paulson@13436
  1262
paulson@13628
  1263
text{*This result is a hint of how little can be done without the Reflection
paulson@13436
  1264
  Theorem.  The quantifier has to be bounded by a set.  We also need another
paulson@13436
  1265
  instance of Separation!*}
paulson@13564
  1266
lemma (in M_basic) separation_rall:
paulson@13628
  1267
     "[|M(Y); \<forall>y[M]. separation(M, \<lambda>x. P(x,y));
paulson@13436
  1268
        \<forall>z[M]. strong_replacement(M, \<lambda>x y. y = {u \<in> z . P(u,x)})|]
paulson@13628
  1269
      ==> separation(M, \<lambda>x. \<forall>y[M]. y\<in>Y --> P(x,y))"
paulson@13436
  1270
apply (simp del: separation_closed rall_abs
paulson@13628
  1271
         add: separation_iff Collect_rall_eq)
paulson@13628
  1272
apply (blast intro!: Inter_closed RepFun_closed dest: transM)
paulson@13436
  1273
done
paulson@13436
  1274
paulson@13436
  1275
paulson@13290
  1276
subsubsection{*Functions and function space*}
paulson@13268
  1277
paulson@13628
  1278
text{*The assumption @{term "M(A->B)"} is unusual, but essential: in
paulson@13268
  1279
all but trivial cases, A->B cannot be expected to belong to @{term M}.*}
paulson@13564
  1280
lemma (in M_basic) is_funspace_abs [simp]:
paulson@13268
  1281
     "[|M(A); M(B); M(F); M(A->B)|] ==> is_funspace(M,A,B,F) <-> F = A->B";
paulson@13268
  1282
apply (simp add: is_funspace_def)
paulson@13268
  1283
apply (rule iffI)
paulson@13628
  1284
 prefer 2 apply blast
paulson@13268
  1285
apply (rule M_equalityI)
paulson@13268
  1286
  apply simp_all
paulson@13268
  1287
done
paulson@13268
  1288
paulson@13564
  1289
lemma (in M_basic) succ_fun_eq2:
paulson@13268
  1290
     "[|M(B); M(n->B)|] ==>
paulson@13628
  1291
      succ(n) -> B =
paulson@13268
  1292
      \<Union>{z. p \<in> (n->B)*B, \<exists>f[M]. \<exists>b[M]. p = <f,b> & z = {cons(<n,b>, f)}}"
paulson@13268
  1293
apply (simp add: succ_fun_eq)
paulson@13628
  1294
apply (blast dest: transM)
paulson@13268
  1295
done
paulson@13268
  1296
paulson@13564
  1297
lemma (in M_basic) funspace_succ:
paulson@13268
  1298
     "[|M(n); M(B); M(n->B) |] ==> M(succ(n) -> B)"
paulson@13628
  1299
apply (insert funspace_succ_replacement [of n], simp)
paulson@13628
  1300
apply (force simp add: succ_fun_eq2 univalent_def)
paulson@13268
  1301
done
paulson@13268
  1302
paulson@13268
  1303
text{*@{term M} contains all finite function spaces.  Needed to prove the
paulson@13628
  1304
absoluteness of transitive closure.  See the definition of
paulson@13628
  1305
@{text rtrancl_alt} in in @{text WF_absolute.thy}.*}
paulson@13564
  1306
lemma (in M_basic) finite_funspace_closed [intro,simp]:
paulson@13268
  1307
     "[|n\<in>nat; M(B)|] ==> M(n->B)"
paulson@13268
  1308
apply (induct_tac n, simp)
paulson@13628
  1309
apply (simp add: funspace_succ nat_into_M)
paulson@13268
  1310
done
paulson@13268
  1311
paulson@13350
  1312
paulson@13423
  1313
subsection{*Relativization and Absoluteness for Boolean Operators*}
paulson@13423
  1314
wenzelm@21233
  1315
definition
paulson@13423
  1316
  is_bool_of_o :: "[i=>o, o, i] => o"
paulson@13423
  1317
   "is_bool_of_o(M,P,z) == (P & number1(M,z)) | (~P & empty(M,z))"
paulson@13423
  1318
paulson@13423
  1319
  is_not :: "[i=>o, i, i] => o"
paulson@13628
  1320
   "is_not(M,a,z) == (number1(M,a)  & empty(M,z)) |
paulson@13423
  1321
                     (~number1(M,a) & number1(M,z))"
paulson@13423
  1322
paulson@13423
  1323
  is_and :: "[i=>o, i, i, i] => o"
paulson@13628
  1324
   "is_and(M,a,b,z) == (number1(M,a)  & z=b) |
paulson@13423
  1325
                       (~number1(M,a) & empty(M,z))"
paulson@13423
  1326
paulson@13423
  1327
  is_or :: "[i=>o, i, i, i] => o"
paulson@13628
  1328
   "is_or(M,a,b,z) == (number1(M,a)  & number1(M,z)) |
paulson@13423
  1329
                      (~number1(M,a) & z=b)"
paulson@13423
  1330
paulson@13628
  1331
lemma (in M_trivial) bool_of_o_abs [simp]:
paulson@13628
  1332
     "M(z) ==> is_bool_of_o(M,P,z) <-> z = bool_of_o(P)"
paulson@13628
  1333
by (simp add: is_bool_of_o_def bool_of_o_def)
paulson@13423
  1334
paulson@13423
  1335
paulson@13628
  1336
lemma (in M_trivial) not_abs [simp]:
paulson@13423
  1337
     "[| M(a); M(z)|] ==> is_not(M,a,z) <-> z = not(a)"
paulson@13628
  1338
by (simp add: Bool.not_def cond_def is_not_def)
paulson@13423
  1339
paulson@13628
  1340
lemma (in M_trivial) and_abs [simp]:
paulson@13423
  1341
     "[| M(a); M(b); M(z)|] ==> is_and(M,a,b,z) <-> z = a and b"
paulson@13628
  1342
by (simp add: Bool.and_def cond_def is_and_def)
paulson@13423
  1343
paulson@13628
  1344
lemma (in M_trivial) or_abs [simp]:
paulson@13423
  1345
     "[| M(a); M(b); M(z)|] ==> is_or(M,a,b,z) <-> z = a or b"
paulson@13423
  1346
by (simp add: Bool.or_def cond_def is_or_def)
paulson@13423
  1347
paulson@13423
  1348
paulson@13564
  1349
lemma (in M_trivial) bool_of_o_closed [intro,simp]:
paulson@13423
  1350
     "M(bool_of_o(P))"
paulson@13628
  1351
by (simp add: bool_of_o_def)
paulson@13423
  1352
paulson@13564
  1353
lemma (in M_trivial) and_closed [intro,simp]:
paulson@13423
  1354
     "[| M(p); M(q) |] ==> M(p and q)"
paulson@13628
  1355
by (simp add: and_def cond_def)
paulson@13423
  1356
paulson@13564
  1357
lemma (in M_trivial) or_closed [intro,simp]:
paulson@13423
  1358
     "[| M(p); M(q) |] ==> M(p or q)"
paulson@13628
  1359
by (simp add: or_def cond_def)
paulson@13423
  1360
paulson@13564
  1361
lemma (in M_trivial) not_closed [intro,simp]:
paulson@13423
  1362
     "M(p) ==> M(not(p))"
paulson@13628
  1363
by (simp add: Bool.not_def cond_def)
paulson@13423
  1364
paulson@13423
  1365
paulson@13397
  1366
subsection{*Relativization and Absoluteness for List Operators*}
paulson@13397
  1367
wenzelm@21233
  1368
definition
paulson@13397
  1369
paulson@13397
  1370
  is_Nil :: "[i=>o, i] => o"
paulson@13397
  1371
     --{* because @{term "[] \<equiv> Inl(0)"}*}
paulson@13397
  1372
    "is_Nil(M,xs) == \<exists>zero[M]. empty(M,zero) & is_Inl(M,zero,xs)"
paulson@13397
  1373
paulson@13397
  1374
  is_Cons :: "[i=>o,i,i,i] => o"
paulson@13397
  1375
     --{* because @{term "Cons(a, l) \<equiv> Inr(\<langle>a,l\<rangle>)"}*}
paulson@13397
  1376
    "is_Cons(M,a,l,Z) == \<exists>p[M]. pair(M,a,l,p) & is_Inr(M,p,Z)"
paulson@13397
  1377
paulson@13397
  1378
paulson@13564
  1379
lemma (in M_trivial) Nil_in_M [intro,simp]: "M(Nil)"
paulson@13397
  1380
by (simp add: Nil_def)
paulson@13397
  1381
paulson@13564
  1382
lemma (in M_trivial) Nil_abs [simp]: "M(Z) ==> is_Nil(M,Z) <-> (Z = Nil)"
paulson@13397
  1383
by (simp add: is_Nil_def Nil_def)
paulson@13397
  1384
paulson@13564
  1385
lemma (in M_trivial) Cons_in_M_iff [iff]: "M(Cons(a,l)) <-> M(a) & M(l)"
paulson@13628
  1386
by (simp add: Cons_def)
paulson@13397
  1387
paulson@13564
  1388
lemma (in M_trivial) Cons_abs [simp]:
paulson@13397
  1389
     "[|M(a); M(l); M(Z)|] ==> is_Cons(M,a,l,Z) <-> (Z = Cons(a,l))"
paulson@13397
  1390
by (simp add: is_Cons_def Cons_def)
paulson@13397
  1391
paulson@13397
  1392
wenzelm@21233
  1393
definition
paulson@13397
  1394
paulson@13397
  1395
  quasilist :: "i => o"
paulson@13397
  1396
    "quasilist(xs) == xs=Nil | (\<exists>x l. xs = Cons(x,l))"
paulson@13397
  1397
paulson@13397
  1398
  is_quasilist :: "[i=>o,i] => o"
paulson@13397
  1399
    "is_quasilist(M,z) == is_Nil(M,z) | (\<exists>x[M]. \<exists>l[M]. is_Cons(M,x,l,z))"
paulson@13397
  1400
paulson@13397
  1401
  list_case' :: "[i, [i,i]=>i, i] => i"
paulson@13397
  1402
    --{*A version of @{term list_case} that's always defined.*}
paulson@13628
  1403
    "list_case'(a,b,xs) ==
paulson@13628
  1404
       if quasilist(xs) then list_case(a,b,xs) else 0"
paulson@13397
  1405
paulson@13397
  1406
  is_list_case :: "[i=>o, i, [i,i,i]=>o, i, i] => o"
paulson@13397
  1407
    --{*Returns 0 for non-lists*}
paulson@13628
  1408
    "is_list_case(M, a, is_b, xs, z) ==
paulson@13397
  1409
       (is_Nil(M,xs) --> z=a) &
paulson@13397
  1410
       (\<forall>x[M]. \<forall>l[M]. is_Cons(M,x,l,xs) --> is_b(x,l,z)) &
paulson@13397
  1411
       (is_quasilist(M,xs) | empty(M,z))"
paulson@13397
  1412
paulson@13397
  1413
  hd' :: "i => i"
paulson@13397
  1414
    --{*A version of @{term hd} that's always defined.*}
paulson@13628
  1415
    "hd'(xs) == if quasilist(xs) then hd(xs) else 0"
paulson@13397
  1416
paulson@13397
  1417
  tl' :: "i => i"
paulson@13397
  1418
    --{*A version of @{term tl} that's always defined.*}
paulson@13628
  1419
    "tl'(xs) == if quasilist(xs) then tl(xs) else 0"
paulson@13397
  1420
paulson@13397
  1421
  is_hd :: "[i=>o,i,i] => o"
paulson@13397
  1422
     --{* @{term "hd([]) = 0"} no constraints if not a list.
paulson@13397
  1423
          Avoiding implication prevents the simplifier's looping.*}
paulson@13628
  1424
    "is_hd(M,xs,H) ==
paulson@13397
  1425
       (is_Nil(M,xs) --> empty(M,H)) &
paulson@13397
  1426
       (\<forall>x[M]. \<forall>l[M]. ~ is_Cons(M,x,l,xs) | H=x) &
paulson@13397
  1427
       (is_quasilist(M,xs) | empty(M,H))"
paulson@13397
  1428
paulson@13397
  1429
  is_tl :: "[i=>o,i,i] => o"
paulson@13397
  1430
     --{* @{term "tl([]) = []"}; see comments about @{term is_hd}*}
paulson@13628
  1431
    "is_tl(M,xs,T) ==
paulson@13397
  1432
       (is_Nil(M,xs) --> T=xs) &
paulson@13397
  1433
       (\<forall>x[M]. \<forall>l[M]. ~ is_Cons(M,x,l,xs) | T=l) &
paulson@13397
  1434
       (is_quasilist(M,xs) | empty(M,T))"
paulson@13397
  1435
paulson@13397
  1436
subsubsection{*@{term quasilist}: For Case-Splitting with @{term list_case'}*}
paulson@13397
  1437
paulson@13397
  1438
lemma [iff]: "quasilist(Nil)"
paulson@13397
  1439
by (simp add: quasilist_def)
paulson@13397
  1440
paulson@13397
  1441
lemma [iff]: "quasilist(Cons(x,l))"
paulson@13397
  1442
by (simp add: quasilist_def)
paulson@13397
  1443
paulson@13397
  1444
lemma list_imp_quasilist: "l \<in> list(A) ==> quasilist(l)"
paulson@13397
  1445
by (erule list.cases, simp_all)
paulson@13397
  1446
paulson@13397
  1447
subsubsection{*@{term list_case'}, the Modified Version of @{term list_case}*}
paulson@13397
  1448
paulson@13397
  1449
lemma list_case'_Nil [simp]: "list_case'(a,b,Nil) = a"
paulson@13397
  1450
by (simp add: list_case'_def quasilist_def)
paulson@13397
  1451
paulson@13397
  1452
lemma list_case'_Cons [simp]: "list_case'(a,b,Cons(x,l)) = b(x,l)"
paulson@13397
  1453
by (simp add: list_case'_def quasilist_def)
paulson@13397
  1454
paulson@13628
  1455
lemma non_list_case: "~ quasilist(x) ==> list_case'(a,b,x) = 0"
paulson@13628
  1456
by (simp add: quasilist_def list_case'_def)
paulson@13397
  1457
paulson@13397
  1458
lemma list_case'_eq_list_case [simp]:
paulson@13397
  1459
     "xs \<in> list(A) ==>list_case'(a,b,xs) = list_case(a,b,xs)"
paulson@13397
  1460
by (erule list.cases, simp_all)
paulson@13397
  1461
paulson@13564
  1462
lemma (in M_basic) list_case'_closed [intro,simp]:
paulson@13397
  1463
  "[|M(k); M(a); \<forall>x[M]. \<forall>y[M]. M(b(x,y))|] ==> M(list_case'(a,b,k))"
paulson@13628
  1464
apply (case_tac "quasilist(k)")
paulson@13628
  1465
 apply (simp add: quasilist_def, force)
paulson@13628
  1466
apply (simp add: non_list_case)
paulson@13397
  1467
done
paulson@13397
  1468
paulson@13628
  1469
lemma (in M_trivial) quasilist_abs [simp]:
paulson@13397
  1470
     "M(z) ==> is_quasilist(M,z) <-> quasilist(z)"
paulson@13397
  1471
by (auto simp add: is_quasilist_def quasilist_def)
paulson@13397
  1472
paulson@13628
  1473
lemma (in M_trivial) list_case_abs [simp]:
paulson@13634
  1474
     "[| relation2(M,is_b,b); M(k); M(z) |]
paulson@13397
  1475
      ==> is_list_case(M,a,is_b,k,z) <-> z = list_case'(a,b,k)"
paulson@13628
  1476
apply (case_tac "quasilist(k)")
paulson@13628
  1477
 prefer 2
paulson@13628
  1478
 apply (simp add: is_list_case_def non_list_case)
paulson@13628
  1479
 apply (force simp add: quasilist_def)
paulson@13397
  1480
apply (simp add: quasilist_def is_list_case_def)
paulson@13628
  1481
apply (elim disjE exE)
paulson@13634
  1482
 apply (simp_all add: relation2_def)
paulson@13397
  1483
done
paulson@13397
  1484
paulson@13397
  1485
paulson@13397
  1486
subsubsection{*The Modified Operators @{term hd'} and @{term tl'}*}
paulson@13397
  1487
paulson@13564
  1488
lemma (in M_trivial) is_hd_Nil: "is_hd(M,[],Z) <-> empty(M,Z)"
paulson@13505
  1489
by (simp add: is_hd_def)
paulson@13397
  1490
paulson@13564
  1491
lemma (in M_trivial) is_hd_Cons:
paulson@13397
  1492
     "[|M(a); M(l)|] ==> is_hd(M,Cons(a,l),Z) <-> Z = a"
paulson@13628
  1493
by (force simp add: is_hd_def)
paulson@13397
  1494
paulson@13564
  1495
lemma (in M_trivial) hd_abs [simp]:
paulson@13397
  1496
     "[|M(x); M(y)|] ==> is_hd(M,x,y) <-> y = hd'(x)"
paulson@13397
  1497
apply (simp add: hd'_def)
paulson@13397
  1498
apply (intro impI conjI)
paulson@13628
  1499
 prefer 2 apply (force simp add: is_hd_def)
paulson@13505
  1500
apply (simp add: quasilist_def is_hd_def)
paulson@13397
  1501
apply (elim disjE exE, auto)
paulson@13628
  1502
done
paulson@13397
  1503
paulson@13564
  1504
lemma (in M_trivial) is_tl_Nil: "is_tl(M,[],Z) <-> Z = []"
paulson@13505
  1505
by (simp add: is_tl_def)
paulson@13397
  1506
paulson@13564
  1507
lemma (in M_trivial) is_tl_Cons:
paulson@13397
  1508
     "[|M(a); M(l)|] ==> is_tl(M,Cons(a,l),Z) <-> Z = l"
paulson@13628
  1509
by (force simp add: is_tl_def)
paulson@13397
  1510
paulson@13564
  1511
lemma (in M_trivial) tl_abs [simp]:
paulson@13397
  1512
     "[|M(x); M(y)|] ==> is_tl(M,x,y) <-> y = tl'(x)"
paulson@13397
  1513
apply (simp add: tl'_def)
paulson@13397
  1514
apply (intro impI conjI)
paulson@13628
  1515
 prefer 2 apply (force simp add: is_tl_def)
paulson@13505
  1516
apply (simp add: quasilist_def is_tl_def)
paulson@13397
  1517
apply (elim disjE exE, auto)
paulson@13628
  1518
done
paulson@13397
  1519
paulson@13634
  1520
lemma (in M_trivial) relation1_tl: "relation1(M, is_tl(M), tl')"
paulson@13634
  1521
by (simp add: relation1_def)
paulson@13397
  1522
paulson@13397
  1523
lemma hd'_Nil: "hd'([]) = 0"
paulson@13397
  1524
by (simp add: hd'_def)
paulson@13397
  1525
paulson@13397
  1526
lemma hd'_Cons: "hd'(Cons(a,l)) = a"
paulson@13397
  1527
by (simp add: hd'_def)
paulson@13397
  1528
paulson@13397
  1529
lemma tl'_Nil: "tl'([]) = []"
paulson@13397
  1530
by (simp add: tl'_def)
paulson@13397
  1531
paulson@13397
  1532
lemma tl'_Cons: "tl'(Cons(a,l)) = l"
paulson@13397
  1533
by (simp add: tl'_def)
paulson@13397
  1534
paulson@13397
  1535
lemma iterates_tl_Nil: "n \<in> nat ==> tl'^n ([]) = []"
paulson@13628
  1536
apply (induct_tac n)
paulson@13628
  1537
apply (simp_all add: tl'_Nil)
paulson@13397
  1538
done
paulson@13397
  1539
paulson@13564
  1540
lemma (in M_basic) tl'_closed: "M(x) ==> M(tl'(x))"
paulson@13397
  1541
apply (simp add: tl'_def)
paulson@13397
  1542
apply (force simp add: quasilist_def)
paulson@13397
  1543
done
paulson@13397
  1544
paulson@13397
  1545
paulson@13223
  1546
end