src/ZF/Constructible/Rank.thy
author wenzelm
Thu Dec 14 11:24:26 2017 +0100 (21 months ago)
changeset 67198 694f29a5433b
parent 61798 27f3c10b0b50
child 67399 eab6ce8368fa
permissions -rw-r--r--
merged
paulson@13634
     1
(*  Title:      ZF/Constructible/Rank.thy
paulson@13634
     2
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
paulson@13634
     3
*)
paulson@13634
     4
wenzelm@60770
     5
section \<open>Absoluteness for Order Types, Rank Functions and Well-Founded 
wenzelm@60770
     6
         Relations\<close>
paulson@13634
     7
haftmann@16417
     8
theory Rank imports WF_absolute begin
paulson@13634
     9
wenzelm@60770
    10
subsection \<open>Order Types: A Direct Construction by Replacement\<close>
paulson@13634
    11
paulson@13634
    12
locale M_ordertype = M_basic +
paulson@13634
    13
assumes well_ord_iso_separation:
paulson@13634
    14
     "[| M(A); M(f); M(r) |]
paulson@46823
    15
      ==> separation (M, \<lambda>x. x\<in>A \<longrightarrow> (\<exists>y[M]. (\<exists>p[M].
wenzelm@32960
    16
                     fun_apply(M,f,x,y) & pair(M,y,x,p) & p \<in> r)))"
paulson@13634
    17
  and obase_separation:
wenzelm@61798
    18
     \<comment>\<open>part of the order type formalization\<close>
paulson@13634
    19
     "[| M(A); M(r) |]
paulson@13634
    20
      ==> separation(M, \<lambda>a. \<exists>x[M]. \<exists>g[M]. \<exists>mx[M]. \<exists>par[M].
wenzelm@32960
    21
             ordinal(M,x) & membership(M,x,mx) & pred_set(M,A,a,r,par) &
wenzelm@32960
    22
             order_isomorphism(M,par,r,x,mx,g))"
paulson@13634
    23
  and obase_equals_separation:
paulson@13634
    24
     "[| M(A); M(r) |]
paulson@46823
    25
      ==> separation (M, \<lambda>x. x\<in>A \<longrightarrow> ~(\<exists>y[M]. \<exists>g[M].
wenzelm@32960
    26
                              ordinal(M,y) & (\<exists>my[M]. \<exists>pxr[M].
wenzelm@32960
    27
                              membership(M,y,my) & pred_set(M,A,x,r,pxr) &
wenzelm@32960
    28
                              order_isomorphism(M,pxr,r,y,my,g))))"
paulson@13634
    29
  and omap_replacement:
paulson@13634
    30
     "[| M(A); M(r) |]
paulson@13634
    31
      ==> strong_replacement(M,
paulson@13634
    32
             \<lambda>a z. \<exists>x[M]. \<exists>g[M]. \<exists>mx[M]. \<exists>par[M].
wenzelm@32960
    33
             ordinal(M,x) & pair(M,a,x,z) & membership(M,x,mx) &
wenzelm@32960
    34
             pred_set(M,A,a,r,par) & order_isomorphism(M,par,r,x,mx,g))"
paulson@13634
    35
paulson@13634
    36
wenzelm@60770
    37
text\<open>Inductive argument for Kunen's Lemma I 6.1, etc.
wenzelm@60770
    38
      Simple proof from Halmos, page 72\<close>
paulson@13634
    39
lemma  (in M_ordertype) wellordered_iso_subset_lemma: 
paulson@13634
    40
     "[| wellordered(M,A,r);  f \<in> ord_iso(A,r, A',r);  A'<= A;  y \<in> A;  
paulson@13634
    41
       M(A);  M(f);  M(r) |] ==> ~ <f`y, y> \<in> r"
paulson@13634
    42
apply (unfold wellordered_def ord_iso_def)
paulson@13634
    43
apply (elim conjE CollectE) 
paulson@13634
    44
apply (erule wellfounded_on_induct, assumption+)
paulson@13634
    45
 apply (insert well_ord_iso_separation [of A f r])
paulson@13634
    46
 apply (simp, clarify) 
paulson@13634
    47
apply (drule_tac a = x in bij_is_fun [THEN apply_type], assumption, blast)
paulson@13634
    48
done
paulson@13634
    49
paulson@13634
    50
wenzelm@60770
    51
text\<open>Kunen's Lemma I 6.1, page 14: 
wenzelm@60770
    52
      there's no order-isomorphism to an initial segment of a well-ordering\<close>
paulson@13634
    53
lemma (in M_ordertype) wellordered_iso_predD:
paulson@13634
    54
     "[| wellordered(M,A,r);  f \<in> ord_iso(A, r, Order.pred(A,x,r), r);  
paulson@13634
    55
       M(A);  M(f);  M(r) |] ==> x \<notin> A"
paulson@13634
    56
apply (rule notI) 
paulson@13634
    57
apply (frule wellordered_iso_subset_lemma, assumption)
paulson@13634
    58
apply (auto elim: predE)  
paulson@13634
    59
(*Now we know  ~ (f`x < x) *)
paulson@13634
    60
apply (drule ord_iso_is_bij [THEN bij_is_fun, THEN apply_type], assumption)
paulson@13634
    61
