src/HOL/Fun.thy
 author kuncar Fri Dec 09 18:07:04 2011 +0100 (2011-12-09) changeset 45802 b16f976db515 parent 45603 d2d9ef16ccaf child 46419 e139d0e29ca1 permissions -rw-r--r--
Quotient_Info stores only relation maps
 clasohm@1475 ` 1` ```(* Title: HOL/Fun.thy ``` clasohm@1475 ` 2` ``` Author: Tobias Nipkow, Cambridge University Computer Laboratory ``` clasohm@923 ` 3` ``` Copyright 1994 University of Cambridge ``` huffman@18154 ` 4` ```*) ``` clasohm@923 ` 5` huffman@18154 ` 6` ```header {* Notions about functions *} ``` clasohm@923 ` 7` paulson@15510 ` 8` ```theory Fun ``` haftmann@44860 ` 9` ```imports Complete_Lattices ``` haftmann@41505 ` 10` ```uses ("Tools/enriched_type.ML") ``` nipkow@15131 ` 11` ```begin ``` nipkow@2912 ` 12` haftmann@26147 ` 13` ```lemma apply_inverse: ``` haftmann@26357 ` 14` ``` "f x = u \ (\x. P x \ g (f x) = x) \ P x \ x = g u" ``` haftmann@26147 ` 15` ``` by auto ``` nipkow@2912 ` 16` wenzelm@12258 ` 17` haftmann@26147 ` 18` ```subsection {* The Identity Function @{text id} *} ``` paulson@6171 ` 19` haftmann@44277 ` 20` ```definition id :: "'a \ 'a" where ``` haftmann@22744 ` 21` ``` "id = (\x. x)" ``` nipkow@13910 ` 22` haftmann@26147 ` 23` ```lemma id_apply [simp]: "id x = x" ``` haftmann@26147 ` 24` ``` by (simp add: id_def) ``` haftmann@26147 ` 25` haftmann@26147 ` 26` ```lemma image_id [simp]: "id ` Y = Y" ``` haftmann@44277 ` 27` ``` by (simp add: id_def) ``` haftmann@26147 ` 28` haftmann@26147 ` 29` ```lemma vimage_id [simp]: "id -` A = A" ``` haftmann@44277 ` 30` ``` by (simp add: id_def) ``` haftmann@26147 ` 31` haftmann@26147 ` 32` haftmann@26147 ` 33` ```subsection {* The Composition Operator @{text "f \ g"} *} ``` haftmann@26147 ` 34` haftmann@44277 ` 35` ```definition comp :: "('b \ 'c) \ ('a \ 'b) \ 'a \ 'c" (infixl "o" 55) where ``` haftmann@22744 ` 36` ``` "f o g = (\x. f (g x))" ``` oheimb@11123 ` 37` wenzelm@21210 ` 38` ```notation (xsymbols) ``` wenzelm@19656 ` 39` ``` comp (infixl "\" 55) ``` wenzelm@19656 ` 40` wenzelm@21210 ` 41` ```notation (HTML output) ``` wenzelm@19656 ` 42` ``` comp (infixl "\" 55) ``` wenzelm@19656 ` 43` paulson@13585 ` 44` ```lemma o_apply [simp]: "(f o g) x = f (g x)" ``` paulson@13585 ` 45` ```by (simp add: comp_def) ``` paulson@13585 ` 46` paulson@13585 ` 47` ```lemma o_assoc: "f o (g o h) = f o g o h" ``` paulson@13585 ` 48` ```by (simp add: comp_def) ``` paulson@13585 ` 49` paulson@13585 ` 50` ```lemma id_o [simp]: "id o g = g" ``` paulson@13585 ` 51` ```by (simp add: comp_def) ``` paulson@13585 ` 52` paulson@13585 ` 53` ```lemma o_id [simp]: "f o id = f" ``` paulson@13585 ` 54` ```by (simp add: comp_def) ``` paulson@13585 ` 55` haftmann@34150 ` 56` ```lemma o_eq_dest: ``` haftmann@34150 ` 57` ``` "a o b = c o d \ a (b v) = c (d v)" ``` haftmann@44277 ` 58` ``` by (simp only: comp_def) (fact fun_cong) ``` haftmann@34150 ` 59` haftmann@34150 ` 60` ```lemma o_eq_elim: ``` haftmann@34150 ` 61` ``` "a o b = c o d \ ((\v. a (b v) = c (d v)) \ R) \ R" ``` haftmann@34150 ` 62` ``` by (erule meta_mp) (fact o_eq_dest) ``` haftmann@34150 ` 63` paulson@13585 ` 64` ```lemma image_compose: "(f o g) ` r = f`(g`r)" ``` paulson@13585 ` 65` ```by (simp add: comp_def, blast) ``` paulson@13585 ` 66` paulson@33044 ` 67` ```lemma vimage_compose: "(g \ f) -` x = f -` (g -` x)" ``` paulson@33044 ` 68` ``` by auto ``` paulson@33044 ` 69` paulson@13585 ` 70` ```lemma UN_o: "UNION A (g o f) = UNION (f`A) g" ``` paulson@13585 ` 71` ```by (unfold comp_def, blast) ``` paulson@13585 ` 72` paulson@13585 ` 73` haftmann@26588 ` 74` ```subsection {* The Forward Composition Operator @{text fcomp} *} ``` haftmann@26357 ` 75` haftmann@44277 ` 76` ```definition fcomp :: "('a \ 'b) \ ('b \ 'c) \ 'a \ 'c" (infixl "\>" 60) where ``` haftmann@37751 ` 77` ``` "f \> g = (\x. g (f x))" ``` haftmann@26357 ` 78` haftmann@37751 ` 79` ```lemma fcomp_apply [simp]: "(f \> g) x = g (f x)" ``` haftmann@26357 ` 80` ``` by (simp add: fcomp_def) ``` haftmann@26357 ` 81` haftmann@37751 ` 82` ```lemma fcomp_assoc: "(f \> g) \> h = f \> (g \> h)" ``` haftmann@26357 ` 83` ``` by (simp add: fcomp_def) ``` haftmann@26357 ` 84` haftmann@37751 ` 85` ```lemma id_fcomp [simp]: "id \> g = g" ``` haftmann@26357 ` 86` ``` by (simp add: fcomp_def) ``` haftmann@26357 ` 87` haftmann@37751 ` 88` ```lemma fcomp_id [simp]: "f \> id = f" ``` haftmann@26357 ` 89` ``` by (simp add: fcomp_def) ``` haftmann@26357 ` 90` haftmann@31202 ` 91` ```code_const fcomp ``` haftmann@31202 ` 92` ``` (Eval infixl 1 "#>") ``` haftmann@31202 ` 93` haftmann@37751 ` 94` ```no_notation fcomp (infixl "\>" 60) ``` haftmann@26588 ` 95` haftmann@26357 ` 96` haftmann@40602 ` 97` ```subsection {* Mapping functions *} ``` haftmann@40602 ` 98` haftmann@40602 ` 99` ```definition map_fun :: "('c \ 'a) \ ('b \ 'd) \ ('a \ 'b) \ 'c \ 'd" where ``` haftmann@40602 ` 100` ``` "map_fun f g h = g \ h \ f" ``` haftmann@40602 ` 101` haftmann@40602 ` 102` ```lemma map_fun_apply [simp]: ``` haftmann@40602 ` 103` ``` "map_fun f g h x = g (h (f x))" ``` haftmann@40602 ` 104` ``` by (simp add: map_fun_def) ``` haftmann@40602 ` 105` haftmann@40602 ` 106` hoelzl@40702 ` 107` ```subsection {* Injectivity and Bijectivity *} ``` hoelzl@39076 ` 108` hoelzl@39076 ` 109` ```definition inj_on :: "('a \ 'b) \ 'a set \ bool" where -- "injective" ``` hoelzl@39076 ` 110` ``` "inj_on f A \ (\x\A. \y\A. f x = f y \ x = y)" ``` haftmann@26147 ` 111` hoelzl@39076 ` 112` ```definition bij_betw :: "('a \ 'b) \ 'a set \ 'b set \ bool" where -- "bijective" ``` hoelzl@39076 ` 113` ``` "bij_betw f A B \ inj_on f A \ f ` A = B" ``` haftmann@26147 ` 114` hoelzl@40702 ` 115` ```text{*A common special case: functions injective, surjective or bijective over ``` hoelzl@40702 ` 116` ```the entire domain type.*} ``` haftmann@26147 ` 117` haftmann@26147 ` 118` ```abbreviation ``` hoelzl@39076 ` 119` ``` "inj f \ inj_on f UNIV" ``` haftmann@26147 ` 120` hoelzl@40702 ` 121` ```abbreviation surj :: "('a \ 'b) \ bool" where -- "surjective" ``` hoelzl@40702 ` 122` ``` "surj f \ (range f = UNIV)" ``` paulson@13585 ` 123` hoelzl@39076 ` 124` ```abbreviation ``` hoelzl@39076 ` 125` ``` "bij f \ bij_betw f UNIV UNIV" ``` haftmann@26147 ` 126` nipkow@43705 ` 127` ```text{* The negated case: *} ``` nipkow@43705 ` 128` ```translations ``` nipkow@43705 ` 129` ```"\ CONST surj f" <= "CONST range f \ CONST UNIV" ``` nipkow@43705 ` 130` haftmann@26147 ` 131` ```lemma injI: ``` haftmann@26147 ` 132` ``` assumes "\x y. f x = f y \ x = y" ``` haftmann@26147 ` 133` ``` shows "inj f" ``` haftmann@26147 ` 134` ``` using assms unfolding inj_on_def by auto ``` paulson@13585 ` 135` berghofe@13637 ` 136` ```theorem range_ex1_eq: "inj f \ b : range f = (EX! x. b = f x)" ``` berghofe@13637 ` 137` ``` by (unfold inj_on_def, blast) ``` berghofe@13637 ` 138` paulson@13585 ` 139` ```lemma injD: "[| inj(f); f(x) = f(y) |] ==> x=y" ``` paulson@13585 ` 140` ```by (simp add: inj_on_def) ``` paulson@13585 ` 141` nipkow@32988 ` 142` ```lemma inj_on_eq_iff: "inj_on f A ==> x:A ==> y:A ==> (f(x) = f(y)) = (x=y)" ``` paulson@13585 ` 143` ```by (force simp add: inj_on_def) ``` paulson@13585 ` 144` hoelzl@40703 ` 145` ```lemma inj_on_cong: ``` hoelzl@40703 ` 146` ``` "(\ a. a : A \ f a = g a) \ inj_on f A = inj_on g A" ``` hoelzl@40703 ` 147` ```unfolding inj_on_def by auto ``` hoelzl@40703 ` 148` hoelzl@40703 ` 149` ```lemma inj_on_strict_subset: ``` hoelzl@40703 ` 150` ``` "\ inj_on f B; A < B \ \ f`A < f`B" ``` hoelzl@40703 ` 151` ```unfolding inj_on_def unfolding image_def by blast ``` hoelzl@40703 ` 152` haftmann@38620 ` 153` ```lemma inj_comp: ``` haftmann@38620 ` 154` ``` "inj f \ inj g \ inj (f \ g)" ``` haftmann@38620 ` 155` ``` by (simp add: inj_on_def) ``` haftmann@38620 ` 156` haftmann@38620 ` 157` ```lemma inj_fun: "inj f \ inj (\x y. f x)" ``` nipkow@39302 ` 158` ``` by (simp add: inj_on_def fun_eq_iff) ``` haftmann@38620 ` 159` nipkow@32988 ` 160` ```lemma inj_eq: "inj f ==> (f(x) = f(y)) = (x=y)" ``` nipkow@32988 ` 161` ```by (simp add: inj_on_eq_iff) ``` nipkow@32988 ` 162` haftmann@26147 ` 163` ```lemma inj_on_id[simp]: "inj_on id A" ``` hoelzl@39076 ` 164` ``` by (simp add: inj_on_def) ``` paulson@13585 ` 165` haftmann@26147 ` 166` ```lemma inj_on_id2[simp]: "inj_on (%x. x) A" ``` hoelzl@39076 ` 167` ```by (simp add: inj_on_def) ``` haftmann@26147 ` 168` hoelzl@40703 ` 169` ```lemma inj_on_Int: "\inj_on f A; inj_on f B\ \ inj_on f (A \ B)" ``` hoelzl@40703 ` 170` ```unfolding inj_on_def by blast ``` hoelzl@40703 ` 171` hoelzl@40703 ` 172` ```lemma inj_on_INTER: ``` hoelzl@40703 ` 173` ``` "\I \ {}; \ i. i \ I \ inj_on f (A i)\ \ inj_on f (\ i \ I. A i)" ``` hoelzl@40703 ` 174` ```unfolding inj_on_def by blast ``` hoelzl@40703 ` 175` hoelzl@40703 ` 176` ```lemma inj_on_Inter: ``` hoelzl@40703 ` 177` ``` "\S \ {}; \ A. A \ S \ inj_on f A\ \ inj_on f (Inter S)" ``` hoelzl@40703 ` 178` ```unfolding inj_on_def by blast ``` hoelzl@40703 ` 179` hoelzl@40703 ` 180` ```lemma inj_on_UNION_chain: ``` hoelzl@40703 ` 181` ``` assumes CH: "\ i j. \i \ I; j \ I\ \ A i \ A j \ A j \ A i" and ``` hoelzl@40703 ` 182` ``` INJ: "\ i. i \ I \ inj_on f (A i)" ``` hoelzl@40703 ` 183` ``` shows "inj_on f (\ i \ I. A i)" ``` hoelzl@44928 ` 184` ```proof(unfold inj_on_def UNION_eq, auto) ``` hoelzl@40703 ` 185` ``` fix i j x y ``` hoelzl@40703 ` 186` ``` assume *: "i \ I" "j \ I" and **: "x \ A i" "y \ A j" ``` hoelzl@40703 ` 187` ``` and ***: "f x = f y" ``` hoelzl@40703 ` 188` ``` show "x = y" ``` hoelzl@40703 ` 189` ``` proof- ``` hoelzl@40703 ` 190` ``` {assume "A i \ A j" ``` hoelzl@40703 ` 191` ``` with ** have "x \ A j" by auto ``` hoelzl@40703 ` 192` ``` with INJ * ** *** have ?thesis ``` hoelzl@40703 ` 193` ``` by(auto simp add: inj_on_def) ``` hoelzl@40703 ` 194` ``` } ``` hoelzl@40703 ` 195` ``` moreover ``` hoelzl@40703 ` 196` ``` {assume "A j \ A i" ``` hoelzl@40703 ` 197` ``` with ** have "y \ A i" by auto ``` hoelzl@40703 ` 198` ``` with INJ * ** *** have ?thesis ``` hoelzl@40703 ` 199` ``` by(auto simp add: inj_on_def) ``` hoelzl@40703 ` 200` ``` } ``` hoelzl@40703 ` 201` ``` ultimately show ?thesis using CH * by blast ``` hoelzl@40703 ` 202` ``` qed ``` hoelzl@40703 ` 203` ```qed ``` hoelzl@40703 ` 204` hoelzl@40702 ` 205` ```lemma surj_id: "surj id" ``` hoelzl@40702 ` 206` ```by simp ``` haftmann@26147 ` 207` hoelzl@39101 ` 208` ```lemma bij_id[simp]: "bij id" ``` hoelzl@39076 ` 209` ```by (simp add: bij_betw_def) ``` paulson@13585 ` 210` paulson@13585 ` 211` ```lemma inj_onI: ``` paulson@13585 ` 212` ``` "(!! x y. [| x:A; y:A; f(x) = f(y) |] ==> x=y) ==> inj_on f A" ``` paulson@13585 ` 213` ```by (simp add: inj_on_def) ``` paulson@13585 ` 214` paulson@13585 ` 215` ```lemma inj_on_inverseI: "(!!x. x:A ==> g(f(x)) = x) ==> inj_on f A" ``` paulson@13585 ` 216` ```by (auto dest: arg_cong [of concl: g] simp add: inj_on_def) ``` paulson@13585 ` 217` paulson@13585 ` 218` ```lemma inj_onD: "[| inj_on f A; f(x)=f(y); x:A; y:A |] ==> x=y" ``` paulson@13585 ` 219` ```by (unfold inj_on_def, blast) ``` paulson@13585 ` 220` paulson@13585 ` 221` ```lemma inj_on_iff: "[| inj_on f A; x:A; y:A |] ==> (f(x)=f(y)) = (x=y)" ``` paulson@13585 ` 222` ```by (blast dest!: inj_onD) ``` paulson@13585 ` 223` paulson@13585 ` 224` ```lemma comp_inj_on: ``` paulson@13585 ` 225` ``` "[| inj_on f A; inj_on g (f`A) |] ==> inj_on (g o f) A" ``` paulson@13585 ` 226` ```by (simp add: comp_def inj_on_def) ``` paulson@13585 ` 227` nipkow@15303 ` 228` ```lemma inj_on_imageI: "inj_on (g o f) A \ inj_on g (f ` A)" ``` nipkow@15303 ` 229` ```apply(simp add:inj_on_def image_def) ``` nipkow@15303 ` 230` ```apply blast ``` nipkow@15303 ` 231` ```done ``` nipkow@15303 ` 232` nipkow@15439 ` 233` ```lemma inj_on_image_iff: "\ ALL x:A. ALL y:A. (g(f x) = g(f y)) = (g x = g y); ``` nipkow@15439 ` 234` ``` inj_on f A \ \ inj_on g (f ` A) = inj_on g A" ``` nipkow@15439 ` 235` ```apply(unfold inj_on_def) ``` nipkow@15439 ` 236` ```apply blast ``` nipkow@15439 ` 237` ```done ``` nipkow@15439 ` 238` paulson@13585 ` 239` ```lemma inj_on_contraD: "[| inj_on f A; ~x=y; x:A; y:A |] ==> ~ f(x)=f(y)" ``` paulson@13585 ` 240` ```by (unfold inj_on_def, blast) ``` wenzelm@12258 ` 241` paulson@13585 ` 242` ```lemma inj_singleton: "inj (%s. {s})" ``` paulson@13585 ` 243` ```by (simp add: inj_on_def) ``` paulson@13585 ` 244` nipkow@15111 ` 245` ```lemma inj_on_empty[iff]: "inj_on f {}" ``` nipkow@15111 ` 246` ```by(simp add: inj_on_def) ``` nipkow@15111 ` 247` nipkow@15303 ` 248` ```lemma subset_inj_on: "[| inj_on f B; A <= B |] ==> inj_on f A" ``` paulson@13585 ` 249` ```by (unfold inj_on_def, blast) ``` paulson@13585 ` 250` nipkow@15111 ` 251` ```lemma inj_on_Un: ``` nipkow@15111 ` 252` ``` "inj_on f (A Un B) = ``` nipkow@15111 ` 253` ``` (inj_on f A & inj_on f B & f`(A-B) Int f`(B-A) = {})" ``` nipkow@15111 ` 254` ```apply(unfold inj_on_def) ``` nipkow@15111 ` 255` ```apply (blast intro:sym) ``` nipkow@15111 ` 256` ```done ``` nipkow@15111 ` 257` nipkow@15111 ` 258` ```lemma inj_on_insert[iff]: ``` nipkow@15111 ` 259` ``` "inj_on f (insert a A) = (inj_on f A & f a ~: f`(A-{a}))" ``` nipkow@15111 ` 260` ```apply(unfold inj_on_def) ``` nipkow@15111 ` 261` ```apply (blast intro:sym) ``` nipkow@15111 ` 262` ```done ``` nipkow@15111 ` 263` nipkow@15111 ` 264` ```lemma inj_on_diff: "inj_on f A ==> inj_on f (A-B)" ``` nipkow@15111 ` 265` ```apply(unfold inj_on_def) ``` nipkow@15111 ` 266` ```apply (blast) ``` nipkow@15111 ` 267` ```done ``` nipkow@15111 ` 268` hoelzl@40703 ` 269` ```lemma comp_inj_on_iff: ``` hoelzl@40703 ` 270` ``` "inj_on f A \ inj_on f' (f ` A) \ inj_on (f' o f) A" ``` hoelzl@40703 ` 271` ```by(auto simp add: comp_inj_on inj_on_def) ``` hoelzl@40703 ` 272` hoelzl@40703 ` 273` ```lemma inj_on_imageI2: ``` hoelzl@40703 ` 274` ``` "inj_on (f' o f) A \ inj_on f A" ``` hoelzl@40703 ` 275` ```by(auto simp add: comp_inj_on inj_on_def) ``` hoelzl@40703 ` 276` hoelzl@40702 ` 277` ```lemma surj_def: "surj f \ (\y. \x. y = f x)" ``` hoelzl@40702 ` 278` ``` by auto ``` hoelzl@39076 ` 279` hoelzl@40702 ` 280` ```lemma surjI: assumes *: "\ x. g (f x) = x" shows "surj g" ``` hoelzl@40702 ` 281` ``` using *[symmetric] by auto ``` paulson@13585 ` 282` hoelzl@39076 ` 283` ```lemma surjD: "surj f \ \x. y = f x" ``` hoelzl@39076 ` 284` ``` by (simp add: surj_def) ``` paulson@13585 ` 285` hoelzl@39076 ` 286` ```lemma surjE: "surj f \ (\x. y = f x \ C) \ C" ``` hoelzl@39076 ` 287` ``` by (simp add: surj_def, blast) ``` paulson@13585 ` 288` paulson@13585 ` 289` ```lemma comp_surj: "[| surj f; surj g |] ==> surj (g o f)" ``` paulson@13585 ` 290` ```apply (simp add: comp_def surj_def, clarify) ``` paulson@13585 ` 291` ```apply (drule_tac x = y in spec, clarify) ``` paulson@13585 ` 292` ```apply (drule_tac x = x in spec, blast) ``` paulson@13585 ` 293` ```done ``` paulson@13585 ` 294` hoelzl@39074 ` 295` ```lemma bij_betw_imp_surj: "bij_betw f A UNIV \ surj f" ``` hoelzl@40702 ` 296` ``` unfolding bij_betw_def by auto ``` hoelzl@39074 ` 297` hoelzl@40703 ` 298` ```lemma bij_betw_empty1: ``` hoelzl@40703 ` 299` ``` assumes "bij_betw f {} A" ``` hoelzl@40703 ` 300` ``` shows "A = {}" ``` hoelzl@40703 ` 301` ```using assms unfolding bij_betw_def by blast ``` hoelzl@40703 ` 302` hoelzl@40703 ` 303` ```lemma bij_betw_empty2: ``` hoelzl@40703 ` 304` ``` assumes "bij_betw f A {}" ``` hoelzl@40703 ` 305` ``` shows "A = {}" ``` hoelzl@40703 ` 306` ```using assms unfolding bij_betw_def by blast ``` hoelzl@40703 ` 307` hoelzl@40703 ` 308` ```lemma inj_on_imp_bij_betw: ``` hoelzl@40703 ` 309` ``` "inj_on f A \ bij_betw f A (f ` A)" ``` hoelzl@40703 ` 310` ```unfolding bij_betw_def by simp ``` hoelzl@40703 ` 311` hoelzl@39076 ` 312` ```lemma bij_def: "bij f \ inj f \ surj f" ``` hoelzl@40702 ` 313` ``` unfolding bij_betw_def .. ``` hoelzl@39074 ` 314` paulson@13585 ` 315` ```lemma bijI: "[| inj f; surj f |] ==> bij f" ``` paulson@13585 ` 316` ```by (simp add: bij_def) ``` paulson@13585 ` 317` paulson@13585 ` 318` ```lemma bij_is_inj: "bij f ==> inj f" ``` paulson@13585 ` 319` ```by (simp add: bij_def) ``` paulson@13585 ` 320` paulson@13585 ` 321` ```lemma bij_is_surj: "bij f ==> surj f" ``` paulson@13585 ` 322` ```by (simp add: bij_def) ``` paulson@13585 ` 323` nipkow@26105 ` 324` ```lemma bij_betw_imp_inj_on: "bij_betw f A B \ inj_on f A" ``` nipkow@26105 ` 325` ```by (simp add: bij_betw_def) ``` nipkow@26105 ` 326` nipkow@31438 ` 327` ```lemma bij_betw_trans: ``` nipkow@31438 ` 328` ``` "bij_betw f A B \ bij_betw g B C \ bij_betw (g o f) A C" ``` nipkow@31438 ` 329` ```by(auto simp add:bij_betw_def comp_inj_on) ``` nipkow@31438 ` 330` hoelzl@40702 ` 331` ```lemma bij_comp: "bij f \ bij g \ bij (g o f)" ``` hoelzl@40702 ` 332` ``` by (rule bij_betw_trans) ``` hoelzl@40702 ` 333` hoelzl@40703 ` 334` ```lemma bij_betw_comp_iff: ``` hoelzl@40703 ` 335` ``` "bij_betw f A A' \ bij_betw f' A' A'' \ bij_betw (f' o f) A A''" ``` hoelzl@40703 ` 336` ```by(auto simp add: bij_betw_def inj_on_def) ``` hoelzl@40703 ` 337` hoelzl@40703 ` 338` ```lemma bij_betw_comp_iff2: ``` hoelzl@40703 ` 339` ``` assumes BIJ: "bij_betw f' A' A''" and IM: "f ` A \ A'" ``` hoelzl@40703 ` 340` ``` shows "bij_betw f A A' \ bij_betw (f' o f) A A''" ``` hoelzl@40703 ` 341` ```using assms ``` hoelzl@40703 ` 342` ```proof(auto simp add: bij_betw_comp_iff) ``` hoelzl@40703 ` 343` ``` assume *: "bij_betw (f' \ f) A A''" ``` hoelzl@40703 ` 344` ``` thus "bij_betw f A A'" ``` hoelzl@40703 ` 345` ``` using IM ``` hoelzl@40703 ` 346` ``` proof(auto simp add: bij_betw_def) ``` hoelzl@40703 ` 347` ``` assume "inj_on (f' \ f) A" ``` hoelzl@40703 ` 348` ``` thus "inj_on f A" using inj_on_imageI2 by blast ``` hoelzl@40703 ` 349` ``` next ``` hoelzl@40703 ` 350` ``` fix a' assume **: "a' \ A'" ``` hoelzl@40703 ` 351` ``` hence "f' a' \ A''" using BIJ unfolding bij_betw_def by auto ``` hoelzl@40703 ` 352` ``` then obtain a where 1: "a \ A \ f'(f a) = f' a'" using * ``` hoelzl@40703 ` 353` ``` unfolding bij_betw_def by force ``` hoelzl@40703 ` 354` ``` hence "f a \ A'" using IM by auto ``` hoelzl@40703 ` 355` ``` hence "f a = a'" using BIJ ** 1 unfolding bij_betw_def inj_on_def by auto ``` hoelzl@40703 ` 356` ``` thus "a' \ f ` A" using 1 by auto ``` hoelzl@40703 ` 357` ``` qed ``` hoelzl@40703 ` 358` ```qed ``` hoelzl@40703 ` 359` nipkow@26105 ` 360` ```lemma bij_betw_inv: assumes "bij_betw f A B" shows "EX g. bij_betw g B A" ``` nipkow@26105 ` 361` ```proof - ``` nipkow@26105 ` 362` ``` have i: "inj_on f A" and s: "f ` A = B" ``` nipkow@26105 ` 363` ``` using assms by(auto simp:bij_betw_def) ``` nipkow@26105 ` 364` ``` let ?P = "%b a. a:A \ f a = b" let ?g = "%b. The (?P b)" ``` nipkow@26105 ` 365` ``` { fix a b assume P: "?P b a" ``` nipkow@26105 ` 366` ``` hence ex1: "\a. ?P b a" using s unfolding image_def by blast ``` nipkow@26105 ` 367` ``` hence uex1: "\!a. ?P b a" by(blast dest:inj_onD[OF i]) ``` nipkow@26105 ` 368` ``` hence " ?g b = a" using the1_equality[OF uex1, OF P] P by simp ``` nipkow@26105 ` 369` ``` } note g = this ``` nipkow@26105 ` 370` ``` have "inj_on ?g B" ``` nipkow@26105 ` 371` ``` proof(rule inj_onI) ``` nipkow@26105 ` 372` ``` fix x y assume "x:B" "y:B" "?g x = ?g y" ``` nipkow@26105 ` 373` ``` from s `x:B` obtain a1 where a1: "?P x a1" unfolding image_def by blast ``` nipkow@26105 ` 374` ``` from s `y:B` obtain a2 where a2: "?P y a2" unfolding image_def by blast ``` nipkow@26105 ` 375` ``` from g[OF a1] a1 g[OF a2] a2 `?g x = ?g y` show "x=y" by simp ``` nipkow@26105 ` 376` ``` qed ``` nipkow@26105 ` 377` ``` moreover have "?g ` B = A" ``` nipkow@26105 ` 378` ``` proof(auto simp:image_def) ``` nipkow@26105 ` 379` ``` fix b assume "b:B" ``` nipkow@26105 ` 380` ``` with s obtain a where P: "?P b a" unfolding image_def by blast ``` nipkow@26105 ` 381` ``` thus "?g b \ A" using g[OF P] by auto ``` nipkow@26105 ` 382` ``` next ``` nipkow@26105 ` 383` ``` fix a assume "a:A" ``` nipkow@26105 ` 384` ``` then obtain b where P: "?P b a" using s unfolding image_def by blast ``` nipkow@26105 ` 385` ``` then have "b:B" using s unfolding image_def by blast ``` nipkow@26105 ` 386` ``` with g[OF P] show "\b\B. a = ?g b" by blast ``` nipkow@26105 ` 387` ``` qed ``` nipkow@26105 ` 388` ``` ultimately show ?thesis by(auto simp:bij_betw_def) ``` nipkow@26105 ` 389` ```qed ``` nipkow@26105 ` 390` hoelzl@40703 ` 391` ```lemma bij_betw_cong: ``` hoelzl@40703 ` 392` ``` "(\ a. a \ A \ f a = g a) \ bij_betw f A A' = bij_betw g A A'" ``` hoelzl@40703 ` 393` ```unfolding bij_betw_def inj_on_def by force ``` hoelzl@40703 ` 394` hoelzl@40703 ` 395` ```lemma bij_betw_id[intro, simp]: ``` hoelzl@40703 ` 396` ``` "bij_betw id A A" ``` hoelzl@40703 ` 397` ```unfolding bij_betw_def id_def by auto ``` hoelzl@40703 ` 398` hoelzl@40703 ` 399` ```lemma bij_betw_id_iff: ``` hoelzl@40703 ` 400` ``` "bij_betw id A B \ A = B" ``` hoelzl@40703 ` 401` ```by(auto simp add: bij_betw_def) ``` hoelzl@40703 ` 402` hoelzl@39075 ` 403` ```lemma bij_betw_combine: ``` hoelzl@39075 ` 404` ``` assumes "bij_betw f A B" "bij_betw f C D" "B \ D = {}" ``` hoelzl@39075 ` 405` ``` shows "bij_betw f (A \ C) (B \ D)" ``` hoelzl@39075 ` 406` ``` using assms unfolding bij_betw_def inj_on_Un image_Un by auto ``` hoelzl@39075 ` 407` hoelzl@40703 ` 408` ```lemma bij_betw_UNION_chain: ``` hoelzl@40703 ` 409` ``` assumes CH: "\ i j. \i \ I; j \ I\ \ A i \ A j \ A j \ A i" and ``` hoelzl@40703 ` 410` ``` BIJ: "\ i. i \ I \ bij_betw f (A i) (A' i)" ``` hoelzl@40703 ` 411` ``` shows "bij_betw f (\ i \ I. A i) (\ i \ I. A' i)" ``` hoelzl@40703 ` 412` ```proof(unfold bij_betw_def, auto simp add: image_def) ``` hoelzl@40703 ` 413` ``` have "\ i. i \ I \ inj_on f (A i)" ``` hoelzl@40703 ` 414` ``` using BIJ bij_betw_def[of f] by auto ``` hoelzl@40703 ` 415` ``` thus "inj_on f (\ i \ I. A i)" ``` hoelzl@40703 ` 416` ``` using CH inj_on_UNION_chain[of I A f] by auto ``` hoelzl@40703 ` 417` ```next ``` hoelzl@40703 ` 418` ``` fix i x ``` hoelzl@40703 ` 419` ``` assume *: "i \ I" "x \ A i" ``` hoelzl@40703 ` 420` ``` hence "f x \ A' i" using BIJ bij_betw_def[of f] by auto ``` hoelzl@40703 ` 421` ``` thus "\j \ I. f x \ A' j" using * by blast ``` hoelzl@40703 ` 422` ```next ``` hoelzl@40703 ` 423` ``` fix i x' ``` hoelzl@40703 ` 424` ``` assume *: "i \ I" "x' \ A' i" ``` hoelzl@40703 ` 425` ``` hence "\x \ A i. x' = f x" using BIJ bij_betw_def[of f] by blast ``` hoelzl@40703 ` 426` ``` thus "\j \ I. \x \ A j. x' = f x" ``` hoelzl@40703 ` 427` ``` using * by blast ``` hoelzl@40703 ` 428` ```qed ``` hoelzl@40703 ` 429` hoelzl@40703 ` 430` ```lemma bij_betw_Disj_Un: ``` hoelzl@40703 ` 431` ``` assumes DISJ: "A \ B = {}" and DISJ': "A' \ B' = {}" and ``` hoelzl@40703 ` 432` ``` B1: "bij_betw f A A'" and B2: "bij_betw f B B'" ``` hoelzl@40703 ` 433` ``` shows "bij_betw f (A \ B) (A' \ B')" ``` hoelzl@40703 ` 434` ```proof- ``` hoelzl@40703 ` 435` ``` have 1: "inj_on f A \ inj_on f B" ``` hoelzl@40703 ` 436` ``` using B1 B2 by (auto simp add: bij_betw_def) ``` hoelzl@40703 ` 437` ``` have 2: "f`A = A' \ f`B = B'" ``` hoelzl@40703 ` 438` ``` using B1 B2 by (auto simp add: bij_betw_def) ``` hoelzl@40703 ` 439` ``` hence "f`(A - B) \ f`(B - A) = {}" ``` hoelzl@40703 ` 440` ``` using DISJ DISJ' by blast ``` hoelzl@40703 ` 441` ``` hence "inj_on f (A \ B)" ``` hoelzl@40703 ` 442` ``` using 1 by (auto simp add: inj_on_Un) ``` hoelzl@40703 ` 443` ``` (* *) ``` hoelzl@40703 ` 444` ``` moreover ``` hoelzl@40703 ` 445` ``` have "f`(A \ B) = A' \ B'" ``` hoelzl@40703 ` 446` ``` using 2 by auto ``` hoelzl@40703 ` 447` ``` ultimately show ?thesis ``` hoelzl@40703 ` 448` ``` unfolding bij_betw_def by auto ``` hoelzl@40703 ` 449` ```qed ``` hoelzl@40703 ` 450` hoelzl@40703 ` 451` ```lemma bij_betw_subset: ``` hoelzl@40703 ` 452` ``` assumes BIJ: "bij_betw f A A'" and ``` hoelzl@40703 ` 453` ``` SUB: "B \ A" and IM: "f ` B = B'" ``` hoelzl@40703 ` 454` ``` shows "bij_betw f B B'" ``` hoelzl@40703 ` 455` ```using assms ``` hoelzl@40703 ` 456` ```by(unfold bij_betw_def inj_on_def, auto simp add: inj_on_def) ``` hoelzl@40703 ` 457` paulson@13585 ` 458` ```lemma surj_image_vimage_eq: "surj f ==> f ` (f -` A) = A" ``` hoelzl@40702 ` 459` ```by simp ``` paulson@13585 ` 460` hoelzl@42903 ` 461` ```lemma surj_vimage_empty: ``` hoelzl@42903 ` 462` ``` assumes "surj f" shows "f -` A = {} \ A = {}" ``` hoelzl@42903 ` 463` ``` using surj_image_vimage_eq[OF `surj f`, of A] ``` nipkow@44890 ` 464` ``` by (intro iffI) fastforce+ ``` hoelzl@42903 ` 465` paulson@13585 ` 466` ```lemma inj_vimage_image_eq: "inj f ==> f -` (f ` A) = A" ``` paulson@13585 ` 467` ```by (simp add: inj_on_def, blast) ``` paulson@13585 ` 468` paulson@13585 ` 469` ```lemma vimage_subsetD: "surj f ==> f -` B <= A ==> B <= f ` A" ``` hoelzl@40702 ` 470` ```by (blast intro: sym) ``` paulson@13585 ` 471` paulson@13585 ` 472` ```lemma vimage_subsetI: "inj f ==> B <= f ` A ==> f -` B <= A" ``` paulson@13585 ` 473` ```by (unfold inj_on_def, blast) ``` paulson@13585 ` 474` paulson@13585 ` 475` ```lemma vimage_subset_eq: "bij f ==> (f -` B <= A) = (B <= f ` A)" ``` paulson@13585 ` 476` ```apply (unfold bij_def) ``` paulson@13585 ` 477` ```apply (blast del: subsetI intro: vimage_subsetI vimage_subsetD) ``` paulson@13585 ` 478` ```done ``` paulson@13585 ` 479` nipkow@31438 ` 480` ```lemma inj_on_Un_image_eq_iff: "inj_on f (A \ B) \ f ` A = f ` B \ A = B" ``` nipkow@31438 ` 481` ```by(blast dest: inj_onD) ``` nipkow@31438 ` 482` paulson@13585 ` 483` ```lemma inj_on_image_Int: ``` paulson@13585 ` 484` ``` "[| inj_on f C; A<=C; B<=C |] ==> f`(A Int B) = f`A Int f`B" ``` paulson@13585 ` 485` ```apply (simp add: inj_on_def, blast) ``` paulson@13585 ` 486` ```done ``` paulson@13585 ` 487` paulson@13585 ` 488` ```lemma inj_on_image_set_diff: ``` paulson@13585 ` 489` ``` "[| inj_on f C; A<=C; B<=C |] ==> f`(A-B) = f`A - f`B" ``` paulson@13585 ` 490` ```apply (simp add: inj_on_def, blast) ``` paulson@13585 ` 491` ```done ``` paulson@13585 ` 492` paulson@13585 ` 493` ```lemma image_Int: "inj f ==> f`(A Int B) = f`A Int f`B" ``` paulson@13585 ` 494` ```by (simp add: inj_on_def, blast) ``` paulson@13585 ` 495` paulson@13585 ` 496` ```lemma image_set_diff: "inj f ==> f`(A-B) = f`A - f`B" ``` paulson@13585 ` 497` ```by (simp add: inj_on_def, blast) ``` paulson@13585 ` 498` paulson@13585 ` 499` ```lemma inj_image_mem_iff: "inj f ==> (f a : f`A) = (a : A)" ``` paulson@13585 ` 500` ```by (blast dest: injD) ``` paulson@13585 ` 501` paulson@13585 ` 502` ```lemma inj_image_subset_iff: "inj f ==> (f`A <= f`B) = (A<=B)" ``` paulson@13585 ` 503` ```by (simp add: inj_on_def, blast) ``` paulson@13585 ` 504` paulson@13585 ` 505` ```lemma inj_image_eq_iff: "inj f ==> (f`A = f`B) = (A = B)" ``` paulson@13585 ` 506` ```by (blast dest: injD) ``` paulson@13585 ` 507` paulson@13585 ` 508` ```(*injectivity's required. Left-to-right inclusion holds even if A is empty*) ``` paulson@13585 ` 509` ```lemma image_INT: ``` paulson@13585 ` 510` ``` "[| inj_on f C; ALL x:A. B x <= C; j:A |] ``` paulson@13585 ` 511` ``` ==> f ` (INTER A B) = (INT x:A. f ` B x)" ``` paulson@13585 ` 512` ```apply (simp add: inj_on_def, blast) ``` paulson@13585 ` 513` ```done ``` paulson@13585 ` 514` paulson@13585 ` 515` ```(*Compare with image_INT: no use of inj_on, and if f is surjective then ``` paulson@13585 ` 516` ``` it doesn't matter whether A is empty*) ``` paulson@13585 ` 517` ```lemma bij_image_INT: "bij f ==> f ` (INTER A B) = (INT x:A. f ` B x)" ``` paulson@13585 ` 518` ```apply (simp add: bij_def) ``` paulson@13585 ` 519` ```apply (simp add: inj_on_def surj_def, blast) ``` paulson@13585 ` 520` ```done ``` paulson@13585 ` 521` paulson@13585 ` 522` ```lemma surj_Compl_image_subset: "surj f ==> -(f`A) <= f`(-A)" ``` hoelzl@40702 ` 523` ```by auto ``` paulson@13585 ` 524` paulson@13585 ` 525` ```lemma inj_image_Compl_subset: "inj f ==> f`(-A) <= -(f`A)" ``` paulson@13585 ` 526` ```by (auto simp add: inj_on_def) ``` paulson@5852 ` 527` paulson@13585 ` 528` ```lemma bij_image_Compl_eq: "bij f ==> f`(-A) = -(f`A)" ``` paulson@13585 ` 529` ```apply (simp add: bij_def) ``` paulson@13585 ` 530` ```apply (rule equalityI) ``` paulson@13585 ` 531` ```apply (simp_all (no_asm_simp) add: inj_image_Compl_subset surj_Compl_image_subset) ``` paulson@13585 ` 532` ```done ``` paulson@13585 ` 533` haftmann@41657 ` 534` ```lemma inj_vimage_singleton: "inj f \ f -` {a} \ {THE x. f x = a}" ``` haftmann@41657 ` 535` ``` -- {* The inverse image of a singleton under an injective function ``` haftmann@41657 ` 536` ``` is included in a singleton. *} ``` haftmann@41657 ` 537` ``` apply (auto simp add: inj_on_def) ``` haftmann@41657 ` 538` ``` apply (blast intro: the_equality [symmetric]) ``` haftmann@41657 ` 539` ``` done ``` haftmann@41657 ` 540` hoelzl@43991 ` 541` ```lemma inj_on_vimage_singleton: ``` hoelzl@43991 ` 542` ``` "inj_on f A \ f -` {a} \ A \ {THE x. x \ A \ f x = a}" ``` hoelzl@43991 ` 543` ``` by (auto simp add: inj_on_def intro: the_equality [symmetric]) ``` hoelzl@43991 ` 544` hoelzl@35584 ` 545` ```lemma (in ordered_ab_group_add) inj_uminus[simp, intro]: "inj_on uminus A" ``` hoelzl@35580 ` 546` ``` by (auto intro!: inj_onI) ``` paulson@13585 ` 547` hoelzl@35584 ` 548` ```lemma (in linorder) strict_mono_imp_inj_on: "strict_mono f \ inj_on f A" ``` hoelzl@35584 ` 549` ``` by (auto intro!: inj_onI dest: strict_mono_eq) ``` hoelzl@35584 ` 550` haftmann@41657 ` 551` paulson@13585 ` 552` ```subsection{*Function Updating*} ``` paulson@13585 ` 553` haftmann@44277 ` 554` ```definition fun_upd :: "('a => 'b) => 'a => 'b => ('a => 'b)" where ``` haftmann@26147 ` 555` ``` "fun_upd f a b == % x. if x=a then b else f x" ``` haftmann@26147 ` 556` wenzelm@41229 ` 557` ```nonterminal updbinds and updbind ``` wenzelm@41229 ` 558` haftmann@26147 ` 559` ```syntax ``` haftmann@26147 ` 560` ``` "_updbind" :: "['a, 'a] => updbind" ("(2_ :=/ _)") ``` haftmann@26147 ` 561` ``` "" :: "updbind => updbinds" ("_") ``` haftmann@26147 ` 562` ``` "_updbinds":: "[updbind, updbinds] => updbinds" ("_,/ _") ``` wenzelm@35115 ` 563` ``` "_Update" :: "['a, updbinds] => 'a" ("_/'((_)')" [1000, 0] 900) ``` haftmann@26147 ` 564` haftmann@26147 ` 565` ```translations ``` wenzelm@35115 ` 566` ``` "_Update f (_updbinds b bs)" == "_Update (_Update f b) bs" ``` wenzelm@35115 ` 567` ``` "f(x:=y)" == "CONST fun_upd f x y" ``` haftmann@26147 ` 568` haftmann@26147 ` 569` ```(* Hint: to define the sum of two functions (or maps), use sum_case. ``` haftmann@26147 ` 570` ``` A nice infix syntax could be defined (in Datatype.thy or below) by ``` wenzelm@35115 ` 571` ```notation ``` wenzelm@35115 ` 572` ``` sum_case (infixr "'(+')"80) ``` haftmann@26147 ` 573` ```*) ``` haftmann@26147 ` 574` paulson@13585 ` 575` ```lemma fun_upd_idem_iff: "(f(x:=y) = f) = (f x = y)" ``` paulson@13585 ` 576` ```apply (simp add: fun_upd_def, safe) ``` paulson@13585 ` 577` ```apply (erule subst) ``` paulson@13585 ` 578` ```apply (rule_tac [2] ext, auto) ``` paulson@13585 ` 579` ```done ``` paulson@13585 ` 580` wenzelm@45603 ` 581` ```lemma fun_upd_idem: "f x = y ==> f(x:=y) = f" ``` wenzelm@45603 ` 582` ``` by (simp only: fun_upd_idem_iff) ``` paulson@13585 ` 583` wenzelm@45603 ` 584` ```lemma fun_upd_triv [iff]: "f(x := f x) = f" ``` wenzelm@45603 ` 585` ``` by (simp only: fun_upd_idem) ``` paulson@13585 ` 586` paulson@13585 ` 587` ```lemma fun_upd_apply [simp]: "(f(x:=y))z = (if z=x then y else f z)" ``` paulson@17084 ` 588` ```by (simp add: fun_upd_def) ``` paulson@13585 ` 589` paulson@13585 ` 590` ```(* fun_upd_apply supersedes these two, but they are useful ``` paulson@13585 ` 591` ``` if fun_upd_apply is intentionally removed from the simpset *) ``` paulson@13585 ` 592` ```lemma fun_upd_same: "(f(x:=y)) x = y" ``` paulson@13585 ` 593` ```by simp ``` paulson@13585 ` 594` paulson@13585 ` 595` ```lemma fun_upd_other: "z~=x ==> (f(x:=y)) z = f z" ``` paulson@13585 ` 596` ```by simp ``` paulson@13585 ` 597` paulson@13585 ` 598` ```lemma fun_upd_upd [simp]: "f(x:=y,x:=z) = f(x:=z)" ``` nipkow@39302 ` 599` ```by (simp add: fun_eq_iff) ``` paulson@13585 ` 600` paulson@13585 ` 601` ```lemma fun_upd_twist: "a ~= c ==> (m(a:=b))(c:=d) = (m(c:=d))(a:=b)" ``` paulson@13585 ` 602` ```by (rule ext, auto) ``` paulson@13585 ` 603` nipkow@15303 ` 604` ```lemma inj_on_fun_updI: "\ inj_on f A; y \ f`A \ \ inj_on (f(x:=y)) A" ``` nipkow@44890 ` 605` ```by (fastforce simp:inj_on_def image_def) ``` nipkow@15303 ` 606` paulson@15510 ` 607` ```lemma fun_upd_image: ``` paulson@15510 ` 608` ``` "f(x:=y) ` A = (if x \ A then insert y (f ` (A-{x})) else f ` A)" ``` paulson@15510 ` 609` ```by auto ``` paulson@15510 ` 610` nipkow@31080 ` 611` ```lemma fun_upd_comp: "f \ (g(x := y)) = (f \ g)(x := f y)" ``` huffman@44921 ` 612` ``` by auto ``` nipkow@31080 ` 613` nipkow@44744 ` 614` ```lemma UNION_fun_upd: ``` nipkow@44744 ` 615` ``` "UNION J (A(i:=B)) = (UNION (J-{i}) A \ (if i\J then B else {}))" ``` nipkow@44744 ` 616` ```by (auto split: if_splits) ``` nipkow@44744 ` 617` haftmann@26147 ` 618` haftmann@26147 ` 619` ```subsection {* @{text override_on} *} ``` haftmann@26147 ` 620` haftmann@44277 ` 621` ```definition override_on :: "('a \ 'b) \ ('a \ 'b) \ 'a set \ 'a \ 'b" where ``` haftmann@26147 ` 622` ``` "override_on f g A = (\a. if a \ A then g a else f a)" ``` nipkow@13910 ` 623` nipkow@15691 ` 624` ```lemma override_on_emptyset[simp]: "override_on f g {} = f" ``` nipkow@15691 ` 625` ```by(simp add:override_on_def) ``` nipkow@13910 ` 626` nipkow@15691 ` 627` ```lemma override_on_apply_notin[simp]: "a ~: A ==> (override_on f g A) a = f a" ``` nipkow@15691 ` 628` ```by(simp add:override_on_def) ``` nipkow@13910 ` 629` nipkow@15691 ` 630` ```lemma override_on_apply_in[simp]: "a : A ==> (override_on f g A) a = g a" ``` nipkow@15691 ` 631` ```by(simp add:override_on_def) ``` nipkow@13910 ` 632` haftmann@26147 ` 633` haftmann@26147 ` 634` ```subsection {* @{text swap} *} ``` paulson@15510 ` 635` haftmann@44277 ` 636` ```definition swap :: "'a \ 'a \ ('a \ 'b) \ ('a \ 'b)" where ``` haftmann@22744 ` 637` ``` "swap a b f = f (a := f b, b:= f a)" ``` paulson@15510 ` 638` huffman@34101 ` 639` ```lemma swap_self [simp]: "swap a a f = f" ``` nipkow@15691 ` 640` ```by (simp add: swap_def) ``` paulson@15510 ` 641` paulson@15510 ` 642` ```lemma swap_commute: "swap a b f = swap b a f" ``` paulson@15510 ` 643` ```by (rule ext, simp add: fun_upd_def swap_def) ``` paulson@15510 ` 644` paulson@15510 ` 645` ```lemma swap_nilpotent [simp]: "swap a b (swap a b f) = f" ``` paulson@15510 ` 646` ```by (rule ext, simp add: fun_upd_def swap_def) ``` paulson@15510 ` 647` huffman@34145 ` 648` ```lemma swap_triple: ``` huffman@34145 ` 649` ``` assumes "a \ c" and "b \ c" ``` huffman@34145 ` 650` ``` shows "swap a b (swap b c (swap a b f)) = swap a c f" ``` nipkow@39302 ` 651` ``` using assms by (simp add: fun_eq_iff swap_def) ``` huffman@34145 ` 652` huffman@34101 ` 653` ```lemma comp_swap: "f \ swap a b g = swap a b (f \ g)" ``` huffman@34101 ` 654` ```by (rule ext, simp add: fun_upd_def swap_def) ``` huffman@34101 ` 655` hoelzl@39076 ` 656` ```lemma swap_image_eq [simp]: ``` hoelzl@39076 ` 657` ``` assumes "a \ A" "b \ A" shows "swap a b f ` A = f ` A" ``` hoelzl@39076 ` 658` ```proof - ``` hoelzl@39076 ` 659` ``` have subset: "\f. swap a b f ` A \ f ` A" ``` hoelzl@39076 ` 660` ``` using assms by (auto simp: image_iff swap_def) ``` hoelzl@39076 ` 661` ``` then have "swap a b (swap a b f) ` A \ (swap a b f) ` A" . ``` hoelzl@39076 ` 662` ``` with subset[of f] show ?thesis by auto ``` hoelzl@39076 ` 663` ```qed ``` hoelzl@39076 ` 664` paulson@15510 ` 665` ```lemma inj_on_imp_inj_on_swap: ``` hoelzl@39076 ` 666` ``` "\inj_on f A; a \ A; b \ A\ \ inj_on (swap a b f) A" ``` hoelzl@39076 ` 667` ``` by (simp add: inj_on_def swap_def, blast) ``` paulson@15510 ` 668` paulson@15510 ` 669` ```lemma inj_on_swap_iff [simp]: ``` hoelzl@39076 ` 670` ``` assumes A: "a \ A" "b \ A" shows "inj_on (swap a b f) A \ inj_on f A" ``` hoelzl@39075 ` 671` ```proof ``` paulson@15510 ` 672` ``` assume "inj_on (swap a b f) A" ``` hoelzl@39075 ` 673` ``` with A have "inj_on (swap a b (swap a b f)) A" ``` hoelzl@39075 ` 674` ``` by (iprover intro: inj_on_imp_inj_on_swap) ``` hoelzl@39075 ` 675` ``` thus "inj_on f A" by simp ``` paulson@15510 ` 676` ```next ``` paulson@15510 ` 677` ``` assume "inj_on f A" ``` krauss@34209 ` 678` ``` with A show "inj_on (swap a b f) A" by (iprover intro: inj_on_imp_inj_on_swap) ``` paulson@15510 ` 679` ```qed ``` paulson@15510 ` 680` hoelzl@39076 ` 681` ```lemma surj_imp_surj_swap: "surj f \ surj (swap a b f)" ``` hoelzl@40702 ` 682` ``` by simp ``` paulson@15510 ` 683` hoelzl@39076 ` 684` ```lemma surj_swap_iff [simp]: "surj (swap a b f) \ surj f" ``` hoelzl@40702 ` 685` ``` by simp ``` haftmann@21547 ` 686` hoelzl@39076 ` 687` ```lemma bij_betw_swap_iff [simp]: ``` hoelzl@39076 ` 688` ``` "\ x \ A; y \ A \ \ bij_betw (swap x y f) A B \ bij_betw f A B" ``` hoelzl@39076 ` 689` ``` by (auto simp: bij_betw_def) ``` hoelzl@39076 ` 690` hoelzl@39076 ` 691` ```lemma bij_swap_iff [simp]: "bij (swap a b f) \ bij f" ``` hoelzl@39076 ` 692` ``` by simp ``` hoelzl@39075 ` 693` wenzelm@36176 ` 694` ```hide_const (open) swap ``` haftmann@21547 ` 695` haftmann@31949 ` 696` ```subsection {* Inversion of injective functions *} ``` haftmann@31949 ` 697` nipkow@33057 ` 698` ```definition the_inv_into :: "'a set => ('a => 'b) => ('b => 'a)" where ``` haftmann@44277 ` 699` ``` "the_inv_into A f == %x. THE y. y : A & f y = x" ``` nipkow@32961 ` 700` nipkow@33057 ` 701` ```lemma the_inv_into_f_f: ``` nipkow@33057 ` 702` ``` "[| inj_on f A; x : A |] ==> the_inv_into A f (f x) = x" ``` nipkow@33057 ` 703` ```apply (simp add: the_inv_into_def inj_on_def) ``` krauss@34209 ` 704` ```apply blast ``` nipkow@32961 ` 705` ```done ``` nipkow@32961 ` 706` nipkow@33057 ` 707` ```lemma f_the_inv_into_f: ``` nipkow@33057 ` 708` ``` "inj_on f A ==> y : f`A ==> f (the_inv_into A f y) = y" ``` nipkow@33057 ` 709` ```apply (simp add: the_inv_into_def) ``` nipkow@32961 ` 710` ```apply (rule the1I2) ``` nipkow@32961 ` 711` ``` apply(blast dest: inj_onD) ``` nipkow@32961 ` 712` ```apply blast ``` nipkow@32961 ` 713` ```done ``` nipkow@32961 ` 714` nipkow@33057 ` 715` ```lemma the_inv_into_into: ``` nipkow@33057 ` 716` ``` "[| inj_on f A; x : f ` A; A <= B |] ==> the_inv_into A f x : B" ``` nipkow@33057 ` 717` ```apply (simp add: the_inv_into_def) ``` nipkow@32961 ` 718` ```apply (rule the1I2) ``` nipkow@32961 ` 719` ``` apply(blast dest: inj_onD) ``` nipkow@32961 ` 720` ```apply blast ``` nipkow@32961 ` 721` ```done ``` nipkow@32961 ` 722` nipkow@33057 ` 723` ```lemma the_inv_into_onto[simp]: ``` nipkow@33057 ` 724` ``` "inj_on f A ==> the_inv_into A f ` (f ` A) = A" ``` nipkow@33057 ` 725` ```by (fast intro:the_inv_into_into the_inv_into_f_f[symmetric]) ``` nipkow@32961 ` 726` nipkow@33057 ` 727` ```lemma the_inv_into_f_eq: ``` nipkow@33057 ` 728` ``` "[| inj_on f A; f x = y; x : A |] ==> the_inv_into A f y = x" ``` nipkow@32961 ` 729` ``` apply (erule subst) ``` nipkow@33057 ` 730` ``` apply (erule the_inv_into_f_f, assumption) ``` nipkow@32961 ` 731` ``` done ``` nipkow@32961 ` 732` nipkow@33057 ` 733` ```lemma the_inv_into_comp: ``` nipkow@32961 ` 734` ``` "[| inj_on f (g ` A); inj_on g A; x : f ` g ` A |] ==> ``` nipkow@33057 ` 735` ``` the_inv_into A (f o g) x = (the_inv_into A g o the_inv_into (g ` A) f) x" ``` nipkow@33057 ` 736` ```apply (rule the_inv_into_f_eq) ``` nipkow@32961 ` 737` ``` apply (fast intro: comp_inj_on) ``` nipkow@33057 ` 738` ``` apply (simp add: f_the_inv_into_f the_inv_into_into) ``` nipkow@33057 ` 739` ```apply (simp add: the_inv_into_into) ``` nipkow@32961 ` 740` ```done ``` nipkow@32961 ` 741` nipkow@33057 ` 742` ```lemma inj_on_the_inv_into: ``` nipkow@33057 ` 743` ``` "inj_on f A \ inj_on (the_inv_into A f) (f ` A)" ``` nipkow@33057 ` 744` ```by (auto intro: inj_onI simp: image_def the_inv_into_f_f) ``` nipkow@32961 ` 745` nipkow@33057 ` 746` ```lemma bij_betw_the_inv_into: ``` nipkow@33057 ` 747` ``` "bij_betw f A B \ bij_betw (the_inv_into A f) B A" ``` nipkow@33057 ` 748` ```by (auto simp add: bij_betw_def inj_on_the_inv_into the_inv_into_into) ``` nipkow@32961 ` 749` berghofe@32998 ` 750` ```abbreviation the_inv :: "('a \ 'b) \ ('b \ 'a)" where ``` nipkow@33057 ` 751` ``` "the_inv f \ the_inv_into UNIV f" ``` berghofe@32998 ` 752` berghofe@32998 ` 753` ```lemma the_inv_f_f: ``` berghofe@32998 ` 754` ``` assumes "inj f" ``` berghofe@32998 ` 755` ``` shows "the_inv f (f x) = x" using assms UNIV_I ``` nipkow@33057 ` 756` ``` by (rule the_inv_into_f_f) ``` berghofe@32998 ` 757` haftmann@44277 ` 758` haftmann@44277 ` 759` ```text{*compatibility*} ``` haftmann@44277 ` 760` ```lemmas o_def = comp_def ``` haftmann@44277 ` 761` haftmann@44277 ` 762` hoelzl@40703 ` 763` ```subsection {* Cantor's Paradox *} ``` hoelzl@40703 ` 764` blanchet@42238 ` 765` ```lemma Cantors_paradox [no_atp]: ``` hoelzl@40703 ` 766` ``` "\(\f. f ` A = Pow A)" ``` hoelzl@40703 ` 767` ```proof clarify ``` hoelzl@40703 ` 768` ``` fix f assume "f ` A = Pow A" hence *: "Pow A \ f ` A" by blast ``` hoelzl@40703 ` 769` ``` let ?X = "{a \ A. a \ f a}" ``` hoelzl@40703 ` 770` ``` have "?X \ Pow A" unfolding Pow_def by auto ``` hoelzl@40703 ` 771` ``` with * obtain x where "x \ A \ f x = ?X" by blast ``` hoelzl@40703 ` 772` ``` thus False by best ``` hoelzl@40703 ` 773` ```qed ``` haftmann@31949 ` 774` haftmann@40969 ` 775` ```subsection {* Setup *} ``` haftmann@40969 ` 776` haftmann@40969 ` 777` ```subsubsection {* Proof tools *} ``` haftmann@22845 ` 778` haftmann@22845 ` 779` ```text {* simplifies terms of the form ``` haftmann@22845 ` 780` ``` f(...,x:=y,...,x:=z,...) to f(...,x:=z,...) *} ``` haftmann@22845 ` 781` wenzelm@24017 ` 782` ```simproc_setup fun_upd2 ("f(v := w, x := y)") = {* fn _ => ``` haftmann@22845 ` 783` ```let ``` haftmann@22845 ` 784` ``` fun gen_fun_upd NONE T _ _ = NONE ``` wenzelm@24017 ` 785` ``` | gen_fun_upd (SOME f) T x y = SOME (Const (@{const_name fun_upd}, T) \$ f \$ x \$ y) ``` haftmann@22845 ` 786` ``` fun dest_fun_T1 (Type (_, T :: Ts)) = T ``` haftmann@22845 ` 787` ``` fun find_double (t as Const (@{const_name fun_upd},T) \$ f \$ x \$ y) = ``` haftmann@22845 ` 788` ``` let ``` haftmann@22845 ` 789` ``` fun find (Const (@{const_name fun_upd},T) \$ g \$ v \$ w) = ``` haftmann@22845 ` 790` ``` if v aconv x then SOME g else gen_fun_upd (find g) T v w ``` haftmann@22845 ` 791` ``` | find t = NONE ``` haftmann@22845 ` 792` ``` in (dest_fun_T1 T, gen_fun_upd (find f) T x y) end ``` wenzelm@24017 ` 793` wenzelm@24017 ` 794` ``` fun proc ss ct = ``` wenzelm@24017 ` 795` ``` let ``` wenzelm@24017 ` 796` ``` val ctxt = Simplifier.the_context ss ``` wenzelm@24017 ` 797` ``` val t = Thm.term_of ct ``` wenzelm@24017 ` 798` ``` in ``` wenzelm@24017 ` 799` ``` case find_double t of ``` wenzelm@24017 ` 800` ``` (T, NONE) => NONE ``` wenzelm@24017 ` 801` ``` | (T, SOME rhs) => ``` wenzelm@27330 ` 802` ``` SOME (Goal.prove ctxt [] [] (Logic.mk_equals (t, rhs)) ``` wenzelm@24017 ` 803` ``` (fn _ => ``` wenzelm@24017 ` 804` ``` rtac eq_reflection 1 THEN ``` wenzelm@24017 ` 805` ``` rtac ext 1 THEN ``` wenzelm@24017 ` 806` ``` simp_tac (Simplifier.inherit_context ss @{simpset}) 1)) ``` wenzelm@24017 ` 807` ``` end ``` wenzelm@24017 ` 808` ```in proc end ``` haftmann@22845 ` 809` ```*} ``` haftmann@22845 ` 810` haftmann@22845 ` 811` haftmann@40969 ` 812` ```subsubsection {* Code generator *} ``` haftmann@21870 ` 813` haftmann@21870 ` 814` ```code_const "op \" ``` haftmann@21870 ` 815` ``` (SML infixl 5 "o") ``` haftmann@21870 ` 816` ``` (Haskell infixr 9 ".") ``` haftmann@21870 ` 817` haftmann@21906 ` 818` ```code_const "id" ``` haftmann@21906 ` 819` ``` (Haskell "id") ``` haftmann@21906 ` 820` haftmann@40969 ` 821` haftmann@40969 ` 822` ```subsubsection {* Functorial structure of types *} ``` haftmann@40969 ` 823` haftmann@41505 ` 824` ```use "Tools/enriched_type.ML" ``` haftmann@40969 ` 825` nipkow@2912 ` 826` ```end ```