author  haftmann 
Mon, 08 Oct 2012 12:03:49 +0200  
changeset 49739  13aa6d8268ec 
parent 48891  c0eafbd55de3 
child 49905  a81f95693c68 
permissions  rwrr 
1475  1 
(* Title: HOL/Fun.thy 
2 
Author: Tobias Nipkow, Cambridge University Computer Laboratory 

923  3 
Copyright 1994 University of Cambridge 
18154  4 
*) 
923  5 

18154  6 
header {* Notions about functions *} 
923  7 

15510  8 
theory Fun 
44860
56101fa00193
renamed theory Complete_Lattice to Complete_Lattices, in accordance with Lattices, Orderings etc.
haftmann
parents:
44744
diff
changeset

9 
imports Complete_Lattices 
46950
d0181abdbdac
declare command keywords via theory header, including strict checking outside Pure;
wenzelm
parents:
46586
diff
changeset

10 
keywords "enriched_type" :: thy_goal 
15131  11 
begin 
2912  12 

26147  13 
lemma apply_inverse: 
26357  14 
"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 

12258  17 

26147  18 
subsection {* The Identity Function @{text id} *} 
6171  19 

44277
bcb696533579
moved fundamental lemma fun_eq_iff to theory HOL; tuned whitespace
haftmann
parents:
43991
diff
changeset

20 
definition id :: "'a \<Rightarrow> 'a" where 
22744
5cbe966d67a2
Isar definitions are now added explicitly to code theorem table
haftmann
parents:
22577
diff
changeset

21 
"id = (\<lambda>x. x)" 
13910  22 

26147  23 
lemma id_apply [simp]: "id x = x" 
24 
by (simp add: id_def) 

25 

47579  26 
lemma image_id [simp]: "image id = id" 
27 
by (simp add: id_def fun_eq_iff) 

26147  28 

47579  29 
lemma vimage_id [simp]: "vimage id = id" 
30 
by (simp add: id_def fun_eq_iff) 

26147  31 

32 

33 
subsection {* The Composition Operator @{text "f \<circ> g"} *} 

34 

44277
bcb696533579
moved fundamental lemma fun_eq_iff to theory HOL; tuned whitespace
haftmann
parents:
43991
diff
changeset

35 
definition comp :: "('b \<Rightarrow> 'c) \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> 'a \<Rightarrow> 'c" (infixl "o" 55) where 
22744
5cbe966d67a2
Isar definitions are now added explicitly to code theorem table
haftmann
parents:
22577
diff
changeset

36 
"f o g = (\<lambda>x. f (g x))" 
11123  37 

21210  38 
notation (xsymbols) 
19656
09be06943252
tuned concrete syntax  abbreviation/const_syntax;
wenzelm
parents:
19536
diff
changeset

39 
comp (infixl "\<circ>" 55) 
09be06943252
tuned concrete syntax  abbreviation/const_syntax;
wenzelm
parents:
19536
diff
changeset

40 

21210  41 
notation (HTML output) 
19656
09be06943252
tuned concrete syntax  abbreviation/const_syntax;
wenzelm
parents:
19536
diff
changeset

42 
comp (infixl "\<circ>" 55) 
09be06943252
tuned concrete syntax  abbreviation/const_syntax;
wenzelm
parents:
19536
diff
changeset

43 

49739  44 
lemma comp_apply [simp]: "(f o g) x = f (g x)" 
45 
by (simp add: comp_def) 

13585  46 

49739  47 
lemma comp_assoc: "(f o g) o h = f o (g o h)" 
48 
by (simp add: fun_eq_iff) 

13585  49 

49739  50 
lemma id_comp [simp]: "id o g = g" 
51 
by (simp add: fun_eq_iff) 

13585  52 

49739  53 
lemma comp_id [simp]: "f o id = f" 
54 
by (simp add: fun_eq_iff) 

55 

56 
lemma comp_eq_dest: 

34150  57 
"a o b = c o d \<Longrightarrow> a (b v) = c (d v)" 
49739  58 
by (simp add: fun_eq_iff) 
34150  59 

49739  60 
lemma comp_eq_elim: 
34150  61 
"a o b = c o d \<Longrightarrow> ((\<And>v. a (b v) = c (d v)) \<Longrightarrow> R) \<Longrightarrow> R" 
49739  62 
by (simp add: fun_eq_iff) 
34150  63 

49739  64 
lemma image_comp: 
65 
"(f o g) ` r = f ` (g ` r)" 

33044  66 
by auto 
67 

49739  68 
lemma vimage_comp: 
69 
"(g \<circ> f) ` x = f ` (g ` x)" 

70 
by auto 

71 

72 
lemma INF_comp: 

73 
"INFI A (g \<circ> f) = INFI (f ` A) g" 

74 
by (simp add: INF_def image_comp) 

75 

76 
lemma SUP_comp: 

77 
"SUPR A (g \<circ> f) = SUPR (f ` A) g" 

78 
by (simp add: SUP_def image_comp) 

13585  79 

80 

26588
d83271bfaba5
removed syntax from monad combinators; renamed mbind to scomp
haftmann
parents:
26357
diff
changeset

81 
subsection {* The Forward Composition Operator @{text fcomp} *} 
26357  82 

44277
bcb696533579
moved fundamental lemma fun_eq_iff to theory HOL; tuned whitespace
haftmann
parents:
43991
diff
changeset

83 
definition fcomp :: "('a \<Rightarrow> 'b) \<Rightarrow> ('b \<Rightarrow> 'c) \<Rightarrow> 'a \<Rightarrow> 'c" (infixl "\<circ>>" 60) where 
37751  84 
"f \<circ>> g = (\<lambda>x. g (f x))" 
26357  85 

37751  86 
lemma fcomp_apply [simp]: "(f \<circ>> g) x = g (f x)" 
26357  87 
by (simp add: fcomp_def) 
88 

37751  89 
lemma fcomp_assoc: "(f \<circ>> g) \<circ>> h = f \<circ>> (g \<circ>> h)" 
26357  90 
by (simp add: fcomp_def) 
91 

37751  92 
lemma id_fcomp [simp]: "id \<circ>> g = g" 
26357  93 
by (simp add: fcomp_def) 
94 

37751  95 
lemma fcomp_id [simp]: "f \<circ>> id = f" 
26357  96 
by (simp add: fcomp_def) 
97 

31202
52d332f8f909
pretty printing of functional combinators for evaluation code
haftmann
parents:
31080
diff
changeset

98 
code_const fcomp 
52d332f8f909
pretty printing of functional combinators for evaluation code
haftmann
parents:
31080
diff
changeset

99 
(Eval infixl 1 "#>") 
52d332f8f909
pretty printing of functional combinators for evaluation code
haftmann
parents:
31080
diff
changeset

100 

37751  101 
no_notation fcomp (infixl "\<circ>>" 60) 
26588
d83271bfaba5
removed syntax from monad combinators; renamed mbind to scomp
haftmann
parents:
26357
diff
changeset

102 

26357  103 

40602  104 
subsection {* Mapping functions *} 
105 

106 
definition map_fun :: "('c \<Rightarrow> 'a) \<Rightarrow> ('b \<Rightarrow> 'd) \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> 'c \<Rightarrow> 'd" where 

107 
"map_fun f g h = g \<circ> h \<circ> f" 

108 

109 
lemma map_fun_apply [simp]: 

110 
"map_fun f g h x = g (h (f x))" 

111 
by (simp add: map_fun_def) 