(*Now we also know f`x  \<in> pred(A,x,r);  contradiction! *)
paulson@13634
    62
apply (simp add: Order.pred_def)
paulson@13634
    63
done
paulson@13634
    64
paulson@13634
    65
paulson@13634
    66
lemma (in M_ordertype) wellordered_iso_pred_eq_lemma:
paulson@13634
    67
     "[| f \<in> \<langle>Order.pred(A,y,r), r\<rangle> \<cong> \<langle>Order.pred(A,x,r), r\<rangle>;
paulson@13634
    68
       wellordered(M,A,r); x\<in>A; y\<in>A; M(A); M(f); M(r) |] ==> <x,y> \<notin> r"
paulson@13634
    69
apply (frule wellordered_is_trans_on, assumption)
paulson@13634
    70
apply (rule notI) 
paulson@13634
    71
apply (drule_tac x2=y and x=x and r2=r in 
paulson@13634
    72
         wellordered_subset [OF _ pred_subset, THEN wellordered_iso_predD]) 
paulson@13634
    73
apply (simp add: trans_pred_pred_eq) 
paulson@13634
    74
apply (blast intro: predI dest: transM)+
paulson@13634
    75
done
paulson@13634
    76
paulson@13634
    77
wenzelm@60770
    78
text\<open>Simple consequence of Lemma 6.1\<close>
paulson@13634
    79
lemma (in M_ordertype) wellordered_iso_pred_eq:
paulson@13634
    80
     "[| wellordered(M,A,r);
paulson@13634
    81
       f \<in> ord_iso(Order.pred(A,a,r), r, Order.pred(A,c,r), r);   
paulson@13634
    82
       M(A);  M(f);  M(r);  a\<in>A;  c\<in>A |] ==> a=c"
paulson@13634
    83
apply (frule wellordered_is_trans_on, assumption)
paulson@13634
    84
apply (frule wellordered_is_linear, assumption)
paulson@13634
    85
apply (erule_tac x=a and y=c in linearE, auto) 
paulson@13634
    86
apply (drule ord_iso_sym)
paulson@13634
    87
(*two symmetric cases*)
paulson@13634
    88
apply (blast dest: wellordered_iso_pred_eq_lemma)+ 
paulson@13634
    89
done
paulson@13634
    90
paulson@13634
    91
wenzelm@60770
    92
text\<open>Following Kunen's Theorem I 7.6, page 17.  Note that this material is
wenzelm@60770
    93
not required elsewhere.\<close>
paulson@13634
    94
wenzelm@61798
    95
text\<open>Can't use \<open>well_ord_iso_preserving\<close> because it needs the
wenzelm@60770
    96
strong premise @{term "well_ord(A,r)"}\<close>
paulson@13634
    97
lemma (in M_ordertype) ord_iso_pred_imp_lt:
paulson@13634
    98
     "[| f \<in> ord_iso(Order.pred(A,x,r), r, i, Memrel(i));
paulson@13634
    99
         g \<in> ord_iso(Order.pred(A,y,r), r, j, Memrel(j));
paulson@13634
   100
         wellordered(M,A,r);  x \<in> A;  y \<in> A; M(A); M(r); M(f); M(g); M(j);
paulson@13634
   101
         Ord(i); Ord(j); \<langle>x,y\<rangle> \<in> r |]
paulson@13634
   102
      ==> i < j"
paulson@13634
   103
apply (frule wellordered_is_trans_on, assumption)
paulson@13634
   104
apply (frule_tac y=y in transM, assumption) 
paulson@13634
   105
apply (rule_tac i=i and j=j in Ord_linear_lt, auto)  
wenzelm@60770
   106
txt\<open>case @{term "i=j"} yields a contradiction\<close>
paulson@13634
   107
 apply (rule_tac x1=x and A1="Order.pred(A,y,r)" in 
paulson@13634
   108
          wellordered_iso_predD [THEN notE]) 
paulson@13634
   109
   apply (blast intro: wellordered_subset [OF _ pred_subset]) 
paulson@13634
   110
  apply (simp add: trans_pred_pred_eq)
paulson@13634
   111
  apply (blast intro: Ord_iso_implies_eq ord_iso_sym ord_iso_trans) 
paulson@13634
   112
 apply (simp_all add: pred_iff pred_closed converse_closed comp_closed)
wenzelm@60770
   113
txt\<open>case @{term "j<i"} also yields a contradiction\<close>
paulson@13634
   114
apply (frule restrict_ord_iso2, assumption+) 
paulson@13634
   115
apply (frule ord_iso_sym [THEN ord_iso_is_bij, THEN bij_is_fun]) 
paulson@13634
   116
apply (frule apply_type, blast intro: ltD) 
wenzelm@61798
   117
  \<comment>\<open>thus @{term "converse(f)`j \<in> Order.pred(A,x,r)"}\<close>
paulson@13634
   118
apply (simp add: pred_iff) 
paulson@13634
   119
apply (subgoal_tac
paulson@13634
   120
       "\<exists>h[M]. h \<in> ord_iso(Order.pred(A,y,r), r, 
paulson@13634
   121
                               Order.pred(A, converse(f)`j, r), r)")
paulson@13634
   122
 apply (clarify, frule wellordered_iso_pred_eq, assumption+)
paulson@13634
   123
 apply (blast dest: wellordered_asym)  
paulson@13634
   124
apply (intro rexI)
paulson@13634
   125
 apply (blast intro: Ord_iso_implies_eq ord_iso_sym ord_iso_trans)+
paulson@13634
   126
done
paulson@13634
   127
paulson@13634
   128
paulson@13634
   129
lemma ord_iso_converse1:
paulson@13634
   130
     "[| f: ord_iso(A,r,B,s);  <b, f`a>: s;  a:A;  b:B |] 
paulson@13721
   131
      ==> <converse(f) ` b, a> \<in> r"
paulson@13634
   132
apply (frule ord_iso_converse, assumption+) 
paulson@13634
   133
apply (blast intro: ord_iso_is_bij [THEN bij_is_fun, THEN apply_funtype]) 
paulson@13634
   134
apply (simp add: left_inverse_bij [OF ord_iso_is_bij])
paulson@13634
   135
done
paulson@13634
   136
paulson@13634
   137
wenzelm@21404
   138
definition  
wenzelm@21404
   139
  obase :: "[i=>o,i,i] => i" where
wenzelm@61798
   140
       \<comment>\<open>the domain of \<open>om\<close>, eventually shown to equal \<open>A\<close>\<close>
paulson@13634
   141
   "obase(M,A,r) == {a\<in>A. \<exists>x[M]. \<exists>g[M]. Ord(x) & 
paulson@13634
   142
                          g \<in> ord_iso(Order.pred(A,a,r),r,x,Memrel(x))}"
paulson@13634
   143
wenzelm@21404
   144
definition
wenzelm@21404
   145
  omap :: "[i=>o,i,i,i] => o" where
wenzelm@61798
   146
    \<comment>\<open>the function that maps wosets to order types\<close>
paulson@13634
   147
   "omap(M,A,r,f) == 
wenzelm@32960
   148
        \<forall>z[M].
paulson@46823
   149
         z \<in> f \<longleftrightarrow> (\<exists>a\<in>A. \<exists>x[M]. \<exists>g[M]. z = <a,x> & Ord(x) & 
paulson@13634
   150
                        g \<in> ord_iso(Order.pred(A,a,r),r,x,Memrel(x)))"
paulson@13634
   151
wenzelm@21404
   152
definition
wenzelm@61798
   153
  otype :: "[i=>o,i,i,i] => o" where \<comment>\<open>the order types themselves\<close>
paulson@13634
   154
   "otype(M,A,r,i) == \<exists>f[M]. omap(M,A,r,f) & is_range(M,f,i)"
paulson@13634
   155
paulson@13634
   156
wenzelm@60770
   157
text\<open>Can also be proved with the premise @{term "M(z)"} instead of
paulson@13634
   158
      @{term "M(f)"}, but that version is less useful.  This lemma
wenzelm@61798
   159
      is also more useful than the definition, \<open>omap_def\<close>.\<close>
paulson@13634
   160
lemma (in M_ordertype) omap_iff:
paulson@13634
   161
     "[| omap(M,A,r,f); M(A); M(f) |] 
paulson@46823
   162
      ==> z \<in> f \<longleftrightarrow>
paulson@13634
   163
          (\<exists>a\<in>A. \<exists>x[M]. \<exists>g[M]. z = <a,x> & Ord(x) & 
paulson@13634
   164
                                g \<in> ord_iso(Order.pred(A,a,r),r,x,Memrel(x)))"
paulson@13634
   165
apply (simp add: omap_def Memrel_closed pred_closed) 
paulson@13634
   166
apply (rule iffI)
paulson@13634
   167
 apply (drule_tac [2] x=z in rspec)
paulson@13634
   168
 apply (drule_tac x=z in rspec)
paulson@13634
   169
 apply (blast dest: transM)+
paulson@13634
   170
done
paulson@13634
   171
paulson@13634
   172
lemma (in M_ordertype) omap_unique:
paulson@13634
   173
     "[| omap(M,A,r,f); omap(M,A,r,f'); M(A); M(r); M(f); M(f') |] ==> f' = f" 
paulson@13634
   174
apply (rule equality_iffI) 
paulson@13634
   175
apply (simp add: omap_iff) 
paulson@13634
   176
done
paulson@13634
   177
paulson@13634
   178
lemma (in M_ordertype) omap_yields_Ord:
paulson@13634
   179
     "[| omap(M,A,r,f); \<langle>a,x\<rangle> \<in> f; M(a); M(x) |]  ==> Ord(x)"
paulson@13634
   180
  by (simp add: omap_def)
paulson@13634
   181
paulson@13634
   182
lemma (in M_ordertype) otype_iff:
paulson@13634
   183
     "[| otype(M,A,r,i); M(A); M(r); M(i) |] 
paulson@46823
   184
      ==> x \<in> i \<longleftrightarrow> 
paulson@13634
   185
          (M(x) & Ord(x) & 
paulson@13634
   186
           (\<exists>a\<in>A. \<exists>g[M]. g \<in> ord_iso(Order.pred(A,a,r),r,x,Memrel(x))))"
paulson@13634
   187
apply (auto simp add: omap_iff otype_def)
paulson@13634
   188
 apply (blast intro: transM) 
paulson@13634
   189
apply (rule rangeI) 
paulson@13634
   190
apply (frule transM, assumption)
paulson@13634
   191
apply (simp add: omap_iff, blast)
paulson@13634
   192
done
paulson@13634
   193
paulson@13634
   194
lemma (in M_ordertype) otype_eq_range:
paulson@13634
   195
     "[| omap(M,A,r,f); otype(M,A,r,i); M(A); M(r); M(f); M(i) |] 
paulson@13634
   196
      ==> i = range(f)"
paulson@13634
   197
apply (auto simp add: otype_def omap_iff)
paulson@13634
   198
apply (blast dest: omap_unique) 
paulson@13634
   199
done
paulson@13634
   200
paulson@13634
   201
paulson@13634
   202
lemma (in M_ordertype) Ord_otype:
paulson@13634
   203
     "[| otype(M,A,r,i); trans[A](r); M(A); M(r); M(i) |] ==> Ord(i)"
paulson@13634
   204
apply (rule OrdI) 
paulson@13634
   205
prefer 2 
paulson@13634
   206
    apply (simp add: Ord_def otype_def omap_def) 
paulson@13634
   207
    apply clarify 
paulson@13634
   208
    apply (frule pair_components_in_M, assumption) 
paulson@13634
   209
    apply blast 
paulson@13634
   210
apply (auto simp add: Transset_def otype_iff) 
paulson@13634
   211
  apply (blast intro: transM)
paulson@13634
   212
 apply (blast intro: Ord_in_Ord) 
paulson@13634
   213
apply (rename_tac y a g)
paulson@13634
   214
apply (frule ord_iso_sym [THEN ord_iso_is_bij, THEN bij_is_fun, 
wenzelm@32960
   215
                          THEN apply_funtype],  assumption)  
paulson@13634
   216
apply (rule_tac x="converse(g)`y" in bexI)
paulson@13634
   217
 apply (frule_tac a="converse(g) ` y" in ord_iso_restrict_pred, assumption) 
paulson@13634
   218
apply (safe elim!: predE) 
paulson@13634
   219
apply (blast intro: restrict_ord_iso ord_iso_sym ltI dest: transM)
paulson@13634
   220
done
paulson@13634
   221
paulson@13634
   222
lemma (in M_ordertype) domain_omap:
paulson@13634
   223
     "[| omap(M,A,r,f);  M(A); M(r); M(B); M(f) |] 
paulson@13634
   224
      ==> domain(f) = obase(M,A,r)"
paulson@13634
   225
apply (simp add: domain_closed obase_def) 
paulson@13634
   226
apply (rule equality_iffI) 
paulson@13634
   227
apply (simp add: domain_iff omap_iff, blast) 
paulson@13634
   228
done
paulson@13634
   229
paulson@13634
   230
lemma (in M_ordertype) omap_subset: 
paulson@13634
   231
     "[| omap(M,A,r,f); otype(M,A,r,i); 
paulson@13634
   232
       M(A); M(r); M(f); M(B); M(i) |] ==> f \<subseteq> obase(M,A,r) * i"
paulson@13634
   233
apply clarify 
paulson@13634
   234
apply (simp add: omap_iff obase_def) 
paulson@13634
   235
apply (force simp add: otype_iff) 
paulson@13634
   236
done
paulson@13634
   237
paulson@13634
   238
lemma (in M_ordertype) omap_funtype: 
paulson@13634
   239
     "[| omap(M,A,r,f); otype(M,A,r,i); 
paulson@13634
   240
         M(A); M(r); M(f); M(i) |] ==> f \<in> obase(M,A,r) -> i"
