author | nipkow |
Thu, 07 Jul 2005 12:39:17 +0200 | |
changeset 16733 | 236dfafbeb63 |
parent 15691 | 900cf45ff0a6 |
child 16973 | b2a894562b8f |
permissions | -rw-r--r-- |
1475 | 1 |
(* Title: HOL/Fun.thy |
923 | 2 |
ID: $Id$ |
1475 | 3 |
Author: Tobias Nipkow, Cambridge University Computer Laboratory |
923 | 4 |
Copyright 1994 University of Cambridge |
5 |
||
2912 | 6 |
Notions about functions. |
923 | 7 |
*) |
8 |
||
15510 | 9 |
theory Fun |
15140 | 10 |
imports Typedef |
15131 | 11 |
begin |
2912 | 12 |
|
12338
de0f4a63baa5
renamed class "term" to "type" (actually "HOL.type");
wenzelm
parents:
12258
diff
changeset
|
13 |
instance set :: (type) order |
13585 | 14 |
by (intro_classes, |
15 |
(assumption | rule subset_refl subset_trans subset_antisym psubset_eq)+) |
|
16 |
||
17 |
constdefs |
|
18 |
fun_upd :: "('a => 'b) => 'a => 'b => ('a => 'b)" |
|
19 |
"fun_upd f a b == % x. if x=a then b else f x" |
|
6171 | 20 |
|
9141 | 21 |
nonterminals |
22 |
updbinds updbind |
|
5305 | 23 |
syntax |
13585 | 24 |
"_updbind" :: "['a, 'a] => updbind" ("(2_ :=/ _)") |
25 |
"" :: "updbind => updbinds" ("_") |
|
26 |
"_updbinds":: "[updbind, updbinds] => updbinds" ("_,/ _") |
|
27 |
"_Update" :: "['a, updbinds] => 'a" ("_/'((_)')" [1000,0] 900) |
|
5305 | 28 |
|
29 |
translations |
|
30 |
"_Update f (_updbinds b bs)" == "_Update (_Update f b) bs" |
|
31 |
"f(x:=y)" == "fun_upd f x y" |
|
2912 | 32 |
|
9340 | 33 |
(* Hint: to define the sum of two functions (or maps), use sum_case. |
34 |
A nice infix syntax could be defined (in Datatype.thy or below) by |
|
35 |
consts |
|
36 |
fun_sum :: "('a => 'c) => ('b => 'c) => (('a+'b) => 'c)" (infixr "'(+')"80) |
|
37 |
translations |
|
13585 | 38 |
"fun_sum" == sum_case |
9340 | 39 |
*) |
12258 | 40 |
|
6171 | 41 |
constdefs |
15691 | 42 |
override_on :: "('a => 'b) => ('a => 'b) => 'a set => ('a => 'b)" |
43 |
"override_on f g A == %a. if a : A then g a else f a" |
|
6171 | 44 |
|
13910 | 45 |
id :: "'a => 'a" |
46 |
"id == %x. x" |
|
47 |
||
48 |
comp :: "['b => 'c, 'a => 'b, 'a] => 'c" (infixl "o" 55) |
|
49 |
"f o g == %x. f(g(x))" |
|
11123 | 50 |
|
13585 | 51 |
text{*compatibility*} |
52 |
lemmas o_def = comp_def |
|
2912 | 53 |
|
12114
a8e860c86252
eliminated old "symbols" syntax, use "xsymbols" instead;
wenzelm
parents:
11609
diff
changeset
|
54 |
syntax (xsymbols) |
13585 | 55 |
comp :: "['b => 'c, 'a => 'b, 'a] => 'c" (infixl "\<circ>" 55) |
14565 | 56 |
syntax (HTML output) |
57 |
comp :: "['b => 'c, 'a => 'b, 'a] => 'c" (infixl "\<circ>" 55) |
|
13585 | 58 |
|
9352 | 59 |
|
13585 | 60 |
constdefs |
61 |
inj_on :: "['a => 'b, 'a set] => bool" (*injective*) |
|
62 |
"inj_on f A == ! x:A. ! y:A. f(x)=f(y) --> x=y" |
|
6171 | 63 |
|
13585 | 64 |
text{*A common special case: functions injective over the entire domain type.*} |
65 |
syntax inj :: "('a => 'b) => bool" |
|
6171 | 66 |
translations |
67 |
"inj f" == "inj_on f UNIV" |
|
5852 | 68 |
|
7374 | 69 |
constdefs |
13585 | 70 |
surj :: "('a => 'b) => bool" (*surjective*) |
7374 | 71 |
"surj f == ! y. ? x. y=f(x)" |
12258 | 72 |
|
13585 | 73 |
bij :: "('a => 'b) => bool" (*bijective*) |
7374 | 74 |
"bij f == inj f & surj f" |
12258 | 75 |
|
7374 | 76 |
|
13585 | 77 |
|
78 |
text{*As a simplification rule, it replaces all function equalities by |
|
79 |
first-order equalities.*} |
|
80 |
lemma expand_fun_eq: "(f = g) = (! x. f(x)=g(x))" |
|
81 |
apply (rule iffI) |
|
82 |
apply (simp (no_asm_simp)) |
|
83 |
apply (rule ext, simp (no_asm_simp)) |
|
84 |
done |
|
85 |
||
86 |
lemma apply_inverse: |
|
87 |
"[| f(x)=u; !!x. P(x) ==> g(f(x)) = x; P(x) |] ==> x=g(u)" |
|
88 |
by auto |
|
89 |
||
90 |
||
91 |
text{*The Identity Function: @{term id}*} |
|
92 |
lemma id_apply [simp]: "id x = x" |
|
93 |
by (simp add: id_def) |
|
94 |
||
16733
236dfafbeb63
linear arithmetic now takes "&" in assumptions apart.
nipkow
parents:
15691
diff
changeset
|
95 |
lemma inj_on_id[simp]: "inj_on id A" |
15510 | 96 |
by (simp add: inj_on_def) |
97 |
||
16733
236dfafbeb63
linear arithmetic now takes "&" in assumptions apart.
nipkow
parents:
15691
diff
changeset
|
98 |
lemma inj_on_id2[simp]: "inj_on (%x. x) A" |
236dfafbeb63
linear arithmetic now takes "&" in assumptions apart.
nipkow
parents:
15691
diff
changeset
|
99 |
by (simp add: inj_on_def) |
236dfafbeb63
linear arithmetic now takes "&" in assumptions apart.
nipkow
parents:
15691
diff
changeset
|
100 |
|
236dfafbeb63
linear arithmetic now takes "&" in assumptions apart.
nipkow
parents:
15691
diff
changeset
|
101 |
lemma surj_id[simp]: "surj id" |
15510 | 102 |
by (simp add: surj_def) |
103 |
||
16733
236dfafbeb63
linear arithmetic now takes "&" in assumptions apart.
nipkow
parents:
15691
diff
changeset
|
104 |
lemma bij_id[simp]: "bij id" |
15510 | 105 |
by (simp add: bij_def inj_on_id surj_id) |
106 |
||
107 |
||
13585 | 108 |
|
109 |
subsection{*The Composition Operator: @{term "f \<circ> g"}*} |
|
110 |
||
111 |
lemma o_apply [simp]: "(f o g) x = f (g x)" |
|
112 |
by (simp add: comp_def) |
|
113 |
||
114 |
lemma o_assoc: "f o (g o h) = f o g o h" |
|
115 |
by (simp add: comp_def) |
|
116 |
||
117 |
lemma id_o [simp]: "id o g = g" |
|
118 |
by (simp add: comp_def) |
|
119 |
||
120 |
lemma o_id [simp]: "f o id = f" |
|
121 |
by (simp add: comp_def) |
|
122 |
||
123 |
lemma image_compose: "(f o g) ` r = f`(g`r)" |
|
124 |
by (simp add: comp_def, blast) |
|
125 |
||
126 |
lemma image_eq_UN: "f`A = (UN x:A. {f x})" |
|
127 |
by blast |
|
128 |
||
129 |
lemma UN_o: "UNION A (g o f) = UNION (f`A) g" |
|
130 |
by (unfold comp_def, blast) |
|
131 |
||
132 |
||
133 |
subsection{*The Injectivity Predicate, @{term inj}*} |
|
134 |
||
135 |
text{*NB: @{term inj} now just translates to @{term inj_on}*} |
|
136 |
||
137 |
||
138 |
text{*For Proofs in @{text "Tools/datatype_rep_proofs"}*} |
|
139 |
lemma datatype_injI: |
|
140 |
"(!! x. ALL y. f(x) = f(y) --> x=y) ==> inj(f)" |
|
141 |
by (simp add: inj_on_def) |
|
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 |
||
149 |
(*Useful with the simplifier*) |
|
150 |
lemma inj_eq: "inj(f) ==> (f(x) = f(y)) = (x=y)" |
|
151 |
by (force simp add: inj_on_def) |
|
152 |
||
153 |
||
154 |
subsection{*The Predicate @{term inj_on}: Injectivity On A Restricted Domain*} |
|
155 |
||
156 |
lemma inj_onI: |
|
157 |
"(!! x y. [| x:A; y:A; f(x) = f(y) |] ==> x=y) ==> inj_on f A" |
|
158 |
by (simp add: inj_on_def) |
|
159 |
||
160 |
lemma inj_on_inverseI: "(!!x. x:A ==> g(f(x)) = x) ==> inj_on f A" |
|
161 |
by (auto dest: arg_cong [of concl: g] simp add: inj_on_def) |
|
162 |
||
163 |
lemma inj_onD: "[| inj_on f A; f(x)=f(y); x:A; y:A |] ==> x=y" |
|
164 |
by (unfold inj_on_def, blast) |
|
165 |
||
166 |
lemma inj_on_iff: "[| inj_on f A; x:A; y:A |] ==> (f(x)=f(y)) = (x=y)" |
|
167 |
by (blast dest!: inj_onD) |
|
168 |
||
169 |
lemma comp_inj_on: |
|
170 |
"[| inj_on f A; inj_on g (f`A) |] ==> inj_on (g o f) A" |
|
171 |
by (simp add: comp_def inj_on_def) |
|
172 |
||
15303 | 173 |
lemma inj_on_imageI: "inj_on (g o f) A \<Longrightarrow> inj_on g (f ` A)" |
174 |
apply(simp add:inj_on_def image_def) |
|
175 |
apply blast |
|
176 |
done |
|
177 |
||
15439 | 178 |
lemma inj_on_image_iff: "\<lbrakk> ALL x:A. ALL y:A. (g(f x) = g(f y)) = (g x = g y); |
179 |
inj_on f A \<rbrakk> \<Longrightarrow> inj_on g (f ` A) = inj_on g A" |
|
180 |
apply(unfold inj_on_def) |
|
181 |
apply blast |
|
182 |
done |
|
183 |
||
13585 | 184 |
lemma inj_on_contraD: "[| inj_on f A; ~x=y; x:A; y:A |] ==> ~ f(x)=f(y)" |
185 |
by (unfold inj_on_def, blast) |
|
12258 | 186 |
|
13585 | 187 |
lemma inj_singleton: "inj (%s. {s})" |
188 |
by (simp add: inj_on_def) |
|
189 |
||
15111 | 190 |
lemma inj_on_empty[iff]: "inj_on f {}" |
191 |
by(simp add: inj_on_def) |
|
192 |
||
15303 | 193 |
lemma subset_inj_on: "[| inj_on f B; A <= B |] ==> inj_on f A" |
13585 | 194 |
by (unfold inj_on_def, blast) |
195 |
||
15111 | 196 |
lemma inj_on_Un: |
197 |
"inj_on f (A Un B) = |
|
198 |
(inj_on f A & inj_on f B & f`(A-B) Int f`(B-A) = {})" |
|
199 |
apply(unfold inj_on_def) |
|
200 |
apply (blast intro:sym) |
|
201 |
done |
|
202 |
||
203 |
lemma inj_on_insert[iff]: |
|
204 |
"inj_on f (insert a A) = (inj_on f A & f a ~: f`(A-{a}))" |
|
205 |
apply(unfold inj_on_def) |
|
206 |
apply (blast intro:sym) |
|
207 |
done |
|
208 |
||
209 |
lemma inj_on_diff: "inj_on f A ==> inj_on f (A-B)" |
|
210 |
apply(unfold inj_on_def) |
|
211 |
apply (blast) |
|
212 |
done |
|
213 |
||
13585 | 214 |
|
215 |
subsection{*The Predicate @{term surj}: Surjectivity*} |
|
216 |
||
217 |
lemma surjI: "(!! x. g(f x) = x) ==> surj g" |
|
218 |
apply (simp add: surj_def) |
|
219 |
apply (blast intro: sym) |
|
220 |
done |
|
221 |
||
222 |
lemma surj_range: "surj f ==> range f = UNIV" |
|
223 |
by (auto simp add: surj_def) |
|
224 |
||
225 |
lemma surjD: "surj f ==> EX x. y = f x" |
|
226 |
by (simp add: surj_def) |
|
227 |
||
228 |
lemma surjE: "surj f ==> (!!x. y = f x ==> C) ==> C" |
|
229 |
by (simp add: surj_def, blast) |
|
230 |
||
231 |
lemma comp_surj: "[| surj f; surj g |] ==> surj (g o f)" |
|
232 |
apply (simp add: comp_def surj_def, clarify) |
|
233 |
apply (drule_tac x = y in spec, clarify) |
|
234 |
apply (drule_tac x = x in spec, blast) |
|
235 |
done |
|
236 |
||
237 |
||
238 |
||
239 |
subsection{*The Predicate @{term bij}: Bijectivity*} |
|
240 |
||
241 |
lemma bijI: "[| inj f; surj f |] ==> bij f" |
|
242 |
by (simp add: bij_def) |
|
243 |
||
244 |
lemma bij_is_inj: "bij f ==> inj f" |
|
245 |
by (simp add: bij_def) |
|
246 |
||
247 |
lemma bij_is_surj: "bij f ==> surj f" |
|
248 |
by (simp add: bij_def) |
|
249 |
||
250 |
||
251 |
subsection{*Facts About the Identity Function*} |
|
5852 | 252 |
|
13585 | 253 |
text{*We seem to need both the @{term id} forms and the @{term "\<lambda>x. x"} |
254 |
forms. The latter can arise by rewriting, while @{term id} may be used |
|
255 |
explicitly.*} |
|
256 |
||
257 |
lemma image_ident [simp]: "(%x. x) ` Y = Y" |
|
258 |
by blast |
|
259 |
||
260 |
lemma image_id [simp]: "id ` Y = Y" |
|
261 |
by (simp add: id_def) |
|
262 |
||
263 |
lemma vimage_ident [simp]: "(%x. x) -` Y = Y" |
|
264 |
by blast |
|
265 |
||
266 |
lemma vimage_id [simp]: "id -` A = A" |
|
267 |
by (simp add: id_def) |
|
268 |
||
269 |
lemma vimage_image_eq: "f -` (f ` A) = {y. EX x:A. f x = f y}" |
|
270 |
by (blast intro: sym) |
|
271 |
||
272 |
lemma image_vimage_subset: "f ` (f -` A) <= A" |
|
273 |
by blast |
|
274 |
||
275 |
lemma image_vimage_eq [simp]: "f ` (f -` A) = A Int range f" |
|
276 |
by blast |
|
277 |
||
278 |
lemma surj_image_vimage_eq: "surj f ==> f ` (f -` A) = A" |
|
279 |
by (simp add: surj_range) |
|
280 |
||
281 |
lemma inj_vimage_image_eq: "inj f ==> f -` (f ` A) = A" |
|
282 |
by (simp add: inj_on_def, blast) |
|
283 |
||
284 |
lemma vimage_subsetD: "surj f ==> f -` B <= A ==> B <= f ` A" |
|
285 |
apply (unfold surj_def) |
|
286 |
apply (blast intro: sym) |
|
287 |
done |
|
288 |
||
289 |
lemma vimage_subsetI: "inj f ==> B <= f ` A ==> f -` B <= A" |
|
290 |
by (unfold inj_on_def, blast) |
|
291 |
||
292 |
lemma vimage_subset_eq: "bij f ==> (f -` B <= A) = (B <= f ` A)" |
|
293 |
apply (unfold bij_def) |
|
294 |
apply (blast del: subsetI intro: vimage_subsetI vimage_subsetD) |
|
295 |
done |
|
296 |
||
297 |
lemma image_Int_subset: "f`(A Int B) <= f`A Int f`B" |
|
298 |
by blast |
|
299 |
||
300 |
lemma image_diff_subset: "f`A - f`B <= f`(A - B)" |
|
301 |
by blast |
|
5852 | 302 |
|
13585 | 303 |
lemma inj_on_image_Int: |
304 |
"[| inj_on f C; A<=C; B<=C |] ==> f`(A Int B) = f`A Int f`B" |
|
305 |
apply (simp add: inj_on_def, blast) |
|
306 |
done |
|
307 |
||
308 |
lemma inj_on_image_set_diff: |
|
309 |
"[| inj_on f C; A<=C; B<=C |] ==> f`(A-B) = f`A - f`B" |
|
310 |
apply (simp add: inj_on_def, blast) |
|
311 |
done |
|
312 |
||
313 |
lemma image_Int: "inj f ==> f`(A Int B) = f`A Int f`B" |
|
314 |
by (simp add: inj_on_def, blast) |
|
315 |
||
316 |
lemma image_set_diff: "inj f ==> f`(A-B) = f`A - f`B" |
|
317 |
by (simp add: inj_on_def, blast) |
|
318 |
||
319 |
lemma inj_image_mem_iff: "inj f ==> (f a : f`A) = (a : A)" |
|
320 |
by (blast dest: injD) |
|
321 |
||
322 |
lemma inj_image_subset_iff: "inj f ==> (f`A <= f`B) = (A<=B)" |
|
323 |
by (simp add: inj_on_def, blast) |
|
324 |
||
325 |
lemma inj_image_eq_iff: "inj f ==> (f`A = f`B) = (A = B)" |
|
326 |
by (blast dest: injD) |
|
327 |
||
328 |
lemma image_UN: "(f ` (UNION A B)) = (UN x:A.(f ` (B x)))" |
|
329 |
by blast |
|
330 |
||
331 |
(*injectivity's required. Left-to-right inclusion holds even if A is empty*) |
|
332 |
lemma image_INT: |
|
333 |
"[| inj_on f C; ALL x:A. B x <= C; j:A |] |
|
334 |
==> f ` (INTER A B) = (INT x:A. f ` B x)" |
|
335 |
apply (simp add: inj_on_def, blast) |
|
336 |
done |
|
337 |
||
338 |
(*Compare with image_INT: no use of inj_on, and if f is surjective then |
|
339 |
it doesn't matter whether A is empty*) |
|
340 |
lemma bij_image_INT: "bij f ==> f ` (INTER A B) = (INT x:A. f ` B x)" |
|
341 |
apply (simp add: bij_def) |
|
342 |
apply (simp add: inj_on_def surj_def, blast) |
|
343 |
done |
|
344 |
||
345 |
lemma surj_Compl_image_subset: "surj f ==> -(f`A) <= f`(-A)" |
|
346 |
by (auto simp add: surj_def) |
|
347 |
||
348 |
lemma inj_image_Compl_subset: "inj f ==> f`(-A) <= -(f`A)" |
|
349 |
by (auto simp add: inj_on_def) |
|
5852 | 350 |
|
13585 | 351 |
lemma bij_image_Compl_eq: "bij f ==> f`(-A) = -(f`A)" |
352 |
apply (simp add: bij_def) |
|
353 |
apply (rule equalityI) |
|
354 |
apply (simp_all (no_asm_simp) add: inj_image_Compl_subset surj_Compl_image_subset) |
|
355 |
done |
|
356 |
||
357 |
||
358 |
subsection{*Function Updating*} |
|
359 |
||
360 |
lemma fun_upd_idem_iff: "(f(x:=y) = f) = (f x = y)" |
|
361 |
apply (simp add: fun_upd_def, safe) |
|
362 |
apply (erule subst) |
|
363 |
apply (rule_tac [2] ext, auto) |
|
364 |
done |
|
365 |
||
366 |
(* f x = y ==> f(x:=y) = f *) |
|
367 |
lemmas fun_upd_idem = fun_upd_idem_iff [THEN iffD2, standard] |
|
368 |
||
369 |
(* f(x := f x) = f *) |
|
370 |
declare refl [THEN fun_upd_idem, iff] |
|
371 |
||
372 |
lemma fun_upd_apply [simp]: "(f(x:=y))z = (if z=x then y else f z)" |
|
373 |
apply (simp (no_asm) add: fun_upd_def) |
|
374 |
done |
|
375 |
||
376 |
(* fun_upd_apply supersedes these two, but they are useful |
|
377 |
if fun_upd_apply is intentionally removed from the simpset *) |
|
378 |
lemma fun_upd_same: "(f(x:=y)) x = y" |
|
379 |
by simp |
|
380 |
||
381 |
lemma fun_upd_other: "z~=x ==> (f(x:=y)) z = f z" |
|
382 |
by simp |
|
383 |
||
384 |
lemma fun_upd_upd [simp]: "f(x:=y,x:=z) = f(x:=z)" |
|
385 |
by (simp add: expand_fun_eq) |
|
386 |
||
387 |
lemma fun_upd_twist: "a ~= c ==> (m(a:=b))(c:=d) = (m(c:=d))(a:=b)" |
|
388 |
by (rule ext, auto) |
|
389 |
||
15303 | 390 |
lemma inj_on_fun_updI: "\<lbrakk> inj_on f A; y \<notin> f`A \<rbrakk> \<Longrightarrow> inj_on (f(x:=y)) A" |
391 |
by(fastsimp simp:inj_on_def image_def) |
|
392 |
||
15510 | 393 |
lemma fun_upd_image: |
394 |
"f(x:=y) ` A = (if x \<in> A then insert y (f ` (A-{x})) else f ` A)" |
|
395 |
by auto |
|
396 |
||
15691 | 397 |
subsection{* @{text override_on} *} |
13910 | 398 |
|
15691 | 399 |
lemma override_on_emptyset[simp]: "override_on f g {} = f" |
400 |
by(simp add:override_on_def) |
|
13910 | 401 |
|
15691 | 402 |
lemma override_on_apply_notin[simp]: "a ~: A ==> (override_on f g A) a = f a" |
403 |
by(simp add:override_on_def) |
|
13910 | 404 |
|
15691 | 405 |
lemma override_on_apply_in[simp]: "a : A ==> (override_on f g A) a = g a" |
406 |
by(simp add:override_on_def) |
|
13910 | 407 |
|
15510 | 408 |
subsection{* swap *} |
409 |
||
410 |
constdefs |
|
411 |
swap :: "['a, 'a, 'a => 'b] => ('a => 'b)" |
|
412 |
"swap a b f == f(a := f b, b:= f a)" |
|
413 |
||
414 |
lemma swap_self: "swap a a f = f" |
|
15691 | 415 |
by (simp add: swap_def) |
15510 | 416 |
|
417 |
lemma swap_commute: "swap a b f = swap b a f" |
|
418 |
by (rule ext, simp add: fun_upd_def swap_def) |
|
419 |
||
420 |
lemma swap_nilpotent [simp]: "swap a b (swap a b f) = f" |
|
421 |
by (rule ext, simp add: fun_upd_def swap_def) |
|
422 |
||
423 |
lemma inj_on_imp_inj_on_swap: |
|
424 |
"[|inj_on f A; a \<in> A; b \<in> A|] ==> inj_on (swap a b f) A" |
|
425 |
by (simp add: inj_on_def swap_def, blast) |
|
426 |
||
427 |
lemma inj_on_swap_iff [simp]: |
|
428 |
assumes A: "a \<in> A" "b \<in> A" shows "inj_on (swap a b f) A = inj_on f A" |
|
429 |
proof |
|
430 |
assume "inj_on (swap a b f) A" |
|
431 |
with A have "inj_on (swap a b (swap a b f)) A" |
|
432 |
by (rules intro: inj_on_imp_inj_on_swap) |
|
433 |
thus "inj_on f A" by simp |
|
434 |
next |
|
435 |
assume "inj_on f A" |
|
436 |
with A show "inj_on (swap a b f) A" by (rules intro: inj_on_imp_inj_on_swap) |
|
437 |
qed |
|
438 |
||
439 |
lemma surj_imp_surj_swap: "surj f ==> surj (swap a b f)" |
|
440 |
apply (simp add: surj_def swap_def, clarify) |
|
441 |
apply (rule_tac P = "y = f b" in case_split_thm, blast) |
|
442 |
apply (rule_tac P = "y = f a" in case_split_thm, auto) |
|
443 |
--{*We don't yet have @{text case_tac}*} |
|
444 |
done |
|
445 |
||
446 |
lemma surj_swap_iff [simp]: "surj (swap a b f) = surj f" |
|
447 |
proof |
|
448 |
assume "surj (swap a b f)" |
|
449 |
hence "surj (swap a b (swap a b f))" by (rule surj_imp_surj_swap) |
|
450 |
thus "surj f" by simp |
|
451 |
next |
|
452 |
assume "surj f" |
|
453 |
thus "surj (swap a b f)" by (rule surj_imp_surj_swap) |
|
454 |
qed |
|
455 |
||
456 |
lemma bij_swap_iff: "bij (swap a b f) = bij f" |
|
457 |
by (simp add: bij_def) |
|
458 |
||
459 |
||
13585 | 460 |
text{*The ML section includes some compatibility bindings and a simproc |
461 |
for function updates, in addition to the usual ML-bindings of theorems.*} |
|
462 |
ML |
|
463 |
{* |
|
464 |
val id_def = thm "id_def"; |
|
465 |
val inj_on_def = thm "inj_on_def"; |
|
466 |
val surj_def = thm "surj_def"; |
|
467 |
val bij_def = thm "bij_def"; |
|
468 |
val fun_upd_def = thm "fun_upd_def"; |
|
11451
8abfb4f7bd02
partial restructuring to reduce dependence on Axiom of Choice
paulson
parents:
11123
diff
changeset
|
469 |
|
13585 | 470 |
val o_def = thm "comp_def"; |
471 |
val injI = thm "inj_onI"; |
|
472 |
val inj_inverseI = thm "inj_on_inverseI"; |
|
473 |
val set_cs = claset() delrules [equalityI]; |
|
474 |
||
475 |
val print_translation = [("Pi", dependent_tr' ("@Pi", "op funcset"))]; |
|
476 |
||
477 |
(* simplifies terms of the form f(...,x:=y,...,x:=z,...) to f(...,x:=z,...) *) |
|
478 |
local |
|
15531 | 479 |
fun gen_fun_upd NONE T _ _ = NONE |
480 |
| gen_fun_upd (SOME f) T x y = SOME (Const ("Fun.fun_upd",T) $ f $ x $ y) |
|
13585 | 481 |
fun dest_fun_T1 (Type (_, T :: Ts)) = T |
482 |
fun find_double (t as Const ("Fun.fun_upd",T) $ f $ x $ y) = |
|
483 |
let |
|
484 |
fun find (Const ("Fun.fun_upd",T) $ g $ v $ w) = |
|
15531 | 485 |
if v aconv x then SOME g else gen_fun_upd (find g) T v w |
486 |
| find t = NONE |
|
13585 | 487 |
in (dest_fun_T1 T, gen_fun_upd (find f) T x y) end |
488 |
||
489 |
val ss = simpset () |
|
490 |
val fun_upd_prover = K (rtac eq_reflection 1 THEN rtac ext 1 THEN simp_tac ss 1) |
|
491 |
in |
|
492 |
val fun_upd2_simproc = |
|
493 |
Simplifier.simproc (Theory.sign_of (the_context ())) |
|
494 |
"fun_upd2" ["f(v := w, x := y)"] |
|
495 |
(fn sg => fn _ => fn t => |
|
15531 | 496 |
case find_double t of (T, NONE) => NONE |
497 |
| (T, SOME rhs) => SOME (Tactic.prove sg [] [] (Term.equals T $ t $ rhs) fun_upd_prover)) |
|
13585 | 498 |
end; |
499 |
Addsimprocs[fun_upd2_simproc]; |
|
5852 | 500 |
|
13585 | 501 |
val expand_fun_eq = thm "expand_fun_eq"; |
502 |
val apply_inverse = thm "apply_inverse"; |
|
503 |
val id_apply = thm "id_apply"; |
|
504 |
val o_apply = thm "o_apply"; |
|
505 |
val o_assoc = thm "o_assoc"; |
|
506 |
val id_o = thm "id_o"; |
|
507 |
val o_id = thm "o_id"; |
|
508 |
val image_compose = thm "image_compose"; |
|
509 |
val image_eq_UN = thm "image_eq_UN"; |
|
510 |
val UN_o = thm "UN_o"; |
|
511 |
val datatype_injI = thm "datatype_injI"; |
|
512 |
val injD = thm "injD"; |
|
513 |
val inj_eq = thm "inj_eq"; |
|
514 |
val inj_onI = thm "inj_onI"; |
|
515 |
val inj_on_inverseI = thm "inj_on_inverseI"; |
|
516 |
val inj_onD = thm "inj_onD"; |
|
517 |
val inj_on_iff = thm "inj_on_iff"; |
|
518 |
val comp_inj_on = thm "comp_inj_on"; |
|
519 |
val inj_on_contraD = thm "inj_on_contraD"; |
|
520 |
val inj_singleton = thm "inj_singleton"; |
|
521 |
val subset_inj_on = thm "subset_inj_on"; |
|
522 |
val surjI = thm "surjI"; |
|
523 |
val surj_range = thm "surj_range"; |
|
524 |
val surjD = thm "surjD"; |
|
525 |
val surjE = thm "surjE"; |
|
526 |
val comp_surj = thm "comp_surj"; |
|
527 |
val bijI = thm "bijI"; |
|
528 |
val bij_is_inj = thm "bij_is_inj"; |
|
529 |
val bij_is_surj = thm "bij_is_surj"; |
|
530 |
val image_ident = thm "image_ident"; |
|
531 |
val image_id = thm "image_id"; |
|
532 |
val vimage_ident = thm "vimage_ident"; |
|
533 |
val vimage_id = thm "vimage_id"; |
|
534 |
val vimage_image_eq = thm "vimage_image_eq"; |
|
535 |
val image_vimage_subset = thm "image_vimage_subset"; |
|
536 |
val image_vimage_eq = thm "image_vimage_eq"; |
|
537 |
val surj_image_vimage_eq = thm "surj_image_vimage_eq"; |
|
538 |
val inj_vimage_image_eq = thm "inj_vimage_image_eq"; |
|
539 |
val vimage_subsetD = thm "vimage_subsetD"; |
|
540 |
val vimage_subsetI = thm "vimage_subsetI"; |
|
541 |
val vimage_subset_eq = thm "vimage_subset_eq"; |
|
542 |
val image_Int_subset = thm "image_Int_subset"; |
|
543 |
val image_diff_subset = thm "image_diff_subset"; |
|
544 |
val inj_on_image_Int = thm "inj_on_image_Int"; |
|
545 |
val inj_on_image_set_diff = thm "inj_on_image_set_diff"; |
|
546 |
val image_Int = thm "image_Int"; |
|
547 |
val image_set_diff = thm "image_set_diff"; |
|
548 |
val inj_image_mem_iff = thm "inj_image_mem_iff"; |
|
549 |
val inj_image_subset_iff = thm "inj_image_subset_iff"; |
|
550 |
val inj_image_eq_iff = thm "inj_image_eq_iff"; |
|
551 |
val image_UN = thm "image_UN"; |
|
552 |
val image_INT = thm "image_INT"; |
|
553 |
val bij_image_INT = thm "bij_image_INT"; |
|
554 |
val surj_Compl_image_subset = thm "surj_Compl_image_subset"; |
|
555 |
val inj_image_Compl_subset = thm "inj_image_Compl_subset"; |
|
556 |
val bij_image_Compl_eq = thm "bij_image_Compl_eq"; |
|
557 |
val fun_upd_idem_iff = thm "fun_upd_idem_iff"; |
|
558 |
val fun_upd_idem = thm "fun_upd_idem"; |
|
559 |
val fun_upd_apply = thm "fun_upd_apply"; |
|
560 |
val fun_upd_same = thm "fun_upd_same"; |
|
561 |
val fun_upd_other = thm "fun_upd_other"; |
|
562 |
val fun_upd_upd = thm "fun_upd_upd"; |
|
563 |
val fun_upd_twist = thm "fun_upd_twist"; |
|
13637 | 564 |
val range_ex1_eq = thm "range_ex1_eq"; |
13585 | 565 |
*} |
5852 | 566 |
|
2912 | 567 |
end |