112 

113 

40702  114 
subsection {* Injectivity and Bijectivity *} 
39076
b3a9b6734663
Introduce surj_on and replace surj and bij by abbreviations.
hoelzl
parents:
39075
diff
changeset

115 

b3a9b6734663
Introduce surj_on and replace surj and bij by abbreviations.
hoelzl
parents:
39075
diff
changeset

116 
definition inj_on :: "('a \<Rightarrow> 'b) \<Rightarrow> 'a set \<Rightarrow> bool" where  "injective" 
b3a9b6734663
Introduce surj_on and replace surj and bij by abbreviations.
hoelzl
parents:
39075
diff
changeset

117 
"inj_on f A \<longleftrightarrow> (\<forall>x\<in>A. \<forall>y\<in>A. f x = f y \<longrightarrow> x = y)" 
26147  118 

39076
b3a9b6734663
Introduce surj_on and replace surj and bij by abbreviations.
hoelzl
parents:
39075
diff
changeset

119 
definition bij_betw :: "('a \<Rightarrow> 'b) \<Rightarrow> 'a set \<Rightarrow> 'b set \<Rightarrow> bool" where  "bijective" 
b3a9b6734663
Introduce surj_on and replace surj and bij by abbreviations.
hoelzl
parents:
39075
diff
changeset

120 
"bij_betw f A B \<longleftrightarrow> inj_on f A \<and> f ` A = B" 
26147  121 

40702  122 
text{*A common special case: functions injective, surjective or bijective over 
123 
the entire domain type.*} 

26147  124 

125 
abbreviation 

39076
b3a9b6734663
Introduce surj_on and replace surj and bij by abbreviations.
hoelzl
parents:
39075
diff
changeset

126 
"inj f \<equiv> inj_on f UNIV" 
26147  127 

40702  128 
abbreviation surj :: "('a \<Rightarrow> 'b) \<Rightarrow> bool" where  "surjective" 
129 
"surj f \<equiv> (range f = UNIV)" 

13585  130 

39076
b3a9b6734663
Introduce surj_on and replace surj and bij by abbreviations.
hoelzl
parents:
39075
diff
changeset

131 
abbreviation 
b3a9b6734663
Introduce surj_on and replace surj and bij by abbreviations.
hoelzl
parents:
39075
diff
changeset

132 
"bij f \<equiv> bij_betw f UNIV UNIV" 
26147  133 

43705
8e421a529a48
added translation to fix critical pair between abbreviations for surj and ~=
nipkow
parents:
42903
diff
changeset

134 
text{* The negated case: *} 
8e421a529a48
added translation to fix critical pair between abbreviations for surj and ~=
nipkow
parents:
42903
diff
changeset

135 
translations 
8e421a529a48
added translation to fix critical pair between abbreviations for surj and ~=
nipkow
parents:
42903
diff
changeset

136 
"\<not> CONST surj f" <= "CONST range f \<noteq> CONST UNIV" 
8e421a529a48
added translation to fix critical pair between abbreviations for surj and ~=
nipkow
parents:
42903
diff
changeset

137 

26147  138 
lemma injI: 
139 
assumes "\<And>x y. f x = f y \<Longrightarrow> x = y" 

140 
shows "inj f" 

141 
using assms unfolding inj_on_def by auto 

13585  142 

13637  143 
theorem range_ex1_eq: "inj f \<Longrightarrow> b : range f = (EX! x. b = f x)" 
144 
by (unfold inj_on_def, blast) 

145 

13585  146 
lemma injD: "[ inj(f); f(x) = f(y) ] ==> x=y" 
147 
by (simp add: inj_on_def) 

148 

32988  149 
lemma inj_on_eq_iff: "inj_on f A ==> x:A ==> y:A ==> (f(x) = f(y)) = (x=y)" 
13585  150 
by (force simp add: inj_on_def) 
151 

40703
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

152 
lemma inj_on_cong: 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

153 
"(\<And> a. a : A \<Longrightarrow> f a = g a) \<Longrightarrow> inj_on f A = inj_on g A" 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

154 
unfolding inj_on_def by auto 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

155 

d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

156 
lemma inj_on_strict_subset: 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

157 
"\<lbrakk> inj_on f B; A < B \<rbrakk> \<Longrightarrow> f`A < f`B" 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

158 
unfolding inj_on_def unfolding image_def by blast 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

159 

38620  160 
lemma inj_comp: 
161 
"inj f \<Longrightarrow> inj g \<Longrightarrow> inj (f \<circ> g)" 

162 
by (simp add: inj_on_def) 

163 

164 
lemma inj_fun: "inj f \<Longrightarrow> inj (\<lambda>x y. f x)" 

39302
d7728f65b353
renamed lemmas: ext_iff > fun_eq_iff, set_ext_iff > set_eq_iff, set_ext > set_eqI
nipkow
parents:
39213
diff
changeset

165 
by (simp add: inj_on_def fun_eq_iff) 
38620  166 

32988  167 
lemma inj_eq: "inj f ==> (f(x) = f(y)) = (x=y)" 
168 
by (simp add: inj_on_eq_iff) 

169 

26147  170 
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

171 
by (simp add: inj_on_def) 
13585  172 

26147  173 
lemma inj_on_id2[simp]: "inj_on (%x. x) A" 
39076
b3a9b6734663
Introduce surj_on and replace surj and bij by abbreviations.
hoelzl
parents:
39075
diff
changeset

174 
by (simp add: inj_on_def) 
26147  175 

46586  176 
lemma inj_on_Int: "inj_on f A \<or> inj_on f B \<Longrightarrow> inj_on f (A \<inter> B)" 
40703
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

177 
unfolding inj_on_def by blast 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

178 

d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

179 
lemma inj_on_INTER: 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

180 
"\<lbrakk>I \<noteq> {}; \<And> i. i \<in> I \<Longrightarrow> inj_on f (A i)\<rbrakk> \<Longrightarrow> inj_on f (\<Inter> i \<in> I. A i)" 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

181 
unfolding inj_on_def by blast 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

182 

d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

183 
lemma inj_on_Inter: 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

184 
"\<lbrakk>S \<noteq> {}; \<And> A. A \<in> S \<Longrightarrow> inj_on f A\<rbrakk> \<Longrightarrow> inj_on f (Inter S)" 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

185 
unfolding inj_on_def by blast 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

186 

d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

187 
lemma inj_on_UNION_chain: 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

188 
assumes CH: "\<And> i j. \<lbrakk>i \<in> I; j \<in> I\<rbrakk> \<Longrightarrow> A i \<le> A j \<or> A j \<le> A i" and 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

189 
INJ: "\<And> i. i \<in> I \<Longrightarrow> inj_on f (A i)" 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

190 
shows "inj_on f (\<Union> i \<in> I. A i)" 
44928
7ef6505bde7f
renamed Complete_Lattices lemmas, removed legacy names
hoelzl
parents:
44921
diff
changeset

191 
proof(unfold inj_on_def UNION_eq, auto) 
40703
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

192 
fix i j x y 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

193 
assume *: "i \<in> I" "j \<in> I" and **: "x \<in> A i" "y \<in> A j" 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

194 
and ***: "f x = f y" 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

195 
show "x = y" 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

196 
proof 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

197 
{assume "A i \<le> A j" 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

198 
with ** have "x \<in> A j" by auto 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

199 
with INJ * ** *** have ?thesis 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

200 
by(auto simp add: inj_on_def) 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

201 
} 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