paulson@13634
   241
apply (simp add: domain_omap omap_subset Pi_iff function_def omap_iff) 
paulson@13634
   242
apply (blast intro: Ord_iso_implies_eq ord_iso_sym ord_iso_trans) 
paulson@13634
   243
done
paulson@13634
   244
paulson@13634
   245
paulson@13634
   246
lemma (in M_ordertype) wellordered_omap_bij:
paulson@13634
   247
     "[| wellordered(M,A,r); omap(M,A,r,f); otype(M,A,r,i); 
paulson@13634
   248
       M(A); M(r); M(f); M(i) |] ==> f \<in> bij(obase(M,A,r),i)"
paulson@13634
   249
apply (insert omap_funtype [of A r f i]) 
paulson@13634
   250
apply (auto simp add: bij_def inj_def) 
paulson@13634
   251
prefer 2  apply (blast intro: fun_is_surj dest: otype_eq_range) 
paulson@13634
   252
apply (frule_tac a=w in apply_Pair, assumption) 
paulson@13634
   253
apply (frule_tac a=x in apply_Pair, assumption) 
paulson@13634
   254
apply (simp add: omap_iff) 
paulson@13634
   255
apply (blast intro: wellordered_iso_pred_eq ord_iso_sym ord_iso_trans) 
paulson@13634
   256
done
paulson@13634
   257
paulson@13634
   258
wenzelm@60770
   259
text\<open>This is not the final result: we must show @{term "oB(A,r) = A"}\<close>
paulson@13634
   260
lemma (in M_ordertype) omap_ord_iso:
paulson@13634
   261
     "[| wellordered(M,A,r); omap(M,A,r,f); otype(M,A,r,i); 
paulson@13634
   262
       M(A); M(r); M(f); M(i) |] ==> f \<in> ord_iso(obase(M,A,r),r,i,Memrel(i))"
paulson@13634
   263
apply (rule ord_isoI)
paulson@13634
   264
 apply (erule wellordered_omap_bij, assumption+) 
paulson@13634
   265
apply (insert omap_funtype [of A r f i], simp) 
paulson@13634
   266
apply (frule_tac a=x in apply_Pair, assumption) 
paulson@13634
   267
apply (frule_tac a=y in apply_Pair, assumption) 
paulson@13634
   268
apply (auto simp add: omap_iff)
wenzelm@60770
   269
 txt\<open>direction 1: assuming @{term "\<langle>x,y\<rangle> \<in> r"}\<close>
paulson@13634
   270
 apply (blast intro: ltD ord_iso_pred_imp_lt)
wenzelm@60770
   271
 txt\<open>direction 2: proving @{term "\<langle>x,y\<rangle> \<in> r"} using linearity of @{term r}\<close>
paulson@13634
   272
apply (rename_tac x y g ga) 
paulson@13634
   273
apply (frule wellordered_is_linear, assumption, 
paulson@13634
   274
       erule_tac x=x and y=y in linearE, assumption+) 
wenzelm@60770
   275
txt\<open>the case @{term "x=y"} leads to immediate contradiction\<close> 
paulson@13634
   276
apply (blast elim: mem_irrefl) 
wenzelm@60770
   277
txt\<open>the case @{term "\<langle>y,x\<rangle> \<in> r"}: handle like the opposite direction\<close>
paulson@13634
   278
apply (blast dest: ord_iso_pred_imp_lt ltD elim: mem_asym) 
paulson@13634
   279
done
paulson@13634
   280
paulson@13634
   281
lemma (in M_ordertype) Ord_omap_image_pred:
paulson@13634
   282
     "[| wellordered(M,A,r); omap(M,A,r,f); otype(M,A,r,i); 
paulson@13634
   283
       M(A); M(r); M(f); M(i); b \<in> A |] ==> Ord(f `` Order.pred(A,b,r))"
paulson@13634
   284
apply (frule wellordered_is_trans_on, assumption)
paulson@13634
   285
apply (rule OrdI) 
wenzelm@32960
   286
        prefer 2 apply (simp add: image_iff omap_iff Ord_def, blast) 
wenzelm@60770
   287
txt\<open>Hard part is to show that the image is a transitive set.\<close>
paulson@13634
   288
apply (simp add: Transset_def, clarify) 
paulson@13634
   289
apply (simp add: image_iff pred_iff apply_iff [OF omap_funtype [of A r f i]])
paulson@13634
   290
apply (rename_tac c j, clarify)
paulson@13634
   291
apply (frule omap_funtype [of A r f, THEN apply_funtype], assumption+)
paulson@13721
   292
apply (subgoal_tac "j \<in> i") 
wenzelm@32960
   293
        prefer 2 apply (blast intro: Ord_trans Ord_otype)
paulson@13721
   294
apply (subgoal_tac "converse(f) ` j \<in> obase(M,A,r)") 
wenzelm@32960
   295
        prefer 2 
wenzelm@32960
   296
        apply (blast dest: wellordered_omap_bij [THEN bij_converse_bij, 
paulson@13634
   297
                                      THEN bij_is_fun, THEN apply_funtype])
paulson@13634
   298
apply (rule_tac x="converse(f) ` j" in bexI) 
paulson@13634
   299
 apply (simp add: right_inverse_bij [OF wellordered_omap_bij]) 
paulson@13634
   300
apply (intro predI conjI)
paulson@13634
   301
 apply (erule_tac b=c in trans_onD) 
paulson@13634
   302
 apply (rule ord_iso_converse1 [OF omap_ord_iso [of A r f i]])
paulson@13634
   303
apply (auto simp add: obase_def)
paulson@13634
   304
done
paulson@13634
   305
paulson@13634
   306
lemma (in M_ordertype) restrict_omap_ord_iso:
paulson@13634
   307
     "[| wellordered(M,A,r); omap(M,A,r,f); otype(M,A,r,i); 
paulson@13634
   308
       D \<subseteq> obase(M,A,r); M(A); M(r); M(f); M(i) |] 
paulson@13634
   309
      ==> restrict(f,D) \<in> (\<langle>D,r\<rangle> \<cong> \<langle>f``D, Memrel(f``D)\<rangle>)"
paulson@13634
   310
apply (frule ord_iso_restrict_image [OF omap_ord_iso [of A r f i]], 
paulson@13634
   311
       assumption+)
paulson@13634
   312
apply (drule ord_iso_sym [THEN subset_ord_iso_Memrel]) 
paulson@13634
   313
apply (blast dest: subsetD [OF omap_subset]) 
paulson@13634
   314
apply (drule ord_iso_sym, simp) 
paulson@13634
   315
done
paulson@13634
   316
paulson@13634
   317
lemma (in M_ordertype) obase_equals: 
paulson@13634
   318
     "[| wellordered(M,A,r); omap(M,A,r,f); otype(M,A,r,i);
paulson@13634
   319
       M(A); M(r); M(f); M(i) |] ==> obase(M,A,r) = A"
paulson@13634
   320
apply (rule equalityI, force simp add: obase_def, clarify) 
paulson@13634
   321
apply (unfold obase_def, simp) 
paulson@13634
   322
apply (frule wellordered_is_wellfounded_on, assumption)
paulson@13634
   323
apply (erule wellfounded_on_induct, assumption+)
paulson@13634
   324
 apply (frule obase_equals_separation [of A r], assumption) 
paulson@13634
   325
 apply (simp, clarify) 
paulson@13634
   326
apply (rename_tac b) 
paulson@46823
   327
apply (subgoal_tac "Order.pred(A,b,r) \<subseteq> obase(M,A,r)") 
paulson@13634
   328
 apply (blast intro!: restrict_omap_ord_iso Ord_omap_image_pred)
paulson@13634
   329
apply (force simp add: pred_iff obase_def)  
paulson@13634
   330
done
paulson@13634
   331
paulson@13634
   332
paulson@13634
   333
wenzelm@60770
   334
text\<open>Main result: @{term om} gives the order-isomorphism 
wenzelm@60770
   335
      @{term "\<langle>A,r\<rangle> \<cong> \<langle>i, Memrel(i)\<rangle>"}\<close>
paulson@13634
   336
theorem (in M_ordertype) omap_ord_iso_otype:
paulson@13634
   337
     "[| wellordered(M,A,r); omap(M,A,r,f); otype(M,A,r,i);
paulson@13634
   338
       M(A); M(r); M(f); M(i) |] ==> f \<in> ord_iso(A, r, i, Memrel(i))"
