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