202 
moreover 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

203 
{assume "A j \<le> A i" 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

204 
with ** have "y \<in> A i" by auto 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

205 
with INJ * ** *** have ?thesis 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

206 
by(auto simp add: inj_on_def) 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

207 
} 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

208 
ultimately show ?thesis using CH * by blast 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

209 
qed 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

210 
qed 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

211 

40702  212 
lemma surj_id: "surj id" 
213 
by simp 

26147  214 

39101
606432dd1896
Revert bij_betw changes to simp set (Problem in afp/Ordinals_and_Cardinals)
hoelzl
parents:
39076
diff
changeset

215 
lemma bij_id[simp]: "bij id" 
39076
b3a9b6734663
Introduce surj_on and replace surj and bij by abbreviations.
hoelzl
parents:
39075
diff
changeset

216 
by (simp add: bij_betw_def) 
13585  217 

218 
lemma inj_onI: 

219 
"(!! x y. [ x:A; y:A; f(x) = f(y) ] ==> x=y) ==> inj_on f A" 

220 
by (simp add: inj_on_def) 

221 

222 
lemma inj_on_inverseI: "(!!x. x:A ==> g(f(x)) = x) ==> inj_on f A" 

223 
by (auto dest: arg_cong [of concl: g] simp add: inj_on_def) 

224 

225 
lemma inj_onD: "[ inj_on f A; f(x)=f(y); x:A; y:A ] ==> x=y" 

226 
by (unfold inj_on_def, blast) 

227 

228 
lemma inj_on_iff: "[ inj_on f A; x:A; y:A ] ==> (f(x)=f(y)) = (x=y)" 

229 
by (blast dest!: inj_onD) 

230 

231 
lemma comp_inj_on: 

232 
"[ inj_on f A; inj_on g (f`A) ] ==> inj_on (g o f) A" 

233 
by (simp add: comp_def inj_on_def) 

234 

15303  235 
lemma inj_on_imageI: "inj_on (g o f) A \<Longrightarrow> inj_on g (f ` A)" 
236 
apply(simp add:inj_on_def image_def) 

237 
apply blast 

238 
done 

239 

15439  240 
lemma inj_on_image_iff: "\<lbrakk> ALL x:A. ALL y:A. (g(f x) = g(f y)) = (g x = g y); 
241 
inj_on f A \<rbrakk> \<Longrightarrow> inj_on g (f ` A) = inj_on g A" 

242 
apply(unfold inj_on_def) 

243 
apply blast 

244 
done 

245 

13585  246 
lemma inj_on_contraD: "[ inj_on f A; ~x=y; x:A; y:A ] ==> ~ f(x)=f(y)" 
247 
by (unfold inj_on_def, blast) 

12258  248 

13585  249 
lemma inj_singleton: "inj (%s. {s})" 
250 
by (simp add: inj_on_def) 

251 

15111  252 
lemma inj_on_empty[iff]: "inj_on f {}" 
253 
by(simp add: inj_on_def) 

254 

15303  255 
lemma subset_inj_on: "[ inj_on f B; A <= B ] ==> inj_on f A" 
13585  256 
by (unfold inj_on_def, blast) 
257 

15111  258 
lemma inj_on_Un: 
259 
"inj_on f (A Un B) = 

260 
(inj_on f A & inj_on f B & f`(AB) Int f`(BA) = {})" 

261 
apply(unfold inj_on_def) 

262 
apply (blast intro:sym) 

263 
done 

264 

265 
lemma inj_on_insert[iff]: 

266 
"inj_on f (insert a A) = (inj_on f A & f a ~: f`(A{a}))" 

267 
apply(unfold inj_on_def) 

268 
apply (blast intro:sym) 

269 
done 

270 

271 
lemma inj_on_diff: "inj_on f A ==> inj_on f (AB)" 

272 
apply(unfold inj_on_def) 

273 
apply (blast) 

274 
done 

275 

40703
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

276 
lemma comp_inj_on_iff: 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

277 
"inj_on f A \<Longrightarrow> inj_on f' (f ` A) \<longleftrightarrow> inj_on (f' o f) A" 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

278 
by(auto simp add: comp_inj_on inj_on_def) 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

279 

d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

280 
lemma inj_on_imageI2: 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

281 
"inj_on (f' o f) A \<Longrightarrow> inj_on f A" 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

282 
by(auto simp add: comp_inj_on inj_on_def) 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

283 

40702  284 
lemma surj_def: "surj f \<longleftrightarrow> (\<forall>y. \<exists>x. y = f x)" 
285 
by auto 

39076
b3a9b6734663
Introduce surj_on and replace surj and bij by abbreviations.
hoelzl
parents:
39075
diff
changeset

286 

40702  287 
lemma surjI: assumes *: "\<And> x. g (f x) = x" shows "surj g" 
288 
using *[symmetric] by auto 

13585  289 

39076
b3a9b6734663
Introduce surj_on and replace surj and bij by abbreviations.
hoelzl
parents:
39075
diff
changeset

290 
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

291 
by (simp add: surj_def) 
13585  292 

39076
b3a9b6734663
Introduce surj_on and replace surj and bij by abbreviations.
hoelzl
parents:
39075
diff
changeset

293 
lemma surjE: "surj f \<Longrightarrow> (\<And>x. y = f x \<Longrightarrow> C) \<Longrightarrow> C" 
b3a9b6734663
Introduce surj_on and replace surj and bij by abbreviations.
hoelzl
parents:
39075
diff
changeset

294 
by (simp add: surj_def, blast) 
13585  295 

296 
lemma comp_surj: "[ surj f; surj g ] ==> surj (g o f)" 

297 
apply (simp add: comp_def surj_def, clarify) 

298 
apply (drule_tac x = y in spec, clarify) 

299 
apply (drule_tac x = x in spec, blast) 

300 
done 

301 

39074  302 
lemma bij_betw_imp_surj: "bij_betw f A UNIV \<Longrightarrow> surj f" 
40702  303 
unfolding bij_betw_def by auto 
39074  304 

40703
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

305 
lemma bij_betw_empty1: 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

306 
assumes "bij_betw f {} A" 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

307 
shows "A = {}" 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

308 
using assms unfolding bij_betw_def by blast 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

309 

d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

310 
lemma bij_betw_empty2: 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

311 
assumes "bij_betw f A {}" 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

312 
shows "A = {}" 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

313 
using assms unfolding bij_betw_def by blast 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

314 

d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

315 
lemma inj_on_imp_bij_betw: 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

316 
"inj_on f A \<Longrightarrow> bij_betw f A (f ` A)" 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

317 
unfolding bij_betw_def by simp 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

318 

39076
b3a9b6734663
Introduce surj_on and replace surj and bij by abbreviations.
hoelzl
parents:
39075
diff
changeset

319 
lemma bij_def: "bij f \<longleftrightarrow> inj f \<and> surj f" 
40702  320 
unfolding bij_betw_def .. 
39074  321 

13585  322 
lemma bijI: "[ inj f; surj f ] ==> bij f" 
323 
by (simp add: bij_def) 

324 

325 
lemma bij_is_inj: "bij f ==> inj f" 

326 
by (simp add: bij_def) 

327 

328 
lemma bij_is_surj: "bij f ==> surj f" 

329 
by (simp add: bij_def) 

330 

26105
ae06618225ec
moved bij_betw from Library/FuncSet to Fun, redistributed some lemmas, and
nipkow
parents:
25886
diff
changeset

