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