author | paulson |
Fri, 04 Apr 1997 11:18:19 +0200 | |
changeset 2890 | f27002fc531d |
parent 2499 | 0bc87b063447 |
child 2912 | 3fac3e8d5d3e |
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 |
||
9 |
goal Fun.thy "(f = g) = (!x. f(x)=g(x))"; |
|
10 |
by (rtac iffI 1); |
|
1264 | 11 |
by (Asm_simp_tac 1); |
12 |
by (rtac ext 1 THEN Asm_simp_tac 1); |
|
923 | 13 |
qed "expand_fun_eq"; |
14 |
||
15 |
val prems = goal Fun.thy |
|
16 |
"[| f(x)=u; !!x. P(x) ==> g(f(x)) = x; P(x) |] ==> x=g(u)"; |
|
17 |
by (rtac (arg_cong RS box_equals) 1); |
|
18 |
by (REPEAT (resolve_tac (prems@[refl]) 1)); |
|
19 |
qed "apply_inverse"; |
|
20 |
||
21 |
||
1883 | 22 |
(*** Image of a set under a function ***) |
923 | 23 |
|
24 |
(*Frequently b does not have the syntactic form of f(x).*) |
|
25 |
val prems = goalw Fun.thy [image_def] "[| b=f(x); x:A |] ==> b : f``A"; |
|
26 |
by (REPEAT (resolve_tac (prems @ [CollectI,bexI,prem]) 1)); |
|
27 |
qed "image_eqI"; |
|
28 |
||
1883 | 29 |
bind_thm ("imageI", refl RS image_eqI); |
923 | 30 |
|
31 |
(*The eta-expansion gives variable-name preservation.*) |
|
32 |
val major::prems = goalw Fun.thy [image_def] |
|
33 |
"[| b : (%x.f(x))``A; !!x.[| b=f(x); x:A |] ==> P |] ==> P"; |
|
34 |
by (rtac (major RS CollectD RS bexE) 1); |
|
35 |
by (REPEAT (ares_tac prems 1)); |
|
36 |
qed "imageE"; |
|
37 |
||
2890
f27002fc531d
Adds image_eqI instead of imageI, as the former is more general
paulson
parents:
2499
diff
changeset
|
38 |
AddIs [image_eqI]; |
2499
0bc87b063447
Tidying of proofs. New theorems are enterred immediately into the
paulson
parents:
2031
diff
changeset
|
39 |
AddSEs [imageE]; |
0bc87b063447
Tidying of proofs. New theorems are enterred immediately into the
paulson
parents:
2031
diff
changeset
|
40 |
|
923 | 41 |
goalw Fun.thy [o_def] "(f o g)``r = f``(g``r)"; |
2499
0bc87b063447
Tidying of proofs. New theorems are enterred immediately into the
paulson
parents:
2031
diff
changeset
|
42 |
by (Fast_tac 1); |
923 | 43 |
qed "image_compose"; |
44 |
||
45 |
goal Fun.thy "f``(A Un B) = f``A Un f``B"; |
|
2499
0bc87b063447
Tidying of proofs. New theorems are enterred immediately into the
paulson
parents:
2031
diff
changeset
|
46 |
by (Fast_tac 1); |
923 | 47 |
qed "image_Un"; |
48 |
||
1883 | 49 |
(*** Range of a function -- just a translation for image! ***) |
50 |
||
51 |
goal Fun.thy "!!b. b=f(x) ==> b : range(f)"; |
|
52 |
by (EVERY1 [etac image_eqI, rtac UNIV_I]); |
|
53 |
bind_thm ("range_eqI", UNIV_I RSN (2,image_eqI)); |
|
54 |
||
55 |
bind_thm ("rangeI", UNIV_I RS imageI); |
|
56 |
||
57 |
val [major,minor] = goal Fun.thy |
|
58 |
"[| b : range(%x.f(x)); !!x. b=f(x) ==> P |] ==> P"; |
|
59 |
by (rtac (major RS imageE) 1); |
|
60 |
by (etac minor 1); |
|
61 |
qed "rangeE"; |
|
2890
f27002fc531d
Adds image_eqI instead of imageI, as the former is more general
paulson
parents:
2499
diff
changeset
|
62 |
|
f27002fc531d
Adds image_eqI instead of imageI, as the former is more general
paulson
parents:
2499
diff
changeset
|
63 |
|
923 | 64 |
(*** inj(f): f is a one-to-one function ***) |
65 |
||
66 |
val prems = goalw Fun.thy [inj_def] |
|
67 |
"[| !! x y. f(x) = f(y) ==> x=y |] ==> inj(f)"; |
|
1754
852093aeb0ab
Replaced fast_tac by Fast_tac (which uses default claset)
berghofe
parents:
1672
diff
changeset
|
68 |
by (fast_tac (!claset addIs prems) 1); |
923 | 69 |
qed "injI"; |
70 |
||
71 |
val [major] = goal Fun.thy "(!!x. g(f(x)) = x) ==> inj(f)"; |
|
72 |
by (rtac injI 1); |
|
73 |
by (etac (arg_cong RS box_equals) 1); |
|
74 |
by (rtac major 1); |
|
75 |
by (rtac major 1); |
|
76 |
qed "inj_inverseI"; |
|
77 |
||
78 |
val [major,minor] = goalw Fun.thy [inj_def] |
|
79 |
"[| inj(f); f(x) = f(y) |] ==> x=y"; |
|
80 |
by (rtac (major RS spec RS spec RS mp) 1); |
|
81 |
by (rtac minor 1); |
|
82 |
qed "injD"; |
|
83 |
||
84 |
(*Useful with the simplifier*) |
|
85 |
val [major] = goal Fun.thy "inj(f) ==> (f(x) = f(y)) = (x=y)"; |
|
86 |
by (rtac iffI 1); |
|
87 |
by (etac (major RS injD) 1); |
|
88 |
by (etac arg_cong 1); |
|
89 |
qed "inj_eq"; |
|
90 |
||
91 |
val [major] = goal Fun.thy "inj(f) ==> (@x.f(x)=f(y)) = y"; |
|
92 |
by (rtac (major RS injD) 1); |
|
93 |
by (rtac selectI 1); |
|
94 |
by (rtac refl 1); |
|
95 |
qed "inj_select"; |
|
96 |
||
97 |
(*A one-to-one function has an inverse (given using select).*) |
|
98 |
val [major] = goalw Fun.thy [Inv_def] "inj(f) ==> Inv f (f x) = x"; |
|
99 |
by (EVERY1 [rtac (major RS inj_select)]); |
|
100 |
qed "Inv_f_f"; |
|
101 |
||
102 |
(* Useful??? *) |
|
103 |
val [oneone,minor] = goal Fun.thy |
|
104 |
"[| inj(f); !!y. y: range(f) ==> P(Inv f y) |] ==> P(x)"; |
|
105 |
by (res_inst_tac [("t", "x")] (oneone RS (Inv_f_f RS subst)) 1); |
|
106 |
by (rtac (rangeI RS minor) 1); |
|
107 |
qed "inj_transfer"; |
|
108 |
||
109 |
||
110 |
(*** inj_onto f A: f is one-to-one over A ***) |
|
111 |
||
112 |
val prems = goalw Fun.thy [inj_onto_def] |
|
113 |
"(!! x y. [| f(x) = f(y); x:A; y:A |] ==> x=y) ==> inj_onto f A"; |
|
2499
0bc87b063447
Tidying of proofs. New theorems are enterred immediately into the
paulson
parents:
2031
diff
changeset
|
114 |
by (fast_tac (!claset addIs prems) 1); |
923 | 115 |
qed "inj_ontoI"; |
116 |
||
117 |
val [major] = goal Fun.thy |
|
118 |
"(!!x. x:A ==> g(f(x)) = x) ==> inj_onto f A"; |
|
119 |
by (rtac inj_ontoI 1); |
|
120 |
by (etac (apply_inverse RS trans) 1); |
|
121 |
by (REPEAT (eresolve_tac [asm_rl,major] 1)); |
|
122 |
qed "inj_onto_inverseI"; |
|
123 |
||
124 |
val major::prems = goalw Fun.thy [inj_onto_def] |
|
125 |
"[| inj_onto f A; f(x)=f(y); x:A; y:A |] ==> x=y"; |
|
126 |
by (rtac (major RS bspec RS bspec RS mp) 1); |
|
127 |
by (REPEAT (resolve_tac prems 1)); |
|
128 |
qed "inj_ontoD"; |
|
129 |
||
130 |
goal Fun.thy "!!x y.[| inj_onto f A; x:A; y:A |] ==> (f(x)=f(y)) = (x=y)"; |
|
1754
852093aeb0ab
Replaced fast_tac by Fast_tac (which uses default claset)
berghofe
parents:
1672
diff
changeset
|
131 |
by (fast_tac (!claset addSEs [inj_ontoD]) 1); |
923 | 132 |
qed "inj_onto_iff"; |
133 |
||
134 |
val major::prems = goal Fun.thy |
|
135 |
"[| inj_onto f A; ~x=y; x:A; y:A |] ==> ~ f(x)=f(y)"; |
|
136 |
by (rtac contrapos 1); |
|
137 |
by (etac (major RS inj_ontoD) 2); |
|
138 |
by (REPEAT (resolve_tac prems 1)); |
|
139 |
qed "inj_onto_contraD"; |
|
140 |
||
141 |
||
142 |
(*** Lemmas about inj ***) |
|
143 |
||
144 |
val prems = goalw Fun.thy [o_def] |
|
145 |
"[| inj(f); inj_onto g (range f) |] ==> inj(g o f)"; |
|
146 |
by (cut_facts_tac prems 1); |
|
2499
0bc87b063447
Tidying of proofs. New theorems are enterred immediately into the
paulson
parents:
2031
diff
changeset
|
147 |
by (fast_tac (!claset addIs [injI] |
923 | 148 |
addEs [injD,inj_ontoD]) 1); |
149 |
qed "comp_inj"; |
|
150 |
||
151 |
val [prem] = goal Fun.thy "inj(f) ==> inj_onto f A"; |
|
1754
852093aeb0ab
Replaced fast_tac by Fast_tac (which uses default claset)
berghofe
parents:
1672
diff
changeset
|
152 |
by (fast_tac (!claset addIs [prem RS injD, inj_ontoI]) 1); |
923 | 153 |
qed "inj_imp"; |
154 |
||
155 |
val [prem] = goalw Fun.thy [Inv_def] "y : range(f) ==> f(Inv f y) = y"; |
|
156 |
by (EVERY1 [rtac (prem RS rangeE), rtac selectI, etac sym]); |
|
157 |
qed "f_Inv_f"; |
|
158 |
||
159 |
val prems = goal Fun.thy |
|
160 |
"[| Inv f x=Inv f y; x: range(f); y: range(f) |] ==> x=y"; |
|
161 |
by (rtac (arg_cong RS box_equals) 1); |
|
162 |
by (REPEAT (resolve_tac (prems @ [f_Inv_f]) 1)); |
|
163 |
qed "Inv_injective"; |
|
164 |
||
165 |
val prems = goal Fun.thy |
|
166 |
"[| inj(f); A<=range(f) |] ==> inj_onto (Inv f) A"; |
|
167 |
by (cut_facts_tac prems 1); |
|
1754
852093aeb0ab
Replaced fast_tac by Fast_tac (which uses default claset)
berghofe
parents:
1672
diff
changeset
|
168 |
by (fast_tac (!claset addIs [inj_ontoI] |
2499
0bc87b063447
Tidying of proofs. New theorems are enterred immediately into the
paulson
parents:
2031
diff
changeset
|
169 |
addEs [Inv_injective,injD]) 1); |
923 | 170 |
qed "inj_onto_Inv"; |
171 |
||
172 |
||
2499
0bc87b063447
Tidying of proofs. New theorems are enterred immediately into the
paulson
parents:
2031
diff
changeset
|
173 |
AddIs [rangeI]; |
0bc87b063447
Tidying of proofs. New theorems are enterred immediately into the
paulson
parents:
2031
diff
changeset
|
174 |
AddSEs [rangeE]; |
1754
852093aeb0ab
Replaced fast_tac by Fast_tac (which uses default claset)
berghofe
parents:
1672
diff
changeset
|
175 |
|
1837 | 176 |
val set_cs = !claset delrules [equalityI]; |
923 | 177 |
|
1883 | 178 |