src/ZF/OrderArith.thy
 author paulson Thu Jan 23 10:30:14 2003 +0100 (2003-01-23) changeset 13784 b9f6154427a4 parent 13634 99a593b49b04 child 13823 d49ffd9f9662 permissions -rw-r--r--
tidying (by script)
```     1 (*  Title:      ZF/OrderArith.thy
```
```     2     ID:         \$Id\$
```
```     3     Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
```
```     4     Copyright   1994  University of Cambridge
```
```     5
```
```     6 *)
```
```     7
```
```     8 header{*Combining Orderings: Foundations of Ordinal Arithmetic*}
```
```     9
```
```    10 theory OrderArith = Order + Sum + Ordinal:
```
```    11 constdefs
```
```    12
```
```    13   (*disjoint sum of two relations; underlies ordinal addition*)
```
```    14   radd    :: "[i,i,i,i]=>i"
```
```    15     "radd(A,r,B,s) ==
```
```    16                 {z: (A+B) * (A+B).
```
```    17                     (EX x y. z = <Inl(x), Inr(y)>)   |
```
```    18                     (EX x' x. z = <Inl(x'), Inl(x)> & <x',x>:r)   |
```
```    19                     (EX y' y. z = <Inr(y'), Inr(y)> & <y',y>:s)}"
```
```    20
```
```    21   (*lexicographic product of two relations; underlies ordinal multiplication*)
```
```    22   rmult   :: "[i,i,i,i]=>i"
```
```    23     "rmult(A,r,B,s) ==
```
```    24                 {z: (A*B) * (A*B).
```
```    25                     EX x' y' x y. z = <<x',y'>, <x,y>> &
```
```    26                        (<x',x>: r | (x'=x & <y',y>: s))}"
```
```    27
```
```    28   (*inverse image of a relation*)
```
```    29   rvimage :: "[i,i,i]=>i"
```
```    30     "rvimage(A,f,r) == {z: A*A. EX x y. z = <x,y> & <f`x,f`y>: r}"
```
```    31
```
```    32   measure :: "[i, i\<Rightarrow>i] \<Rightarrow> i"
```
```    33     "measure(A,f) == {<x,y>: A*A. f(x) < f(y)}"
```
```    34
```
```    35
```
```    36 subsection{*Addition of Relations -- Disjoint Sum*}
```
```    37
```
```    38 subsubsection{*Rewrite rules.  Can be used to obtain introduction rules*}
```
```    39
```
```    40 lemma radd_Inl_Inr_iff [iff]:
```
```    41     "<Inl(a), Inr(b)> : radd(A,r,B,s)  <->  a:A & b:B"
```
```    42 by (unfold radd_def, blast)
```
```    43
```
```    44 lemma radd_Inl_iff [iff]:
```
```    45     "<Inl(a'), Inl(a)> : radd(A,r,B,s)  <->  a':A & a:A & <a',a>:r"
```
```    46 by (unfold radd_def, blast)
```
```    47
```
```    48 lemma radd_Inr_iff [iff]:
```
```    49     "<Inr(b'), Inr(b)> : radd(A,r,B,s) <->  b':B & b:B & <b',b>:s"
```
```    50 by (unfold radd_def, blast)
```
```    51
```
```    52 lemma radd_Inr_Inl_iff [iff]:
```
```    53     "<Inr(b), Inl(a)> : radd(A,r,B,s) <->  False"
```
```    54 by (unfold radd_def, blast)
```
```    55
```
```    56 subsubsection{*Elimination Rule*}
```
```    57
```
```    58 lemma raddE:
```
```    59     "[| <p',p> : radd(A,r,B,s);
```
```    60         !!x y. [| p'=Inl(x); x:A; p=Inr(y); y:B |] ==> Q;
```
```    61         !!x' x. [| p'=Inl(x'); p=Inl(x); <x',x>: r; x':A; x:A |] ==> Q;
```
```    62         !!y' y. [| p'=Inr(y'); p=Inr(y); <y',y>: s; y':B; y:B |] ==> Q
```
```    63      |] ==> Q"
```
```    64 by (unfold radd_def, blast)
```
```    65
```
```    66 subsubsection{*Type checking*}
```
```    67
```
```    68 lemma radd_type: "radd(A,r,B,s) <= (A+B) * (A+B)"
```
```    69 apply (unfold radd_def)
```
```    70 apply (rule Collect_subset)
```
```    71 done
```
```    72
```
```    73 lemmas field_radd = radd_type [THEN field_rel_subset]
```
```    74
```
```    75 subsubsection{*Linearity*}
```
```    76
```
```    77 lemma linear_radd:
```
```    78     "[| linear(A,r);  linear(B,s) |] ==> linear(A+B,radd(A,r,B,s))"
```
```    79 by (unfold linear_def, blast)
```
```    80
```
```    81
```
```    82 subsubsection{*Well-foundedness*}
```
```    83
```
```    84 lemma wf_on_radd: "[| wf[A](r);  wf[B](s) |] ==> wf[A+B](radd(A,r,B,s))"
```
```    85 apply (rule wf_onI2)
```
```    86 apply (subgoal_tac "ALL x:A. Inl (x) : Ba")
```
```    87  --{*Proving the lemma, which is needed twice!*}
```
```    88  prefer 2
```
```    89  apply (erule_tac V = "y : A + B" in thin_rl)
```
```    90  apply (rule_tac ballI)
```
```    91  apply (erule_tac r = r and a = x in wf_on_induct, assumption)
```
```    92  apply blast
```
```    93 txt{*Returning to main part of proof*}
```
```    94 apply safe
```
```    95 apply blast
```
```    96 apply (erule_tac r = s and a = ya in wf_on_induct, assumption, blast)
```
```    97 done
```
```    98
```
```    99 lemma wf_radd: "[| wf(r);  wf(s) |] ==> wf(radd(field(r),r,field(s),s))"
```
```   100 apply (simp add: wf_iff_wf_on_field)
```
```   101 apply (rule wf_on_subset_A [OF _ field_radd])
```
```   102 apply (blast intro: wf_on_radd)
```
```   103 done
```
```   104
```
```   105 lemma well_ord_radd:
```
```   106      "[| well_ord(A,r);  well_ord(B,s) |] ==> well_ord(A+B, radd(A,r,B,s))"
```
```   107 apply (rule well_ordI)
```
```   108 apply (simp add: well_ord_def wf_on_radd)
```
```   109 apply (simp add: well_ord_def tot_ord_def linear_radd)
```
```   110 done
```
```   111
```
```   112 subsubsection{*An @{term ord_iso} congruence law*}
```
```   113
```
```   114 lemma sum_bij:
```
```   115      "[| f: bij(A,C);  g: bij(B,D) |]
```
```   116       ==> (lam z:A+B. case(%x. Inl(f`x), %y. Inr(g`y), z)) : bij(A+B, C+D)"
```
```   117 apply (rule_tac d = "case (%x. Inl (converse(f)`x), %y. Inr(converse(g)`y))"
```
```   118        in lam_bijective)
```
```   119 apply (typecheck add: bij_is_inj inj_is_fun)
```
```   120 apply (auto simp add: left_inverse_bij right_inverse_bij)
```
```   121 done
```
```   122
```
```   123 lemma sum_ord_iso_cong:
```
```   124     "[| f: ord_iso(A,r,A',r');  g: ord_iso(B,s,B',s') |] ==>
```
```   125             (lam z:A+B. case(%x. Inl(f`x), %y. Inr(g`y), z))
```
```   126             : ord_iso(A+B, radd(A,r,B,s), A'+B', radd(A',r',B',s'))"
```
```   127 apply (unfold ord_iso_def)
```
```   128 apply (safe intro!: sum_bij)
```
```   129 (*Do the beta-reductions now*)
```
```   130 apply (auto cong add: conj_cong simp add: bij_is_fun [THEN apply_type])
```
```   131 done
```
```   132
```
```   133 (*Could we prove an ord_iso result?  Perhaps
```
```   134      ord_iso(A+B, radd(A,r,B,s), A Un B, r Un s) *)
```
```   135 lemma sum_disjoint_bij: "A Int B = 0 ==>
```
```   136             (lam z:A+B. case(%x. x, %y. y, z)) : bij(A+B, A Un B)"
```
```   137 apply (rule_tac d = "%z. if z:A then Inl (z) else Inr (z) " in lam_bijective)
```
```   138 apply auto
```
```   139 done
```
```   140
```
```   141 subsubsection{*Associativity*}
```
```   142
```
```   143 lemma sum_assoc_bij:
```
```   144      "(lam z:(A+B)+C. case(case(Inl, %y. Inr(Inl(y))), %y. Inr(Inr(y)), z))
```
```   145       : bij((A+B)+C, A+(B+C))"
```
```   146 apply (rule_tac d = "case (%x. Inl (Inl (x)), case (%x. Inl (Inr (x)), Inr))"
```
```   147        in lam_bijective)
```
```   148 apply auto
```
```   149 done
```
```   150
```
```   151 lemma sum_assoc_ord_iso:
```
```   152      "(lam z:(A+B)+C. case(case(Inl, %y. Inr(Inl(y))), %y. Inr(Inr(y)), z))
```
```   153       : ord_iso((A+B)+C, radd(A+B, radd(A,r,B,s), C, t),
```
```   154                 A+(B+C), radd(A, r, B+C, radd(B,s,C,t)))"
```
```   155 by (rule sum_assoc_bij [THEN ord_isoI], auto)
```
```   156
```
```   157
```
```   158 subsection{*Multiplication of Relations -- Lexicographic Product*}
```
```   159
```
```   160 subsubsection{*Rewrite rule.  Can be used to obtain introduction rules*}
```
```   161
```
```   162 lemma  rmult_iff [iff]:
```
```   163     "<<a',b'>, <a,b>> : rmult(A,r,B,s) <->
```
```   164             (<a',a>: r  & a':A & a:A & b': B & b: B) |
```
```   165             (<b',b>: s  & a'=a & a:A & b': B & b: B)"
```
```   166
```
```   167 by (unfold rmult_def, blast)
```
```   168
```
```   169 lemma rmultE:
```
```   170     "[| <<a',b'>, <a,b>> : rmult(A,r,B,s);
```
```   171         [| <a',a>: r;  a':A;  a:A;  b':B;  b:B |] ==> Q;
```
```   172         [| <b',b>: s;  a:A;  a'=a;  b':B;  b:B |] ==> Q
```
```   173      |] ==> Q"
```
```   174 by blast
```
```   175
```
```   176 subsubsection{*Type checking*}
```
```   177
```
```   178 lemma rmult_type: "rmult(A,r,B,s) <= (A*B) * (A*B)"
```
```   179 by (unfold rmult_def, rule Collect_subset)
```
```   180
```
```   181 lemmas field_rmult = rmult_type [THEN field_rel_subset]
```
```   182
```
```   183 subsubsection{*Linearity*}
```
```   184
```
```   185 lemma linear_rmult:
```
```   186     "[| linear(A,r);  linear(B,s) |] ==> linear(A*B,rmult(A,r,B,s))"
```
```   187 by (simp add: linear_def, blast)
```
```   188
```
```   189 subsubsection{*Well-foundedness*}
```
```   190
```
```   191 lemma wf_on_rmult: "[| wf[A](r);  wf[B](s) |] ==> wf[A*B](rmult(A,r,B,s))"
```
```   192 apply (rule wf_onI2)
```
```   193 apply (erule SigmaE)
```
```   194 apply (erule ssubst)
```
```   195 apply (subgoal_tac "ALL b:B. <x,b>: Ba", blast)
```
```   196 apply (erule_tac a = x in wf_on_induct, assumption)
```
```   197 apply (rule ballI)
```
```   198 apply (erule_tac a = b in wf_on_induct, assumption)
```
```   199 apply (best elim!: rmultE bspec [THEN mp])
```
```   200 done
```
```   201
```
```   202
```
```   203 lemma wf_rmult: "[| wf(r);  wf(s) |] ==> wf(rmult(field(r),r,field(s),s))"
```
```   204 apply (simp add: wf_iff_wf_on_field)
```
```   205 apply (rule wf_on_subset_A [OF _ field_rmult])
```
```   206 apply (blast intro: wf_on_rmult)
```
```   207 done
```
```   208
```
```   209 lemma well_ord_rmult:
```
```   210      "[| well_ord(A,r);  well_ord(B,s) |] ==> well_ord(A*B, rmult(A,r,B,s))"
```
```   211 apply (rule well_ordI)
```
```   212 apply (simp add: well_ord_def wf_on_rmult)
```
```   213 apply (simp add: well_ord_def tot_ord_def linear_rmult)
```
```   214 done
```
```   215
```
```   216
```
```   217 subsubsection{*An @{term ord_iso} congruence law*}
```
```   218
```
```   219 lemma prod_bij:
```
```   220      "[| f: bij(A,C);  g: bij(B,D) |]
```
```   221       ==> (lam <x,y>:A*B. <f`x, g`y>) : bij(A*B, C*D)"
```
```   222 apply (rule_tac d = "%<x,y>. <converse (f) `x, converse (g) `y>"
```
```   223        in lam_bijective)
```
```   224 apply (typecheck add: bij_is_inj inj_is_fun)
```
```   225 apply (auto simp add: left_inverse_bij right_inverse_bij)
```
```   226 done
```
```   227
```
```   228 lemma prod_ord_iso_cong:
```
```   229     "[| f: ord_iso(A,r,A',r');  g: ord_iso(B,s,B',s') |]
```
```   230      ==> (lam <x,y>:A*B. <f`x, g`y>)
```
```   231          : ord_iso(A*B, rmult(A,r,B,s), A'*B', rmult(A',r',B',s'))"
```
```   232 apply (unfold ord_iso_def)
```
```   233 apply (safe intro!: prod_bij)
```
```   234 apply (simp_all add: bij_is_fun [THEN apply_type])
```
```   235 apply (blast intro: bij_is_inj [THEN inj_apply_equality])
```
```   236 done
```
```   237
```
```   238 lemma singleton_prod_bij: "(lam z:A. <x,z>) : bij(A, {x}*A)"
```
```   239 by (rule_tac d = snd in lam_bijective, auto)
```
```   240
```
```   241 (*Used??*)
```
```   242 lemma singleton_prod_ord_iso:
```
```   243      "well_ord({x},xr) ==>
```
```   244           (lam z:A. <x,z>) : ord_iso(A, r, {x}*A, rmult({x}, xr, A, r))"
```
```   245 apply (rule singleton_prod_bij [THEN ord_isoI])
```
```   246 apply (simp (no_asm_simp))
```
```   247 apply (blast dest: well_ord_is_wf [THEN wf_on_not_refl])
```
```   248 done
```
```   249
```
```   250 (*Here we build a complicated function term, then simplify it using
```
```   251   case_cong, id_conv, comp_lam, case_case.*)
```
```   252 lemma prod_sum_singleton_bij:
```
```   253      "a~:C ==>
```
```   254        (lam x:C*B + D. case(%x. x, %y.<a,y>, x))
```
```   255        : bij(C*B + D, C*B Un {a}*D)"
```
```   256 apply (rule subst_elem)
```
```   257 apply (rule id_bij [THEN sum_bij, THEN comp_bij])
```
```   258 apply (rule singleton_prod_bij)
```
```   259 apply (rule sum_disjoint_bij, blast)
```
```   260 apply (simp (no_asm_simp) cong add: case_cong)
```
```   261 apply (rule comp_lam [THEN trans, symmetric])
```
```   262 apply (fast elim!: case_type)
```
```   263 apply (simp (no_asm_simp) add: case_case)
```
```   264 done
```
```   265
```
```   266 lemma prod_sum_singleton_ord_iso:
```
```   267  "[| a:A;  well_ord(A,r) |] ==>
```
```   268     (lam x:pred(A,a,r)*B + pred(B,b,s). case(%x. x, %y.<a,y>, x))
```
```   269     : ord_iso(pred(A,a,r)*B + pred(B,b,s),
```
```   270                   radd(A*B, rmult(A,r,B,s), B, s),
```
```   271               pred(A,a,r)*B Un {a}*pred(B,b,s), rmult(A,r,B,s))"
```
```   272 apply (rule prod_sum_singleton_bij [THEN ord_isoI])
```
```   273 apply (simp (no_asm_simp) add: pred_iff well_ord_is_wf [THEN wf_on_not_refl])
```
```   274 apply (auto elim!: well_ord_is_wf [THEN wf_on_asym] predE)
```
```   275 done
```
```   276
```
```   277 subsubsection{*Distributive law*}
```
```   278
```
```   279 lemma sum_prod_distrib_bij:
```
```   280      "(lam <x,z>:(A+B)*C. case(%y. Inl(<y,z>), %y. Inr(<y,z>), x))
```
```   281       : bij((A+B)*C, (A*C)+(B*C))"
```
```   282 by (rule_tac d = "case (%<x,y>.<Inl (x),y>, %<x,y>.<Inr (x),y>) "
```
```   283     in lam_bijective, auto)
```
```   284
```
```   285 lemma sum_prod_distrib_ord_iso:
```
```   286  "(lam <x,z>:(A+B)*C. case(%y. Inl(<y,z>), %y. Inr(<y,z>), x))
```
```   287   : ord_iso((A+B)*C, rmult(A+B, radd(A,r,B,s), C, t),
```
```   288             (A*C)+(B*C), radd(A*C, rmult(A,r,C,t), B*C, rmult(B,s,C,t)))"
```
```   289 by (rule sum_prod_distrib_bij [THEN ord_isoI], auto)
```
```   290
```
```   291 subsubsection{*Associativity*}
```
```   292
```
```   293 lemma prod_assoc_bij:
```
```   294      "(lam <<x,y>, z>:(A*B)*C. <x,<y,z>>) : bij((A*B)*C, A*(B*C))"
```
```   295 by (rule_tac d = "%<x, <y,z>>. <<x,y>, z>" in lam_bijective, auto)
```
```   296
```
```   297 lemma prod_assoc_ord_iso:
```
```   298  "(lam <<x,y>, z>:(A*B)*C. <x,<y,z>>)
```
```   299   : ord_iso((A*B)*C, rmult(A*B, rmult(A,r,B,s), C, t),
```
```   300             A*(B*C), rmult(A, r, B*C, rmult(B,s,C,t)))"
```
```   301 by (rule prod_assoc_bij [THEN ord_isoI], auto)
```
```   302
```
```   303 subsection{*Inverse Image of a Relation*}
```
```   304
```
```   305 subsubsection{*Rewrite rule*}
```
```   306
```
```   307 lemma rvimage_iff: "<a,b> : rvimage(A,f,r)  <->  <f`a,f`b>: r & a:A & b:A"
```
```   308 by (unfold rvimage_def, blast)
```
```   309
```
```   310 subsubsection{*Type checking*}
```
```   311
```
```   312 lemma rvimage_type: "rvimage(A,f,r) <= A*A"
```
```   313 by (unfold rvimage_def, rule Collect_subset)
```
```   314
```
```   315 lemmas field_rvimage = rvimage_type [THEN field_rel_subset]
```
```   316
```
```   317 lemma rvimage_converse: "rvimage(A,f, converse(r)) = converse(rvimage(A,f,r))"
```
```   318 by (unfold rvimage_def, blast)
```
```   319
```
```   320
```
```   321 subsubsection{*Partial Ordering Properties*}
```
```   322
```
```   323 lemma irrefl_rvimage:
```
```   324     "[| f: inj(A,B);  irrefl(B,r) |] ==> irrefl(A, rvimage(A,f,r))"
```
```   325 apply (unfold irrefl_def rvimage_def)
```
```   326 apply (blast intro: inj_is_fun [THEN apply_type])
```
```   327 done
```
```   328
```
```   329 lemma trans_on_rvimage:
```
```   330     "[| f: inj(A,B);  trans[B](r) |] ==> trans[A](rvimage(A,f,r))"
```
```   331 apply (unfold trans_on_def rvimage_def)
```
```   332 apply (blast intro: inj_is_fun [THEN apply_type])
```
```   333 done
```
```   334
```
```   335 lemma part_ord_rvimage:
```
```   336     "[| f: inj(A,B);  part_ord(B,r) |] ==> part_ord(A, rvimage(A,f,r))"
```
```   337 apply (unfold part_ord_def)
```
```   338 apply (blast intro!: irrefl_rvimage trans_on_rvimage)
```
```   339 done
```
```   340
```
```   341 subsubsection{*Linearity*}
```
```   342
```
```   343 lemma linear_rvimage:
```
```   344     "[| f: inj(A,B);  linear(B,r) |] ==> linear(A,rvimage(A,f,r))"
```
```   345 apply (simp add: inj_def linear_def rvimage_iff)
```
```   346 apply (blast intro: apply_funtype)
```
```   347 done
```
```   348
```
```   349 lemma tot_ord_rvimage:
```
```   350     "[| f: inj(A,B);  tot_ord(B,r) |] ==> tot_ord(A, rvimage(A,f,r))"
```
```   351 apply (unfold tot_ord_def)
```
```   352 apply (blast intro!: part_ord_rvimage linear_rvimage)
```
```   353 done
```
```   354
```
```   355
```
```   356 subsubsection{*Well-foundedness*}
```
```   357
```
```   358 lemma wf_rvimage [intro!]: "wf(r) ==> wf(rvimage(A,f,r))"
```
```   359 apply (simp (no_asm_use) add: rvimage_def wf_eq_minimal)
```
```   360 apply clarify
```
```   361 apply (subgoal_tac "EX w. w : {w: {f`x. x:Q}. EX x. x: Q & (f`x = w) }")
```
```   362  apply (erule allE)
```
```   363  apply (erule impE)
```
```   364  apply assumption
```
```   365  apply blast
```
```   366 apply blast
```
```   367 done
```
```   368
```
```   369 text{*But note that the combination of @{text wf_imp_wf_on} and
```
```   370  @{text wf_rvimage} gives @{term "wf(r) ==> wf[C](rvimage(A,f,r))"}*}
```
```   371 lemma wf_on_rvimage: "[| f: A->B;  wf[B](r) |] ==> wf[A](rvimage(A,f,r))"
```
```   372 apply (rule wf_onI2)
```
```   373 apply (subgoal_tac "ALL z:A. f`z=f`y --> z: Ba")
```
```   374  apply blast
```
```   375 apply (erule_tac a = "f`y" in wf_on_induct)
```
```   376  apply (blast intro!: apply_funtype)
```
```   377 apply (blast intro!: apply_funtype dest!: rvimage_iff [THEN iffD1])
```
```   378 done
```
```   379
```
```   380 (*Note that we need only wf[A](...) and linear(A,...) to get the result!*)
```
```   381 lemma well_ord_rvimage:
```
```   382      "[| f: inj(A,B);  well_ord(B,r) |] ==> well_ord(A, rvimage(A,f,r))"
```
```   383 apply (rule well_ordI)
```
```   384 apply (unfold well_ord_def tot_ord_def)
```
```   385 apply (blast intro!: wf_on_rvimage inj_is_fun)
```
```   386 apply (blast intro!: linear_rvimage)
```
```   387 done
```
```   388
```
```   389 lemma ord_iso_rvimage:
```
```   390     "f: bij(A,B) ==> f: ord_iso(A, rvimage(A,f,s), B, s)"
```
```   391 apply (unfold ord_iso_def)
```
```   392 apply (simp add: rvimage_iff)
```
```   393 done
```
```   394
```
```   395 lemma ord_iso_rvimage_eq:
```
```   396     "f: ord_iso(A,r, B,s) ==> rvimage(A,f,s) = r Int A*A"
```
```   397 by (unfold ord_iso_def rvimage_def, blast)
```
```   398
```
```   399
```
```   400 subsection{*Every well-founded relation is a subset of some inverse image of
```
```   401       an ordinal*}
```
```   402
```
```   403 lemma wf_rvimage_Ord: "Ord(i) \<Longrightarrow> wf(rvimage(A, f, Memrel(i)))"
```
```   404 by (blast intro: wf_rvimage wf_Memrel)
```
```   405
```
```   406
```
```   407 constdefs
```
```   408   wfrank :: "[i,i]=>i"
```
```   409     "wfrank(r,a) == wfrec(r, a, %x f. \<Union>y \<in> r-``{x}. succ(f`y))"
```
```   410
```
```   411 constdefs
```
```   412   wftype :: "i=>i"
```
```   413     "wftype(r) == \<Union>y \<in> range(r). succ(wfrank(r,y))"
```
```   414
```
```   415 lemma wfrank: "wf(r) ==> wfrank(r,a) = (\<Union>y \<in> r-``{a}. succ(wfrank(r,y)))"
```
```   416 by (subst wfrank_def [THEN def_wfrec], simp_all)
```
```   417
```
```   418 lemma Ord_wfrank: "wf(r) ==> Ord(wfrank(r,a))"
```
```   419 apply (rule_tac a=a in wf_induct, assumption)
```
```   420 apply (subst wfrank, assumption)
```
```   421 apply (rule Ord_succ [THEN Ord_UN], blast)
```
```   422 done
```
```   423
```
```   424 lemma wfrank_lt: "[|wf(r); <a,b> \<in> r|] ==> wfrank(r,a) < wfrank(r,b)"
```
```   425 apply (rule_tac a1 = b in wfrank [THEN ssubst], assumption)
```
```   426 apply (rule UN_I [THEN ltI])
```
```   427 apply (simp add: Ord_wfrank vimage_iff)+
```
```   428 done
```
```   429
```
```   430 lemma Ord_wftype: "wf(r) ==> Ord(wftype(r))"
```
```   431 by (simp add: wftype_def Ord_wfrank)
```
```   432
```
```   433 lemma wftypeI: "\<lbrakk>wf(r);  x \<in> field(r)\<rbrakk> \<Longrightarrow> wfrank(r,x) \<in> wftype(r)"
```
```   434 apply (simp add: wftype_def)
```
```   435 apply (blast intro: wfrank_lt [THEN ltD])
```
```   436 done
```
```   437
```
```   438
```
```   439 lemma wf_imp_subset_rvimage:
```
```   440      "[|wf(r); r \<subseteq> A*A|] ==> \<exists>i f. Ord(i) & r <= rvimage(A, f, Memrel(i))"
```
```   441 apply (rule_tac x="wftype(r)" in exI)
```
```   442 apply (rule_tac x="\<lambda>x\<in>A. wfrank(r,x)" in exI)
```
```   443 apply (simp add: Ord_wftype, clarify)
```
```   444 apply (frule subsetD, assumption, clarify)
```
```   445 apply (simp add: rvimage_iff wfrank_lt [THEN ltD])
```
```   446 apply (blast intro: wftypeI)
```
```   447 done
```
```   448
```
```   449 theorem wf_iff_subset_rvimage:
```
```   450   "relation(r) ==> wf(r) <-> (\<exists>i f A. Ord(i) & r <= rvimage(A, f, Memrel(i)))"
```
```   451 by (blast dest!: relation_field_times_field wf_imp_subset_rvimage
```
```   452           intro: wf_rvimage_Ord [THEN wf_subset])
```
```   453
```
```   454
```
```   455 subsection{*Other Results*}
```
```   456
```
```   457 lemma wf_times: "A Int B = 0 ==> wf(A*B)"
```
```   458 by (simp add: wf_def, blast)
```
```   459
```
```   460 text{*Could also be used to prove @{text wf_radd}*}
```
```   461 lemma wf_Un:
```
```   462      "[| range(r) Int domain(s) = 0; wf(r);  wf(s) |] ==> wf(r Un s)"
```
```   463 apply (simp add: wf_def, clarify)
```
```   464 apply (rule equalityI)
```
```   465  prefer 2 apply blast
```
```   466 apply clarify
```
```   467 apply (drule_tac x=Z in spec)
```
```   468 apply (drule_tac x="Z Int domain(s)" in spec)
```
```   469 apply simp
```
```   470 apply (blast intro: elim: equalityE)
```
```   471 done
```
```   472
```
```   473 subsubsection{*The Empty Relation*}
```
```   474
```
```   475 lemma wf0: "wf(0)"
```
```   476 by (simp add: wf_def, blast)
```
```   477
```
```   478 lemma linear0: "linear(0,0)"
```
```   479 by (simp add: linear_def)
```
```   480
```
```   481 lemma well_ord0: "well_ord(0,0)"
```
```   482 by (blast intro: wf_imp_wf_on well_ordI wf0 linear0)
```
```   483
```
```   484 subsubsection{*The "measure" relation is useful with wfrec*}
```
```   485
```
```   486 lemma measure_eq_rvimage_Memrel:
```
```   487      "measure(A,f) = rvimage(A,Lambda(A,f),Memrel(Collect(RepFun(A,f),Ord)))"
```
```   488 apply (simp (no_asm) add: measure_def rvimage_def Memrel_iff)
```
```   489 apply (rule equalityI, auto)
```
```   490 apply (auto intro: Ord_in_Ord simp add: lt_def)
```
```   491 done
```
```   492
```
```   493 lemma wf_measure [iff]: "wf(measure(A,f))"
```
```   494 by (simp (no_asm) add: measure_eq_rvimage_Memrel wf_Memrel wf_rvimage)
```
```   495
```
```   496 lemma measure_iff [iff]: "<x,y> : measure(A,f) <-> x:A & y:A & f(x)<f(y)"
```
```   497 by (simp (no_asm) add: measure_def)
```
```   498
```
```   499 lemma linear_measure:
```
```   500  assumes Ordf: "!!x. x \<in> A ==> Ord(f(x))"
```
```   501      and inj:  "!!x y. [|x \<in> A; y \<in> A; f(x) = f(y) |] ==> x=y"
```
```   502  shows "linear(A, measure(A,f))"
```
```   503 apply (auto simp add: linear_def)
```
```   504 apply (rule_tac i="f(x)" and j="f(y)" in Ord_linear_lt)
```
```   505     apply (simp_all add: Ordf)
```
```   506 apply (blast intro: inj)
```
```   507 done
```
```   508
```
```   509 lemma wf_on_measure: "wf[B](measure(A,f))"
```
```   510 by (rule wf_imp_wf_on [OF wf_measure])
```
```   511
```
```   512 lemma well_ord_measure:
```
```   513  assumes Ordf: "!!x. x \<in> A ==> Ord(f(x))"
```
```   514      and inj:  "!!x y. [|x \<in> A; y \<in> A; f(x) = f(y) |] ==> x=y"
```
```   515  shows "well_ord(A, measure(A,f))"
```
```   516 apply (rule well_ordI)
```
```   517 apply (rule wf_on_measure)
```
```   518 apply (blast intro: linear_measure Ordf inj)
```
```   519 done
```
```   520
```
```   521 lemma measure_type: "measure(A,f) <= A*A"
```
```   522 by (auto simp add: measure_def)
```
```   523
```
```   524 subsubsection{*Well-foundedness of Unions*}
```
```   525
```
```   526 lemma wf_on_Union:
```
```   527  assumes wfA: "wf[A](r)"
```
```   528      and wfB: "!!a. a\<in>A ==> wf[B(a)](s)"
```
```   529      and ok: "!!a u v. [|<u,v> \<in> s; v \<in> B(a); a \<in> A|]
```
```   530                        ==> (\<exists>a'\<in>A. <a',a> \<in> r & u \<in> B(a')) | u \<in> B(a)"
```
```   531  shows "wf[\<Union>a\<in>A. B(a)](s)"
```
```   532 apply (rule wf_onI2)
```
```   533 apply (erule UN_E)
```
```   534 apply (subgoal_tac "\<forall>z \<in> B(a). z \<in> Ba", blast)
```
```   535 apply (rule_tac a = a in wf_on_induct [OF wfA], assumption)
```
```   536 apply (rule ballI)
```
```   537 apply (rule_tac a = z in wf_on_induct [OF wfB], assumption, assumption)
```
```   538 apply (rename_tac u)
```
```   539 apply (drule_tac x=u in bspec, blast)
```
```   540 apply (erule mp, clarify)
```
```   541 apply (frule ok, assumption+, blast)
```
```   542 done
```
```   543
```
```   544
```
```   545 ML {*
```
```   546 val measure_def = thm "measure_def";
```
```   547 val radd_Inl_Inr_iff = thm "radd_Inl_Inr_iff";
```
```   548 val radd_Inl_iff = thm "radd_Inl_iff";
```
```   549 val radd_Inr_iff = thm "radd_Inr_iff";
```
```   550 val radd_Inr_Inl_iff = thm "radd_Inr_Inl_iff";
```
```   551 val raddE = thm "raddE";
```
```   552 val radd_type = thm "radd_type";
```
```   553 val field_radd = thm "field_radd";
```
```   554 val linear_radd = thm "linear_radd";
```
```   555 val wf_on_radd = thm "wf_on_radd";
```
```   556 val wf_radd = thm "wf_radd";
```
```   557 val well_ord_radd = thm "well_ord_radd";
```
```   558 val sum_bij = thm "sum_bij";
```
```   559 val sum_ord_iso_cong = thm "sum_ord_iso_cong";
```
```   560 val sum_disjoint_bij = thm "sum_disjoint_bij";
```
```   561 val sum_assoc_bij = thm "sum_assoc_bij";
```
```   562 val sum_assoc_ord_iso = thm "sum_assoc_ord_iso";
```
```   563 val rmult_iff = thm "rmult_iff";
```
```   564 val rmultE = thm "rmultE";
```
```   565 val rmult_type = thm "rmult_type";
```
```   566 val field_rmult = thm "field_rmult";
```
```   567 val linear_rmult = thm "linear_rmult";
```
```   568 val wf_on_rmult = thm "wf_on_rmult";
```
```   569 val wf_rmult = thm "wf_rmult";
```
```   570 val well_ord_rmult = thm "well_ord_rmult";
```
```   571 val prod_bij = thm "prod_bij";
```
```   572 val prod_ord_iso_cong = thm "prod_ord_iso_cong";
```
```   573 val singleton_prod_bij = thm "singleton_prod_bij";
```
```   574 val singleton_prod_ord_iso = thm "singleton_prod_ord_iso";
```
```   575 val prod_sum_singleton_bij = thm "prod_sum_singleton_bij";
```
```   576 val prod_sum_singleton_ord_iso = thm "prod_sum_singleton_ord_iso";
```
```   577 val sum_prod_distrib_bij = thm "sum_prod_distrib_bij";
```
```   578 val sum_prod_distrib_ord_iso = thm "sum_prod_distrib_ord_iso";
```
```   579 val prod_assoc_bij = thm "prod_assoc_bij";
```
```   580 val prod_assoc_ord_iso = thm "prod_assoc_ord_iso";
```
```   581 val rvimage_iff = thm "rvimage_iff";
```
```   582 val rvimage_type = thm "rvimage_type";
```
```   583 val field_rvimage = thm "field_rvimage";
```
```   584 val rvimage_converse = thm "rvimage_converse";
```
```   585 val irrefl_rvimage = thm "irrefl_rvimage";
```
```   586 val trans_on_rvimage = thm "trans_on_rvimage";
```
```   587 val part_ord_rvimage = thm "part_ord_rvimage";
```
```   588 val linear_rvimage = thm "linear_rvimage";
```
```   589 val tot_ord_rvimage = thm "tot_ord_rvimage";
```
```   590 val wf_rvimage = thm "wf_rvimage";
```
```   591 val wf_on_rvimage = thm "wf_on_rvimage";
```
```   592 val well_ord_rvimage = thm "well_ord_rvimage";
```
```   593 val ord_iso_rvimage = thm "ord_iso_rvimage";
```
```   594 val ord_iso_rvimage_eq = thm "ord_iso_rvimage_eq";
```
```   595 val measure_eq_rvimage_Memrel = thm "measure_eq_rvimage_Memrel";
```
```   596 val wf_measure = thm "wf_measure";
```
```   597 val measure_iff = thm "measure_iff";
```
```   598 *}
```
```   599
```
```   600 end
```