paulson@13634
   339
apply (frule omap_ord_iso, assumption+)
paulson@13634
   340
apply (simp add: obase_equals)  
paulson@13634
   341
done 
paulson@13634
   342
paulson@13634
   343
lemma (in M_ordertype) obase_exists:
paulson@13634
   344
     "[| M(A); M(r) |] ==> M(obase(M,A,r))"
paulson@13634
   345
apply (simp add: obase_def) 
paulson@13634
   346
apply (insert obase_separation [of A r])
paulson@13634
   347
apply (simp add: separation_def)  
paulson@13634
   348
done
paulson@13634
   349
paulson@13634
   350
lemma (in M_ordertype) omap_exists:
paulson@13634
   351
     "[| M(A); M(r) |] ==> \<exists>z[M]. omap(M,A,r,z)"
paulson@13634
   352
apply (simp add: omap_def) 
paulson@13634
   353
apply (insert omap_replacement [of A r])
paulson@13634
   354
apply (simp add: strong_replacement_def) 
paulson@13634
   355
apply (drule_tac x="obase(M,A,r)" in rspec) 
paulson@13634
   356
 apply (simp add: obase_exists) 
paulson@13634
   357
apply (simp add: Memrel_closed pred_closed obase_def)
paulson@13634
   358
apply (erule impE) 
paulson@13634
   359
 apply (clarsimp simp add: univalent_def)
paulson@13634
   360
 apply (blast intro: Ord_iso_implies_eq ord_iso_sym ord_iso_trans, clarify)  
paulson@13634
   361
apply (rule_tac x=Y in rexI) 
paulson@13634
   362
apply (simp add: Memrel_closed pred_closed obase_def, blast, assumption)
paulson@13634
   363
done
paulson@13634
   364
paulson@13634
   365
declare rall_simps [simp] rex_simps [simp]
paulson@13634
   366
paulson@13634
   367
lemma (in M_ordertype) otype_exists:
paulson@13634
   368
     "[| wellordered(M,A,r); M(A); M(r) |] ==> \<exists>i[M]. otype(M,A,r,i)"
paulson@13634
   369
apply (insert omap_exists [of A r])  
paulson@13634
   370
apply (simp add: otype_def, safe)
paulson@13634
   371
apply (rule_tac x="range(x)" in rexI) 
paulson@13634
   372
apply blast+
paulson@13634
   373
done
paulson@13634
   374
paulson@13634
   375
lemma (in M_ordertype) ordertype_exists:
paulson@13634
   376
     "[| wellordered(M,A,r); M(A); M(r) |]
paulson@13634
   377
      ==> \<exists>f[M]. (\<exists>i[M]. Ord(i) & f \<in> ord_iso(A, r, i, Memrel(i)))"
paulson@13634
   378
apply (insert obase_exists [of A r] omap_exists [of A r] otype_exists [of A r], simp, clarify)
paulson@13634
   379
apply (rename_tac i) 
paulson@13634
   380
apply (subgoal_tac "Ord(i)", blast intro: omap_ord_iso_otype)
paulson@13634
   381
apply (rule Ord_otype) 
paulson@13634
   382
    apply (force simp add: otype_def range_closed) 
paulson@13634
   383
   apply (simp_all add: wellordered_is_trans_on) 
paulson@13634
   384
done
paulson@13634
   385
paulson@13634
   386
paulson@13634
   387
lemma (in M_ordertype) relativized_imp_well_ord: 
paulson@13634
   388
     "[| wellordered(M,A,r); M(A); M(r) |] ==> well_ord(A,r)" 
paulson@13634
   389
apply (insert ordertype_exists [of A r], simp)
paulson@13634
   390
apply (blast intro: well_ord_ord_iso well_ord_Memrel)  
paulson@13634
   391
done
paulson@13634
   392
wenzelm@60770
   393
subsection \<open>Kunen's theorem 5.4, page 127\<close>
paulson@13634
   394
wenzelm@60770
   395
text\<open>(a) The notion of Wellordering is absolute\<close>
paulson@13634
   396
theorem (in M_ordertype) well_ord_abs [simp]: 
paulson@46823
   397
     "[| M(A); M(r) |] ==> wellordered(M,A,r) \<longleftrightarrow> well_ord(A,r)" 
paulson@13634
   398
by (blast intro: well_ord_imp_relativized relativized_imp_well_ord)  
paulson@13634
   399
paulson@13634
   400
wenzelm@60770
   401
text\<open>(b) Order types are absolute\<close>
paulson@13634
   402
theorem (in M_ordertype) 
paulson@13634
   403
     "[| wellordered(M,A,r); f \<in> ord_iso(A, r, i, Memrel(i));
paulson@13634
   404
       M(A); M(r); M(f); M(i); Ord(i) |] ==> i = ordertype(A,r)"
paulson@13634
   405
by (blast intro: Ord_ordertype relativized_imp_well_ord ordertype_ord_iso
paulson@13634
   406
                 Ord_iso_implies_eq ord_iso_sym ord_iso_trans)
paulson@13634
   407
paulson@13634
   408
wenzelm@60770
   409
subsection\<open>Ordinal Arithmetic: Two Examples of Recursion\<close>
paulson@13634
   410
wenzelm@60770
   411
text\<open>Note: the remainder of this theory is not needed elsewhere.\<close>
paulson@13634
   412
wenzelm@60770
   413
subsubsection\<open>Ordinal Addition\<close>
paulson@13634
   414
paulson@13634
   415
(*FIXME: update to use new techniques!!*)
paulson@13634
   416
 (*This expresses ordinal addition in the language of ZF.  It also 
paulson@13634
   417
   provides an abbreviation that can be used in the instance of strong
paulson@13634
   418
   replacement below.  Here j is used to define the relation, namely
paulson@13634
   419
   Memrel(succ(j)), while x determines the domain of f.*)
wenzelm@21404
   420
definition
wenzelm@21404
   421
  is_oadd_fun :: "[i=>o,i,i,i,i] => o" where
paulson@13634
   422
    "is_oadd_fun(M,i,j,x,f) == 
paulson@46823
   423
       (\<forall>sj msj. M(sj) \<longrightarrow> M(msj) \<longrightarrow> 
paulson@46823
   424
                 successor(M,j,sj) \<longrightarrow> membership(M,sj,msj) \<longrightarrow> 
wenzelm@32960
   425
                 M_is_recfun(M, 
wenzelm@32960
   426
                     %x g y. \<exists>gx[M]. image(M,g,x,gx) & union(M,i,gx,y),
wenzelm@32960
   427
                     msj, x, f))"
paulson@13634
   428
wenzelm@21404
   429
definition
wenzelm@21404
   430
  is_oadd :: "[i=>o,i,i,i] => o" where
paulson@13634
   431
    "is_oadd(M,i,j,k) == 
paulson@13634
   432
        (~ ordinal(M,i) & ~ ordinal(M,j) & k=0) |
paulson@13634
   433
        (~ ordinal(M,i) & ordinal(M,j) & k=j) |
paulson@13634
   434
        (ordinal(M,i) & ~ ordinal(M,j) & k=i) |
paulson@13634
   435
        (ordinal(M,i) & ordinal(M,j) & 
wenzelm@32960
   436
         (\<exists>f fj sj. M(f) & M(fj) & M(sj) & 
wenzelm@32960
   437
                    successor(M,j,sj) & is_oadd_fun(M,i,sj,sj,f) & 
wenzelm@32960
   438
                    fun_apply(M,f,j,fj) & fj = k))"
paulson@13634
   439
wenzelm@21404
   440
definition
paulson@13634
   441
 (*NEEDS RELATIVIZATION*)
wenzelm@21404
   442
  omult_eqns :: "[i,i,i,i] => o" where
paulson@13634
   443
    "omult_eqns(i,x,g,z) ==
paulson@13634
   444
            Ord(x) & 
paulson@46823
   445
            (x=0 \<longrightarrow> z=0) &
paulson@46823
   446
            (\<forall>j. x = succ(j) \<longrightarrow> z = g`j ++ i) &
paulson@46823
   447
            (Limit(x) \<longrightarrow> z = \<Union>(g``x))"
paulson@13634
   448
wenzelm@21404
   449
definition
wenzelm@21404
   450
  is_omult_fun :: "[i=>o,i,i,i] => o" where
paulson@13634
   451
    "is_omult_fun(M,i,j,f) == 
wenzelm@32960
   452
            (\<exists>df. M(df) & is_function(M,f) & 
paulson@13634
   453
                  is_domain(M,f,df) & subset(M, j, df)) & 
paulson@13634
   454
            (\<forall>x\<in>j. omult_eqns(i,x,f,f`x))"
paulson@13634
   455
wenzelm@21404
   456
definition
wenzelm@21404
   457
  is_omult :: "[i=>o,i,i,i] => o" where
paulson@13634
   458
    "is_omult(M,i,j,k) == 
wenzelm@32960
   459
        \<exists>f fj sj. M(f) & M(fj) & M(sj) & 
paulson@13634
   460
                  successor(M,j,sj) & is_omult_fun(M,i,sj,f) & 
paulson@13634
   461
                  fun_apply(M,f,j,fj) & fj = k"
