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