331 
lemma bij_betw_imp_inj_on: "bij_betw f A B \<Longrightarrow> inj_on f A" 
ae06618225ec
moved bij_betw from Library/FuncSet to Fun, redistributed some lemmas, and
nipkow
parents:
25886
diff
changeset

332 
by (simp add: bij_betw_def) 
ae06618225ec
moved bij_betw from Library/FuncSet to Fun, redistributed some lemmas, and
nipkow
parents:
25886
diff
changeset

333 

31438  334 
lemma bij_betw_trans: 
335 
"bij_betw f A B \<Longrightarrow> bij_betw g B C \<Longrightarrow> bij_betw (g o f) A C" 

336 
by(auto simp add:bij_betw_def comp_inj_on) 

337 

40702  338 
lemma bij_comp: "bij f \<Longrightarrow> bij g \<Longrightarrow> bij (g o f)" 
339 
by (rule bij_betw_trans) 

340 

40703
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

341 
lemma bij_betw_comp_iff: 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

342 
"bij_betw f A A' \<Longrightarrow> bij_betw f' A' A'' \<longleftrightarrow> bij_betw (f' o f) A A''" 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

343 
by(auto simp add: bij_betw_def inj_on_def) 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

344 

d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

345 
lemma bij_betw_comp_iff2: 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

346 
assumes BIJ: "bij_betw f' A' A''" and IM: "f ` A \<le> A'" 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

347 
shows "bij_betw f A A' \<longleftrightarrow> bij_betw (f' o f) A A''" 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

348 
using assms 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

349 
proof(auto simp add: bij_betw_comp_iff) 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

350 
assume *: "bij_betw (f' \<circ> f) A A''" 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

351 
thus "bij_betw f A A'" 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

352 
using IM 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

353 
proof(auto simp add: bij_betw_def) 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

354 
assume "inj_on (f' \<circ> f) A" 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

355 
thus "inj_on f A" using inj_on_imageI2 by blast 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

356 
next 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

357 
fix a' assume **: "a' \<in> A'" 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

358 
hence "f' a' \<in> A''" using BIJ unfolding bij_betw_def by auto 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

359 
then obtain a where 1: "a \<in> A \<and> f'(f a) = f' a'" using * 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

360 
unfolding bij_betw_def by force 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

361 
hence "f a \<in> A'" using IM by auto 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

362 
hence "f a = a'" using BIJ ** 1 unfolding bij_betw_def inj_on_def by auto 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

363 
thus "a' \<in> f ` A" using 1 by auto 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

364 
qed 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

365 
qed 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

366 

26105
ae06618225ec
moved bij_betw from Library/FuncSet to Fun, redistributed some lemmas, and
nipkow
parents:
25886
diff
changeset

367 
lemma bij_betw_inv: assumes "bij_betw f A B" shows "EX g. bij_betw g B A" 
ae06618225ec
moved bij_betw from Library/FuncSet to Fun, redistributed some lemmas, and
nipkow
parents:
25886
diff
changeset

368 
proof  
ae06618225ec
moved bij_betw from Library/FuncSet to Fun, redistributed some lemmas, and
nipkow
parents:
25886
diff
changeset

369 
have i: "inj_on f A" and s: "f ` A = B" 
ae06618225ec
moved bij_betw from Library/FuncSet to Fun, redistributed some lemmas, and
nipkow
parents:
25886
diff
changeset

370 
using assms by(auto simp:bij_betw_def) 
ae06618225ec
moved bij_betw from Library/FuncSet to Fun, redistributed some lemmas, and
nipkow
parents:
25886
diff
changeset

371 
let ?P = "%b a. a:A \<and> f a = b" let ?g = "%b. The (?P b)" 
ae06618225ec
moved bij_betw from Library/FuncSet to Fun, redistributed some lemmas, and
nipkow
parents:
25886
diff
changeset

372 
{ fix a b assume P: "?P b a" 
ae06618225ec
moved bij_betw from Library/FuncSet to Fun, redistributed some lemmas, and
nipkow
parents:
25886
diff
changeset

373 
hence ex1: "\<exists>a. ?P b a" using s unfolding image_def by blast 
ae06618225ec
moved bij_betw from Library/FuncSet to Fun, redistributed some lemmas, and
nipkow
parents:
25886
diff
changeset

374 
hence uex1: "\<exists>!a. ?P b a" by(blast dest:inj_onD[OF i]) 
ae06618225ec
moved bij_betw from Library/FuncSet to Fun, redistributed some lemmas, and
nipkow
parents:
25886
diff
changeset

375 
hence " ?g b = a" using the1_equality[OF uex1, OF P] P by simp 
ae06618225ec
moved bij_betw from Library/FuncSet to Fun, redistributed some lemmas, and
nipkow
parents:
25886
diff
changeset

376 
} note g = this 
ae06618225ec
moved bij_betw from Library/FuncSet to Fun, redistributed some lemmas, and
nipkow
parents:
25886
diff
changeset

377 
have "inj_on ?g B" 
ae06618225ec
moved bij_betw from Library/FuncSet to Fun, redistributed some lemmas, and
nipkow
parents:
25886
diff
changeset

378 
proof(rule inj_onI) 
ae06618225ec
moved bij_betw from Library/FuncSet to Fun, redistributed some lemmas, and
nipkow
parents:
25886
diff
changeset

379 
fix x y assume "x:B" "y:B" "?g x = ?g y" 
ae06618225ec
moved bij_betw from Library/FuncSet to Fun, redistributed some lemmas, and
nipkow
parents:
25886
diff
changeset

380 
from s `x:B` obtain a1 where a1: "?P x a1" unfolding image_def by blast 
ae06618225ec
moved bij_betw from Library/FuncSet to Fun, redistributed some lemmas, and
nipkow
parents:
25886
diff
changeset

381 
from s `y:B` obtain a2 where a2: "?P y a2" unfolding image_def by blast 
ae06618225ec
moved bij_betw from Library/FuncSet to Fun, redistributed some lemmas, and
nipkow
parents:
25886
diff
changeset

382 
from g[OF a1] a1 g[OF a2] a2 `?g x = ?g y` show "x=y" by simp 
ae06618225ec
moved bij_betw from Library/FuncSet to Fun, redistributed some lemmas, and
nipkow
parents:
25886
diff
changeset

383 
qed 
ae06618225ec
moved bij_betw from Library/FuncSet to Fun, redistributed some lemmas, and
nipkow
parents:
25886
diff
changeset

384 
moreover have "?g ` B = A" 
ae06618225ec
moved bij_betw from Library/FuncSet to Fun, redistributed some lemmas, and
nipkow
parents:
25886
diff
changeset

385 
proof(auto simp:image_def) 
ae06618225ec
moved bij_betw from Library/FuncSet to Fun, redistributed some lemmas, and
nipkow
parents:
25886
diff
changeset

386 
fix b assume "b:B" 
ae06618225ec
moved bij_betw from Library/FuncSet to Fun, redistributed some lemmas, and
nipkow
parents:
25886
diff
changeset

387 
with s obtain a where P: "?P b a" unfolding image_def by blast 
ae06618225ec
moved bij_betw from Library/FuncSet to Fun, redistributed some lemmas, and
nipkow
parents:
25886
diff
changeset

388 
thus "?g b \<in> A" using g[OF P] by auto 
ae06618225ec
moved bij_betw from Library/FuncSet to Fun, redistributed some lemmas, and
nipkow
parents:
25886
diff
changeset