paulson@13634
   462
paulson@13634
   463
paulson@13634
   464
locale M_ord_arith = M_ordertype +
paulson@13634
   465
  assumes oadd_strong_replacement:
paulson@13634
   466
   "[| M(i); M(j) |] ==>
paulson@13634
   467
    strong_replacement(M, 
paulson@13634
   468
         \<lambda>x z. \<exists>y[M]. pair(M,x,y,z) & 
paulson@13634
   469
                  (\<exists>f[M]. \<exists>fx[M]. is_oadd_fun(M,i,j,x,f) & 
paulson@46823
   470
                           image(M,f,x,fx) & y = i \<union> fx))"
paulson@13634
   471
paulson@13634
   472
 and omult_strong_replacement':
paulson@13634
   473
   "[| M(i); M(j) |] ==>
paulson@13634
   474
    strong_replacement(M, 
paulson@13634
   475
         \<lambda>x z. \<exists>y[M]. z = <x,y> &
wenzelm@32960
   476
             (\<exists>g[M]. is_recfun(Memrel(succ(j)),x,%x g. THE z. omult_eqns(i,x,g,z),g) & 
wenzelm@32960
   477
             y = (THE z. omult_eqns(i, x, g, z))))" 
paulson@13634
   478
paulson@13634
   479
paulson@13634
   480
wenzelm@61798
   481
text\<open>\<open>is_oadd_fun\<close>: Relating the pure "language of set theory" to Isabelle/ZF\<close>
paulson@13634
   482
lemma (in M_ord_arith) is_oadd_fun_iff:
paulson@13634
   483
   "[| a\<le>j; M(i); M(j); M(a); M(f) |] 
paulson@46823
   484
    ==> is_oadd_fun(M,i,j,a,f) \<longleftrightarrow>
