7998
|
1 |
(*
|
|
2 |
Abstract class ring (commutative, with 1)
|
|
3 |
$Id$
|
|
4 |
Author: Clemens Ballarin, started 9 December 1996
|
|
5 |
*)
|
|
6 |
|
|
7 |
open Ring;
|
|
8 |
|
|
9 |
Blast.overloaded ("Divides.op dvd", domain_type);
|
|
10 |
|
|
11 |
section "Rings";
|
|
12 |
|
|
13 |
fun make_left_commute assoc commute s =
|
|
14 |
[rtac (commute RS trans) 1, rtac (assoc RS trans) 1,
|
|
15 |
rtac (commute RS arg_cong) 1];
|
|
16 |
|
|
17 |
(* addition *)
|
|
18 |
|
|
19 |
qed_goal "a_lcomm" Ring.thy "!!a::'a::ring. a+(b+c) = b+(a+c)"
|
|
20 |
(make_left_commute a_assoc a_comm);
|
|
21 |
|
|
22 |
val a_ac = [a_assoc, a_comm, a_lcomm];
|
|
23 |
|
|
24 |
qed_goal "r_zero" Ring.thy "!!a::'a::ring. a + <0> = a"
|
|
25 |
(fn _ => [rtac (a_comm RS trans) 1, rtac l_zero 1]);
|
|
26 |
|
|
27 |
qed_goal "r_neg" Ring.thy "!!a::'a::ring. a + (-a) = <0>"
|
|
28 |
(fn _ => [rtac (a_comm RS trans) 1, rtac l_neg 1]);
|
|
29 |
|
|
30 |
Goal "!! a::'a::ring. a + b = a + c ==> b = c";
|
|
31 |
by (rtac box_equals 1);
|
|
32 |
by (rtac l_zero 2);
|
|
33 |
by (rtac l_zero 2);
|
|
34 |
by (res_inst_tac [("a1", "a")] (l_neg RS subst) 1);
|
|
35 |
by (asm_simp_tac (simpset() addsimps [a_assoc]) 1);
|
|
36 |
qed "a_lcancel";
|
|
37 |
|
|
38 |
Goal "!! a::'a::ring. b + a = c + a ==> b = c";
|
|
39 |
by (rtac a_lcancel 1);
|
|
40 |
by (asm_simp_tac (simpset() addsimps a_ac) 1);
|
|
41 |
qed "a_rcancel";
|
|
42 |
|
|
43 |
Goal "!! a::'a::ring. (a + b = a + c) = (b = c)";
|
|
44 |
by (auto_tac (claset() addSDs [a_lcancel], simpset()));
|
|
45 |
qed "a_lcancel_eq";
|
|
46 |
|
|
47 |
Goal "!! a::'a::ring. (b + a = c + a) = (b = c)";
|
|
48 |
by (simp_tac (simpset() addsimps [a_lcancel_eq, a_comm]) 1);
|
|
49 |
qed "a_rcancel_eq";
|
|
50 |
|
|
51 |
Addsimps [a_lcancel_eq, a_rcancel_eq];
|
|
52 |
|
|
53 |
Goal "!!a::'a::ring. -(-a) = a";
|
|
54 |
by (rtac a_lcancel 1);
|
|
55 |
by (rtac (r_neg RS trans) 1);
|
|
56 |
by (rtac (l_neg RS sym) 1);
|
|
57 |
qed "minus_minus";
|
|
58 |
|
|
59 |
Goal "- <0> = (<0>::'a::ring)";
|
|
60 |
by (rtac a_lcancel 1);
|
|
61 |
by (rtac (r_neg RS trans) 1);
|
|
62 |
by (rtac (l_zero RS sym) 1);
|
|
63 |
qed "minus0";
|
|
64 |
|
|
65 |
Goal "!!a::'a::ring. -(a + b) = (-a) + (-b)";
|
|
66 |
by (res_inst_tac [("a", "a+b")] a_lcancel 1);
|
|
67 |
by (simp_tac (simpset() addsimps ([r_neg, l_neg, l_zero]@a_ac)) 1);
|
|
68 |
qed "minus_add";
|
|
69 |
|
|
70 |
(* multiplication *)
|
|
71 |
|
|
72 |
qed_goal "m_lcomm" Ring.thy "!!a::'a::ring. a*(b*c) = b*(a*c)"
|
|
73 |
(make_left_commute m_assoc m_comm);
|
|
74 |
|
|
75 |
val m_ac = [m_assoc, m_comm, m_lcomm];
|
|
76 |
|
|
77 |
qed_goal "r_one" Ring.thy "!!a::'a::ring. a * <1> = a"
|
|
78 |
(fn _ => [rtac (m_comm RS trans) 1, rtac l_one 1]);
|
|
79 |
|
|
80 |
(* distributive and derived *)
|
|
81 |
|
|
82 |
Goal "!!a::'a::ring. a * (b + c) = a * b + a * c";
|
|
83 |
by (rtac (m_comm RS trans) 1);
|
|
84 |
by (rtac (l_distr RS trans) 1);
|
|
85 |
by (simp_tac (simpset() addsimps [m_comm]) 1);
|
|
86 |
qed "r_distr";
|
|
87 |
|
|
88 |
val m_distr = m_ac @ [l_distr, r_distr];
|
|
89 |
|
|
90 |
(* the following two proofs can be found in
|
|
91 |
Jacobson, Basic Algebra I, pp. 88-89 *)
|
|
92 |
|
|
93 |
Goal "!!a::'a::ring. <0> * a = <0>";
|
|
94 |
by (rtac a_lcancel 1);
|
|
95 |
by (rtac (l_distr RS sym RS trans) 1);
|
|
96 |
by (simp_tac (simpset() addsimps [r_zero]) 1);
|
|
97 |
qed "l_null";
|
|
98 |
|
|
99 |
qed_goal "r_null" Ring.thy "!!a::'a::ring. a * <0> = <0>"
|
|
100 |
(fn _ => [rtac (m_comm RS trans) 1, rtac l_null 1]);
|
|
101 |
|
|
102 |
Goal "!!a::'a::ring. (-a) * b = - (a * b)";
|
|
103 |
by (rtac a_lcancel 1);
|
|
104 |
by (rtac (r_neg RS sym RSN (2, trans)) 1);
|
|
105 |
by (rtac (l_distr RS sym RS trans) 1);
|
|
106 |
by (simp_tac (simpset() addsimps [l_null, r_neg]) 1);
|
|
107 |
qed "l_minus";
|
|
108 |
|
|
109 |
Goal "!!a::'a::ring. a * (-b) = - (a * b)";
|
|
110 |
by (rtac a_lcancel 1);
|
|
111 |
by (rtac (r_neg RS sym RSN (2, trans)) 1);
|
|
112 |
by (rtac (r_distr RS sym RS trans) 1);
|
|
113 |
by (simp_tac (simpset() addsimps [r_null, r_neg]) 1);
|
|
114 |
qed "r_minus";
|
|
115 |
|
|
116 |
val m_minus = [l_minus, r_minus];
|
|
117 |
|
|
118 |
(* one and zero are distinct *)
|
|
119 |
|
|
120 |
qed_goal "zero_not_one" Ring.thy "<0> ~= (<1>::'a::ring)"
|
|
121 |
(fn _ => [rtac not_sym 1, rtac one_not_zero 1]);
|
|
122 |
|
|
123 |
Addsimps [l_zero, r_zero, l_neg, r_neg, minus_minus, minus0,
|
|
124 |
l_one, r_one, l_null, r_null,
|
|
125 |
one_not_zero, zero_not_one];
|
|
126 |
|
|
127 |
(* further rules *)
|
|
128 |
|
|
129 |
Goal "!!a::'a::ring. -a = <0> ==> a = <0>";
|
|
130 |
by (res_inst_tac [("t", "a")] (minus_minus RS subst) 1);
|
|
131 |
by (Asm_simp_tac 1);
|
|
132 |
qed "uminus_monom";
|
|
133 |
|
|
134 |
Goal "!!a::'a::ring. a ~= <0> ==> -a ~= <0>";
|
|
135 |
by (etac contrapos 1);
|
|
136 |
by (rtac uminus_monom 1);
|
|
137 |
by (assume_tac 1);
|
|
138 |
qed "uminus_monom_neq";
|
|
139 |
|
|
140 |
Goal "!!a::'a::ring. a * b ~= <0> ==> a ~= <0>";
|
|
141 |
by (etac contrapos 1);
|
|
142 |
by (Asm_simp_tac 1);
|
|
143 |
qed "l_nullD";
|
|
144 |
|
|
145 |
Goal "!!a::'a::ring. a * b ~= <0> ==> b ~= <0>";
|
|
146 |
by (etac contrapos 1);
|
|
147 |
by (Asm_simp_tac 1);
|
|
148 |
qed "r_nullD";
|
|
149 |
|
|
150 |
(* reflection between a = b and a -- b = <0> *)
|
|
151 |
|
|
152 |
Goal "!!a::'a::ring. a = b ==> a + (-b) = <0>";
|
|
153 |
by (Asm_simp_tac 1);
|
|
154 |
qed "eq_imp_diff_zero";
|
|
155 |
|
|
156 |
Goal "!!a::'a::ring. a + (-b) = <0> ==> a = b";
|
|
157 |
by (res_inst_tac [("a", "-b")] a_rcancel 1);
|
|
158 |
by (Asm_simp_tac 1);
|
|
159 |
qed "diff_zero_imp_eq";
|
|
160 |
|
|
161 |
(* this could be a rewrite rule, but won't terminate
|
|
162 |
==> make it a simproc?
|
|
163 |
Goal "!!a::'a::ring. (a = b) = (a -- b = <0>)";
|
|
164 |
*)
|
|
165 |
|
|
166 |
(* Power *)
|
|
167 |
|
|
168 |
Goal "!!a::'a::ring. a ^ 0 = <1>";
|
|
169 |
by (simp_tac (simpset() addsimps [power_ax]) 1);
|
|
170 |
qed "power_0";
|
|
171 |
|
|
172 |
Goal "!!a::'a::ring. a ^ Suc n = a ^ n * a";
|
|
173 |
by (simp_tac (simpset() addsimps [power_ax]) 1);
|
|
174 |
qed "power_Suc";
|
|
175 |
|
|
176 |
Addsimps [power_0, power_Suc];
|
|
177 |
|
|
178 |
Goal "<1> ^ n = (<1>::'a::ring)";
|
|
179 |
by (nat_ind_tac "n" 1);
|
|
180 |
by (Simp_tac 1);
|
|
181 |
by (Asm_simp_tac 1);
|
|
182 |
qed "power_one";
|
|
183 |
|
|
184 |
Goal "!!n. n ~= 0 ==> <0> ^ n = (<0>::'a::ring)";
|
|
185 |
by (etac rev_mp 1);
|
|
186 |
by (nat_ind_tac "n" 1);
|
|
187 |
by (Simp_tac 1);
|
|
188 |
by (Simp_tac 1);
|
|
189 |
qed "power_zero";
|
|
190 |
|
|
191 |
Addsimps [power_zero, power_one];
|
|
192 |
|
|
193 |
Goal "!! a::'a::ring. a ^ m * a ^ n = a ^ (m + n)";
|
|
194 |
by (nat_ind_tac "m" 1);
|
|
195 |
by (Simp_tac 1);
|
|
196 |
by (asm_simp_tac (simpset() addsimps m_ac) 1);
|
|
197 |
qed "power_mult";
|
|
198 |
|
|
199 |
(* Divisibility *)
|
|
200 |
section "Divisibility";
|
|
201 |
|
|
202 |
Goalw [dvd_def] "!! a::'a::ring. a dvd <0>";
|
|
203 |
by (res_inst_tac [("x", "<0>")] exI 1);
|
|
204 |
by (Simp_tac 1);
|
|
205 |
qed "dvd_zero_right";
|
|
206 |
|
|
207 |
Goalw [dvd_def] "!! a::'a::ring. <0> dvd a ==> a = <0>";
|
|
208 |
by Auto_tac;
|
|
209 |
qed "dvd_zero_left";
|
|
210 |
|
|
211 |
Goalw [dvd_def] "!! a::'a::ring. a dvd a";
|
|
212 |
by (res_inst_tac [("x", "<1>")] exI 1);
|
|
213 |
by (Simp_tac 1);
|
|
214 |
qed "dvd_refl_ring";
|
|
215 |
|
|
216 |
Goalw [dvd_def] "!! a::'a::ring. [| a dvd b; b dvd c |] ==> a dvd c";
|
|
217 |
by (Step_tac 1);
|
|
218 |
by (res_inst_tac [("x", "k * ka")] exI 1);
|
|
219 |
by (simp_tac (simpset() addsimps m_ac) 1);
|
|
220 |
qed "dvd_trans_ring";
|
|
221 |
|
|
222 |
Addsimps [dvd_zero_right, dvd_refl_ring];
|
|
223 |
|
|
224 |
Goal "!! a::'a::ring. a dvd <1> ==> a ~= <0>";
|
|
225 |
by (auto_tac (claset() addDs [dvd_zero_left], simpset()));
|
|
226 |
qed "unit_imp_nonzero";
|
|
227 |
|
|
228 |
Goalw [dvd_def]
|
|
229 |
"!!a::'a::ring. [| a dvd <1>; b dvd <1> |] ==> a * b dvd <1>";
|
|
230 |
by (Clarify_tac 1);
|
|
231 |
by (res_inst_tac [("x", "k * ka")] exI 1);
|
|
232 |
by (asm_full_simp_tac (simpset() addsimps m_ac) 1);
|
|
233 |
qed "unit_mult";
|
|
234 |
|
|
235 |
Goal "!!a::'a::ring. a dvd <1> ==> a^n dvd <1>";
|
|
236 |
by (induct_tac "n" 1);
|
|
237 |
by (Simp_tac 1);
|
|
238 |
by (asm_simp_tac (simpset() addsimps [unit_mult]) 1);
|
|
239 |
qed "unit_power";
|
|
240 |
|
|
241 |
Goalw [dvd_def]
|
|
242 |
"!! a::'a::ring. [| a dvd b; a dvd c |] ==> a dvd (b + c)";
|
|
243 |
by (Clarify_tac 1);
|
|
244 |
by (res_inst_tac [("x", "k + ka")] exI 1);
|
|
245 |
by (simp_tac (simpset() addsimps [r_distr]) 1);
|
|
246 |
qed "dvd_add_right";
|
|
247 |
|
|
248 |
Goalw [dvd_def]
|
|
249 |
"!! a::'a::ring. a dvd b ==> a dvd (-b)";
|
|
250 |
by (Clarify_tac 1);
|
|
251 |
by (res_inst_tac [("x", "-k")] exI 1);
|
|
252 |
by (simp_tac (simpset() addsimps [r_minus]) 1);
|
|
253 |
qed "dvd_uminus_right";
|
|
254 |
|
|
255 |
Goalw [dvd_def]
|
|
256 |
"!! a::'a::ring. a dvd b ==> a dvd (c * b)";
|
|
257 |
by (Clarify_tac 1);
|
|
258 |
by (res_inst_tac [("x", "c * k")] exI 1);
|
|
259 |
by (simp_tac (simpset() addsimps m_ac) 1);
|
|
260 |
qed "dvd_l_mult_right";
|
|
261 |
|
|
262 |
Goalw [dvd_def]
|
|
263 |
"!! a::'a::ring. a dvd b ==> a dvd (b * c)";
|
|
264 |
by (Clarify_tac 1);
|
|
265 |
by (res_inst_tac [("x", "k * c")] exI 1);
|
|
266 |
by (simp_tac (simpset() addsimps m_ac) 1);
|
|
267 |
qed "dvd_r_mult_right";
|
|
268 |
|
|
269 |
Addsimps [dvd_add_right, dvd_uminus_right, dvd_l_mult_right, dvd_r_mult_right];
|
|
270 |
|
|
271 |
(* Inverse of multiplication *)
|
|
272 |
|
|
273 |
section "inverse";
|
|
274 |
|
|
275 |
Goal "!! a::'a::ring. [| a * x = <1>; a * y = <1> |] ==> x = y";
|
|
276 |
by (res_inst_tac [("a", "(a*y)*x"), ("b", "y*(a*x)")] box_equals 1);
|
|
277 |
by (simp_tac (simpset() addsimps m_ac) 1);
|
|
278 |
by Auto_tac;
|
|
279 |
qed "inverse_unique";
|
|
280 |
|
|
281 |
Goalw [inverse_def, dvd_def]
|
|
282 |
"!! a::'a::ring. a dvd <1> ==> a * inverse a = <1>";
|
|
283 |
by (Asm_simp_tac 1);
|
|
284 |
by (Clarify_tac 1);
|
|
285 |
by (rtac selectI 1);
|
|
286 |
by (rtac sym 1);
|
|
287 |
by (assume_tac 1);
|
|
288 |
qed "r_inverse_ring";
|
|
289 |
|
|
290 |
Goal "!! a::'a::ring. a dvd <1> ==> inverse a * a= <1>";
|
|
291 |
by (asm_simp_tac (simpset() addsimps r_inverse_ring::m_ac) 1);
|
|
292 |
qed "l_inverse_ring";
|
|
293 |
|
|
294 |
(* Integral domain *)
|
|
295 |
|
|
296 |
section "Integral domains";
|
|
297 |
|
|
298 |
Goal
|
|
299 |
"!! a. [| a * b = <0>; a ~= <0> |] ==> (b::'a::domain) = <0>";
|
|
300 |
by (dtac integral 1);
|
|
301 |
by (Fast_tac 1);
|
|
302 |
qed "r_integral";
|
|
303 |
|
|
304 |
Goal
|
|
305 |
"!! a. [| a * b = <0>; b ~= <0> |] ==> (a::'a::domain) = <0>";
|
|
306 |
by (dtac integral 1);
|
|
307 |
by (Fast_tac 1);
|
|
308 |
qed "l_integral";
|
|
309 |
|
|
310 |
Goal
|
|
311 |
"!! a::'a::domain. [| a ~= <0>; b ~= <0> |] ==> a * b ~= <0>";
|
|
312 |
by (etac contrapos 1);
|
|
313 |
by (rtac l_integral 1);
|
|
314 |
by (assume_tac 1);
|
|
315 |
by (assume_tac 1);
|
|
316 |
qed "not_integral";
|
|
317 |
|
|
318 |
Addsimps [not_integral];
|
|
319 |
|
|
320 |
Goal "!! a::'a::domain. [| a * x = x; x ~= <0> |] ==> a = <1>";
|
|
321 |
by (res_inst_tac [("a", "- <1>")] a_lcancel 1);
|
|
322 |
by (Simp_tac 1);
|
|
323 |
by (rtac l_integral 1);
|
|
324 |
by (assume_tac 2);
|
|
325 |
by (asm_simp_tac (simpset() addsimps [l_distr, l_minus]) 1);
|
|
326 |
qed "l_one_integral";
|
|
327 |
|
|
328 |
Goal "!! a::'a::domain. [| x * a = x; x ~= <0> |] ==> a = <1>";
|
|
329 |
by (res_inst_tac [("a", "- <1>")] a_rcancel 1);
|
|
330 |
by (Simp_tac 1);
|
|
331 |
by (rtac r_integral 1);
|
|
332 |
by (assume_tac 2);
|
|
333 |
by (asm_simp_tac (simpset() addsimps [r_distr, r_minus]) 1);
|
|
334 |
qed "r_one_integral";
|
|
335 |
|
|
336 |
(* cancellation laws for multiplication *)
|
|
337 |
|
|
338 |
Goal "!! a::'a::domain. [| a ~= <0>; a * b = a * c |] ==> b = c";
|
|
339 |
by (rtac diff_zero_imp_eq 1);
|
|
340 |
by (dtac eq_imp_diff_zero 1);
|
|
341 |
by (full_simp_tac (simpset() addsimps [r_minus RS sym, r_distr RS sym]) 1);
|
|
342 |
by (fast_tac (claset() addIs [l_integral]) 1);
|
|
343 |
qed "m_lcancel";
|
|
344 |
|
|
345 |
Goal "!! a::'a::domain. [| a ~= <0>; b * a = c * a |] ==> b = c";
|
|
346 |
by (rtac m_lcancel 1);
|
|
347 |
by (assume_tac 1);
|
|
348 |
by (asm_full_simp_tac (simpset() addsimps m_ac) 1);
|
|
349 |
qed "m_rcancel";
|
|
350 |
|
|
351 |
Goal "!! a::'a::domain. a ~= <0> ==> (a * b = a * c) = (b = c)";
|
|
352 |
by (auto_tac (claset() addDs [m_lcancel], simpset()));
|
|
353 |
qed "m_lcancel_eq";
|
|
354 |
|
|
355 |
Goal "!! a::'a::domain. a ~= <0> ==> (b * a = c * a) = (b = c)";
|
|
356 |
by (asm_simp_tac (simpset() addsimps [m_lcancel_eq, m_comm]) 1);
|
|
357 |
qed "m_rcancel_eq";
|
|
358 |
|
|
359 |
Addsimps [m_lcancel_eq, m_rcancel_eq];
|
|
360 |
|
|
361 |
(* Fields *)
|
|
362 |
|
|
363 |
section "Fields";
|
|
364 |
|
|
365 |
Goal "!! a::'a::field. a dvd <1> = (a ~= <0>)";
|
|
366 |
by (blast_tac (claset() addDs [field_ax, unit_imp_nonzero]) 1);
|
|
367 |
qed "field_unit";
|
|
368 |
|
|
369 |
Addsimps [field_unit];
|
|
370 |
|
|
371 |
Goal "!! a::'a::field. a ~= <0> ==> a * inverse a = <1>";
|
|
372 |
by (asm_full_simp_tac (simpset() addsimps [r_inverse_ring]) 1);
|
|
373 |
qed "r_inverse";
|
|
374 |
|
|
375 |
Goal "!! a::'a::field. a ~= <0> ==> inverse a * a= <1>";
|
|
376 |
by (asm_full_simp_tac (simpset() addsimps [l_inverse_ring]) 1);
|
|
377 |
qed "l_inverse";
|
|
378 |
|
|
379 |
Addsimps [l_inverse, r_inverse];
|
|
380 |
|
|
381 |
(* fields are factorial domains *)
|
|
382 |
|
|
383 |
Goal "!! a::'a::field. a * b = <0> ==> a = <0> | b = <0>";
|
|
384 |
by (Step_tac 1);
|
|
385 |
by (res_inst_tac [("a", "(a*b)*inverse b")] box_equals 1);
|
|
386 |
by (rtac refl 3);
|
|
387 |
by (simp_tac (simpset() addsimps m_ac) 2);
|
|
388 |
by Auto_tac;
|
|
389 |
qed "field_integral";
|
|
390 |
|
|
391 |
Goalw [prime_def, irred_def] "!! a::'a::field. irred a ==> prime a";
|
|
392 |
by (blast_tac (claset() addIs [field_ax]) 1);
|
|
393 |
qed "field_fact_prime";
|
|
394 |
|
|
395 |
|
|
396 |
|