author | nipkow |
Mon, 17 Aug 1998 11:00:27 +0200 | |
changeset 5322 | 504b129e0502 |
parent 5318 | 72bf8039b53f |
child 5441 | 45bd13b15d80 |
permissions | -rw-r--r-- |
1465 | 1 |
(* Title: HOL/Fun |
923 | 2 |
ID: $Id$ |
1465 | 3 |
Author: Tobias Nipkow, Cambridge University Computer Laboratory |
923 | 4 |
Copyright 1993 University of Cambridge |
5 |
||
6 |
Lemmas about functions. |
|
7 |
*) |
|
8 |
||
4656 | 9 |
|
5069 | 10 |
Goal "(f = g) = (!x. f(x)=g(x))"; |
923 | 11 |
by (rtac iffI 1); |
1264 | 12 |
by (Asm_simp_tac 1); |
13 |
by (rtac ext 1 THEN Asm_simp_tac 1); |
|
923 | 14 |
qed "expand_fun_eq"; |
15 |
||
5316 | 16 |
val prems = Goal |
923 | 17 |
"[| f(x)=u; !!x. P(x) ==> g(f(x)) = x; P(x) |] ==> x=g(u)"; |
18 |
by (rtac (arg_cong RS box_equals) 1); |
|
19 |
by (REPEAT (resolve_tac (prems@[refl]) 1)); |
|
20 |
qed "apply_inverse"; |
|
21 |
||
22 |
||
4656 | 23 |
(** "Axiom" of Choice, proved using the description operator **) |
24 |
||
5316 | 25 |
Goal "!!Q. ALL x. EX y. Q x y ==> EX f. ALL x. Q x (f x)"; |
4656 | 26 |
by (fast_tac (claset() addEs [selectI]) 1); |
27 |
qed "choice"; |
|
28 |
||
5316 | 29 |
Goal "!!S. ALL x:S. EX y. Q x y ==> EX f. ALL x:S. Q x (f x)"; |
4656 | 30 |
by (fast_tac (claset() addEs [selectI]) 1); |
31 |
qed "bchoice"; |
|
32 |
||
33 |
||
5306 | 34 |
section "o"; |
35 |
||
36 |
qed_goalw "o_apply" thy [o_def] "(f o g) x = f (g x)" |
|
37 |
(K [rtac refl 1]); |
|
38 |
Addsimps [o_apply]; |
|
39 |
||
40 |
qed_goalw "o_assoc" thy [o_def] "f o (g o h) = f o g o h" |
|
41 |
(K [rtac ext 1, rtac refl 1]); |
|
42 |
||
43 |
qed_goalw "Id_o" thy [Id_def] "Id o g = g" |
|
44 |
(K [rtac ext 1, Simp_tac 1]); |
|
45 |
Addsimps [Id_o]; |
|
46 |
||
47 |
qed_goalw "o_Id" thy [Id_def] "f o Id = f" |
|
48 |
(K [rtac ext 1, Simp_tac 1]); |
|
49 |
Addsimps [o_Id]; |
|
50 |
||
51 |
Goalw [o_def] "(f o g)``r = f``(g``r)"; |
|
52 |
by (Blast_tac 1); |
|
53 |
qed "image_compose"; |
|
54 |
||
55 |
||
56 |
section "inj"; |
|
57 |
||
923 | 58 |
(*** inj(f): f is a one-to-one function ***) |
59 |
||
5316 | 60 |
val prems = Goalw [inj_def] |
923 | 61 |
"[| !! x y. f(x) = f(y) ==> x=y |] ==> inj(f)"; |
4089 | 62 |
by (blast_tac (claset() addIs prems) 1); |
923 | 63 |
qed "injI"; |
64 |
||
5316 | 65 |
val [major] = Goal "(!!x. g(f(x)) = x) ==> inj(f)"; |
923 | 66 |
by (rtac injI 1); |
67 |
by (etac (arg_cong RS box_equals) 1); |
|
68 |
by (rtac major 1); |
|
69 |
by (rtac major 1); |
|
70 |
qed "inj_inverseI"; |
|
71 |
||
5316 | 72 |
Goalw [inj_def] "[| inj(f); f(x) = f(y) |] ==> x=y"; |
73 |
by (Blast_tac 1); |
|
923 | 74 |
qed "injD"; |
75 |
||
76 |
(*Useful with the simplifier*) |
|
5316 | 77 |
Goal "inj(f) ==> (f(x) = f(y)) = (x=y)"; |
923 | 78 |
by (rtac iffI 1); |
5316 | 79 |
by (etac arg_cong 2); |
80 |
by (etac injD 1); |
|
5318 | 81 |
by (assume_tac 1); |
923 | 82 |
qed "inj_eq"; |
83 |
||
5316 | 84 |
Goal "inj(f) ==> (@x. f(x)=f(y)) = y"; |
85 |
by (etac injD 1); |
|
923 | 86 |
by (rtac selectI 1); |
87 |
by (rtac refl 1); |
|
88 |
qed "inj_select"; |
|
89 |
||
90 |
(*A one-to-one function has an inverse (given using select).*) |
|
5316 | 91 |
Goalw [inv_def] "inj(f) ==> inv f (f x) = x"; |
92 |
by (etac inj_select 1); |
|
2912 | 93 |
qed "inv_f_f"; |
923 | 94 |
|
95 |
(* Useful??? *) |
|
5316 | 96 |
val [oneone,minor] = Goal |
2912 | 97 |
"[| inj(f); !!y. y: range(f) ==> P(inv f y) |] ==> P(x)"; |
98 |
by (res_inst_tac [("t", "x")] (oneone RS (inv_f_f RS subst)) 1); |
|
923 | 99 |
by (rtac (rangeI RS minor) 1); |
100 |
qed "inj_transfer"; |
|
101 |
||
102 |
||
4830 | 103 |
(*** inj_on f A: f is one-to-one over A ***) |
923 | 104 |
|
5316 | 105 |
val prems = Goalw [inj_on_def] |
4830 | 106 |
"(!! x y. [| f(x) = f(y); x:A; y:A |] ==> x=y) ==> inj_on f A"; |
4089 | 107 |
by (blast_tac (claset() addIs prems) 1); |
4830 | 108 |
qed "inj_onI"; |
923 | 109 |
|
5316 | 110 |
val [major] = Goal |
4830 | 111 |
"(!!x. x:A ==> g(f(x)) = x) ==> inj_on f A"; |
112 |
by (rtac inj_onI 1); |
|
923 | 113 |
by (etac (apply_inverse RS trans) 1); |
114 |
by (REPEAT (eresolve_tac [asm_rl,major] 1)); |
|
4830 | 115 |
qed "inj_on_inverseI"; |
923 | 116 |
|
5316 | 117 |
Goalw [inj_on_def] "[| inj_on f A; f(x)=f(y); x:A; y:A |] ==> x=y"; |
118 |
by (Blast_tac 1); |
|
4830 | 119 |
qed "inj_onD"; |
923 | 120 |
|
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5069
diff
changeset
|
121 |
Goal "[| inj_on f A; x:A; y:A |] ==> (f(x)=f(y)) = (x=y)"; |
4830 | 122 |
by (blast_tac (claset() addSDs [inj_onD]) 1); |
123 |
qed "inj_on_iff"; |
|
923 | 124 |
|
5316 | 125 |
Goalw [inj_on_def] "[| inj_on f A; ~x=y; x:A; y:A |] ==> ~ f(x)=f(y)"; |
126 |
by (Blast_tac 1); |
|
4830 | 127 |
qed "inj_on_contraD"; |
923 | 128 |
|
5316 | 129 |
Goalw [inj_on_def] "[| A<=B; inj_on f B |] ==> inj_on f A"; |
3341 | 130 |
by (Blast_tac 1); |
4830 | 131 |
qed "subset_inj_on"; |
3341 | 132 |
|
923 | 133 |
|
134 |
(*** Lemmas about inj ***) |
|
135 |
||
5316 | 136 |
Goalw [o_def] "[| inj(f); inj_on g (range f) |] ==> inj(g o f)"; |
4830 | 137 |
by (fast_tac (claset() addIs [injI] addEs [injD, inj_onD]) 1); |
923 | 138 |
qed "comp_inj"; |
139 |
||
5316 | 140 |
Goal "inj(f) ==> inj_on f A"; |
141 |
by (blast_tac (claset() addIs [injD, inj_onI]) 1); |
|
923 | 142 |
qed "inj_imp"; |
143 |
||
5316 | 144 |
Goalw [inv_def] "y : range(f) ==> f(inv f y) = y"; |
145 |
by (fast_tac (claset() addIs [selectI]) 1); |
|
2912 | 146 |
qed "f_inv_f"; |
923 | 147 |
|
5316 | 148 |
Goal "[| inv f x=inv f y; x: range(f); y: range(f) |] ==> x=y"; |
2912 | 149 |
by (rtac (arg_cong RS box_equals) 1); |
5316 | 150 |
by (REPEAT (ares_tac [f_inv_f] 1)); |
2912 | 151 |
qed "inv_injective"; |
152 |
||
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5069
diff
changeset
|
153 |
Goal "[| inj(f); A<=range(f) |] ==> inj_on (inv f) A"; |
4830 | 154 |
by (fast_tac (claset() addIs [inj_onI] |
2912 | 155 |
addEs [inv_injective,injD]) 1); |
4830 | 156 |
qed "inj_on_inv"; |
923 | 157 |
|
5069 | 158 |
Goalw [inj_on_def] |
5148
74919e8f221c
More tidying and removal of "\!\!... from Goal commands
paulson
parents:
5143
diff
changeset
|
159 |
"[| inj_on f C; A<=C; B<=C |] ==> f``(A Int B) = f``A Int f``B"; |
4059 | 160 |
by (Blast_tac 1); |
4830 | 161 |
qed "inj_on_image_Int"; |
4059 | 162 |
|
5069 | 163 |
Goalw [inj_on_def] |
5148
74919e8f221c
More tidying and removal of "\!\!... from Goal commands
paulson
parents:
5143
diff
changeset
|
164 |
"[| inj_on f C; A<=C; B<=C |] ==> f``(A-B) = f``A - f``B"; |
4059 | 165 |
by (Blast_tac 1); |
4830 | 166 |
qed "inj_on_image_set_diff"; |
4059 | 167 |
|
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5069
diff
changeset
|
168 |
Goalw [inj_def] "inj f ==> f``(A Int B) = f``A Int f``B"; |
4059 | 169 |
by (Blast_tac 1); |
170 |
qed "image_Int"; |
|
171 |
||
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5069
diff
changeset
|
172 |
Goalw [inj_def] "inj f ==> f``(A-B) = f``A - f``B"; |
4059 | 173 |
by (Blast_tac 1); |
174 |
qed "image_set_diff"; |
|
175 |
||
923 | 176 |
|
4089 | 177 |
val set_cs = claset() delrules [equalityI]; |
5305 | 178 |
|
179 |
||
180 |
section "fun_upd"; |
|
181 |
||
182 |
Goalw [fun_upd_def] "(f(x:=y) = f) = (f x = y)"; |
|
183 |
by Safe_tac; |
|
184 |
by (etac subst 1); |
|
185 |
by (rtac ext 2); |
|
186 |
by Auto_tac; |
|
187 |
qed "fun_upd_idem_iff"; |
|
188 |
||
189 |
(* f x = y ==> f(x:=y) = f *) |
|
190 |
bind_thm("fun_upd_idem", fun_upd_idem_iff RS iffD2); |
|
191 |
||
192 |
(* f(x := f x) = f *) |
|
193 |
AddIffs [refl RS fun_upd_idem]; |
|
194 |
||
195 |
Goal "(f(x:=y))z = (if z=x then y else f z)"; |
|
196 |
by (simp_tac (simpset() addsimps [fun_upd_def]) 1); |
|
197 |
qed "fun_upd_apply"; |
|
198 |
Addsimps [fun_upd_apply]; |
|
199 |
||
200 |
qed_goal "fun_upd_same" thy "(f(x:=y)) x = y" |
|
201 |
(K [Simp_tac 1]); |
|
5306 | 202 |
qed_goal "fun_upd_other" thy "!!X. z~=x ==> (f(x:=y)) z = f z" |
5305 | 203 |
(K [Asm_simp_tac 1]); |
204 |
(*Addsimps [fun_upd_same, fun_upd_other];*) |
|
205 |
||
206 |
Goal "a ~= c ==> m(a:=b)(c:=d) = m(c:=d)(a:=b)"; |
|
207 |
by (rtac ext 1); |
|
208 |
by (Auto_tac); |
|
209 |
qed "fun_upd_twist"; |