paulson@46823
   485
        f \<in> a \<rightarrow> range(f) & (\<forall>x. M(x) \<longrightarrow> x < a \<longrightarrow> f`x = i \<union> f``x)"
paulson@13634
   486
apply (frule lt_Ord) 
paulson@13634
   487
apply (simp add: is_oadd_fun_def Memrel_closed Un_closed 
paulson@46823
   488
             relation2_def is_recfun_abs [of "%x g. i \<union> g``x"]
paulson@13634
   489
             image_closed is_recfun_iff_equation  
paulson@13634
   490
             Ball_def lt_trans [OF ltI, of _ a] lt_Memrel)
paulson@13634
   491
apply (simp add: lt_def) 
paulson@13634
   492
apply (blast dest: transM) 
paulson@13634
   493
done
paulson@13634
   494
paulson@13634
   495
paulson@13634
   496
lemma (in M_ord_arith) oadd_strong_replacement':
paulson@13634
   497
    "[| M(i); M(j) |] ==>
paulson@13634
   498
     strong_replacement(M, 
paulson@13634
   499
            \<lambda>x z. \<exists>y[M]. z = <x,y> &
paulson@46823
   500
                  (\<exists>g[M]. is_recfun(Memrel(succ(j)),x,%x g. i \<union> g``x,g) & 
paulson@46823
   501
                  y = i \<union> g``x))" 
paulson@13634
   502
apply (insert oadd_strong_replacement [of i j]) 
paulson@13634
   503
apply (simp add: is_oadd_fun_def relation2_def
paulson@46823
   504
                 is_recfun_abs [of "%x g. i \<union> g``x"])  
paulson@13634
   505
done
paulson@13634
   506
paulson@13634
   507
paulson@13634
   508
lemma (in M_ord_arith) exists_oadd:
paulson@13634
   509
    "[| Ord(j);  M(i);  M(j) |]
paulson@46823
   510
     ==> \<exists>f[M]. is_recfun(Memrel(succ(j)), j, %x g. i \<union> g``x, f)"
paulson@13634
   511
apply (rule wf_exists_is_recfun [OF wf_Memrel trans_Memrel])
paulson@13634
   512
    apply (simp_all add: Memrel_type oadd_strong_replacement') 
paulson@13634
   513
done 
paulson@13634
   514
paulson@13634
   515
lemma (in M_ord_arith) exists_oadd_fun:
paulson@13634
   516
    "[| Ord(j);  M(i);  M(j) |] ==> \<exists>f[M]. is_oadd_fun(M,i,succ(j),succ(j),f)"
paulson@13634
   517
apply (rule exists_oadd [THEN rexE])
paulson@13634
   518
apply (erule Ord_succ, assumption, simp) 
paulson@13634
   519
apply (rename_tac f) 
paulson@13634
   520
apply (frule is_recfun_type)
paulson@13634
   521
apply (rule_tac x=f in rexI) 
paulson@13634
   522
 apply (simp add: fun_is_function domain_of_fun lt_Memrel apply_recfun lt_def
paulson@13634
   523
                  is_oadd_fun_iff Ord_trans [OF _ succI1], assumption)
paulson@13634
   524
done
paulson@13634
   525
paulson@13634
   526
lemma (in M_ord_arith) is_oadd_fun_apply:
paulson@13634
   527
    "[| x < j; M(i); M(j); M(f); is_oadd_fun(M,i,j,j,f) |] 
paulson@46823
   528
     ==> f`x = i \<union> (\<Union>k\<in>x. {f ` k})"
paulson@13634
   529
apply (simp add: is_oadd_fun_iff lt_Ord2, clarify) 
paulson@13634
   530
apply (frule lt_closed, simp)
paulson@13634
   531
apply (frule leI [THEN le_imp_subset])  
paulson@13634
   532
apply (simp add: image_fun, blast) 
paulson@13634
   533
done
paulson@13634
   534
paulson@13634
   535
lemma (in M_ord_arith) is_oadd_fun_iff_oadd [rule_format]:
paulson@13634
   536
    "[| is_oadd_fun(M,i,J,J,f); M(i); M(J); M(f); Ord(i); Ord(j) |] 
paulson@46823
   537
     ==> j<J \<longrightarrow> f`j = i++j"
paulson@13634
   538
apply (erule_tac i=j in trans_induct, clarify) 
paulson@13634
   539
apply (subgoal_tac "\<forall>k\<in>x. k<J")
paulson@13634
   540
 apply (simp (no_asm_simp) add: is_oadd_def oadd_unfold is_oadd_fun_apply)
paulson@13634
   541
apply (blast intro: lt_trans ltI lt_Ord) 
paulson@13634
   542
done
paulson@13634
   543
paulson@13634
   544
lemma (in M_ord_arith) Ord_oadd_abs:
paulson@46823
   545
    "[| M(i); M(j); M(k); Ord(i); Ord(j) |] ==> is_oadd(M,i,j,k) \<longleftrightarrow> k = i++j"
paulson@13634
   546
apply (simp add: is_oadd_def is_oadd_fun_iff_oadd)
paulson@13634
   547
apply (frule exists_oadd_fun [of j i], blast+)
paulson@13634
   548
done
paulson@13634
   549
paulson@13634
   550
lemma (in M_ord_arith) oadd_abs:
paulson@46823
   551
    "[| M(i); M(j); M(k) |] ==> is_oadd(M,i,j,k) \<longleftrightarrow> k = i++j"
paulson@13634
   552
apply (case_tac "Ord(i) & Ord(j)")
paulson@13634
   553
 apply (simp add: Ord_oadd_abs)
paulson@13634
   554
apply (auto simp add: is_oadd_def oadd_eq_if_raw_oadd)
paulson@13634
   555
done
paulson@13634
   556
paulson@13634
   557
lemma (in M_ord_arith) oadd_closed [intro,simp]:
paulson@13634
   558
    "[| M(i); M(j) |] ==> M(i++j)"
paulson@13634
   559
apply (simp add: oadd_eq_if_raw_oadd, clarify) 
paulson@13634
   560
apply (simp add: raw_oadd_eq_oadd) 
paulson@13634
   561
apply (frule exists_oadd_fun [of j i], auto)
paulson@13634
   562
apply (simp add: apply_closed is_oadd_fun_iff_oadd [symmetric]) 
paulson@13634
   563
done
paulson@13634
   564
paulson@13634
   565
wenzelm@60770
   566
subsubsection\<open>Ordinal Multiplication\<close>
paulson@13634
   567
paulson@13634
   568
lemma omult_eqns_unique:
wenzelm@58860
   569
     "[| omult_eqns(i,x,g,z); omult_eqns(i,x,g,z') |] ==> z=z'"
paulson@13634
   570
apply (simp add: omult_eqns_def, clarify) 
paulson@13634
   571
apply (erule Ord_cases, simp_all) 
paulson@13634
   572
done
paulson@13634
   573
paulson@46823
   574
lemma omult_eqns_0: "omult_eqns(i,0,g,z) \<longleftrightarrow> z=0"
paulson@13634
   575
by (simp add: omult_eqns_def)
paulson@13634
   576
paulson@13634
   577
lemma the_omult_eqns_0: "(THE z. omult_eqns(i,0,g,z)) = 0"
paulson@13634
   578
by (simp add: omult_eqns_0)
paulson@13634
   579
paulson@46823
   580
lemma omult_eqns_succ: "omult_eqns(i,succ(j),g,z) \<longleftrightarrow> Ord(j) & z = g`j ++ i"
paulson@13634
   581
by (simp add: omult_eqns_def)
paulson@13634
   582
paulson@13634
   583
lemma the_omult_eqns_succ:
paulson@13634
   584
     "Ord(j) ==> (THE z. omult_eqns(i,succ(j),g,z)) = g`j ++ i"
paulson@13634
   585
by (simp add: omult_eqns_succ) 
paulson@13634
   586
paulson@13634
   587
lemma omult_eqns_Limit:
paulson@46823
   588
     "Limit(x) ==> omult_eqns(i,x,g,z) \<longleftrightarrow> z = \<Union>(g``x)"
paulson@13634
   589
apply (simp add: omult_eqns_def) 
paulson@13634
   590
apply (blast intro: Limit_is_Ord) 
paulson@13634
   591
done
paulson@13634
   592
paulson@13634
   593
lemma the_omult_eqns_Limit:
paulson@13634
   594
     "Limit(x) ==> (THE z. omult_eqns(i,x,g,z)) = \<Union>(g``x)"
paulson@13634
   595
by (simp add: omult_eqns_Limit)
paulson@13634
   596
paulson@13634
   597
lemma omult_eqns_Not: "~ Ord(x) ==> ~ omult_eqns(i,x,g,z)"
paulson@13634
   598
by (simp add: omult_eqns_def)
paulson@13634
   599
paulson@13634
   600
paulson@13634
   601
lemma (in M_ord_arith) the_omult_eqns_closed:
paulson@13634
   602
    "[| M(i); M(x); M(g); function(g) |] 
paulson@13634
   603
     ==> M(THE z. omult_eqns(i, x, g, z))"
paulson@13634
   604
apply (case_tac "Ord(x)")
wenzelm@61798
   605
 prefer 2 apply (simp add: omult_eqns_Not) \<comment>\<open>trivial, non-Ord case\<close>
paulson@13634
   606
apply (erule Ord_cases) 
paulson@13634
   607
  apply (simp add: omult_eqns_0)
paulson@13634
   608
 apply (simp add: omult_eqns_succ apply_closed oadd_closed) 
paulson@13634
   609
apply (simp add: omult_eqns_Limit) 
paulson@13634
   610
done
paulson@13634
   611
paulson@13634
   612
lemma (in M_ord_arith) exists_omult:
paulson@13634
   613
    "[| Ord(j);  M(i);  M(j) |]
paulson@13634
   614
     ==> \<exists>f[M]. is_recfun(Memrel(succ(j)), j, %x g. THE z. omult_eqns(i,x,g,z), f)"
paulson@13634
   615
apply (rule wf_exists_is_recfun [OF wf_Memrel trans_Memrel])
paulson@13634
   616
    apply (simp_all add: Memrel_type omult_strong_replacement') 
paulson@13634
   617
apply (blast intro: the_omult_eqns_closed) 
paulson@13634
   618
done
paulson@13634
   619
paulson@13634
   620
lemma (in M_ord_arith) exists_omult_fun:
paulson@13634
   621
    "[| Ord(j);  M(i);  M(j) |] ==> \<exists>f[M]. is_omult_fun(M,i,succ(j),f)"
paulson@13634
   622
apply (rule exists_omult [THEN rexE])
paulson@13634
   623
apply (erule Ord_succ, assumption, simp) 
paulson@13634
   624
apply (rename_tac f) 
paulson@13634
   625
apply (frule is_recfun_type)
paulson@13634
   626
apply (rule_tac x=f in rexI) 
paulson@13634
   627
apply (simp add: fun_is_function domain_of_fun lt_Memrel apply_recfun lt_def
paulson@13634
   628
                 is_omult_fun_def Ord_trans [OF _ succI1])
paulson@13634
   629
 apply (force dest: Ord_in_Ord' 
paulson@13634
   630
              simp add: omult_eqns_def the_omult_eqns_0 the_omult_eqns_succ
paulson@13634
   631
                        the_omult_eqns_Limit, assumption)
paulson@13634
   632
done
paulson@13634
   633
paulson@13634
   634
lemma (in M_ord_arith) is_omult_fun_apply_0:
paulson@13634
   635
    "[| 0 < j; is_omult_fun(M,i,j,f) |] ==> f`0 = 0"
paulson@13634
   636
by (simp add: is_omult_fun_def omult_eqns_def lt_def ball_conj_distrib)
paulson@13634
   637
paulson@13634
   638
lemma (in M_ord_arith) is_omult_fun_apply_succ:
paulson@13634
   639
    "[| succ(x) < j; is_omult_fun(M,i,j,f) |] ==> f`succ(x) = f`x ++ i"
paulson@13634
   640
by (simp add: is_omult_fun_def omult_eqns_def lt_def, blast) 
paulson@13634
   641
paulson@13634
   642
lemma (in M_ord_arith) is_omult_fun_apply_Limit:
paulson@13634
   643
    "[| x < j; Limit(x); M(j); M(f); is_omult_fun(M,i,j,f) |] 
paulson@13634
   644
     ==> f ` x = (\<Union>y\<in>x. f`y)"
paulson@13634
   645
apply (simp add: is_omult_fun_def omult_eqns_def domain_closed lt_def, clarify)
paulson@13634
   646
apply (drule subset_trans [OF OrdmemD], assumption+)  
paulson@13634
   647
apply (simp add: ball_conj_distrib omult_Limit image_function)
paulson@13634
   648
done
paulson@13634
   649
paulson@13634
   650
lemma (in M_ord_arith) is_omult_fun_eq_omult:
paulson@13634
   651
    "[| is_omult_fun(M,i,J,f); M(J); M(f); Ord(i); Ord(j) |] 
paulson@46823
   652
     ==> j<J \<longrightarrow> f`j = i**j"
paulson@13634
   653
apply (erule_tac i=j in trans_induct3)
paulson@13634
   654
apply (safe del: impCE)
paulson@13634
   655
  apply (simp add: is_omult_fun_apply_0) 
paulson@13634
   656
 apply (subgoal_tac "x<J") 
paulson@13634
   657
  apply (simp add: is_omult_fun_apply_succ omult_succ)  
paulson@13634
   658
 apply (blast intro: lt_trans) 
paulson@13634
   659
apply (subgoal_tac "\<forall>k\<in>x. k<J")
paulson@13634
   660
 apply (simp add: is_omult_fun_apply_Limit omult_Limit) 
paulson@13634
   661
apply (blast intro: lt_trans ltI lt_Ord) 
paulson@13634
   662
done
paulson@13634
   663
paulson@13634
   664
lemma (in M_ord_arith) omult_abs:
paulson@46823
   665
    "[| M(i); M(j); M(k); Ord(i); Ord(j) |] ==> is_omult(M,i,j,k) \<longleftrightarrow> k = i**j"
paulson@13634
   666
apply (simp add: is_omult_def is_omult_fun_eq_omult)
paulson@13634
   667
apply (frule exists_omult_fun [of j i], blast+)
paulson@13634
   668
done
paulson@13634
   669
paulson@13634
   670
paulson@13634
   671
wenzelm@60770
   672
subsection \<open>Absoluteness of Well-Founded Relations\<close>
paulson@13647
   673
wenzelm@60770
   674
text\<open>Relativized to @{term M}: Every well-founded relation is a subset of some
paulson@13647
   675
inverse image of an ordinal.  Key step is the construction (in @{term M}) of a
wenzelm@60770
   676
rank function.\<close>
paulson@13647
   677
paulson@13634
   678
locale M_wfrank = M_trancl +
paulson@13634
   679
  assumes wfrank_separation:
paulson@13634
   680
     "M(r) ==>
paulson@13634
   681
      separation (M, \<lambda>x. 
paulson@46823
   682
         \<forall>rplus[M]. tran_closure(M,r,rplus) \<longrightarrow>
paulson@13634
   683
         ~ (\<exists>f[M]. M_is_recfun(M, %x f y. is_range(M,f,y), rplus, x, f)))"
paulson@13634
   684
 and wfrank_strong_replacement:
paulson@13634
   685
     "M(r) ==>
paulson@13634
   686
      strong_replacement(M, \<lambda>x z. 
paulson@46823
   687
         \<forall>rplus[M]. tran_closure(M,r,rplus) \<longrightarrow>
paulson@13634
   688
         (\<exists>y[M]. \<exists>f[M]. pair(M,x,y,z)  & 
paulson@13634
   689
                        M_is_recfun(M, %x f y. is_range(M,f,y), rplus, x, f) &
paulson@13634
   690
                        is_range(M,f,y)))"
paulson@13634
   691
 and Ord_wfrank_separation:
paulson@13634
   692
     "M(r) ==>
paulson@13634
   693
      separation (M, \<lambda>x.
paulson@46823
   694
         \<forall>rplus[M]. tran_closure(M,r,rplus) \<longrightarrow> 
paulson@13634
   695
          ~ (\<forall>f[M]. \<forall>rangef[M]. 
paulson@46823
   696
             is_range(M,f,rangef) \<longrightarrow>
paulson@46823
   697
             M_is_recfun(M, \<lambda>x f y. is_range(M,f,y), rplus, x, f) \<longrightarrow>
paulson@13634
   698
             ordinal(M,rangef)))" 
paulson@13634
   699
paulson@13634
   700
wenzelm@60770
   701
text\<open>Proving that the relativized instances of Separation or Replacement
wenzelm@60770
   702
agree with the "real" ones.\<close>
paulson@13634
   703
paulson@13634
   704
lemma (in M_wfrank) wfrank_separation':
paulson@13634
   705
     "M(r) ==>
paulson@13634
   706
      separation
wenzelm@32960
   707
           (M, \<lambda>x. ~ (\<exists>f[M]. is_recfun(r^+, x, %x f. range(f), f)))"
paulson@13634
   708
apply (insert wfrank_separation [of r])
paulson@13634
   709
apply (simp add: relation2_def is_recfun_abs [of "%x. range"])
paulson@13634
   710
done
paulson@13634
   711
paulson@13634
   712
lemma (in M_wfrank) wfrank_strong_replacement':
paulson@13634
   713
     "M(r) ==>
paulson@13634
   714
      strong_replacement(M, \<lambda>x z. \<exists>y[M]. \<exists>f[M]. 
wenzelm@32960
   715
                  pair(M,x,y,z) & is_recfun(r^+, x, %x f. range(f), f) &
wenzelm@32960
   716
                  y = range(f))"
paulson@13634
   717
apply (insert wfrank_strong_replacement [of r])
paulson@13634
   718
apply (simp add: relation2_def is_recfun_abs [of "%x. range"])
paulson@13634
   719
done
paulson@13634
   720
paulson@13634
   721
lemma (in M_wfrank) Ord_wfrank_separation':
paulson@13634
   722
     "M(r) ==>
paulson@13634
   723
      separation (M, \<lambda>x. 
paulson@46823
   724
         ~ (\<forall>f[M]. is_recfun(r^+, x, \<lambda>x. range, f) \<longrightarrow> Ord(range(f))))" 
paulson@13634
   725
apply (insert Ord_wfrank_separation [of r])
paulson@13634
   726
apply (simp add: relation2_def is_recfun_abs [of "%x. range"])
paulson@13634
   727
done
paulson@13634
   728
wenzelm@60770
   729
text\<open>This function, defined using replacement, is a rank function for
wenzelm@60770
   730
well-founded relations within the class M.\<close>
wenzelm@21233
   731
definition
wenzelm@21404
   732
  wellfoundedrank :: "[i=>o,i,i] => i" where
paulson@13634
   733
    "wellfoundedrank(M,r,A) ==
paulson@13634
   734
        {p. x\<in>A, \<exists>y[M]. \<exists>f[M]. 
paulson@13634
   735
                       p = <x,y> & is_recfun(r^+, x, %x f. range(f), f) &
paulson@13634
   736
                       y = range(f)}"
paulson@13634
   737
paulson@13634
   738
lemma (in M_wfrank) exists_wfrank:
paulson@13634
   739
    "[| wellfounded(M,r); M(a); M(r) |]
paulson@13634
   740
     ==> \<exists>f[M]. is_recfun(r^+, a, %x f. range(f), f)"
paulson@13634
   741
apply (rule wellfounded_exists_is_recfun)
paulson@13634
   742
      apply (blast intro: wellfounded_trancl)
paulson@13634
   743
     apply (rule trans_trancl)
paulson@13634
   744
    apply (erule wfrank_separation')
paulson@13634
   745
   apply (erule wfrank_strong_replacement')
paulson@13634
   746
apply (simp_all add: trancl_subset_times)
paulson@13634
   747
done
paulson@13634
   748
paulson@13634
   749
lemma (in M_wfrank) M_wellfoundedrank:
paulson@13634
   750
    "[| wellfounded(M,r); M(r); M(A) |] ==> M(wellfoundedrank(M,r,A))"
paulson@13634
   751
apply (insert wfrank_strong_replacement' [of r])
paulson@13634
   752
apply (simp add: wellfoundedrank_def)
paulson@13634
   753
apply (rule strong_replacement_closed)
paulson@13634
   754
   apply assumption+
paulson@13634
   755
 apply (rule univalent_is_recfun)
paulson@13634
   756
   apply (blast intro: wellfounded_trancl)
paulson@13634
   757
  apply (rule trans_trancl)
paulson@13634
   758
 apply (simp add: trancl_subset_times) 
paulson@13634
   759
apply (blast dest: transM) 
paulson@13634
   760
done
paulson@13634
   761
paulson@13634
   762
lemma (in M_wfrank) Ord_wfrank_range [rule_format]:
paulson@13634
   763
    "[| wellfounded(M,r); a\<in>A; M(r); M(A) |]
paulson@46823
   764
     ==> \<forall>f[M]. is_recfun(r^+, a, %x f. range(f), f) \<longrightarrow> Ord(range(f))"
paulson@13634
   765
apply (drule wellfounded_trancl, assumption)
paulson@13634
   766
apply (rule wellfounded_induct, assumption, erule (1) transM)
paulson@13634
   767
  apply simp
paulson@13634
   768
 apply (blast intro: Ord_wfrank_separation', clarify)
wenzelm@60770
   769
txt\<open>The reasoning in both cases is that we get @{term y} such that
paulson@13634
   770
   @{term "\<langle>y, x\<rangle> \<in> r^+"}.  We find that
wenzelm@60770
   771
   @{term "f`y = restrict(f, r^+ -`` {y})"}.\<close>
paulson@13634
   772
apply (rule OrdI [OF _ Ord_is_Transset])
wenzelm@60770
   773
 txt\<open>An ordinal is a transitive set...\<close>
paulson@13634
   774
 apply (simp add: Transset_def)
paulson@13634
   775
 apply clarify
paulson@13634
   776
 apply (frule apply_recfun2, assumption)
paulson@13634
   777
 apply (force simp add: restrict_iff)
wenzelm@60770
   778
txt\<open>...of ordinals.  This second case requires the induction hyp.\<close>
paulson@13634
   779
apply clarify
paulson@13634
   780
apply (rename_tac i y)
paulson@13634
   781
apply (frule apply_recfun2, assumption)
paulson@13634
   782
apply (frule is_recfun_imp_in_r, assumption)
paulson@13634
   783
apply (frule is_recfun_restrict)
paulson@13634
   784
    (*simp_all won't work*)
paulson@13634
   785
    apply (simp add: trans_trancl trancl_subset_times)+
paulson@13634
   786
apply (drule spec [THEN mp], assumption)
paulson@13634
   787
apply (subgoal_tac "M(restrict(f, r^+ -`` {y}))")
paulson@13634
   788
 apply (drule_tac x="restrict(f, r^+ -`` {y})" in rspec)
paulson@13634
   789
apply assumption
paulson@13634
   790
 apply (simp add: function_apply_equality [OF _ is_recfun_imp_function])
paulson@13634
   791
apply (blast dest: pair_components_in_M)
paulson@13634
   792
done
paulson@13634
   793
paulson@13634
   794
lemma (in M_wfrank) Ord_range_wellfoundedrank:
paulson@13634
   795
    "[| wellfounded(M,r); r \<subseteq> A*A;  M(r); M(A) |]
paulson@13634
   796
     ==> Ord (range(wellfoundedrank(M,r,A)))"
paulson@13634
   797
apply (frule wellfounded_trancl, assumption)
paulson@13634
   798
apply (frule trancl_subset_times)
paulson@13634
   799
apply (simp add: wellfoundedrank_def)
paulson@13634
   800
apply (rule OrdI [OF _ Ord_is_Transset])
paulson@13634
   801
 prefer 2
wenzelm@60770
   802
 txt\<open>by our previous result the range consists of ordinals.\<close>
paulson@13634
   803
 apply (blast intro: Ord_wfrank_range)
wenzelm@60770
   804
txt\<open>We still must show that the range is a transitive set.\<close>
paulson@13634
   805
apply (simp add: Transset_def, clarify, simp)
paulson@13634
   806
apply (rename_tac x i f u)
paulson@13634
   807
apply (frule is_recfun_imp_in_r, assumption)
paulson@13634
   808
apply (subgoal_tac "M(u) & M(i) & M(x)")
paulson@13634
   809
 prefer 2 apply (blast dest: transM, clarify)
paulson@13634
   810
apply (rule_tac a=u in rangeI)
paulson@13634
   811
apply (rule_tac x=u in ReplaceI)
paulson@13634
   812
  apply simp 
paulson@13634
   813
  apply (rule_tac x="restrict(f, r^+ -`` {u})" in rexI)
paulson@13634
   814
   apply (blast intro: is_recfun_restrict trans_trancl dest: apply_recfun2)
paulson@13634
   815
  apply simp 
paulson@13634
   816
apply blast 
wenzelm@60770
   817
txt\<open>Unicity requirement of Replacement\<close>
paulson@13634
   818
apply clarify
paulson@13634
   819
apply (frule apply_recfun2, assumption)
paulson@13634
   820
apply (simp add: trans_trancl is_recfun_cut)
paulson@13634
   821
done
paulson@13634
   822
paulson@13634
   823
lemma (in M_wfrank) function_wellfoundedrank:
paulson@13634
   824
    "[| wellfounded(M,r); M(r); M(A)|]
paulson@13634
   825
     ==> function(wellfoundedrank(M,r,A))"
paulson@13634
   826
apply (simp add: wellfoundedrank_def function_def, clarify)
wenzelm@60770
   827
txt\<open>Uniqueness: repeated below!\<close>
paulson@13634
   828
apply (drule is_recfun_functional, assumption)
paulson@13634
   829
     apply (blast intro: wellfounded_trancl)
paulson@13634
   830
    apply (simp_all add: trancl_subset_times trans_trancl)
paulson@13634
   831
done
paulson@13634
   832
paulson@13634
   833
lemma (in M_wfrank) domain_wellfoundedrank:
paulson@13634
   834
    "[| wellfounded(M,r); M(r); M(A)|]
paulson@13634
   835
     ==> domain(wellfoundedrank(M,r,A)) = A"
paulson@13634
   836
apply (simp add: wellfoundedrank_def function_def)
paulson@13634
   837
apply (rule equalityI, auto)
paulson@13634
   838
apply (frule transM, assumption)
paulson@13634
   839
apply (frule_tac a=x in exists_wfrank, assumption+, clarify)
paulson@13634
   840
apply (rule_tac b="range(f)" in domainI)
paulson@13634
   841
apply (rule_tac x=x in ReplaceI)
paulson@13634
   842
  apply simp 
paulson@13634
   843
  apply (rule_tac x=f in rexI, blast, simp_all)
wenzelm@60770
   844
txt\<open>Uniqueness (for Replacement): repeated above!\<close>
paulson@13634
   845
apply clarify
paulson@13634
   846
apply (drule is_recfun_functional, assumption)
paulson@13634
   847
    apply (blast intro: wellfounded_trancl)
paulson@13634
   848
    apply (simp_all add: trancl_subset_times trans_trancl)
paulson@13634
   849
done
paulson@13634
   850
paulson@13634
   851
lemma (in M_wfrank) wellfoundedrank_type:
paulson@13634
   852
    "[| wellfounded(M,r);  M(r); M(A)|]
paulson@13634
   853
     ==> wellfoundedrank(M,r,A) \<in> A -> range(wellfoundedrank(M,r,A))"
paulson@13634
   854
apply (frule function_wellfoundedrank [of r A], assumption+)
paulson@13634
   855
apply (frule function_imp_Pi)
paulson@13634
   856
 apply (simp add: wellfoundedrank_def relation_def)
paulson@13634
   857
 apply blast
paulson@13634
   858
apply (simp add: domain_wellfoundedrank)
paulson@13634
   859
done
paulson@13634
   860
paulson@13634
   861
lemma (in M_wfrank) Ord_wellfoundedrank:
paulson@13634
   862
    "[| wellfounded(M,r); a \<in> A; r \<subseteq> A*A;  M(r); M(A) |]
paulson@13634
   863
     ==> Ord(wellfoundedrank(M,r,A) ` a)"
paulson@13634
   864
by (blast intro: apply_funtype [OF wellfoundedrank_type]
paulson@13634
   865
                 Ord_in_Ord [OF Ord_range_wellfoundedrank])
paulson@13634
   866
paulson@13634
   867
lemma (in M_wfrank) wellfoundedrank_eq:
paulson@13634
   868
     "[| is_recfun(r^+, a, %x. range, f);
paulson@13634
   869
         wellfounded(M,r);  a \<in> A; M(f); M(r); M(A)|]
paulson@13634
   870
      ==> wellfoundedrank(M,r,A) ` a = range(f)"
paulson@13634
   871
apply (rule apply_equality)
paulson@13634
   872
 prefer 2 apply (blast intro: wellfoundedrank_type)
paulson@13634
   873
apply (simp add: wellfoundedrank_def)
paulson@13634
   874
apply (rule ReplaceI)
paulson@13634
   875
  apply (rule_tac x="range(f)" in rexI) 
paulson@13634
   876
  apply blast
paulson@13634
   877
 apply simp_all
wenzelm@60770
   878
txt\<open>Unicity requirement of Replacement\<close>
paulson@13634
   879
apply clarify
paulson@13634
   880
apply (drule is_recfun_functional, assumption)
paulson@13634
   881
    apply (blast intro: wellfounded_trancl)
paulson@13634
   882
    apply (simp_all add: trancl_subset_times trans_trancl)
paulson@13634
   883
done
paulson@13634
   884
paulson@13634
   885
paulson@13634
   886
lemma (in M_wfrank) wellfoundedrank_lt:
paulson@13634
   887
     "[| <a,b> \<in> r;
paulson@13634
   888
         wellfounded(M,r); r \<subseteq> A*A;  M(r); M(A)|]
paulson@13634
   889
      ==> wellfoundedrank(M,r,A) ` a < wellfoundedrank(M,r,A) ` b"
paulson@13634
   890
apply (frule wellfounded_trancl, assumption)
paulson@13634
   891
apply (subgoal_tac "a\<in>A & b\<in>A")
paulson@13634
   892
 prefer 2 apply blast
paulson@13634
   893
apply (simp add: lt_def Ord_wellfoundedrank, clarify)
paulson@13634
   894
apply (frule exists_wfrank [of concl: _ b], erule (1) transM, assumption)
paulson@13634
   895
apply clarify
paulson@13634
   896
apply (rename_tac fb)
paulson@13634
   897
apply (frule is_recfun_restrict [of concl: "r^+" a])
paulson@13634
   898
    apply (rule trans_trancl, assumption)
paulson@13634
   899
   apply (simp_all add: r_into_trancl trancl_subset_times)
wenzelm@61798
   900
txt\<open>Still the same goal, but with new \<open>is_recfun\<close> assumptions.\<close>
paulson@13634
   901
apply (simp add: wellfoundedrank_eq)
paulson@13634
   902
apply (frule_tac a=a in wellfoundedrank_eq, assumption+)
paulson@13634
   903
   apply (simp_all add: transM [of a])
wenzelm@60770
   904
txt\<open>We have used equations for wellfoundedrank and now must use some
wenzelm@61798
   905
    for  \<open>is_recfun\<close>.\<close>
paulson@13634
   906
apply (rule_tac a=a in rangeI)
paulson@13634
   907
apply (simp add: is_recfun_type [THEN apply_iff] vimage_singleton_iff
paulson@13634
   908
                 r_into_trancl apply_recfun r_into_trancl)
paulson@13634
   909
done
paulson@13634
   910
paulson@13634
   911
paulson@13634
   912
lemma (in M_wfrank) wellfounded_imp_subset_rvimage:
paulson@13634
   913
     "[|wellfounded(M,r); r \<subseteq> A*A; M(r); M(A)|]
paulson@46823
   914
      ==> \<exists>i f. Ord(i) & r \<subseteq> rvimage(A, f, Memrel(i))"
paulson@13634
   915
apply (rule_tac x="range(wellfoundedrank(M,r,A))" in exI)
paulson@13634
   916
apply (rule_tac x="wellfoundedrank(M,r,A)" in exI)
paulson@13634
   917
apply (simp add: Ord_range_wellfoundedrank, clarify)
paulson@13634
   918
apply (frule subsetD, assumption, clarify)
paulson@13634
   919
apply (simp add: rvimage_iff wellfoundedrank_lt [THEN ltD])
paulson@13634
   920
apply (blast intro: apply_rangeI wellfoundedrank_type)
paulson@13634
   921
done
paulson@13634
   922
paulson@13634
   923
lemma (in M_wfrank) wellfounded_imp_wf:
paulson@13634
   924
     "[|wellfounded(M,r); relation(r); M(r)|] ==> wf(r)"
paulson@13634
   925
by (blast dest!: relation_field_times_field wellfounded_imp_subset_rvimage
paulson@13634
   926
          intro: wf_rvimage_Ord [THEN wf_subset])
paulson@13634
   927
paulson@13634
   928
lemma (in M_wfrank) wellfounded_on_imp_wf_on:
paulson@13634
   929
     "[|wellfounded_on(M,A,r); relation(r); M(r); M(A)|] ==> wf[A](r)"
paulson@13634
   930
apply (simp add: wellfounded_on_iff_wellfounded wf_on_def)
paulson@13634
   931
apply (rule wellfounded_imp_wf)
paulson@13634
   932
apply (simp_all add: relation_def)
paulson@13634
   933
done
paulson@13634
   934
paulson@13634
   935
paulson@13634
   936
theorem (in M_wfrank) wf_abs:
paulson@46823
   937
     "[|relation(r); M(r)|] ==> wellfounded(M,r) \<longleftrightarrow> wf(r)"
paulson@13634
   938
by (blast intro: wellfounded_imp_wf wf_imp_relativized)
paulson@13634
   939
paulson@13634
   940
theorem (in M_wfrank) wf_on_abs:
paulson@46823
   941
     "[|relation(r); M(r); M(A)|] ==> wellfounded_on(M,A,r) \<longleftrightarrow> wf[A](r)"
paulson@13634
   942
by (blast intro: wellfounded_on_imp_wf_on wf_on_imp_relativized)
paulson@13634
   943
paulson@13634
   944
end