389 
next 
ae06618225ec
moved bij_betw from Library/FuncSet to Fun, redistributed some lemmas, and
nipkow
parents:
25886
diff
changeset

390 
fix a assume "a:A" 
ae06618225ec
moved bij_betw from Library/FuncSet to Fun, redistributed some lemmas, and
nipkow
parents:
25886
diff
changeset

391 
then obtain b where P: "?P b a" using s unfolding image_def by blast 
ae06618225ec
moved bij_betw from Library/FuncSet to Fun, redistributed some lemmas, and
nipkow
parents:
25886
diff
changeset

392 
then have "b:B" using s unfolding image_def by blast 
ae06618225ec
moved bij_betw from Library/FuncSet to Fun, redistributed some lemmas, and
nipkow
parents:
25886
diff
changeset

393 
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

394 
qed 
ae06618225ec
moved bij_betw from Library/FuncSet to Fun, redistributed some lemmas, and
nipkow
parents:
25886
diff
changeset

395 
ultimately show ?thesis by(auto simp:bij_betw_def) 
ae06618225ec
moved bij_betw from Library/FuncSet to Fun, redistributed some lemmas, and
nipkow
parents:
25886
diff
changeset

396 
qed 
ae06618225ec
moved bij_betw from Library/FuncSet to Fun, redistributed some lemmas, and
nipkow
parents:
25886
diff
changeset

397 

40703
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

398 
lemma bij_betw_cong: 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

399 
"(\<And> a. a \<in> A \<Longrightarrow> f a = g a) \<Longrightarrow> bij_betw f A A' = bij_betw g A A'" 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

400 
unfolding bij_betw_def inj_on_def by force 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

401 

d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

402 
lemma bij_betw_id[intro, simp]: 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

403 
"bij_betw id A A" 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

404 
unfolding bij_betw_def id_def by auto 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

405 

d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

406 
lemma bij_betw_id_iff: 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

407 
"bij_betw id A B \<longleftrightarrow> A = B" 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

408 
by(auto simp add: bij_betw_def) 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

409 

39075  410 
lemma bij_betw_combine: 
411 
assumes "bij_betw f A B" "bij_betw f C D" "B \<inter> D = {}" 

412 
shows "bij_betw f (A \<union> C) (B \<union> D)" 

413 
using assms unfolding bij_betw_def inj_on_Un image_Un by auto 

414 

40703
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

415 
lemma bij_betw_UNION_chain: 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

416 
assumes CH: "\<And> i j. \<lbrakk>i \<in> I; j \<in> I\<rbrakk> \<Longrightarrow> A i \<le> A j \<or> A j \<le> A i" and 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

417 
BIJ: "\<And> i. i \<in> I \<Longrightarrow> bij_betw f (A i) (A' i)" 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

418 
shows "bij_betw f (\<Union> i \<in> I. A i) (\<Union> i \<in> I. A' i)" 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

419 
proof(unfold bij_betw_def, auto simp add: image_def) 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

420 
have "\<And> i. i \<in> I \<Longrightarrow> inj_on f (A i)" 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

421 
using BIJ bij_betw_def[of f] by auto 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

422 
thus "inj_on f (\<Union> i \<in> I. A i)" 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

423 
using CH inj_on_UNION_chain[of I A f] by auto 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

424 
next 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

425 
fix i x 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

426 
assume *: "i \<in> I" "x \<in> A i" 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

427 
hence "f x \<in> A' i" using BIJ bij_betw_def[of f] by auto 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

428 
thus "\<exists>j \<in> I. f x \<in> A' j" using * by blast 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

429 
next 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

430 
fix i x' 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

431 
assume *: "i \<in> I" "x' \<in> A' i" 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

432 
hence "\<exists>x \<in> A i. x' = f x" using BIJ bij_betw_def[of f] by blast 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

433 
thus "\<exists>j \<in> I. \<exists>x \<in> A j. x' = f x" 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

434 
using * by blast 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

435 
qed 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

436 

d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

437 
lemma bij_betw_subset: 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

438 
assumes BIJ: "bij_betw f A A'" and 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

439 
SUB: "B \<le> A" and IM: "f ` B = B'" 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

440 
shows "bij_betw f B B'" 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

441 
using assms 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

442 
by(unfold bij_betw_def inj_on_def, auto simp add: inj_on_def) 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

443 

13585  444 
lemma surj_image_vimage_eq: "surj f ==> f ` (f ` A) = A" 
40702  445 
by simp 
13585  446 

42903  447 
lemma surj_vimage_empty: 
448 
assumes "surj f" shows "f ` A = {} \<longleftrightarrow> A = {}" 

449 
using surj_image_vimage_eq[OF `surj f`, of A] 

44890
22f665a2e91c
new fastforce replacing fastsimp  less confusing name
nipkow
parents:
44860
diff
changeset

450 
by (intro iffI) fastforce+ 
42903  451 

13585  452 
lemma inj_vimage_image_eq: "inj f ==> f ` (f ` A) = A" 
453 
by (simp add: inj_on_def, blast) 

454 

455 
lemma vimage_subsetD: "surj f ==> f ` B <= A ==> B <= f ` A" 

40702  456 
by (blast intro: sym) 
13585  457 

458 
lemma vimage_subsetI: "inj f ==> B <= f ` A ==> f ` B <= A" 

459 
by (unfold inj_on_def, blast) 

460 

461 
lemma vimage_subset_eq: "bij f ==> (f ` B <= A) = (B <= f ` A)" 

462 
apply (unfold bij_def) 

463 
apply (blast del: subsetI intro: vimage_subsetI vimage_subsetD) 

464 
done 

465 

31438  466 
lemma inj_on_Un_image_eq_iff: "inj_on f (A \<union> B) \<Longrightarrow> f ` A = f ` B \<longleftrightarrow> A = B" 
467 
by(blast dest: inj_onD) 

468 

13585  469 
lemma inj_on_image_Int: 
470 
"[ inj_on f C; A<=C; B<=C ] ==> f`(A Int B) = f`A Int f`B" 

471 
apply (simp add: inj_on_def, blast) 

472 
done 

473 

474 
lemma inj_on_image_set_diff: 

475 
"[ inj_on f C; A<=C; B<=C ] ==> f`(AB) = f`A  f`B" 

476 
apply (simp add: inj_on_def, blast) 

477 
done 

478 

479 
lemma image_Int: "inj f ==> f`(A Int B) = f`A Int f`B" 

480 
by (simp add: inj_on_def, blast) 

481 

482 
lemma image_set_diff: "inj f ==> f`(AB) = f`A  f`B" 

483 
by (simp add: inj_on_def, blast) 

484 

485 
lemma inj_image_mem_iff: "inj f ==> (f a : f`A) = (a : A)" 

486 
by (blast dest: injD) 

487 

488 
lemma inj_image_subset_iff: "inj f ==> (f`A <= f`B) = (A<=B)" 

489 
by (simp add: inj_on_def, blast) 

490 

491 
lemma inj_image_eq_iff: "inj f ==> (f`A = f`B) = (A = B)" 

492 
by (blast dest: injD) 

493 

494 
(*injectivity's required. Lefttoright inclusion holds even if A is empty*) 

495 
lemma image_INT: 

496 
"[ inj_on f C; ALL x:A. B x <= C; j:A ] 

497 
==> f ` (INTER A B) = (INT x:A. f ` B x)" 

