author | haftmann |
Thu, 02 Jul 2020 12:10:58 +0000 | |
changeset 71989 | bad75618fb82 |
parent 71857 | d73955442df5 |
child 72125 | cf8399df4d76 |
permissions | -rw-r--r-- |
1475 | 1 |
(* Title: HOL/Fun.thy |
2 |
Author: Tobias Nipkow, Cambridge University Computer Laboratory |
|
55019
0d5e831175de
moved lemmas from 'Fun_More_FP' to where they belong
blanchet
parents:
54578
diff
changeset
|
3 |
Author: Andrei Popescu, TU Muenchen |
0d5e831175de
moved lemmas from 'Fun_More_FP' to where they belong
blanchet
parents:
54578
diff
changeset
|
4 |
Copyright 1994, 2012 |
18154 | 5 |
*) |
923 | 6 |
|
60758 | 7 |
section \<open>Notions about functions\<close> |
923 | 8 |
|
15510 | 9 |
theory Fun |
63575 | 10 |
imports Set |
69913 | 11 |
keywords "functor" :: thy_goal_defn |
15131 | 12 |
begin |
2912 | 13 |
|
63322 | 14 |
lemma apply_inverse: "f x = u \<Longrightarrow> (\<And>x. P x \<Longrightarrow> g (f x) = x) \<Longrightarrow> P x \<Longrightarrow> x = g u" |
26147 | 15 |
by auto |
2912 | 16 |
|
63322 | 17 |
text \<open>Uniqueness, so NOT the axiom of choice.\<close> |
59504
8c6747dba731
New lemmas and a bit of tidying up.
paulson <lp15@cam.ac.uk>
parents:
58889
diff
changeset
|
18 |
lemma uniq_choice: "\<forall>x. \<exists>!y. Q x y \<Longrightarrow> \<exists>f. \<forall>x. Q x (f x)" |
8c6747dba731
New lemmas and a bit of tidying up.
paulson <lp15@cam.ac.uk>
parents:
58889
diff
changeset
|
19 |
by (force intro: theI') |
8c6747dba731
New lemmas and a bit of tidying up.
paulson <lp15@cam.ac.uk>
parents:
58889
diff
changeset
|
20 |
|
8c6747dba731
New lemmas and a bit of tidying up.
paulson <lp15@cam.ac.uk>
parents:
58889
diff
changeset
|
21 |
lemma b_uniq_choice: "\<forall>x\<in>S. \<exists>!y. Q x y \<Longrightarrow> \<exists>f. \<forall>x\<in>S. Q x (f x)" |
8c6747dba731
New lemmas and a bit of tidying up.
paulson <lp15@cam.ac.uk>
parents:
58889
diff
changeset
|
22 |
by (force intro: theI') |
12258 | 23 |
|
63400 | 24 |
|
61799 | 25 |
subsection \<open>The Identity Function \<open>id\<close>\<close> |
6171 | 26 |
|
63322 | 27 |
definition id :: "'a \<Rightarrow> 'a" |
28 |
where "id = (\<lambda>x. x)" |
|
13910 | 29 |
|
26147 | 30 |
lemma id_apply [simp]: "id x = x" |
31 |
by (simp add: id_def) |
|
32 |
||
47579 | 33 |
lemma image_id [simp]: "image id = id" |
34 |
by (simp add: id_def fun_eq_iff) |
|
26147 | 35 |
|
47579 | 36 |
lemma vimage_id [simp]: "vimage id = id" |
37 |
by (simp add: id_def fun_eq_iff) |
|
26147 | 38 |
|
62843
313d3b697c9a
Mostly renaming (from HOL Light to Isabelle conventions), with a couple of new results
paulson <lp15@cam.ac.uk>
parents:
62618
diff
changeset
|
39 |
lemma eq_id_iff: "(\<forall>x. f x = x) \<longleftrightarrow> f = id" |
313d3b697c9a
Mostly renaming (from HOL Light to Isabelle conventions), with a couple of new results
paulson <lp15@cam.ac.uk>
parents:
62618
diff
changeset
|
40 |
by auto |
313d3b697c9a
Mostly renaming (from HOL Light to Isabelle conventions), with a couple of new results
paulson <lp15@cam.ac.uk>
parents:
62618
diff
changeset
|
41 |
|
52435
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents:
51717
diff
changeset
|
42 |
code_printing |
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents:
51717
diff
changeset
|
43 |
constant id \<rightharpoonup> (Haskell) "id" |
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents:
51717
diff
changeset
|
44 |
|
26147 | 45 |
|
61799 | 46 |
subsection \<open>The Composition Operator \<open>f \<circ> g\<close>\<close> |
26147 | 47 |
|
61955
e96292f32c3c
former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
wenzelm
parents:
61799
diff
changeset
|
48 |
definition comp :: "('b \<Rightarrow> 'c) \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> 'a \<Rightarrow> 'c" (infixl "\<circ>" 55) |
e96292f32c3c
former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
wenzelm
parents:
61799
diff
changeset
|
49 |
where "f \<circ> g = (\<lambda>x. f (g x))" |
11123 | 50 |
|
61955
e96292f32c3c
former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
wenzelm
parents:
61799
diff
changeset
|
51 |
notation (ASCII) |
e96292f32c3c
former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
wenzelm
parents:
61799
diff
changeset
|
52 |
comp (infixl "o" 55) |
19656
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
wenzelm
parents:
19536
diff
changeset
|
53 |
|
63322 | 54 |
lemma comp_apply [simp]: "(f \<circ> g) x = f (g x)" |
49739 | 55 |
by (simp add: comp_def) |
13585 | 56 |
|
63322 | 57 |
lemma comp_assoc: "(f \<circ> g) \<circ> h = f \<circ> (g \<circ> h)" |
49739 | 58 |
by (simp add: fun_eq_iff) |
13585 | 59 |
|
63322 | 60 |
lemma id_comp [simp]: "id \<circ> g = g" |
49739 | 61 |
by (simp add: fun_eq_iff) |
13585 | 62 |
|
63322 | 63 |
lemma comp_id [simp]: "f \<circ> id = f" |
49739 | 64 |
by (simp add: fun_eq_iff) |
65 |
||
63575 | 66 |
lemma comp_eq_dest: "a \<circ> b = c \<circ> d \<Longrightarrow> a (b v) = c (d v)" |
49739 | 67 |
by (simp add: fun_eq_iff) |
34150 | 68 |
|
63575 | 69 |
lemma comp_eq_elim: "a \<circ> b = c \<circ> d \<Longrightarrow> ((\<And>v. a (b v) = c (d v)) \<Longrightarrow> R) \<Longrightarrow> R" |
61204 | 70 |
by (simp add: fun_eq_iff) |
34150 | 71 |
|
63322 | 72 |
lemma comp_eq_dest_lhs: "a \<circ> b = c \<Longrightarrow> a (b v) = c v" |
55066 | 73 |
by clarsimp |
74 |
||
63322 | 75 |
lemma comp_eq_id_dest: "a \<circ> b = id \<circ> c \<Longrightarrow> a (b v) = c v" |
76 |
by clarsimp |
|
77 |
||
78 |
lemma image_comp: "f ` (g ` r) = (f \<circ> g) ` r" |
|
33044 | 79 |
by auto |
80 |
||
63322 | 81 |
lemma vimage_comp: "f -` (g -` x) = (g \<circ> f) -` x" |
49739 | 82 |
by auto |
83 |
||
63322 | 84 |
lemma image_eq_imp_comp: "f ` A = g ` B \<Longrightarrow> (h \<circ> f) ` A = (h \<circ> g) ` B" |
59504
8c6747dba731
New lemmas and a bit of tidying up.
paulson <lp15@cam.ac.uk>
parents:
58889
diff
changeset
|
85 |
by (auto simp: comp_def elim!: equalityE) |
8c6747dba731
New lemmas and a bit of tidying up.
paulson <lp15@cam.ac.uk>
parents:
58889
diff
changeset
|
86 |
|
67399 | 87 |
lemma image_bind: "f ` (Set.bind A g) = Set.bind A ((`) f \<circ> g)" |
63322 | 88 |
by (auto simp add: Set.bind_def) |
59512 | 89 |
|
90 |
lemma bind_image: "Set.bind (f ` A) g = Set.bind A (g \<circ> f)" |
|
63322 | 91 |
by (auto simp add: Set.bind_def) |
59512 | 92 |
|
63322 | 93 |
lemma (in group_add) minus_comp_minus [simp]: "uminus \<circ> uminus = id" |
60929 | 94 |
by (simp add: fun_eq_iff) |
95 |
||
63322 | 96 |
lemma (in boolean_algebra) minus_comp_minus [simp]: "uminus \<circ> uminus = id" |
60929 | 97 |
by (simp add: fun_eq_iff) |
98 |
||
52435
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents:
51717
diff
changeset
|
99 |
code_printing |
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents:
51717
diff
changeset
|
100 |
constant comp \<rightharpoonup> (SML) infixl 5 "o" and (Haskell) infixr 9 "." |
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents:
51717
diff
changeset
|
101 |
|
13585 | 102 |
|
61799 | 103 |
subsection \<open>The Forward Composition Operator \<open>fcomp\<close>\<close> |
26357 | 104 |
|
63575 | 105 |
definition fcomp :: "('a \<Rightarrow> 'b) \<Rightarrow> ('b \<Rightarrow> 'c) \<Rightarrow> 'a \<Rightarrow> 'c" (infixl "\<circ>>" 60) |
63322 | 106 |
where "f \<circ>> g = (\<lambda>x. g (f x))" |
26357 | 107 |
|
37751 | 108 |
lemma fcomp_apply [simp]: "(f \<circ>> g) x = g (f x)" |
26357 | 109 |
by (simp add: fcomp_def) |
110 |
||
37751 | 111 |
lemma fcomp_assoc: "(f \<circ>> g) \<circ>> h = f \<circ>> (g \<circ>> h)" |
26357 | 112 |
by (simp add: fcomp_def) |
113 |
||
37751 | 114 |
lemma id_fcomp [simp]: "id \<circ>> g = g" |
26357 | 115 |
by (simp add: fcomp_def) |
116 |
||
37751 | 117 |
lemma fcomp_id [simp]: "f \<circ>> id = f" |
26357 | 118 |
by (simp add: fcomp_def) |
119 |
||
63322 | 120 |
lemma fcomp_comp: "fcomp f g = comp g f" |
61699
a81dc5c4d6a9
New theorems mostly from Peter Gammie
paulson <lp15@cam.ac.uk>
parents:
61630
diff
changeset
|
121 |
by (simp add: ext) |
a81dc5c4d6a9
New theorems mostly from Peter Gammie
paulson <lp15@cam.ac.uk>
parents:
61630
diff
changeset
|
122 |
|
52435
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents:
51717
diff
changeset
|
123 |
code_printing |
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents:
51717
diff
changeset
|
124 |
constant fcomp \<rightharpoonup> (Eval) infixl 1 "#>" |
31202
52d332f8f909
pretty printing of functional combinators for evaluation code
haftmann
parents:
31080
diff
changeset
|
125 |
|
37751 | 126 |
no_notation fcomp (infixl "\<circ>>" 60) |
26588
d83271bfaba5
removed syntax from monad combinators; renamed mbind to scomp
haftmann
parents:
26357
diff
changeset
|
127 |
|
26357 | 128 |
|
60758 | 129 |
subsection \<open>Mapping functions\<close> |
40602 | 130 |
|
63322 | 131 |
definition map_fun :: "('c \<Rightarrow> 'a) \<Rightarrow> ('b \<Rightarrow> 'd) \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> 'c \<Rightarrow> 'd" |
132 |
where "map_fun f g h = g \<circ> h \<circ> f" |
|
40602 | 133 |
|
63322 | 134 |
lemma map_fun_apply [simp]: "map_fun f g h x = g (h (f x))" |
40602 | 135 |
by (simp add: map_fun_def) |
136 |
||
137 |
||
60758 | 138 |
subsection \<open>Injectivity and Bijectivity\<close> |
39076
b3a9b6734663
Introduce surj_on and replace surj and bij by abbreviations.
hoelzl
parents:
39075
diff
changeset
|
139 |
|
63322 | 140 |
definition inj_on :: "('a \<Rightarrow> 'b) \<Rightarrow> 'a set \<Rightarrow> bool" \<comment> \<open>injective\<close> |
141 |
where "inj_on f A \<longleftrightarrow> (\<forall>x\<in>A. \<forall>y\<in>A. f x = f y \<longrightarrow> x = y)" |
|
26147 | 142 |
|
63322 | 143 |
definition bij_betw :: "('a \<Rightarrow> 'b) \<Rightarrow> 'a set \<Rightarrow> 'b set \<Rightarrow> bool" \<comment> \<open>bijective\<close> |
144 |
where "bij_betw f A B \<longleftrightarrow> inj_on f A \<and> f ` A = B" |
|
26147 | 145 |
|
63575 | 146 |
text \<open> |
147 |
A common special case: functions injective, surjective or bijective over |
|
148 |
the entire domain type. |
|
149 |
\<close> |
|
26147 | 150 |
|
65170
53675f36820d
restored surj as output abbreviation, amending 6af79184bef3
haftmann
parents:
64966
diff
changeset
|
151 |
abbreviation inj :: "('a \<Rightarrow> 'b) \<Rightarrow> bool" |
53675f36820d
restored surj as output abbreviation, amending 6af79184bef3
haftmann
parents:
64966
diff
changeset
|
152 |
where "inj f \<equiv> inj_on f UNIV" |
26147 | 153 |
|
65170
53675f36820d
restored surj as output abbreviation, amending 6af79184bef3
haftmann
parents:
64966
diff
changeset
|
154 |
abbreviation surj :: "('a \<Rightarrow> 'b) \<Rightarrow> bool" |
63322 | 155 |
where "surj f \<equiv> range f = UNIV" |
13585 | 156 |
|
67226 | 157 |
translations \<comment> \<open>The negated case:\<close> |
65170
53675f36820d
restored surj as output abbreviation, amending 6af79184bef3
haftmann
parents:
64966
diff
changeset
|
158 |
"\<not> CONST surj f" \<leftharpoondown> "CONST range f \<noteq> CONST UNIV" |
53675f36820d
restored surj as output abbreviation, amending 6af79184bef3
haftmann
parents:
64966
diff
changeset
|
159 |
|
53675f36820d
restored surj as output abbreviation, amending 6af79184bef3
haftmann
parents:
64966
diff
changeset
|
160 |
abbreviation bij :: "('a \<Rightarrow> 'b) \<Rightarrow> bool" |
53675f36820d
restored surj as output abbreviation, amending 6af79184bef3
haftmann
parents:
64966
diff
changeset
|
161 |
where "bij f \<equiv> bij_betw f UNIV UNIV" |
26147 | 162 |
|
64966
d53d7ca3303e
added inj_def (redundant, analogous to surj_def, bij_def);
wenzelm
parents:
64965
diff
changeset
|
163 |
lemma inj_def: "inj f \<longleftrightarrow> (\<forall>x y. f x = f y \<longrightarrow> x = y)" |
d53d7ca3303e
added inj_def (redundant, analogous to surj_def, bij_def);
wenzelm
parents:
64965
diff
changeset
|
164 |
unfolding inj_on_def by blast |
d53d7ca3303e
added inj_def (redundant, analogous to surj_def, bij_def);
wenzelm
parents:
64965
diff
changeset
|
165 |
|
63322 | 166 |
lemma injI: "(\<And>x y. f x = f y \<Longrightarrow> x = y) \<Longrightarrow> inj f" |
64966
d53d7ca3303e
added inj_def (redundant, analogous to surj_def, bij_def);
wenzelm
parents:
64965
diff
changeset
|
167 |
unfolding inj_def by blast |
13585 | 168 |
|
63322 | 169 |
theorem range_ex1_eq: "inj f \<Longrightarrow> b \<in> range f \<longleftrightarrow> (\<exists>!x. b = f x)" |
64966
d53d7ca3303e
added inj_def (redundant, analogous to surj_def, bij_def);
wenzelm
parents:
64965
diff
changeset
|
170 |
unfolding inj_def by blast |
40703
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOL-image.
hoelzl
parents:
40702
diff
changeset
|
171 |
|
63322 | 172 |
lemma injD: "inj f \<Longrightarrow> f x = f y \<Longrightarrow> x = y" |
64966
d53d7ca3303e
added inj_def (redundant, analogous to surj_def, bij_def);
wenzelm
parents:
64965
diff
changeset
|
173 |
by (simp add: inj_def) |
63322 | 174 |
|
175 |
lemma inj_on_eq_iff: "inj_on f A \<Longrightarrow> x \<in> A \<Longrightarrow> y \<in> A \<Longrightarrow> f x = f y \<longleftrightarrow> x = y" |
|
64966
d53d7ca3303e
added inj_def (redundant, analogous to surj_def, bij_def);
wenzelm
parents:
64965
diff
changeset
|
176 |
by (auto simp: inj_on_def) |
63322 | 177 |
|
64965 | 178 |
lemma inj_on_cong: "(\<And>a. a \<in> A \<Longrightarrow> f a = g a) \<Longrightarrow> inj_on f A \<longleftrightarrow> inj_on g A" |
64966
d53d7ca3303e
added inj_def (redundant, analogous to surj_def, bij_def);
wenzelm
parents:
64965
diff
changeset
|
179 |
by (auto simp: inj_on_def) |
63322 | 180 |
|
181 |
lemma inj_on_strict_subset: "inj_on f B \<Longrightarrow> A \<subset> B \<Longrightarrow> f ` A \<subset> f ` B" |
|
182 |
unfolding inj_on_def by blast |
|
183 |
||
69700
7a92cbec7030
new material about summations and powers, along with some tweaks
paulson <lp15@cam.ac.uk>
parents:
69661
diff
changeset
|
184 |
lemma inj_compose: "inj f \<Longrightarrow> inj g \<Longrightarrow> inj (f \<circ> g)" |
64966
d53d7ca3303e
added inj_def (redundant, analogous to surj_def, bij_def);
wenzelm
parents:
64965
diff
changeset
|
185 |
by (simp add: inj_def) |
38620 | 186 |
|
187 |
lemma inj_fun: "inj f \<Longrightarrow> inj (\<lambda>x y. f x)" |
|
64966
d53d7ca3303e
added inj_def (redundant, analogous to surj_def, bij_def);
wenzelm
parents:
64965
diff
changeset
|
188 |
by (simp add: inj_def fun_eq_iff) |
38620 | 189 |
|
63322 | 190 |
lemma inj_eq: "inj f \<Longrightarrow> f x = f y \<longleftrightarrow> x = y" |
191 |
by (simp add: inj_on_eq_iff) |
|
32988 | 192 |
|
71827 | 193 |
lemma inj_on_iff_Uniq: "inj_on f A \<longleftrightarrow> (\<forall>x\<in>A. \<exists>\<^sub>\<le>\<^sub>1y. y\<in>A \<and> f x = f y)" |
194 |
by (auto simp: Uniq_def inj_on_def) |
|
195 |
||
26147 | 196 |
lemma inj_on_id[simp]: "inj_on id A" |
39076
b3a9b6734663
Introduce surj_on and replace surj and bij by abbreviations.
hoelzl
parents:
39075
diff
changeset
|
197 |
by (simp add: inj_on_def) |
13585 | 198 |
|
63322 | 199 |
lemma inj_on_id2[simp]: "inj_on (\<lambda>x. x) A" |
200 |
by (simp add: inj_on_def) |
|
26147 | 201 |
|
46586 | 202 |
lemma inj_on_Int: "inj_on f A \<or> inj_on f B \<Longrightarrow> inj_on f (A \<inter> B)" |
63322 | 203 |
unfolding inj_on_def by blast |
40703
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOL-image.
hoelzl
parents:
40702
diff
changeset
|
204 |
|
40702 | 205 |
lemma surj_id: "surj id" |
63322 | 206 |
by simp |
26147 | 207 |
|
39101
606432dd1896
Revert bij_betw changes to simp set (Problem in afp/Ordinals_and_Cardinals)
hoelzl
parents:
39076
diff
changeset
|
208 |
lemma bij_id[simp]: "bij id" |
63322 | 209 |
by (simp add: bij_betw_def) |
13585 | 210 |
|
63322 | 211 |
lemma bij_uminus: "bij (uminus :: 'a \<Rightarrow> 'a::ab_group_add)" |
212 |
unfolding bij_betw_def inj_on_def |
|
213 |
by (force intro: minus_minus [symmetric]) |
|
63072 | 214 |
|
63322 | 215 |
lemma inj_onI [intro?]: "(\<And>x y. x \<in> A \<Longrightarrow> y \<in> A \<Longrightarrow> f x = f y \<Longrightarrow> x = y) \<Longrightarrow> inj_on f A" |
216 |
by (simp add: inj_on_def) |
|
13585 | 217 |
|
63322 | 218 |
lemma inj_on_inverseI: "(\<And>x. x \<in> A \<Longrightarrow> g (f x) = x) \<Longrightarrow> inj_on f A" |
64965 | 219 |
by (auto dest: arg_cong [of concl: g] simp add: inj_on_def) |
13585 | 220 |
|
63322 | 221 |
lemma inj_onD: "inj_on f A \<Longrightarrow> f x = f y \<Longrightarrow> x \<in> A \<Longrightarrow> y \<in> A \<Longrightarrow> x = y" |
222 |
unfolding inj_on_def by blast |
|
13585 | 223 |
|
63365 | 224 |
lemma inj_on_subset: |
225 |
assumes "inj_on f A" |
|
63575 | 226 |
and "B \<subseteq> A" |
63365 | 227 |
shows "inj_on f B" |
228 |
proof (rule inj_onI) |
|
229 |
fix a b |
|
230 |
assume "a \<in> B" and "b \<in> B" |
|
231 |
with assms have "a \<in> A" and "b \<in> A" |
|
232 |
by auto |
|
233 |
moreover assume "f a = f b" |
|
64965 | 234 |
ultimately show "a = b" |
235 |
using assms by (auto dest: inj_onD) |
|
63365 | 236 |
qed |
237 |
||
63322 | 238 |
lemma comp_inj_on: "inj_on f A \<Longrightarrow> inj_on g (f ` A) \<Longrightarrow> inj_on (g \<circ> f) A" |
239 |
by (simp add: comp_def inj_on_def) |
|
240 |
||
241 |
lemma inj_on_imageI: "inj_on (g \<circ> f) A \<Longrightarrow> inj_on g (f ` A)" |
|
63072 | 242 |
by (auto simp add: inj_on_def) |
15303 | 243 |
|
63322 | 244 |
lemma inj_on_image_iff: |
64965 | 245 |
"\<forall>x\<in>A. \<forall>y\<in>A. g (f x) = g (f y) \<longleftrightarrow> g x = g y \<Longrightarrow> inj_on f A \<Longrightarrow> inj_on g (f ` A) \<longleftrightarrow> inj_on g A" |
63322 | 246 |
unfolding inj_on_def by blast |
15439 | 247 |
|
63322 | 248 |
lemma inj_on_contraD: "inj_on f A \<Longrightarrow> x \<noteq> y \<Longrightarrow> x \<in> A \<Longrightarrow> y \<in> A \<Longrightarrow> f x \<noteq> f y" |
249 |
unfolding inj_on_def by blast |
|
12258 | 250 |
|
63072 | 251 |
lemma inj_singleton [simp]: "inj_on (\<lambda>x. {x}) A" |
252 |
by (simp add: inj_on_def) |
|
13585 | 253 |
|
15111 | 254 |
lemma inj_on_empty[iff]: "inj_on f {}" |
63322 | 255 |
by (simp add: inj_on_def) |
13585 | 256 |
|
63322 | 257 |
lemma subset_inj_on: "inj_on f B \<Longrightarrow> A \<subseteq> B \<Longrightarrow> inj_on f A" |
258 |
unfolding inj_on_def by blast |
|
259 |
||
260 |
lemma inj_on_Un: "inj_on f (A \<union> B) \<longleftrightarrow> inj_on f A \<and> inj_on f B \<and> f ` (A - B) \<inter> f ` (B - A) = {}" |
|
261 |
unfolding inj_on_def by (blast intro: sym) |
|
15111 | 262 |
|
63322 | 263 |
lemma inj_on_insert [iff]: "inj_on f (insert a A) \<longleftrightarrow> inj_on f A \<and> f a \<notin> f ` (A - {a})" |
264 |
unfolding inj_on_def by (blast intro: sym) |
|
265 |
||
266 |
lemma inj_on_diff: "inj_on f A \<Longrightarrow> inj_on f (A - B)" |
|
267 |
unfolding inj_on_def by blast |
|
15111 | 268 |
|
63322 | 269 |
lemma comp_inj_on_iff: "inj_on f A \<Longrightarrow> inj_on f' (f ` A) \<longleftrightarrow> inj_on (f' \<circ> f) A" |
64965 | 270 |
by (auto simp: comp_inj_on inj_on_def) |
15111 | 271 |
|
63322 | 272 |
lemma inj_on_imageI2: "inj_on (f' \<circ> f) A \<Longrightarrow> inj_on f A" |
64965 | 273 |
by (auto simp: comp_inj_on inj_on_def) |
40703
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOL-image.
hoelzl
parents:
40702
diff
changeset
|
274 |
|
51598
5dbe537087aa
generalized lemma fold_image thanks to Peter Lammich
haftmann
parents:
49905
diff
changeset
|
275 |
lemma inj_img_insertE: |
5dbe537087aa
generalized lemma fold_image thanks to Peter Lammich
haftmann
parents:
49905
diff
changeset
|
276 |
assumes "inj_on f A" |
63322 | 277 |
assumes "x \<notin> B" |
278 |
and "insert x B = f ` A" |
|
279 |
obtains x' A' where "x' \<notin> A'" and "A = insert x' A'" and "x = f x'" and "B = f ` A'" |
|
51598
5dbe537087aa
generalized lemma fold_image thanks to Peter Lammich
haftmann
parents:
49905
diff
changeset
|
280 |
proof - |
5dbe537087aa
generalized lemma fold_image thanks to Peter Lammich
haftmann
parents:
49905
diff
changeset
|
281 |
from assms have "x \<in> f ` A" by auto |
5dbe537087aa
generalized lemma fold_image thanks to Peter Lammich
haftmann
parents:
49905
diff
changeset
|
282 |
then obtain x' where *: "x' \<in> A" "x = f x'" by auto |
63322 | 283 |
then have A: "A = insert x' (A - {x'})" by auto |
284 |
with assms * have B: "B = f ` (A - {x'})" by (auto dest: inj_on_contraD) |
|
51598
5dbe537087aa
generalized lemma fold_image thanks to Peter Lammich
haftmann
parents:
49905
diff
changeset
|
285 |
have "x' \<notin> A - {x'}" by simp |
63322 | 286 |
from this A \<open>x = f x'\<close> B show ?thesis .. |
51598
5dbe537087aa
generalized lemma fold_image thanks to Peter Lammich
haftmann
parents:
49905
diff
changeset
|
287 |
qed |
5dbe537087aa
generalized lemma fold_image thanks to Peter Lammich
haftmann
parents:
49905
diff
changeset
|
288 |
|
71404
f2b783abfbe7
A few lemmas connected with orderings
paulson <lp15@cam.ac.uk>
parents:
69913
diff
changeset
|
289 |
lemma linorder_inj_onI: |
f2b783abfbe7
A few lemmas connected with orderings
paulson <lp15@cam.ac.uk>
parents:
69913
diff
changeset
|
290 |
fixes A :: "'a::order set" |
f2b783abfbe7
A few lemmas connected with orderings
paulson <lp15@cam.ac.uk>
parents:
69913
diff
changeset
|
291 |
assumes ne: "\<And>x y. \<lbrakk>x < y; x\<in>A; y\<in>A\<rbrakk> \<Longrightarrow> f x \<noteq> f y" and lin: "\<And>x y. \<lbrakk>x\<in>A; y\<in>A\<rbrakk> \<Longrightarrow> x\<le>y \<or> y\<le>x" |
f2b783abfbe7
A few lemmas connected with orderings
paulson <lp15@cam.ac.uk>
parents:
69913
diff
changeset
|
292 |
shows "inj_on f A" |
f2b783abfbe7
A few lemmas connected with orderings
paulson <lp15@cam.ac.uk>
parents:
69913
diff
changeset
|
293 |
proof (rule inj_onI) |
f2b783abfbe7
A few lemmas connected with orderings
paulson <lp15@cam.ac.uk>
parents:
69913
diff
changeset
|
294 |
fix x y |
f2b783abfbe7
A few lemmas connected with orderings
paulson <lp15@cam.ac.uk>
parents:
69913
diff
changeset
|
295 |
assume eq: "f x = f y" and "x\<in>A" "y\<in>A" |
f2b783abfbe7
A few lemmas connected with orderings
paulson <lp15@cam.ac.uk>
parents:
69913
diff
changeset
|
296 |
then show "x = y" |
f2b783abfbe7
A few lemmas connected with orderings
paulson <lp15@cam.ac.uk>
parents:
69913
diff
changeset
|
297 |
using lin [of x y] ne by (force simp: dual_order.order_iff_strict) |
f2b783abfbe7
A few lemmas connected with orderings
paulson <lp15@cam.ac.uk>
parents:
69913
diff
changeset
|
298 |
qed |
f2b783abfbe7
A few lemmas connected with orderings
paulson <lp15@cam.ac.uk>
parents:
69913
diff
changeset
|
299 |
|
54578
9387251b6a46
eliminated dependence of BNF on Infinite_Set by moving 3 theorems from the latter to Main
traytel
parents:
54147
diff
changeset
|
300 |
lemma linorder_injI: |
64965 | 301 |
assumes "\<And>x y::'a::linorder. x < y \<Longrightarrow> f x \<noteq> f y" |
54578
9387251b6a46
eliminated dependence of BNF on Infinite_Set by moving 3 theorems from the latter to Main
traytel
parents:
54147
diff
changeset
|
302 |
shows "inj f" |
71404
f2b783abfbe7
A few lemmas connected with orderings
paulson <lp15@cam.ac.uk>
parents:
69913
diff
changeset
|
303 |
\<comment> \<open>Courtesy of Stephan Merz\<close> |
f2b783abfbe7
A few lemmas connected with orderings
paulson <lp15@cam.ac.uk>
parents:
69913
diff
changeset
|
304 |
using assms by (auto intro: linorder_inj_onI linear) |
69735
8230dca028eb
the theory of Equipollence, and moving Fpow from Cardinals into Main
paulson <lp15@cam.ac.uk>
parents:
69700
diff
changeset
|
305 |
|
8230dca028eb
the theory of Equipollence, and moving Fpow from Cardinals into Main
paulson <lp15@cam.ac.uk>
parents:
69700
diff
changeset
|
306 |
lemma inj_on_image_Pow: "inj_on f A \<Longrightarrow>inj_on (image f) (Pow A)" |
8230dca028eb
the theory of Equipollence, and moving Fpow from Cardinals into Main
paulson <lp15@cam.ac.uk>
parents:
69700
diff
changeset
|
307 |
unfolding Pow_def inj_on_def by blast |
8230dca028eb
the theory of Equipollence, and moving Fpow from Cardinals into Main
paulson <lp15@cam.ac.uk>
parents:
69700
diff
changeset
|
308 |
|
8230dca028eb
the theory of Equipollence, and moving Fpow from Cardinals into Main
paulson <lp15@cam.ac.uk>
parents:
69700
diff
changeset
|
309 |
lemma bij_betw_image_Pow: "bij_betw f A B \<Longrightarrow> bij_betw (image f) (Pow A) (Pow B)" |
8230dca028eb
the theory of Equipollence, and moving Fpow from Cardinals into Main
paulson <lp15@cam.ac.uk>
parents:
69700
diff
changeset
|
310 |
by (auto simp add: bij_betw_def inj_on_image_Pow image_Pow_surj) |
8230dca028eb
the theory of Equipollence, and moving Fpow from Cardinals into Main
paulson <lp15@cam.ac.uk>
parents:
69700
diff
changeset
|
311 |
|
40702 | 312 |
lemma surj_def: "surj f \<longleftrightarrow> (\<forall>y. \<exists>x. y = f x)" |
313 |
by auto |
|
39076
b3a9b6734663
Introduce surj_on and replace surj and bij by abbreviations.
hoelzl
parents:
39075
diff
changeset
|
314 |
|
63322 | 315 |
lemma surjI: |
64965 | 316 |
assumes "\<And>x. g (f x) = x" |
63322 | 317 |
shows "surj g" |
64965 | 318 |
using assms [symmetric] by auto |
13585 | 319 |
|
39076
b3a9b6734663
Introduce surj_on and replace surj and bij by abbreviations.
hoelzl
parents:
39075
diff
changeset
|
320 |
lemma surjD: "surj f \<Longrightarrow> \<exists>x. y = f x" |
b3a9b6734663
Introduce surj_on and replace surj and bij by abbreviations.
hoelzl
parents:
39075
diff
changeset
|
321 |
by (simp add: surj_def) |
13585 | 322 |
|
39076
b3a9b6734663
Introduce surj_on and replace surj and bij by abbreviations.
hoelzl
parents:
39075
diff
changeset
|
323 |
lemma surjE: "surj f \<Longrightarrow> (\<And>x. y = f x \<Longrightarrow> C) \<Longrightarrow> C" |
63575 | 324 |
by (simp add: surj_def) blast |
13585 | 325 |
|
63322 | 326 |
lemma comp_surj: "surj f \<Longrightarrow> surj g \<Longrightarrow> surj (g \<circ> f)" |
69768 | 327 |
using image_comp [of g f UNIV] by simp |
13585 | 328 |
|
63322 | 329 |
lemma bij_betw_imageI: "inj_on f A \<Longrightarrow> f ` A = B \<Longrightarrow> bij_betw f A B" |
330 |
unfolding bij_betw_def by clarify |
|
57282 | 331 |
|
332 |
lemma bij_betw_imp_surj_on: "bij_betw f A B \<Longrightarrow> f ` A = B" |
|
333 |
unfolding bij_betw_def by clarify |
|
334 |
||
39074 | 335 |
lemma bij_betw_imp_surj: "bij_betw f A UNIV \<Longrightarrow> surj f" |
40702 | 336 |
unfolding bij_betw_def by auto |
39074 | 337 |
|
63322 | 338 |
lemma bij_betw_empty1: "bij_betw f {} A \<Longrightarrow> A = {}" |
339 |
unfolding bij_betw_def by blast |
|
40703
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOL-image.
hoelzl
parents:
40702
diff
changeset
|
340 |
|
63322 | 341 |
lemma bij_betw_empty2: "bij_betw f A {} \<Longrightarrow> A = {}" |
342 |
unfolding bij_betw_def by blast |
|
40703
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOL-image.
hoelzl
parents:
40702
diff
changeset
|
343 |
|
63322 | 344 |
lemma inj_on_imp_bij_betw: "inj_on f A \<Longrightarrow> bij_betw f A (f ` A)" |
345 |
unfolding bij_betw_def by simp |
|
40703
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOL-image.
hoelzl
parents:
40702
diff
changeset
|
346 |
|
71464 | 347 |
lemma bij_betw_apply: "\<lbrakk>bij_betw f A B; a \<in> A\<rbrakk> \<Longrightarrow> f a \<in> B" |
348 |
unfolding bij_betw_def by auto |
|
349 |
||
39076
b3a9b6734663
Introduce surj_on and replace surj and bij by abbreviations.
hoelzl
parents:
39075
diff
changeset
|
350 |
lemma bij_def: "bij f \<longleftrightarrow> inj f \<and> surj f" |
64965 | 351 |
by (rule bij_betw_def) |
39074 | 352 |
|
63322 | 353 |
lemma bijI: "inj f \<Longrightarrow> surj f \<Longrightarrow> bij f" |
64965 | 354 |
by (rule bij_betw_imageI) |
13585 | 355 |
|
63322 | 356 |
lemma bij_is_inj: "bij f \<Longrightarrow> inj f" |
357 |
by (simp add: bij_def) |
|
13585 | 358 |
|
63322 | 359 |
lemma bij_is_surj: "bij f \<Longrightarrow> surj f" |
360 |
by (simp add: bij_def) |
|
13585 | 361 |
|
26105
ae06618225ec
moved bij_betw from Library/FuncSet to Fun, redistributed some lemmas, and
nipkow
parents:
25886
diff
changeset
|
362 |
lemma bij_betw_imp_inj_on: "bij_betw f A B \<Longrightarrow> inj_on f A" |
63322 | 363 |
by (simp add: bij_betw_def) |
26105
ae06618225ec
moved bij_betw from Library/FuncSet to Fun, redistributed some lemmas, and
nipkow
parents:
25886
diff
changeset
|
364 |
|
63322 | 365 |
lemma bij_betw_trans: "bij_betw f A B \<Longrightarrow> bij_betw g B C \<Longrightarrow> bij_betw (g \<circ> f) A C" |
366 |
by (auto simp add:bij_betw_def comp_inj_on) |
|
31438 | 367 |
|
63322 | 368 |
lemma bij_comp: "bij f \<Longrightarrow> bij g \<Longrightarrow> bij (g \<circ> f)" |
40702 | 369 |
by (rule bij_betw_trans) |
370 |
||
63322 | 371 |
lemma bij_betw_comp_iff: "bij_betw f A A' \<Longrightarrow> bij_betw f' A' A'' \<longleftrightarrow> bij_betw (f' \<circ> f) A A''" |
372 |
by (auto simp add: bij_betw_def inj_on_def) |
|
40703
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOL-image.
hoelzl
parents:
40702
diff
changeset
|
373 |
|
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOL-image.
hoelzl
parents:
40702
diff
changeset
|
374 |
lemma bij_betw_comp_iff2: |
63322 | 375 |
assumes bij: "bij_betw f' A' A''" |
376 |
and img: "f ` A \<le> A'" |
|
377 |
shows "bij_betw f A A' \<longleftrightarrow> bij_betw (f' \<circ> f) A A''" |
|
378 |
using assms |
|
379 |
proof (auto simp add: bij_betw_comp_iff) |
|
40703
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOL-image.
hoelzl
parents:
40702
diff
changeset
|
380 |
assume *: "bij_betw (f' \<circ> f) A A''" |
63322 | 381 |
then show "bij_betw f A A'" |
382 |
using img |
|
383 |
proof (auto simp add: bij_betw_def) |
|
40703
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOL-image.
hoelzl
parents:
40702
diff
changeset
|
384 |
assume "inj_on (f' \<circ> f) A" |
63575 | 385 |
then show "inj_on f A" |
386 |
using inj_on_imageI2 by blast |
|
40703
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOL-image.
hoelzl
parents:
40702
diff
changeset
|
387 |
next |
63322 | 388 |
fix a' |
389 |
assume **: "a' \<in> A'" |
|
63575 | 390 |
with bij have "f' a' \<in> A''" |
391 |
unfolding bij_betw_def by auto |
|
392 |
with * obtain a where 1: "a \<in> A \<and> f' (f a) = f' a'" |
|
393 |
unfolding bij_betw_def by force |
|
394 |
with img have "f a \<in> A'" by auto |
|
395 |
with bij ** 1 have "f a = a'" |
|
396 |
unfolding bij_betw_def inj_on_def by auto |
|
397 |
with 1 show "a' \<in> f ` A" by auto |
|
40703
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOL-image.
hoelzl
parents:
40702
diff
changeset
|
398 |
qed |
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOL-image.
hoelzl
parents:
40702
diff
changeset
|
399 |
qed |
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOL-image.
hoelzl
parents:
40702
diff
changeset
|
400 |
|
63322 | 401 |
lemma bij_betw_inv: |
402 |
assumes "bij_betw f A B" |
|
403 |
shows "\<exists>g. bij_betw g B A" |
|
26105
ae06618225ec
moved bij_betw from Library/FuncSet to Fun, redistributed some lemmas, and
nipkow
parents:
25886
diff
changeset
|
404 |
proof - |
ae06618225ec
moved bij_betw from Library/FuncSet to Fun, redistributed some lemmas, and
nipkow
parents:
25886
diff
changeset
|
405 |
have i: "inj_on f A" and s: "f ` A = B" |
63322 | 406 |
using assms by (auto simp: bij_betw_def) |
407 |
let ?P = "\<lambda>b a. a \<in> A \<and> f a = b" |
|
408 |
let ?g = "\<lambda>b. The (?P b)" |
|
409 |
have g: "?g b = a" if P: "?P b a" for a b |
|
410 |
proof - |
|
63575 | 411 |
from that s have ex1: "\<exists>a. ?P b a" by blast |
63322 | 412 |
then have uex1: "\<exists>!a. ?P b a" by (blast dest:inj_onD[OF i]) |
63575 | 413 |
then show ?thesis |
414 |
using the1_equality[OF uex1, OF P] P by simp |
|
63322 | 415 |
qed |
26105
ae06618225ec
moved bij_betw from Library/FuncSet to Fun, redistributed some lemmas, and
nipkow
parents:
25886
diff
changeset
|
416 |
have "inj_on ?g B" |
63322 | 417 |
proof (rule inj_onI) |
418 |
fix x y |
|
419 |
assume "x \<in> B" "y \<in> B" "?g x = ?g y" |
|
420 |
from s \<open>x \<in> B\<close> obtain a1 where a1: "?P x a1" by blast |
|
421 |
from s \<open>y \<in> B\<close> obtain a2 where a2: "?P y a2" by blast |
|
422 |
from g [OF a1] a1 g [OF a2] a2 \<open>?g x = ?g y\<close> show "x = y" by simp |
|
26105
ae06618225ec
moved bij_betw from Library/FuncSet to Fun, redistributed some lemmas, and
nipkow
parents:
25886
diff
changeset
|
423 |
qed |
ae06618225ec
moved bij_betw from Library/FuncSet to Fun, redistributed some lemmas, and
nipkow
parents:
25886
diff
changeset
|
424 |
moreover have "?g ` B = A" |
63322 | 425 |
proof (auto simp: image_def) |
426 |
fix b |
|
427 |
assume "b \<in> B" |
|
56077 | 428 |
with s obtain a where P: "?P b a" by blast |
63575 | 429 |
with g[OF P] show "?g b \<in> A" by auto |
26105
ae06618225ec
moved bij_betw from Library/FuncSet to Fun, redistributed some lemmas, and
nipkow
parents:
25886
diff
changeset
|
430 |
next |
63322 | 431 |
fix a |
432 |
assume "a \<in> A" |
|
63575 | 433 |
with s obtain b where P: "?P b a" by blast |
434 |
with s have "b \<in> B" by blast |
|
26105
ae06618225ec
moved bij_betw from Library/FuncSet to Fun, redistributed some lemmas, and
nipkow
parents:
25886
diff
changeset
|
435 |
with g[OF P] show "\<exists>b\<in>B. a = ?g b" by blast |
ae06618225ec
moved bij_betw from Library/FuncSet to Fun, redistributed some lemmas, and
nipkow
parents:
25886
diff
changeset
|
436 |
qed |
63575 | 437 |
ultimately show ?thesis |
438 |
by (auto simp: bij_betw_def) |
|
26105
ae06618225ec
moved bij_betw from Library/FuncSet to Fun, redistributed some lemmas, and
nipkow
parents:
25886
diff
changeset
|
439 |
qed |
ae06618225ec
moved bij_betw from Library/FuncSet to Fun, redistributed some lemmas, and
nipkow
parents:
25886
diff
changeset
|
440 |
|
63588 | 441 |
lemma bij_betw_cong: "(\<And>a. a \<in> A \<Longrightarrow> f a = g a) \<Longrightarrow> bij_betw f A A' = bij_betw g A A'" |
63591 | 442 |
unfolding bij_betw_def inj_on_def by safe force+ (* somewhat slow *) |
40703
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOL-image.
hoelzl
parents:
40702
diff
changeset
|
443 |
|
63322 | 444 |
lemma bij_betw_id[intro, simp]: "bij_betw id A A" |
445 |
unfolding bij_betw_def id_def by auto |
|
40703
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOL-image.
hoelzl
parents:
40702
diff
changeset
|
446 |
|
63322 | 447 |
lemma bij_betw_id_iff: "bij_betw id A B \<longleftrightarrow> A = B" |
448 |
by (auto simp add: bij_betw_def) |
|
40703
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOL-image.
hoelzl
parents:
40702
diff
changeset
|
449 |
|
39075 | 450 |
lemma bij_betw_combine: |
63400 | 451 |
"bij_betw f A B \<Longrightarrow> bij_betw f C D \<Longrightarrow> B \<inter> D = {} \<Longrightarrow> bij_betw f (A \<union> C) (B \<union> D)" |
452 |
unfolding bij_betw_def inj_on_Un image_Un by auto |
|
39075 | 453 |
|
64966
d53d7ca3303e
added inj_def (redundant, analogous to surj_def, bij_def);
wenzelm
parents:
64965
diff
changeset
|
454 |
lemma bij_betw_subset: "bij_betw f A A' \<Longrightarrow> B \<subseteq> A \<Longrightarrow> f ` B = B' \<Longrightarrow> bij_betw f B B'" |
63322 | 455 |
by (auto simp add: bij_betw_def inj_on_def) |
40703
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOL-image.
hoelzl
parents:
40702
diff
changeset
|
456 |
|
58195 | 457 |
lemma bij_pointE: |
458 |
assumes "bij f" |
|
459 |
obtains x where "y = f x" and "\<And>x'. y = f x' \<Longrightarrow> x' = x" |
|
460 |
proof - |
|
461 |
from assms have "inj f" by (rule bij_is_inj) |
|
462 |
moreover from assms have "surj f" by (rule bij_is_surj) |
|
463 |
then have "y \<in> range f" by simp |
|
464 |
ultimately have "\<exists>!x. y = f x" by (simp add: range_ex1_eq) |
|
465 |
with that show thesis by blast |
|
466 |
qed |
|
467 |
||
63322 | 468 |
lemma surj_image_vimage_eq: "surj f \<Longrightarrow> f ` (f -` A) = A" |
469 |
by simp |
|
13585 | 470 |
|
42903 | 471 |
lemma surj_vimage_empty: |
63322 | 472 |
assumes "surj f" |
473 |
shows "f -` A = {} \<longleftrightarrow> A = {}" |
|
474 |
using surj_image_vimage_eq [OF \<open>surj f\<close>, of A] |
|
44890
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
nipkow
parents:
44860
diff
changeset
|
475 |
by (intro iffI) fastforce+ |
42903 | 476 |
|
63322 | 477 |
lemma inj_vimage_image_eq: "inj f \<Longrightarrow> f -` (f ` A) = A" |
64966
d53d7ca3303e
added inj_def (redundant, analogous to surj_def, bij_def);
wenzelm
parents:
64965
diff
changeset
|
478 |
unfolding inj_def by blast |
13585 | 479 |
|
63322 | 480 |
lemma vimage_subsetD: "surj f \<Longrightarrow> f -` B \<subseteq> A \<Longrightarrow> B \<subseteq> f ` A" |
481 |
by (blast intro: sym) |
|
13585 | 482 |
|
63322 | 483 |
lemma vimage_subsetI: "inj f \<Longrightarrow> B \<subseteq> f ` A \<Longrightarrow> f -` B \<subseteq> A" |
64966
d53d7ca3303e
added inj_def (redundant, analogous to surj_def, bij_def);
wenzelm
parents:
64965
diff
changeset
|
484 |
unfolding inj_def by blast |
13585 | 485 |
|
63322 | 486 |
lemma vimage_subset_eq: "bij f \<Longrightarrow> f -` B \<subseteq> A \<longleftrightarrow> B \<subseteq> f ` A" |
487 |
unfolding bij_def by (blast del: subsetI intro: vimage_subsetI vimage_subsetD) |
|
13585 | 488 |
|
63322 | 489 |
lemma inj_on_image_eq_iff: "inj_on f C \<Longrightarrow> A \<subseteq> C \<Longrightarrow> B \<subseteq> C \<Longrightarrow> f ` A = f ` B \<longleftrightarrow> A = B" |
64965 | 490 |
by (fastforce simp: inj_on_def) |
53927 | 491 |
|
31438 | 492 |
lemma inj_on_Un_image_eq_iff: "inj_on f (A \<union> B) \<Longrightarrow> f ` A = f ` B \<longleftrightarrow> A = B" |
63322 | 493 |
by (erule inj_on_image_eq_iff) simp_all |
31438 | 494 |
|
63322 | 495 |
lemma inj_on_image_Int: "inj_on f C \<Longrightarrow> A \<subseteq> C \<Longrightarrow> B \<subseteq> C \<Longrightarrow> f ` (A \<inter> B) = f ` A \<inter> f ` B" |
496 |
unfolding inj_on_def by blast |
|
497 |
||
498 |
lemma inj_on_image_set_diff: "inj_on f C \<Longrightarrow> A - B \<subseteq> C \<Longrightarrow> B \<subseteq> C \<Longrightarrow> f ` (A - B) = f ` A - f ` B" |
|
499 |
unfolding inj_on_def by blast |
|
13585 | 500 |
|
63322 | 501 |
lemma image_Int: "inj f \<Longrightarrow> f ` (A \<inter> B) = f ` A \<inter> f ` B" |
64966
d53d7ca3303e
added inj_def (redundant, analogous to surj_def, bij_def);
wenzelm
parents:
64965
diff
changeset
|
502 |
unfolding inj_def by blast |
13585 | 503 |
|
63322 | 504 |
lemma image_set_diff: "inj f \<Longrightarrow> f ` (A - B) = f ` A - f ` B" |
64966
d53d7ca3303e
added inj_def (redundant, analogous to surj_def, bij_def);
wenzelm
parents:
64965
diff
changeset
|
505 |
unfolding inj_def by blast |
13585 | 506 |
|
63322 | 507 |
lemma inj_on_image_mem_iff: "inj_on f B \<Longrightarrow> a \<in> B \<Longrightarrow> A \<subseteq> B \<Longrightarrow> f a \<in> f ` A \<longleftrightarrow> a \<in> A" |
59504
8c6747dba731
New lemmas and a bit of tidying up.
paulson <lp15@cam.ac.uk>
parents:
58889
diff
changeset
|
508 |
by (auto simp: inj_on_def) |
8c6747dba731
New lemmas and a bit of tidying up.
paulson <lp15@cam.ac.uk>
parents:
58889
diff
changeset
|
509 |
|
63322 | 510 |
lemma inj_image_mem_iff: "inj f \<Longrightarrow> f a \<in> f ` A \<longleftrightarrow> a \<in> A" |
59504
8c6747dba731
New lemmas and a bit of tidying up.
paulson <lp15@cam.ac.uk>
parents:
58889
diff
changeset
|
511 |
by (blast dest: injD) |
13585 | 512 |
|
63322 | 513 |
lemma inj_image_subset_iff: "inj f \<Longrightarrow> f ` A \<subseteq> f ` B \<longleftrightarrow> A \<subseteq> B" |
59504
8c6747dba731
New lemmas and a bit of tidying up.
paulson <lp15@cam.ac.uk>
parents:
58889
diff
changeset
|
514 |
by (blast dest: injD) |
13585 | 515 |
|
63322 | 516 |
lemma inj_image_eq_iff: "inj f \<Longrightarrow> f ` A = f ` B \<longleftrightarrow> A = B" |
59504
8c6747dba731
New lemmas and a bit of tidying up.
paulson <lp15@cam.ac.uk>
parents:
58889
diff
changeset
|
517 |
by (blast dest: injD) |
13585 | 518 |
|
63322 | 519 |
lemma surj_Compl_image_subset: "surj f \<Longrightarrow> - (f ` A) \<subseteq> f ` (- A)" |
520 |
by auto |
|
5852 | 521 |
|
63322 | 522 |
lemma inj_image_Compl_subset: "inj f \<Longrightarrow> f ` (- A) \<subseteq> - (f ` A)" |
64966
d53d7ca3303e
added inj_def (redundant, analogous to surj_def, bij_def);
wenzelm
parents:
64965
diff
changeset
|
523 |
by (auto simp: inj_def) |
63322 | 524 |
|
525 |
lemma bij_image_Compl_eq: "bij f \<Longrightarrow> f ` (- A) = - (f ` A)" |
|
526 |
by (simp add: bij_def inj_image_Compl_subset surj_Compl_image_subset equalityI) |
|
13585 | 527 |
|
41657 | 528 |
lemma inj_vimage_singleton: "inj f \<Longrightarrow> f -` {a} \<subseteq> {THE x. f x = a}" |
63322 | 529 |
\<comment> \<open>The inverse image of a singleton under an injective function is included in a singleton.\<close> |
64966
d53d7ca3303e
added inj_def (redundant, analogous to surj_def, bij_def);
wenzelm
parents:
64965
diff
changeset
|
530 |
by (simp add: inj_def) (blast intro: the_equality [symmetric]) |
41657 | 531 |
|
63322 | 532 |
lemma inj_on_vimage_singleton: "inj_on f A \<Longrightarrow> f -` {a} \<inter> A \<subseteq> {THE x. x \<in> A \<and> f x = a}" |
43991 | 533 |
by (auto simp add: inj_on_def intro: the_equality [symmetric]) |
534 |
||
35584
768f8d92b767
generalized inj_uminus; added strict_mono_imp_inj_on
hoelzl
parents:
35580
diff
changeset
|
535 |
lemma (in ordered_ab_group_add) inj_uminus[simp, intro]: "inj_on uminus A" |
35580 | 536 |
by (auto intro!: inj_onI) |
13585 | 537 |
|
35584
768f8d92b767
generalized inj_uminus; added strict_mono_imp_inj_on
hoelzl
parents:
35580
diff
changeset
|
538 |
lemma (in linorder) strict_mono_imp_inj_on: "strict_mono f \<Longrightarrow> inj_on f A" |
768f8d92b767
generalized inj_uminus; added strict_mono_imp_inj_on
hoelzl
parents:
35580
diff
changeset
|
539 |
by (auto intro!: inj_onI dest: strict_mono_eq) |
768f8d92b767
generalized inj_uminus; added strict_mono_imp_inj_on
hoelzl
parents:
35580
diff
changeset
|
540 |
|
55019
0d5e831175de
moved lemmas from 'Fun_More_FP' to where they belong
blanchet
parents:
54578
diff
changeset
|
541 |
lemma bij_betw_byWitness: |
63322 | 542 |
assumes left: "\<forall>a \<in> A. f' (f a) = a" |
543 |
and right: "\<forall>a' \<in> A'. f (f' a') = a'" |
|
63575 | 544 |
and "f ` A \<subseteq> A'" |
545 |
and img2: "f' ` A' \<subseteq> A" |
|
63322 | 546 |
shows "bij_betw f A A'" |
547 |
using assms |
|
63400 | 548 |
unfolding bij_betw_def inj_on_def |
549 |
proof safe |
|
63322 | 550 |
fix a b |
63575 | 551 |
assume "a \<in> A" "b \<in> A" |
552 |
with left have "a = f' (f a) \<and> b = f' (f b)" by simp |
|
553 |
moreover assume "f a = f b" |
|
554 |
ultimately show "a = b" by simp |
|
55019
0d5e831175de
moved lemmas from 'Fun_More_FP' to where they belong
blanchet
parents:
54578
diff
changeset
|
555 |
next |
0d5e831175de
moved lemmas from 'Fun_More_FP' to where they belong
blanchet
parents:
54578
diff
changeset
|
556 |
fix a' assume *: "a' \<in> A'" |
63575 | 557 |
with img2 have "f' a' \<in> A" by blast |
558 |
moreover from * right have "a' = f (f' a')" by simp |
|
55019
0d5e831175de
moved lemmas from 'Fun_More_FP' to where they belong
blanchet
parents:
54578
diff
changeset
|
559 |
ultimately show "a' \<in> f ` A" by blast |
0d5e831175de
moved lemmas from 'Fun_More_FP' to where they belong
blanchet
parents:
54578
diff
changeset
|
560 |
qed |
0d5e831175de
moved lemmas from 'Fun_More_FP' to where they belong
blanchet
parents:
54578
diff
changeset
|
561 |
|
0d5e831175de
moved lemmas from 'Fun_More_FP' to where they belong
blanchet
parents:
54578
diff
changeset
|
562 |
corollary notIn_Un_bij_betw: |
63322 | 563 |
assumes "b \<notin> A" |
564 |
and "f b \<notin> A'" |
|
565 |
and "bij_betw f A A'" |
|
566 |
shows "bij_betw f (A \<union> {b}) (A' \<union> {f b})" |
|
567 |
proof - |
|
55019
0d5e831175de
moved lemmas from 'Fun_More_FP' to where they belong
blanchet
parents:
54578
diff
changeset
|
568 |
have "bij_betw f {b} {f b}" |
63322 | 569 |
unfolding bij_betw_def inj_on_def by simp |
55019
0d5e831175de
moved lemmas from 'Fun_More_FP' to where they belong
blanchet
parents:
54578
diff
changeset
|
570 |
with assms show ?thesis |
63322 | 571 |
using bij_betw_combine[of f A A' "{b}" "{f b}"] by blast |
55019
0d5e831175de
moved lemmas from 'Fun_More_FP' to where they belong
blanchet
parents:
54578
diff
changeset
|
572 |
qed |
0d5e831175de
moved lemmas from 'Fun_More_FP' to where they belong
blanchet
parents:
54578
diff
changeset
|
573 |
|
0d5e831175de
moved lemmas from 'Fun_More_FP' to where they belong
blanchet
parents:
54578
diff
changeset
|
574 |
lemma notIn_Un_bij_betw3: |
63322 | 575 |
assumes "b \<notin> A" |
576 |
and "f b \<notin> A'" |
|
577 |
shows "bij_betw f A A' = bij_betw f (A \<union> {b}) (A' \<union> {f b})" |
|
55019
0d5e831175de
moved lemmas from 'Fun_More_FP' to where they belong
blanchet
parents:
54578
diff
changeset
|
578 |
proof |
0d5e831175de
moved lemmas from 'Fun_More_FP' to where they belong
blanchet
parents:
54578
diff
changeset
|
579 |
assume "bij_betw f A A'" |
63322 | 580 |
then show "bij_betw f (A \<union> {b}) (A' \<union> {f b})" |
581 |
using assms notIn_Un_bij_betw [of b A f A'] by blast |
|
55019
0d5e831175de
moved lemmas from 'Fun_More_FP' to where they belong
blanchet
parents:
54578
diff
changeset
|
582 |
next |
0d5e831175de
moved lemmas from 'Fun_More_FP' to where they belong
blanchet
parents:
54578
diff
changeset
|
583 |
assume *: "bij_betw f (A \<union> {b}) (A' \<union> {f b})" |
0d5e831175de
moved lemmas from 'Fun_More_FP' to where they belong
blanchet
parents:
54578
diff
changeset
|
584 |
have "f ` A = A'" |
63322 | 585 |
proof auto |
586 |
fix a |
|
587 |
assume **: "a \<in> A" |
|
588 |
then have "f a \<in> A' \<union> {f b}" |
|
589 |
using * unfolding bij_betw_def by blast |
|
55019
0d5e831175de
moved lemmas from 'Fun_More_FP' to where they belong
blanchet
parents:
54578
diff
changeset
|
590 |
moreover |
63322 | 591 |
have False if "f a = f b" |
592 |
proof - |
|
63575 | 593 |
have "a = b" |
594 |
using * ** that unfolding bij_betw_def inj_on_def by blast |
|
63322 | 595 |
with \<open>b \<notin> A\<close> ** show ?thesis by blast |
596 |
qed |
|
55019
0d5e831175de
moved lemmas from 'Fun_More_FP' to where they belong
blanchet
parents:
54578
diff
changeset
|
597 |
ultimately show "f a \<in> A'" by blast |
0d5e831175de
moved lemmas from 'Fun_More_FP' to where they belong
blanchet
parents:
54578
diff
changeset
|
598 |
next |
63322 | 599 |
fix a' |
600 |
assume **: "a' \<in> A'" |
|
601 |
then have "a' \<in> f ` (A \<union> {b})" |
|
602 |
using * by (auto simp add: bij_betw_def) |
|
55019
0d5e831175de
moved lemmas from 'Fun_More_FP' to where they belong
blanchet
parents:
54578
diff
changeset
|
603 |
then obtain a where 1: "a \<in> A \<union> {b} \<and> f a = a'" by blast |
0d5e831175de
moved lemmas from 'Fun_More_FP' to where they belong
blanchet
parents:
54578
diff
changeset
|
604 |
moreover |
63322 | 605 |
have False if "a = b" using 1 ** \<open>f b \<notin> A'\<close> that by blast |
55019
0d5e831175de
moved lemmas from 'Fun_More_FP' to where they belong
blanchet
parents:
54578
diff
changeset
|
606 |
ultimately have "a \<in> A" by blast |
0d5e831175de
moved lemmas from 'Fun_More_FP' to where they belong
blanchet
parents:
54578
diff
changeset
|
607 |
with 1 show "a' \<in> f ` A" by blast |
0d5e831175de
moved lemmas from 'Fun_More_FP' to where they belong
blanchet
parents:
54578
diff
changeset
|
608 |
qed |
63322 | 609 |
then show "bij_betw f A A'" |
610 |
using * bij_betw_subset[of f "A \<union> {b}" _ A] by blast |
|
55019
0d5e831175de
moved lemmas from 'Fun_More_FP' to where they belong
blanchet
parents:
54578
diff
changeset
|
611 |
qed |
0d5e831175de
moved lemmas from 'Fun_More_FP' to where they belong
blanchet
parents:
54578
diff
changeset
|
612 |
|
71857
d73955442df5
a few new lemmas about functions
paulson <lp15@cam.ac.uk>
parents:
71827
diff
changeset
|
613 |
lemma inj_on_disjoint_Un: |
d73955442df5
a few new lemmas about functions
paulson <lp15@cam.ac.uk>
parents:
71827
diff
changeset
|
614 |
assumes "inj_on f A" and "inj_on g B" |
d73955442df5
a few new lemmas about functions
paulson <lp15@cam.ac.uk>
parents:
71827
diff
changeset
|
615 |
and "f ` A \<inter> g ` B = {}" |
d73955442df5
a few new lemmas about functions
paulson <lp15@cam.ac.uk>
parents:
71827
diff
changeset
|
616 |
shows "inj_on (\<lambda>x. if x \<in> A then f x else g x) (A \<union> B)" |
d73955442df5
a few new lemmas about functions
paulson <lp15@cam.ac.uk>
parents:
71827
diff
changeset
|
617 |
using assms by (simp add: inj_on_def disjoint_iff) (blast) |
d73955442df5
a few new lemmas about functions
paulson <lp15@cam.ac.uk>
parents:
71827
diff
changeset
|
618 |
|
d73955442df5
a few new lemmas about functions
paulson <lp15@cam.ac.uk>
parents:
71827
diff
changeset
|
619 |
lemma bij_betw_disjoint_Un: |
d73955442df5
a few new lemmas about functions
paulson <lp15@cam.ac.uk>
parents:
71827
diff
changeset
|
620 |
assumes "bij_betw f A C" and "bij_betw g B D" |
d73955442df5
a few new lemmas about functions
paulson <lp15@cam.ac.uk>
parents:
71827
diff
changeset
|
621 |
and "A \<inter> B = {}" |
d73955442df5
a few new lemmas about functions
paulson <lp15@cam.ac.uk>
parents:
71827
diff
changeset
|
622 |
and "C \<inter> D = {}" |
d73955442df5
a few new lemmas about functions
paulson <lp15@cam.ac.uk>
parents:
71827
diff
changeset
|
623 |
shows "bij_betw (\<lambda>x. if x \<in> A then f x else g x) (A \<union> B) (C \<union> D)" |
d73955442df5
a few new lemmas about functions
paulson <lp15@cam.ac.uk>
parents:
71827
diff
changeset
|
624 |
using assms by (auto simp: inj_on_disjoint_Un bij_betw_def) |
d73955442df5
a few new lemmas about functions
paulson <lp15@cam.ac.uk>
parents:
71827
diff
changeset
|
625 |
|
d73955442df5
a few new lemmas about functions
paulson <lp15@cam.ac.uk>
parents:
71827
diff
changeset
|
626 |
subsubsection \<open>Important examples\<close> |
69502 | 627 |
|
628 |
context cancel_semigroup_add |
|
629 |
begin |
|
630 |
||
69661 | 631 |
lemma inj_on_add [simp]: |
632 |
"inj_on ((+) a) A" |
|
633 |
by (rule inj_onI) simp |
|
634 |
||
635 |
lemma inj_add_left: |
|
636 |
\<open>inj ((+) a)\<close> |
|
637 |
by simp |
|
638 |
||
639 |
lemma inj_on_add' [simp]: |
|
640 |
"inj_on (\<lambda>b. b + a) A" |
|
641 |
by (rule inj_onI) simp |
|
642 |
||
643 |
lemma bij_betw_add [simp]: |
|
644 |
"bij_betw ((+) a) A B \<longleftrightarrow> (+) a ` A = B" |
|
645 |
by (simp add: bij_betw_def) |
|
69502 | 646 |
|
647 |
end |
|
648 |
||
649 |
context ab_group_add |
|
650 |
begin |
|
651 |
||
69661 | 652 |
lemma surj_plus [simp]: |
653 |
"surj ((+) a)" |
|
69768 | 654 |
by (auto intro!: range_eqI [of b "(+) a" "b - a" for b]) (simp add: algebra_simps) |
69661 | 655 |
|
656 |
lemma inj_diff_right [simp]: |
|
657 |
\<open>inj (\<lambda>b. b - a)\<close> |
|
69502 | 658 |
proof - |
659 |
have \<open>inj ((+) (- a))\<close> |
|
660 |
by (fact inj_add_left) |
|
661 |
also have \<open>(+) (- a) = (\<lambda>b. b - a)\<close> |
|
662 |
by (simp add: fun_eq_iff) |
|
663 |
finally show ?thesis . |
|
664 |
qed |
|
665 |
||
69661 | 666 |
lemma surj_diff_right [simp]: |
667 |
"surj (\<lambda>x. x - a)" |
|
668 |
using surj_plus [of "- a"] by (simp cong: image_cong_simp) |
|
669 |
||
670 |
lemma translation_Compl: |
|
671 |
"(+) a ` (- t) = - ((+) a ` t)" |
|
672 |
proof (rule set_eqI) |
|
673 |
fix b |
|
674 |
show "b \<in> (+) a ` (- t) \<longleftrightarrow> b \<in> - (+) a ` t" |
|
675 |
by (auto simp: image_iff algebra_simps intro!: bexI [of _ "b - a"]) |
|
676 |
qed |
|
677 |
||
678 |
lemma translation_subtract_Compl: |
|
679 |
"(\<lambda>x. x - a) ` (- t) = - ((\<lambda>x. x - a) ` t)" |
|
680 |
using translation_Compl [of "- a" t] by (simp cong: image_cong_simp) |
|
681 |
||
682 |
lemma translation_diff: |
|
683 |
"(+) a ` (s - t) = ((+) a ` s) - ((+) a ` t)" |
|
684 |
by auto |
|
685 |
||
686 |
lemma translation_subtract_diff: |
|
687 |
"(\<lambda>x. x - a) ` (s - t) = ((\<lambda>x. x - a) ` s) - ((\<lambda>x. x - a) ` t)" |
|
688 |
using translation_diff [of "- a"] by (simp cong: image_cong_simp) |
|
689 |
||
690 |
lemma translation_Int: |
|
691 |
"(+) a ` (s \<inter> t) = ((+) a ` s) \<inter> ((+) a ` t)" |
|
692 |
by auto |
|
693 |
||
694 |
lemma translation_subtract_Int: |
|
695 |
"(\<lambda>x. x - a) ` (s \<inter> t) = ((\<lambda>x. x - a) ` s) \<inter> ((\<lambda>x. x - a) ` t)" |
|
696 |
using translation_Int [of " -a"] by (simp cong: image_cong_simp) |
|
697 |
||
69502 | 698 |
end |
699 |
||
41657 | 700 |
|
63322 | 701 |
subsection \<open>Function Updating\<close> |
13585 | 702 |
|
63322 | 703 |
definition fun_upd :: "('a \<Rightarrow> 'b) \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> ('a \<Rightarrow> 'b)" |
63324 | 704 |
where "fun_upd f a b = (\<lambda>x. if x = a then b else f x)" |
26147 | 705 |
|
41229
d797baa3d57c
replaced command 'nonterminals' by slightly modernized version 'nonterminal';
wenzelm
parents:
40969
diff
changeset
|
706 |
nonterminal updbinds and updbind |
d797baa3d57c
replaced command 'nonterminals' by slightly modernized version 'nonterminal';
wenzelm
parents:
40969
diff
changeset
|
707 |
|
26147 | 708 |
syntax |
63322 | 709 |
"_updbind" :: "'a \<Rightarrow> 'a \<Rightarrow> updbind" ("(2_ :=/ _)") |
710 |
"" :: "updbind \<Rightarrow> updbinds" ("_") |
|
711 |
"_updbinds":: "updbind \<Rightarrow> updbinds \<Rightarrow> updbinds" ("_,/ _") |
|
712 |
"_Update" :: "'a \<Rightarrow> updbinds \<Rightarrow> 'a" ("_/'((_)')" [1000, 0] 900) |
|
26147 | 713 |
|
714 |
translations |
|
63322 | 715 |
"_Update f (_updbinds b bs)" \<rightleftharpoons> "_Update (_Update f b) bs" |
716 |
"f(x:=y)" \<rightleftharpoons> "CONST fun_upd f x y" |
|
26147 | 717 |
|
55414
eab03e9cee8a
renamed '{prod,sum,bool,unit}_case' to 'case_...'
blanchet
parents:
55066
diff
changeset
|
718 |
(* Hint: to define the sum of two functions (or maps), use case_sum. |
58111 | 719 |
A nice infix syntax could be defined by |
35115 | 720 |
notation |
55414
eab03e9cee8a
renamed '{prod,sum,bool,unit}_case' to 'case_...'
blanchet
parents:
55066
diff
changeset
|
721 |
case_sum (infixr "'(+')"80) |
26147 | 722 |
*) |
723 |
||
63322 | 724 |
lemma fun_upd_idem_iff: "f(x:=y) = f \<longleftrightarrow> f x = y" |
725 |
unfolding fun_upd_def |
|
726 |
apply safe |
|
63575 | 727 |
apply (erule subst) |
728 |
apply (rule_tac [2] ext) |
|
729 |
apply auto |
|
63322 | 730 |
done |
13585 | 731 |
|
63322 | 732 |
lemma fun_upd_idem: "f x = y \<Longrightarrow> f(x := y) = f" |
45603 | 733 |
by (simp only: fun_upd_idem_iff) |
13585 | 734 |
|
45603 | 735 |
lemma fun_upd_triv [iff]: "f(x := f x) = f" |
736 |
by (simp only: fun_upd_idem) |
|
13585 | 737 |
|
63322 | 738 |
lemma fun_upd_apply [simp]: "(f(x := y)) z = (if z = x then y else f z)" |
739 |
by (simp add: fun_upd_def) |
|
13585 | 740 |
|
63322 | 741 |
(* fun_upd_apply supersedes these two, but they are useful |
13585 | 742 |
if fun_upd_apply is intentionally removed from the simpset *) |
63322 | 743 |
lemma fun_upd_same: "(f(x := y)) x = y" |
744 |
by simp |
|
13585 | 745 |
|
63322 | 746 |
lemma fun_upd_other: "z \<noteq> x \<Longrightarrow> (f(x := y)) z = f z" |
747 |
by simp |
|
13585 | 748 |
|
63322 | 749 |
lemma fun_upd_upd [simp]: "f(x := y, x := z) = f(x := z)" |
750 |
by (simp add: fun_eq_iff) |
|
13585 | 751 |
|
63322 | 752 |
lemma fun_upd_twist: "a \<noteq> c \<Longrightarrow> (m(a := b))(c := d) = (m(c := d))(a := b)" |
71616
a9de39608b1a
more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents:
71472
diff
changeset
|
753 |
by auto |
63322 | 754 |
|
755 |
lemma inj_on_fun_updI: "inj_on f A \<Longrightarrow> y \<notin> f ` A \<Longrightarrow> inj_on (f(x := y)) A" |
|
64966
d53d7ca3303e
added inj_def (redundant, analogous to surj_def, bij_def);
wenzelm
parents:
64965
diff
changeset
|
756 |
by (auto simp: inj_on_def) |
15303 | 757 |
|
63322 | 758 |
lemma fun_upd_image: "f(x := y) ` A = (if x \<in> A then insert y (f ` (A - {x})) else f ` A)" |
759 |
by auto |
|
15510 | 760 |
|
31080 | 761 |
lemma fun_upd_comp: "f \<circ> (g(x := y)) = (f \<circ> g)(x := f y)" |
44921 | 762 |
by auto |
31080 | 763 |
|
61630 | 764 |
lemma fun_upd_eqD: "f(x := y) = g(x := z) \<Longrightarrow> y = z" |
63322 | 765 |
by (simp add: fun_eq_iff split: if_split_asm) |
766 |
||
26147 | 767 |
|
61799 | 768 |
subsection \<open>\<open>override_on\<close>\<close> |
26147 | 769 |
|
63322 | 770 |
definition override_on :: "('a \<Rightarrow> 'b) \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> 'a set \<Rightarrow> 'a \<Rightarrow> 'b" |
771 |
where "override_on f g A = (\<lambda>a. if a \<in> A then g a else f a)" |
|
13910 | 772 |
|
15691 | 773 |
lemma override_on_emptyset[simp]: "override_on f g {} = f" |
64965 | 774 |
by (simp add: override_on_def) |
13910 | 775 |
|
63322 | 776 |
lemma override_on_apply_notin[simp]: "a \<notin> A \<Longrightarrow> (override_on f g A) a = f a" |
64965 | 777 |
by (simp add: override_on_def) |
13910 | 778 |
|
63322 | 779 |
lemma override_on_apply_in[simp]: "a \<in> A \<Longrightarrow> (override_on f g A) a = g a" |
64965 | 780 |
by (simp add: override_on_def) |
13910 | 781 |
|
63561
fba08009ff3e
add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents:
63416
diff
changeset
|
782 |
lemma override_on_insert: "override_on f g (insert x X) = (override_on f g X)(x:=g x)" |
64965 | 783 |
by (simp add: override_on_def fun_eq_iff) |
63561
fba08009ff3e
add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents:
63416
diff
changeset
|
784 |
|
fba08009ff3e
add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents:
63416
diff
changeset
|
785 |
lemma override_on_insert': "override_on f g (insert x X) = (override_on (f(x:=g x)) g X)" |
64965 | 786 |
by (simp add: override_on_def fun_eq_iff) |
63561
fba08009ff3e
add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents:
63416
diff
changeset
|
787 |
|
26147 | 788 |
|
61799 | 789 |
subsection \<open>\<open>swap\<close>\<close> |
15510 | 790 |
|
56608 | 791 |
definition swap :: "'a \<Rightarrow> 'a \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> ('a \<Rightarrow> 'b)" |
63322 | 792 |
where "swap a b f = f (a := f b, b:= f a)" |
15510 | 793 |
|
56608 | 794 |
lemma swap_apply [simp]: |
795 |
"swap a b f a = f b" |
|
796 |
"swap a b f b = f a" |
|
797 |
"c \<noteq> a \<Longrightarrow> c \<noteq> b \<Longrightarrow> swap a b f c = f c" |
|
798 |
by (simp_all add: swap_def) |
|
799 |
||
63322 | 800 |
lemma swap_self [simp]: "swap a a f = f" |
56608 | 801 |
by (simp add: swap_def) |
15510 | 802 |
|
63322 | 803 |
lemma swap_commute: "swap a b f = swap b a f" |
56608 | 804 |
by (simp add: fun_upd_def swap_def fun_eq_iff) |
15510 | 805 |
|
63322 | 806 |
lemma swap_nilpotent [simp]: "swap a b (swap a b f) = f" |
63575 | 807 |
by (rule ext) (simp add: fun_upd_def swap_def) |
56608 | 808 |
|
63322 | 809 |
lemma swap_comp_involutory [simp]: "swap a b \<circ> swap a b = id" |
56608 | 810 |
by (rule ext) simp |
15510 | 811 |
|
34145 | 812 |
lemma swap_triple: |
813 |
assumes "a \<noteq> c" and "b \<noteq> c" |
|
814 |
shows "swap a b (swap b c (swap a b f)) = swap a c f" |
|
39302
d7728f65b353
renamed lemmas: ext_iff -> fun_eq_iff, set_ext_iff -> set_eq_iff, set_ext -> set_eqI
nipkow
parents:
39213
diff
changeset
|
815 |
using assms by (simp add: fun_eq_iff swap_def) |
34145 | 816 |
|
34101 | 817 |
lemma comp_swap: "f \<circ> swap a b g = swap a b (f \<circ> g)" |
63322 | 818 |
by (rule ext) (simp add: fun_upd_def swap_def) |
34101 | 819 |
|
39076
b3a9b6734663
Introduce surj_on and replace surj and bij by abbreviations.
hoelzl
parents:
39075
diff
changeset
|
820 |
lemma swap_image_eq [simp]: |
63322 | 821 |
assumes "a \<in> A" "b \<in> A" |
822 |
shows "swap a b f ` A = f ` A" |
|
39076
b3a9b6734663
Introduce surj_on and replace surj and bij by abbreviations.
hoelzl
parents:
39075
diff
changeset
|
823 |
proof - |
b3a9b6734663
Introduce surj_on and replace surj and bij by abbreviations.
hoelzl
parents:
39075
diff
changeset
|
824 |
have subset: "\<And>f. swap a b f ` A \<subseteq> f ` A" |
b3a9b6734663
Introduce surj_on and replace surj and bij by abbreviations.
hoelzl
parents:
39075
diff
changeset
|
825 |
using assms by (auto simp: image_iff swap_def) |
b3a9b6734663
Introduce surj_on and replace surj and bij by abbreviations.
hoelzl
parents:
39075
diff
changeset
|
826 |
then have "swap a b (swap a b f) ` A \<subseteq> (swap a b f) ` A" . |
b3a9b6734663
Introduce surj_on and replace surj and bij by abbreviations.
hoelzl
parents:
39075
diff
changeset
|
827 |
with subset[of f] show ?thesis by auto |
b3a9b6734663
Introduce surj_on and replace surj and bij by abbreviations.
hoelzl
parents:
39075
diff
changeset
|
828 |
qed |
b3a9b6734663
Introduce surj_on and replace surj and bij by abbreviations.
hoelzl
parents:
39075
diff
changeset
|
829 |
|
63322 | 830 |
lemma inj_on_imp_inj_on_swap: "inj_on f A \<Longrightarrow> a \<in> A \<Longrightarrow> b \<in> A \<Longrightarrow> inj_on (swap a b f) A" |
831 |
by (auto simp add: inj_on_def swap_def) |
|
15510 | 832 |
|
833 |
lemma inj_on_swap_iff [simp]: |
|
63322 | 834 |
assumes A: "a \<in> A" "b \<in> A" |
835 |
shows "inj_on (swap a b f) A \<longleftrightarrow> inj_on f A" |
|
39075 | 836 |
proof |
15510 | 837 |
assume "inj_on (swap a b f) A" |
39075 | 838 |
with A have "inj_on (swap a b (swap a b f)) A" |
839 |
by (iprover intro: inj_on_imp_inj_on_swap) |
|
63322 | 840 |
then show "inj_on f A" by simp |
15510 | 841 |
next |
842 |
assume "inj_on f A" |
|
63322 | 843 |
with A show "inj_on (swap a b f) A" |
844 |
by (iprover intro: inj_on_imp_inj_on_swap) |
|
15510 | 845 |
qed |
846 |
||
39076
b3a9b6734663
Introduce surj_on and replace surj and bij by abbreviations.
hoelzl
parents:
39075
diff
changeset
|
847 |
lemma surj_imp_surj_swap: "surj f \<Longrightarrow> surj (swap a b f)" |
40702 | 848 |
by simp |
15510 | 849 |
|
39076
b3a9b6734663
Introduce surj_on and replace surj and bij by abbreviations.
hoelzl
parents:
39075
diff
changeset
|
850 |
lemma surj_swap_iff [simp]: "surj (swap a b f) \<longleftrightarrow> surj f" |
40702 | 851 |
by simp |
21547
9c9fdf4c2949
moved order arities for fun and bool to Fun/Orderings
haftmann
parents:
21327
diff
changeset
|
852 |
|
63322 | 853 |
lemma bij_betw_swap_iff [simp]: "x \<in> A \<Longrightarrow> y \<in> A \<Longrightarrow> bij_betw (swap x y f) A B \<longleftrightarrow> bij_betw f A B" |
39076
b3a9b6734663
Introduce surj_on and replace surj and bij by abbreviations.
hoelzl
parents:
39075
diff
changeset
|
854 |
by (auto simp: bij_betw_def) |
b3a9b6734663
Introduce surj_on and replace surj and bij by abbreviations.
hoelzl
parents:
39075
diff
changeset
|
855 |
|
b3a9b6734663
Introduce surj_on and replace surj and bij by abbreviations.
hoelzl
parents:
39075
diff
changeset
|
856 |
lemma bij_swap_iff [simp]: "bij (swap a b f) \<longleftrightarrow> bij f" |
b3a9b6734663
Introduce surj_on and replace surj and bij by abbreviations.
hoelzl
parents:
39075
diff
changeset
|
857 |
by simp |
39075 | 858 |
|
36176
3fe7e97ccca8
replaced generic 'hide' command by more conventional 'hide_class', 'hide_type', 'hide_const', 'hide_fact' -- frees some popular keywords;
wenzelm
parents:
35584
diff
changeset
|
859 |
hide_const (open) swap |
21547
9c9fdf4c2949
moved order arities for fun and bool to Fun/Orderings
haftmann
parents:
21327
diff
changeset
|
860 |
|
56608 | 861 |
|
60758 | 862 |
subsection \<open>Inversion of injective functions\<close> |
31949 | 863 |
|
63322 | 864 |
definition the_inv_into :: "'a set \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> ('b \<Rightarrow> 'a)" |
63324 | 865 |
where "the_inv_into A f = (\<lambda>x. THE y. y \<in> A \<and> f y = x)" |
63322 | 866 |
|
867 |
lemma the_inv_into_f_f: "inj_on f A \<Longrightarrow> x \<in> A \<Longrightarrow> the_inv_into A f (f x) = x" |
|
868 |
unfolding the_inv_into_def inj_on_def by blast |
|
32961 | 869 |
|
63322 | 870 |
lemma f_the_inv_into_f: "inj_on f A \<Longrightarrow> y \<in> f ` A \<Longrightarrow> f (the_inv_into A f y) = y" |
71857
d73955442df5
a few new lemmas about functions
paulson <lp15@cam.ac.uk>
parents:
71827
diff
changeset
|
871 |
unfolding the_inv_into_def |
d73955442df5
a few new lemmas about functions
paulson <lp15@cam.ac.uk>
parents:
71827
diff
changeset
|
872 |
by (rule the1I2; blast dest: inj_onD) |
32961 | 873 |
|
63322 | 874 |
lemma the_inv_into_into: "inj_on f A \<Longrightarrow> x \<in> f ` A \<Longrightarrow> A \<subseteq> B \<Longrightarrow> the_inv_into A f x \<in> B" |
71857
d73955442df5
a few new lemmas about functions
paulson <lp15@cam.ac.uk>
parents:
71827
diff
changeset
|
875 |
unfolding the_inv_into_def |
d73955442df5
a few new lemmas about functions
paulson <lp15@cam.ac.uk>
parents:
71827
diff
changeset
|
876 |
by (rule the1I2; blast dest: inj_onD) |
32961 | 877 |
|
63322 | 878 |
lemma the_inv_into_onto [simp]: "inj_on f A \<Longrightarrow> the_inv_into A f ` (f ` A) = A" |
879 |
by (fast intro: the_inv_into_into the_inv_into_f_f [symmetric]) |
|
32961 | 880 |
|
63322 | 881 |
lemma the_inv_into_f_eq: "inj_on f A \<Longrightarrow> f x = y \<Longrightarrow> x \<in> A \<Longrightarrow> the_inv_into A f y = x" |
71857
d73955442df5
a few new lemmas about functions
paulson <lp15@cam.ac.uk>
parents:
71827
diff
changeset
|
882 |
by (force simp add: the_inv_into_f_f) |
32961 | 883 |
|
33057 | 884 |
lemma the_inv_into_comp: |
63322 | 885 |
"inj_on f (g ` A) \<Longrightarrow> inj_on g A \<Longrightarrow> x \<in> f ` g ` A \<Longrightarrow> |
886 |
the_inv_into A (f \<circ> g) x = (the_inv_into A g \<circ> the_inv_into (g ` A) f) x" |
|
887 |
apply (rule the_inv_into_f_eq) |
|
888 |
apply (fast intro: comp_inj_on) |
|
889 |
apply (simp add: f_the_inv_into_f the_inv_into_into) |
|
890 |
apply (simp add: the_inv_into_into) |
|
891 |
done |
|
32961 | 892 |
|
63322 | 893 |
lemma inj_on_the_inv_into: "inj_on f A \<Longrightarrow> inj_on (the_inv_into A f) (f ` A)" |
894 |
by (auto intro: inj_onI simp: the_inv_into_f_f) |
|
32961 | 895 |
|
63322 | 896 |
lemma bij_betw_the_inv_into: "bij_betw f A B \<Longrightarrow> bij_betw (the_inv_into A f) B A" |
897 |
by (auto simp add: bij_betw_def inj_on_the_inv_into the_inv_into_into) |
|
32961 | 898 |
|
71857
d73955442df5
a few new lemmas about functions
paulson <lp15@cam.ac.uk>
parents:
71827
diff
changeset
|
899 |
lemma bij_betw_iff_bijections: |
d73955442df5
a few new lemmas about functions
paulson <lp15@cam.ac.uk>
parents:
71827
diff
changeset
|
900 |
"bij_betw f A B \<longleftrightarrow> (\<exists>g. (\<forall>x \<in> A. f x \<in> B \<and> g(f x) = x) \<and> (\<forall>y \<in> B. g y \<in> A \<and> f(g y) = y))" |
d73955442df5
a few new lemmas about functions
paulson <lp15@cam.ac.uk>
parents:
71827
diff
changeset
|
901 |
(is "?lhs = ?rhs") |
d73955442df5
a few new lemmas about functions
paulson <lp15@cam.ac.uk>
parents:
71827
diff
changeset
|
902 |
proof |
d73955442df5
a few new lemmas about functions
paulson <lp15@cam.ac.uk>
parents:
71827
diff
changeset
|
903 |
assume L: ?lhs |
d73955442df5
a few new lemmas about functions
paulson <lp15@cam.ac.uk>
parents:
71827
diff
changeset
|
904 |
then show ?rhs |
d73955442df5
a few new lemmas about functions
paulson <lp15@cam.ac.uk>
parents:
71827
diff
changeset
|
905 |
apply (rule_tac x="the_inv_into A f" in exI) |
d73955442df5
a few new lemmas about functions
paulson <lp15@cam.ac.uk>
parents:
71827
diff
changeset
|
906 |
apply (auto simp: bij_betw_def f_the_inv_into_f the_inv_into_f_f the_inv_into_into) |
d73955442df5
a few new lemmas about functions
paulson <lp15@cam.ac.uk>
parents:
71827
diff
changeset
|
907 |
done |
d73955442df5
a few new lemmas about functions
paulson <lp15@cam.ac.uk>
parents:
71827
diff
changeset
|
908 |
qed (force intro: bij_betw_byWitness) |
d73955442df5
a few new lemmas about functions
paulson <lp15@cam.ac.uk>
parents:
71827
diff
changeset
|
909 |
|
63322 | 910 |
abbreviation the_inv :: "('a \<Rightarrow> 'b) \<Rightarrow> ('b \<Rightarrow> 'a)" |
911 |
where "the_inv f \<equiv> the_inv_into UNIV f" |
|
32998
31b19fa0de0b
Renamed inv to the_inv and turned it into an abbreviation (based on the_inv_onto).
berghofe
parents:
32988
diff
changeset
|
912 |
|
64965 | 913 |
lemma the_inv_f_f: "the_inv f (f x) = x" if "inj f" |
914 |
using that UNIV_I by (rule the_inv_into_f_f) |
|
32998
31b19fa0de0b
Renamed inv to the_inv and turned it into an abbreviation (based on the_inv_onto).
berghofe
parents:
32988
diff
changeset
|
915 |
|
44277
bcb696533579
moved fundamental lemma fun_eq_iff to theory HOL; tuned whitespace
haftmann
parents:
43991
diff
changeset
|
916 |
|
60758 | 917 |
subsection \<open>Cantor's Paradox\<close> |
40703
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOL-image.
hoelzl
parents:
40702
diff
changeset
|
918 |
|
63323 | 919 |
theorem Cantors_paradox: "\<nexists>f. f ` A = Pow A" |
920 |
proof |
|
921 |
assume "\<exists>f. f ` A = Pow A" |
|
922 |
then obtain f where f: "f ` A = Pow A" .. |
|
40703
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOL-image.
hoelzl
parents:
40702
diff
changeset
|
923 |
let ?X = "{a \<in> A. a \<notin> f a}" |
63323 | 924 |
have "?X \<in> Pow A" by blast |
925 |
then have "?X \<in> f ` A" by (simp only: f) |
|
926 |
then obtain x where "x \<in> A" and "f x = ?X" by blast |
|
927 |
then show False by blast |
|
40703
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOL-image.
hoelzl
parents:
40702
diff
changeset
|
928 |
qed |
31949 | 929 |
|
71472
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
930 |
subsection \<open>Monotonic functions over a set\<close> |
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
931 |
|
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
932 |
definition "mono_on f A \<equiv> \<forall>r s. r \<in> A \<and> s \<in> A \<and> r \<le> s \<longrightarrow> f r \<le> f s" |
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
933 |
|
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
934 |
lemma mono_onI: |
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
935 |
"(\<And>r s. r \<in> A \<Longrightarrow> s \<in> A \<Longrightarrow> r \<le> s \<Longrightarrow> f r \<le> f s) \<Longrightarrow> mono_on f A" |
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
936 |
unfolding mono_on_def by simp |
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
937 |
|
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
938 |
lemma mono_onD: |
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
939 |
"\<lbrakk>mono_on f A; r \<in> A; s \<in> A; r \<le> s\<rbrakk> \<Longrightarrow> f r \<le> f s" |
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
940 |
unfolding mono_on_def by simp |
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
941 |
|
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
942 |
lemma mono_imp_mono_on: "mono f \<Longrightarrow> mono_on f A" |
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
943 |
unfolding mono_def mono_on_def by auto |
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
944 |
|
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
945 |
lemma mono_on_subset: "mono_on f A \<Longrightarrow> B \<subseteq> A \<Longrightarrow> mono_on f B" |
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
946 |
unfolding mono_on_def by auto |
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
947 |
|
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
948 |
definition "strict_mono_on f A \<equiv> \<forall>r s. r \<in> A \<and> s \<in> A \<and> r < s \<longrightarrow> f r < f s" |
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
949 |
|
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
950 |
lemma strict_mono_onI: |
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
951 |
"(\<And>r s. r \<in> A \<Longrightarrow> s \<in> A \<Longrightarrow> r < s \<Longrightarrow> f r < f s) \<Longrightarrow> strict_mono_on f A" |
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
952 |
unfolding strict_mono_on_def by simp |
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
953 |
|
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
954 |
lemma strict_mono_onD: |
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
955 |
"\<lbrakk>strict_mono_on f A; r \<in> A; s \<in> A; r < s\<rbrakk> \<Longrightarrow> f r < f s" |
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
956 |
unfolding strict_mono_on_def by simp |
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
957 |
|
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
958 |
lemma mono_on_greaterD: |
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
959 |
assumes "mono_on g A" "x \<in> A" "y \<in> A" "g x > (g (y::_::linorder) :: _ :: linorder)" |
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
960 |
shows "x > y" |
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
961 |
proof (rule ccontr) |
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
962 |
assume "\<not>x > y" |
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
963 |
hence "x \<le> y" by (simp add: not_less) |
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
964 |
from assms(1-3) and this have "g x \<le> g y" by (rule mono_onD) |
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
965 |
with assms(4) show False by simp |
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
966 |
qed |
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
967 |
|
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
968 |
lemma strict_mono_inv: |
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
969 |
fixes f :: "('a::linorder) \<Rightarrow> ('b::linorder)" |
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
970 |
assumes "strict_mono f" and "surj f" and inv: "\<And>x. g (f x) = x" |
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
971 |
shows "strict_mono g" |
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
972 |
proof |
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
973 |
fix x y :: 'b assume "x < y" |
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
974 |
from \<open>surj f\<close> obtain x' y' where [simp]: "x = f x'" "y = f y'" by blast |
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
975 |
with \<open>x < y\<close> and \<open>strict_mono f\<close> have "x' < y'" by (simp add: strict_mono_less) |
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
976 |
with inv show "g x < g y" by simp |
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
977 |
qed |
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
978 |
|
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
979 |
lemma strict_mono_on_imp_inj_on: |
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
980 |
assumes "strict_mono_on (f :: (_ :: linorder) \<Rightarrow> (_ :: preorder)) A" |
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
981 |
shows "inj_on f A" |
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
982 |
proof (rule inj_onI) |
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
983 |
fix x y assume "x \<in> A" "y \<in> A" "f x = f y" |
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
984 |
thus "x = y" |
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
985 |
by (cases x y rule: linorder_cases) |
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
986 |
(auto dest: strict_mono_onD[OF assms, of x y] strict_mono_onD[OF assms, of y x]) |
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
987 |
qed |
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
988 |
|
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
989 |
lemma strict_mono_on_leD: |
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
990 |
assumes "strict_mono_on (f :: (_ :: linorder) \<Rightarrow> _ :: preorder) A" "x \<in> A" "y \<in> A" "x \<le> y" |
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
991 |
shows "f x \<le> f y" |
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
992 |
proof (insert le_less_linear[of y x], elim disjE) |
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
993 |
assume "x < y" |
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
994 |
with assms have "f x < f y" by (rule_tac strict_mono_onD[OF assms(1)]) simp_all |
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
995 |
thus ?thesis by (rule less_imp_le) |
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
996 |
qed (insert assms, simp) |
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
997 |
|
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
998 |
lemma strict_mono_on_eqD: |
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
999 |
fixes f :: "(_ :: linorder) \<Rightarrow> (_ :: preorder)" |
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
1000 |
assumes "strict_mono_on f A" "f x = f y" "x \<in> A" "y \<in> A" |
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
1001 |
shows "y = x" |
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
1002 |
using assms by (rule_tac linorder_cases[of x y]) (auto dest: strict_mono_onD) |
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
1003 |
|
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
1004 |
lemma strict_mono_on_imp_mono_on: |
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
1005 |
"strict_mono_on (f :: (_ :: linorder) \<Rightarrow> _ :: preorder) A \<Longrightarrow> mono_on f A" |
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
1006 |
by (rule mono_onI, rule strict_mono_on_leD) |
c213d067e60f
Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents:
71464
diff
changeset
|
1007 |
|
63322 | 1008 |
|
61204 | 1009 |
subsection \<open>Setup\<close> |
40969 | 1010 |
|
60758 | 1011 |
subsubsection \<open>Proof tools\<close> |
22845 | 1012 |
|
63400 | 1013 |
text \<open>Simplify terms of the form \<open>f(\<dots>,x:=y,\<dots>,x:=z,\<dots>)\<close> to \<open>f(\<dots>,x:=z,\<dots>)\<close>\<close> |
22845 | 1014 |
|
60758 | 1015 |
simproc_setup fun_upd2 ("f(v := w, x := y)") = \<open>fn _ => |
63322 | 1016 |
let |
1017 |
fun gen_fun_upd NONE T _ _ = NONE |
|
69593 | 1018 |
| gen_fun_upd (SOME f) T x y = SOME (Const (\<^const_name>\<open>fun_upd\<close>, T) $ f $ x $ y) |
63322 | 1019 |
fun dest_fun_T1 (Type (_, T :: Ts)) = T |
69593 | 1020 |
fun find_double (t as Const (\<^const_name>\<open>fun_upd\<close>,T) $ f $ x $ y) = |
63322 | 1021 |
let |
69593 | 1022 |
fun find (Const (\<^const_name>\<open>fun_upd\<close>,T) $ g $ v $ w) = |
63322 | 1023 |
if v aconv x then SOME g else gen_fun_upd (find g) T v w |
1024 |
| find t = NONE |
|
1025 |
in (dest_fun_T1 T, gen_fun_upd (find f) T x y) end |
|
24017 | 1026 |
|
69593 | 1027 |
val ss = simpset_of \<^context> |
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51598
diff
changeset
|
1028 |
|
63322 | 1029 |
fun proc ctxt ct = |
1030 |
let |
|
1031 |
val t = Thm.term_of ct |
|
1032 |
in |
|
63400 | 1033 |
(case find_double t of |
63322 | 1034 |
(T, NONE) => NONE |
1035 |
| (T, SOME rhs) => |
|
1036 |
SOME (Goal.prove ctxt [] [] (Logic.mk_equals (t, rhs)) |
|
1037 |
(fn _ => |
|
1038 |
resolve_tac ctxt [eq_reflection] 1 THEN |
|
1039 |
resolve_tac ctxt @{thms ext} 1 THEN |
|
63400 | 1040 |
simp_tac (put_simpset ss ctxt) 1))) |
63322 | 1041 |
end |
1042 |
in proc end |
|
60758 | 1043 |
\<close> |
22845 | 1044 |
|
1045 |
||
60758 | 1046 |
subsubsection \<open>Functorial structure of types\<close> |
40969 | 1047 |
|
69605 | 1048 |
ML_file \<open>Tools/functor.ML\<close> |
40969 | 1049 |
|
55467
a5c9002bc54d
renamed 'enriched_type' to more informative 'functor' (following the renaming of enriched type constructors to bounded natural functors)
blanchet
parents:
55414
diff
changeset
|
1050 |
functor map_fun: map_fun |
47488
be6dd389639d
centralized enriched_type declaration, thanks to in-situ available Isar commands
haftmann
parents:
46950
diff
changeset
|
1051 |
by (simp_all add: fun_eq_iff) |
be6dd389639d
centralized enriched_type declaration, thanks to in-situ available Isar commands
haftmann
parents:
46950
diff
changeset
|
1052 |
|
55467
a5c9002bc54d
renamed 'enriched_type' to more informative 'functor' (following the renaming of enriched type constructors to bounded natural functors)
blanchet
parents:
55414
diff
changeset
|
1053 |
functor vimage |
49739 | 1054 |
by (simp_all add: fun_eq_iff vimage_comp) |
1055 |
||
63322 | 1056 |
|
60758 | 1057 |
text \<open>Legacy theorem names\<close> |
49739 | 1058 |
|
1059 |
lemmas o_def = comp_def |
|
1060 |
lemmas o_apply = comp_apply |
|
1061 |
lemmas o_assoc = comp_assoc [symmetric] |
|
1062 |
lemmas id_o = id_comp |
|
1063 |
lemmas o_id = comp_id |
|
1064 |
lemmas o_eq_dest = comp_eq_dest |
|
1065 |
lemmas o_eq_elim = comp_eq_elim |
|
55066 | 1066 |
lemmas o_eq_dest_lhs = comp_eq_dest_lhs |
1067 |
lemmas o_eq_id_dest = comp_eq_id_dest |
|
47488
be6dd389639d
centralized enriched_type declaration, thanks to in-situ available Isar commands
haftmann
parents:
46950
diff
changeset
|
1068 |
|
2912 | 1069 |
end |