498 
apply (simp add: inj_on_def, blast) 

499 
done 

500 

501 
(*Compare with image_INT: no use of inj_on, and if f is surjective then 

502 
it doesn't matter whether A is empty*) 

503 
lemma bij_image_INT: "bij f ==> f ` (INTER A B) = (INT x:A. f ` B x)" 

504 
apply (simp add: bij_def) 

505 
apply (simp add: inj_on_def surj_def, blast) 

506 
done 

507 

508 
lemma surj_Compl_image_subset: "surj f ==> (f`A) <= f`(A)" 

40702  509 
by auto 
13585  510 

511 
lemma inj_image_Compl_subset: "inj f ==> f`(A) <= (f`A)" 

512 
by (auto simp add: inj_on_def) 

5852  513 

13585  514 
lemma bij_image_Compl_eq: "bij f ==> f`(A) = (f`A)" 
515 
apply (simp add: bij_def) 

516 
apply (rule equalityI) 

517 
apply (simp_all (no_asm_simp) add: inj_image_Compl_subset surj_Compl_image_subset) 

518 
done 

519 

41657  520 
lemma inj_vimage_singleton: "inj f \<Longrightarrow> f ` {a} \<subseteq> {THE x. f x = a}" 
521 
 {* The inverse image of a singleton under an injective function 

522 
is included in a singleton. *} 

523 
apply (auto simp add: inj_on_def) 

524 
apply (blast intro: the_equality [symmetric]) 

525 
done 

526 

43991  527 
lemma inj_on_vimage_singleton: 
528 
"inj_on f A \<Longrightarrow> f ` {a} \<inter> A \<subseteq> {THE x. x \<in> A \<and> f x = a}" 

529 
by (auto simp add: inj_on_def intro: the_equality [symmetric]) 

530 

35584
768f8d92b767
generalized inj_uminus; added strict_mono_imp_inj_on
hoelzl
parents:
35580
diff
changeset

531 
lemma (in ordered_ab_group_add) inj_uminus[simp, intro]: "inj_on uminus A" 
35580  532 
by (auto intro!: inj_onI) 
13585  533 

35584
768f8d92b767
generalized inj_uminus; added strict_mono_imp_inj_on
hoelzl
parents:
35580
diff
changeset

534 
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

535 
by (auto intro!: inj_onI dest: strict_mono_eq) 
768f8d92b767
generalized inj_uminus; added strict_mono_imp_inj_on
hoelzl
parents:
35580
diff
changeset

536 

41657  537 

13585  538 
subsection{*Function Updating*} 
539 

44277
bcb696533579
moved fundamental lemma fun_eq_iff to theory HOL; tuned whitespace
haftmann
parents:
43991
diff
changeset

540 
definition fun_upd :: "('a => 'b) => 'a => 'b => ('a => 'b)" where 
26147  541 
"fun_upd f a b == % x. if x=a then b else f x" 
542 

41229
d797baa3d57c
replaced command 'nonterminals' by slightly modernized version 'nonterminal';
wenzelm
parents:
40969
diff
changeset

543 
nonterminal updbinds and updbind 
d797baa3d57c
replaced command 'nonterminals' by slightly modernized version 'nonterminal';
wenzelm
parents:
40969
diff
changeset

544 

26147  545 
syntax 
546 
"_updbind" :: "['a, 'a] => updbind" ("(2_ :=/ _)") 

547 
"" :: "updbind => updbinds" ("_") 

548 
"_updbinds":: "[updbind, updbinds] => updbinds" ("_,/ _") 

35115  549 
"_Update" :: "['a, updbinds] => 'a" ("_/'((_)')" [1000, 0] 900) 
26147  550 

551 
translations 

35115  552 
"_Update f (_updbinds b bs)" == "_Update (_Update f b) bs" 
553 
"f(x:=y)" == "CONST fun_upd f x y" 

26147  554 

555 
(* Hint: to define the sum of two functions (or maps), use sum_case. 

556 
A nice infix syntax could be defined (in Datatype.thy or below) by 

35115  557 
notation 
558 
sum_case (infixr "'(+')"80) 

26147  559 
*) 
560 

13585  561 
lemma fun_upd_idem_iff: "(f(x:=y) = f) = (f x = y)" 
562 
apply (simp add: fun_upd_def, safe) 

563 
apply (erule subst) 

564 
apply (rule_tac [2] ext, auto) 

565 
done 

566 

45603  567 
lemma fun_upd_idem: "f x = y ==> f(x:=y) = f" 
568 
by (simp only: fun_upd_idem_iff) 

13585  569 

45603  570 
lemma fun_upd_triv [iff]: "f(x := f x) = f" 
571 
by (simp only: fun_upd_idem) 

13585  572 

573 
lemma fun_upd_apply [simp]: "(f(x:=y))z = (if z=x then y else f z)" 

17084
fb0a80aef0be
classical rules must have names for ATP integration
paulson
parents:
16973
diff
changeset

574 
by (simp add: fun_upd_def) 
13585  575 

576 
(* fun_upd_apply supersedes these two, but they are useful 

577 
if fun_upd_apply is intentionally removed from the simpset *) 

578 
lemma fun_upd_same: "(f(x:=y)) x = y" 

579 
by simp 

580 

581 
lemma fun_upd_other: "z~=x ==> (f(x:=y)) z = f z" 

582 
by simp 

583 

584 
lemma fun_upd_upd [simp]: "f(x:=y,x:=z) = f(x:=z)" 

39302
d7728f65b353
renamed lemmas: ext_iff > fun_eq_iff, set_ext_iff > set_eq_iff, set_ext > set_eqI
nipkow
parents:
39213
diff
changeset

585 
by (simp add: fun_eq_iff) 
13585  586 

587 
lemma fun_upd_twist: "a ~= c ==> (m(a:=b))(c:=d) = (m(c:=d))(a:=b)" 

588 
by (rule ext, auto) 

589 

15303  590 
lemma inj_on_fun_updI: "\<lbrakk> inj_on f A; y \<notin> f`A \<rbrakk> \<Longrightarrow> inj_on (f(x:=y)) A" 
44890
22f665a2e91c
new fastforce replacing fastsimp  less confusing name
nipkow
parents:
44860
diff
changeset

591 
by (fastforce simp:inj_on_def image_def) 
15303  592 

15510  593 
lemma fun_upd_image: 
594 
"f(x:=y) ` A = (if x \<in> A then insert y (f ` (A{x})) else f ` A)" 

595 
by auto 

596 

31080  597 
lemma fun_upd_comp: "f \<circ> (g(x := y)) = (f \<circ> g)(x := f y)" 
44921  598 
by auto 
31080  599 

44744  600 
lemma UNION_fun_upd: 
601 
"UNION J (A(i:=B)) = (UNION (J{i}) A \<union> (if i\<in>J then B else {}))" 

602 
by (auto split: if_splits) 

603 

26147  604 

605 
subsection {* @{text override_on} *} 

606 

44277
bcb696533579
moved fundamental lemma fun_eq_iff to theory HOL; tuned whitespace
haftmann
parents:
43991
diff
changeset

607 
definition override_on :: "('a \<Rightarrow> 'b) \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> 'a set \<Rightarrow> 'a \<Rightarrow> 'b" where 
26147  608 
"override_on f g A = (\<lambda>a. if a \<in> A then g a else f a)" 
13910  609 

15691  610 
lemma override_on_emptyset[simp]: "override_on f g {} = f" 
611 
by(simp add:override_on_def) 

13910  612 

15691  613 
lemma override_on_apply_notin[simp]: "a ~: A ==> (override_on f g A) a = f a" 
614 
by(simp add:override_on_def) 

13910  615 

15691  616 
lemma override_on_apply_in[simp]: "a : A ==> (override_on f g A) a = g a" 
617 
by(simp add:override_on_def) 

13910  618 

26147  619 

620 
subsection {* @{text swap} *} 

15510  621 

44277
bcb696533579
moved fundamental lemma fun_eq_iff to theory HOL; tuned whitespace
haftmann
parents:
43991
diff
changeset

622 
definition swap :: "'a \<Rightarrow> 'a \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> ('a \<Rightarrow> 'b)" where 
22744
5cbe966d67a2
Isar definitions are now added explicitly to code theorem table
haftmann
parents:
22577
diff
changeset

623 
"swap a b f = f (a := f b, b:= f a)" 
15510  624 

34101  625 
lemma swap_self [simp]: "swap a a f = f" 
15691  626 
by (simp add: swap_def) 
15510  627 

628 
lemma swap_commute: "swap a b f = swap b a f" 

629 
by (rule ext, simp add: fun_upd_def swap_def) 

630 

631 
lemma swap_nilpotent [simp]: "swap a b (swap a b f) = f" 

632 
by (rule ext, simp add: fun_upd_def swap_def) 

633 

34145  634 
lemma swap_triple: 
635 
assumes "a \<noteq> c" and "b \<noteq> c" 

636 
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

637 
using assms by (simp add: fun_eq_iff swap_def) 
34145  638 

34101  639 
lemma comp_swap: "f \<circ> swap a b g = swap a b (f \<circ> g)" 
640 
by (rule ext, simp add: fun_upd_def swap_def) 

641 

39076
b3a9b6734663
Introduce surj_on and replace surj and bij by abbreviations.
hoelzl
parents:
39075
diff
changeset

642 
lemma swap_image_eq [simp]: 
b3a9b6734663
Introduce surj_on and replace surj and bij by abbreviations.
hoelzl
parents:
39075
diff
changeset

643 
assumes "a \<in> A" "b \<in> A" shows "swap a b f ` A = f ` A" 
b3a9b6734663
Introduce surj_on and replace surj and bij by abbreviations.
hoelzl
parents:
39075
diff
changeset

644 
proof  
b3a9b6734663
Introduce surj_on and replace surj and bij by abbreviations.
hoelzl
parents:
39075
diff
changeset

645 
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

646 
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

647 
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

648 
with subset[of f] show ?thesis by auto 
b3a9b6734663
Introduce surj_on and replace surj and bij by abbreviations.
hoelzl
parents:
39075
diff
changeset

649 
qed 
b3a9b6734663
Introduce surj_on and replace surj and bij by abbreviations.
hoelzl
parents:
39075
diff
changeset

650 

15510  651 
lemma inj_on_imp_inj_on_swap: 
39076
b3a9b6734663
Introduce surj_on and replace surj and bij by abbreviations.
hoelzl
parents:
39075
diff
changeset

652 
"\<lbrakk>inj_on f A; a \<in> A; b \<in> A\<rbrakk> \<Longrightarrow> inj_on (swap a b f) A" 
b3a9b6734663
Introduce surj_on and replace surj and bij by abbreviations.
hoelzl
parents:
39075
diff
changeset

653 
by (simp add: inj_on_def swap_def, blast) 
15510  654 

655 
lemma inj_on_swap_iff [simp]: 

39076
b3a9b6734663
Introduce surj_on and replace surj and bij by abbreviations.
hoelzl
parents:
39075
diff
changeset

656 
assumes A: "a \<in> A" "b \<in> A" shows "inj_on (swap a b f) A \<longleftrightarrow> inj_on f A" 
39075  657 
proof 
15510  658 
assume "inj_on (swap a b f) A" 
39075  659 
with A have "inj_on (swap a b (swap a b f)) A" 
660 
by (iprover intro: inj_on_imp_inj_on_swap) 

661 
thus "inj_on f A" by simp 

15510  662 
next 
663 
assume "inj_on f A" 

34209  664 
with A show "inj_on (swap a b f) A" by (iprover intro: inj_on_imp_inj_on_swap) 
15510  665 
qed 
666 

39076
b3a9b6734663
Introduce surj_on and replace surj and bij by abbreviations.
hoelzl
parents:
39075
diff
changeset

667 
lemma surj_imp_surj_swap: "surj f \<Longrightarrow> surj (swap a b f)" 
40702  668 
by simp 
15510  669 

39076
b3a9b6734663
Introduce surj_on and replace surj and bij by abbreviations.
hoelzl
parents:
39075
diff
changeset

670 
lemma surj_swap_iff [simp]: "surj (swap a b f) \<longleftrightarrow> surj f" 
40702  671 
by simp 
21547
9c9fdf4c2949
moved order arities for fun and bool to Fun/Orderings
haftmann
parents:
21327
diff
changeset

672 

39076
b3a9b6734663
Introduce surj_on and replace surj and bij by abbreviations.
hoelzl
parents:
39075
diff
changeset

673 
lemma bij_betw_swap_iff [simp]: 
b3a9b6734663
Introduce surj_on and replace surj and bij by abbreviations.
hoelzl
parents:
39075
diff
changeset

674 
"\<lbrakk> x \<in> A; y \<in> A \<rbrakk> \<Longrightarrow> bij_betw (swap x y f) A B \<longleftrightarrow> bij_betw f A B" 
b3a9b6734663
Introduce surj_on and replace surj and bij by abbreviations.
hoelzl
parents:
39075
diff
changeset

675 
by (auto simp: bij_betw_def) 
b3a9b6734663
Introduce surj_on and replace surj and bij by abbreviations.
hoelzl
parents:
39075
diff
changeset

676 

b3a9b6734663
Introduce surj_on and replace surj and bij by abbreviations.
hoelzl
parents:
39075
diff
changeset

677 
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

678 
by simp 
39075  679 

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

680 
hide_const (open) swap 
21547
9c9fdf4c2949
moved order arities for fun and bool to Fun/Orderings
haftmann
parents:
21327
diff
changeset

681 

31949  682 
subsection {* Inversion of injective functions *} 
683 

33057  684 
definition the_inv_into :: "'a set => ('a => 'b) => ('b => 'a)" where 
44277
bcb696533579
moved fundamental lemma fun_eq_iff to theory HOL; tuned whitespace
haftmann
parents:
43991
diff
changeset

685 
"the_inv_into A f == %x. THE y. y : A & f y = x" 
32961  686 

33057  687 
lemma the_inv_into_f_f: 
688 
"[ inj_on f A; x : A ] ==> the_inv_into A f (f x) = x" 

689 
apply (simp add: the_inv_into_def inj_on_def) 

34209  690 
apply blast 
32961  691 
done 
692 

33057  693 
lemma f_the_inv_into_f: 
694 
"inj_on f A ==> y : f`A ==> f (the_inv_into A f y) = y" 

695 
apply (simp add: the_inv_into_def) 

32961  696 
apply (rule the1I2) 
697 
apply(blast dest: inj_onD) 

698 
apply blast 

699 
done 

700 

33057  701 
lemma the_inv_into_into: 
702 
"[ inj_on f A; x : f ` A; A <= B ] ==> the_inv_into A f x : B" 

703 
apply (simp add: the_inv_into_def) 

32961  704 
apply (rule the1I2) 
705 
apply(blast dest: inj_onD) 

706 
apply blast 

707 
done 

708 

33057  709 
lemma the_inv_into_onto[simp]: 
710 
"inj_on f A ==> the_inv_into A f ` (f ` A) = A" 

711 
by (fast intro:the_inv_into_into the_inv_into_f_f[symmetric]) 

32961  712 

33057  713 
lemma the_inv_into_f_eq: 
714 
"[ inj_on f A; f x = y; x : A ] ==> the_inv_into A f y = x" 

32961  715 
apply (erule subst) 
33057  716 
apply (erule the_inv_into_f_f, assumption) 
32961  717 
done 
718 

33057  719 
lemma the_inv_into_comp: 
32961  720 
"[ inj_on f (g ` A); inj_on g A; x : f ` g ` A ] ==> 
33057  721 
the_inv_into A (f o g) x = (the_inv_into A g o the_inv_into (g ` A) f) x" 
722 
apply (rule the_inv_into_f_eq) 

32961  723 
apply (fast intro: comp_inj_on) 
33057  724 
apply (simp add: f_the_inv_into_f the_inv_into_into) 
725 
apply (simp add: the_inv_into_into) 

32961  726 
done 
727 

33057  728 
lemma inj_on_the_inv_into: 
729 
"inj_on f A \<Longrightarrow> inj_on (the_inv_into A f) (f ` A)" 

730 
by (auto intro: inj_onI simp: image_def the_inv_into_f_f) 

32961  731 

33057  732 
lemma bij_betw_the_inv_into: 
733 
"bij_betw f A B \<Longrightarrow> bij_betw (the_inv_into A f) B A" 

734 
by (auto simp add: bij_betw_def inj_on_the_inv_into the_inv_into_into) 

32961  735 

32998
31b19fa0de0b
Renamed inv to the_inv and turned it into an abbreviation (based on the_inv_onto).
berghofe
parents:
32988
diff
changeset

736 
abbreviation the_inv :: "('a \<Rightarrow> 'b) \<Rightarrow> ('b \<Rightarrow> 'a)" where 
33057  737 
"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

738 

31b19fa0de0b
Renamed inv to the_inv and turned it into an abbreviation (based on the_inv_onto).
berghofe
parents:
32988
diff
changeset

739 
lemma the_inv_f_f: 
31b19fa0de0b
Renamed inv to the_inv and turned it into an abbreviation (based on the_inv_onto).
berghofe
parents:
32988
diff
changeset

740 
assumes "inj f" 
31b19fa0de0b
Renamed inv to the_inv and turned it into an abbreviation (based on the_inv_onto).
berghofe
parents:
32988
diff
changeset

741 
shows "the_inv f (f x) = x" using assms UNIV_I 
33057  742 
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

743 

44277
bcb696533579
moved fundamental lemma fun_eq_iff to theory HOL; tuned whitespace
haftmann
parents:
43991
diff
changeset

744 

40703
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

745 
subsection {* Cantor's Paradox *} 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

746 

42238  747 
lemma Cantors_paradox [no_atp]: 
40703
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

748 
"\<not>(\<exists>f. f ` A = Pow A)" 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

749 
proof clarify 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

750 
fix f assume "f ` A = Pow A" hence *: "Pow A \<le> f ` A" by blast 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

751 
let ?X = "{a \<in> A. a \<notin> f a}" 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

752 
have "?X \<in> Pow A" unfolding Pow_def by auto 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

753 
with * obtain x where "x \<in> A \<and> f x = ?X" by blast 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

754 
thus False by best 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOLimage.
hoelzl
parents:
40702
diff
changeset

755 
qed 
31949  756 

40969  757 
subsection {* Setup *} 
758 

759 
subsubsection {* Proof tools *} 

22845  760 

761 
text {* simplifies terms of the form 

762 
f(...,x:=y,...,x:=z,...) to f(...,x:=z,...) *} 

763 

24017  764 
simproc_setup fun_upd2 ("f(v := w, x := y)") = {* fn _ => 
22845  765 
let 
766 
fun gen_fun_upd NONE T _ _ = NONE 

24017  767 
 gen_fun_upd (SOME f) T x y = SOME (Const (@{const_name fun_upd}, T) $ f $ x $ y) 
22845  768 
fun dest_fun_T1 (Type (_, T :: Ts)) = T 
769 
fun find_double (t as Const (@{const_name fun_upd},T) $ f $ x $ y) = 

770 
let 

771 
fun find (Const (@{const_name fun_upd},T) $ g $ v $ w) = 

772 
if v aconv x then SOME g else gen_fun_upd (find g) T v w 

773 
 find t = NONE 

774 
in (dest_fun_T1 T, gen_fun_upd (find f) T x y) end 

24017  775 

776 
fun proc ss ct = 

777 
let 

778 
val ctxt = Simplifier.the_context ss 

779 
val t = Thm.term_of ct 

780 
in 

781 
case find_double t of 

782 
(T, NONE) => NONE 

783 
 (T, SOME rhs) => 

27330  784 
SOME (Goal.prove ctxt [] [] (Logic.mk_equals (t, rhs)) 
24017  785 
(fn _ => 
786 
rtac eq_reflection 1 THEN 

787 
rtac ext 1 THEN 

788 
simp_tac (Simplifier.inherit_context ss @{simpset}) 1)) 

789 
end 

790 
in proc end 

22845  791 
*} 
792 

793 

40969  794 
subsubsection {* Code generator *} 
21870  795 

796 
code_const "op \<circ>" 

797 
(SML infixl 5 "o") 

798 
(Haskell infixr 9 ".") 

799 

21906  800 
code_const "id" 
801 
(Haskell "id") 

802 

40969  803 

804 
subsubsection {* Functorial structure of types *} 

805 

48891  806 
ML_file "Tools/enriched_type.ML" 
40969  807 

47488
be6dd389639d
centralized enriched_type declaration, thanks to insitu available Isar commands
haftmann
parents:
46950
diff
changeset

808 
enriched_type map_fun: map_fun 
be6dd389639d
centralized enriched_type declaration, thanks to insitu available Isar commands
haftmann
parents:
46950
diff
changeset

809 
by (simp_all add: fun_eq_iff) 
be6dd389639d
centralized enriched_type declaration, thanks to insitu available Isar commands
haftmann
parents:
46950
diff
changeset

810 

be6dd389639d
centralized enriched_type declaration, thanks to insitu available Isar commands
haftmann
parents:
46950
diff
changeset

811 
enriched_type vimage 
49739  812 
by (simp_all add: fun_eq_iff vimage_comp) 
813 

814 
text {* Legacy theorem names *} 

815 

816 
lemmas o_def = comp_def 

817 
lemmas o_apply = comp_apply 

818 
lemmas o_assoc = comp_assoc [symmetric] 

819 
lemmas id_o = id_comp 

820 
lemmas o_id = comp_id 

821 
lemmas o_eq_dest = comp_eq_dest 

822 
lemmas o_eq_elim = comp_eq_elim 

823 
lemmas image_compose = image_comp 

824 
lemmas vimage_compose = vimage_comp 

47488
be6dd389639d
centralized enriched_type declaration, thanks to insitu available Isar commands
haftmann
parents:
46950
diff
changeset

825 

2912  826 
end 
47488
be6dd389639d
centralized enriched_type declaration, thanks to insitu available Isar commands
haftmann
parents:
46950
diff
changeset

827 