author | wenzelm |
Thu, 12 May 2011 21:14:03 +0200 | |
changeset 42768 | 4db4a8b164c1 |
parent 39159 | 0dec18004e75 |
child 42793 | 88bee9f6eec7 |
permissions | -rw-r--r-- |
29269
5c25a2012975
moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
27651
diff
changeset
|
1 |
(* Title: HOL/Algebra/abstract/Ring2.thy |
5c25a2012975
moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
27651
diff
changeset
|
2 |
Author: Clemens Ballarin |
5c25a2012975
moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
27651
diff
changeset
|
3 |
|
5c25a2012975
moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
27651
diff
changeset
|
4 |
The algebraic hierarchy of rings as axiomatic classes. |
20318
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
5 |
*) |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
6 |
|
27542 | 7 |
header {* The algebraic hierarchy of rings as type classes *} |
20318
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
8 |
|
27542 | 9 |
theory Ring2 |
10 |
imports Main |
|
11 |
begin |
|
20318
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
12 |
|
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
13 |
subsection {* Ring axioms *} |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
14 |
|
31001 | 15 |
class ring = zero + one + plus + minus + uminus + times + inverse + power + dvd + |
27542 | 16 |
assumes a_assoc: "(a + b) + c = a + (b + c)" |
17 |
and l_zero: "0 + a = a" |
|
18 |
and l_neg: "(-a) + a = 0" |
|
19 |
and a_comm: "a + b = b + a" |
|
20318
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
20 |
|
27542 | 21 |
assumes m_assoc: "(a * b) * c = a * (b * c)" |
22 |
and l_one: "1 * a = a" |
|
20318
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
23 |
|
27542 | 24 |
assumes l_distr: "(a + b) * c = a * c + b * c" |
20318
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
25 |
|
27542 | 26 |
assumes m_comm: "a * b = b * a" |
20318
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
27 |
|
27542 | 28 |
assumes minus_def: "a - b = a + (-b)" |
29 |
and inverse_def: "inverse a = (if a dvd 1 then THE x. a*x = 1 else 0)" |
|
30 |
and divide_def: "a / b = a * inverse b" |
|
31 |
begin |
|
20318
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
32 |
|
35848
5443079512ea
slightly more uniform definitions -- eliminated old-style meta-equality;
wenzelm
parents:
35408
diff
changeset
|
33 |
definition |
5443079512ea
slightly more uniform definitions -- eliminated old-style meta-equality;
wenzelm
parents:
35408
diff
changeset
|
34 |
assoc :: "'a \<Rightarrow> 'a \<Rightarrow> bool" (infixl "assoc" 50) |
5443079512ea
slightly more uniform definitions -- eliminated old-style meta-equality;
wenzelm
parents:
35408
diff
changeset
|
35 |
where "a assoc b \<longleftrightarrow> a dvd b & b dvd a" |
20318
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
36 |
|
35848
5443079512ea
slightly more uniform definitions -- eliminated old-style meta-equality;
wenzelm
parents:
35408
diff
changeset
|
37 |
definition |
5443079512ea
slightly more uniform definitions -- eliminated old-style meta-equality;
wenzelm
parents:
35408
diff
changeset
|
38 |
irred :: "'a \<Rightarrow> bool" where |
5443079512ea
slightly more uniform definitions -- eliminated old-style meta-equality;
wenzelm
parents:
35408
diff
changeset
|
39 |
"irred a \<longleftrightarrow> a ~= 0 & ~ a dvd 1 & (ALL d. d dvd a --> d dvd 1 | a dvd d)" |
27542 | 40 |
|
35848
5443079512ea
slightly more uniform definitions -- eliminated old-style meta-equality;
wenzelm
parents:
35408
diff
changeset
|
41 |
definition |
5443079512ea
slightly more uniform definitions -- eliminated old-style meta-equality;
wenzelm
parents:
35408
diff
changeset
|
42 |
prime :: "'a \<Rightarrow> bool" where |
5443079512ea
slightly more uniform definitions -- eliminated old-style meta-equality;
wenzelm
parents:
35408
diff
changeset
|
43 |
"prime p \<longleftrightarrow> p ~= 0 & ~ p dvd 1 & (ALL a b. p dvd (a*b) --> p dvd a | p dvd b)" |
20318
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
44 |
|
27542 | 45 |
end |
46 |
||
47 |
||
20318
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
48 |
subsection {* Integral domains *} |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
49 |
|
27542 | 50 |
class "domain" = ring + |
51 |
assumes one_not_zero: "1 ~= 0" |
|
52 |
and integral: "a * b = 0 ==> a = 0 | b = 0" |
|
20318
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
53 |
|
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
54 |
subsection {* Factorial domains *} |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
55 |
|
27542 | 56 |
class factorial = "domain" + |
20318
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
57 |
(* |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
58 |
Proper definition using divisor chain condition currently not supported. |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
59 |
factorial_divisor: "wf {(a, b). a dvd b & ~ (b dvd a)}" |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
60 |
*) |
29665
2b956243d123
explicit check for exactly one type variable in class specification elements
haftmann
parents:
29269
diff
changeset
|
61 |
(*assumes factorial_divisor: "True"*) |
2b956243d123
explicit check for exactly one type variable in class specification elements
haftmann
parents:
29269
diff
changeset
|
62 |
assumes factorial_prime: "irred a ==> prime a" |
2b956243d123
explicit check for exactly one type variable in class specification elements
haftmann
parents:
29269
diff
changeset
|
63 |
|
20318
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
64 |
|
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
65 |
subsection {* Euclidean domains *} |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
66 |
|
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
67 |
(* |
35330 | 68 |
class euclidean = "domain" + |
69 |
assumes euclidean_ax: "b ~= 0 ==> Ex (% (q, r, e_size::('a::ringS)=>nat). |
|
20318
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
70 |
a = b * q + r & e_size r < e_size b)" |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
71 |
|
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
72 |
Nothing has been proved about Euclidean domains, yet. |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
73 |
Design question: |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
74 |
Fix quo, rem and e_size as constants that are axiomatised with |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
75 |
euclidean_ax? |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
76 |
- advantage: more pragmatic and easier to use |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
77 |
- disadvantage: for every type, one definition of quo and rem will |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
78 |
be fixed, users may want to use differing ones; |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
79 |
also, it seems not possible to prove that fields are euclidean |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
80 |
domains, because that would require generic (type-independent) |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
81 |
definitions of quo and rem. |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
82 |
*) |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
83 |
|
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
84 |
subsection {* Fields *} |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
85 |
|
27542 | 86 |
class field = ring + |
87 |
assumes field_one_not_zero: "1 ~= 0" |
|
20318
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
88 |
(* Avoid a common superclass as the first thing we will |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
89 |
prove about fields is that they are domains. *) |
27542 | 90 |
and field_ax: "a ~= 0 ==> a dvd 1" |
20318
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
91 |
|
21423 | 92 |
|
20318
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
93 |
section {* Basic facts *} |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
94 |
|
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
95 |
subsection {* Normaliser for rings *} |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
96 |
|
21423 | 97 |
(* derived rewrite rules *) |
98 |
||
99 |
lemma a_lcomm: "(a::'a::ring)+(b+c) = b+(a+c)" |
|
100 |
apply (rule a_comm [THEN trans]) |
|
101 |
apply (rule a_assoc [THEN trans]) |
|
102 |
apply (rule a_comm [THEN arg_cong]) |
|
103 |
done |
|
104 |
||
105 |
lemma r_zero: "(a::'a::ring) + 0 = a" |
|
106 |
apply (rule a_comm [THEN trans]) |
|
107 |
apply (rule l_zero) |
|
108 |
done |
|
109 |
||
110 |
lemma r_neg: "(a::'a::ring) + (-a) = 0" |
|
111 |
apply (rule a_comm [THEN trans]) |
|
112 |
apply (rule l_neg) |
|
113 |
done |
|
114 |
||
115 |
lemma r_neg2: "(a::'a::ring) + (-a + b) = b" |
|
116 |
apply (rule a_assoc [symmetric, THEN trans]) |
|
117 |
apply (simp add: r_neg l_zero) |
|
118 |
done |
|
119 |
||
120 |
lemma r_neg1: "-(a::'a::ring) + (a + b) = b" |
|
121 |
apply (rule a_assoc [symmetric, THEN trans]) |
|
122 |
apply (simp add: l_neg l_zero) |
|
123 |
done |
|
124 |
||
125 |
||
126 |
(* auxiliary *) |
|
127 |
||
128 |
lemma a_lcancel: "!! a::'a::ring. a + b = a + c ==> b = c" |
|
129 |
apply (rule box_equals) |
|
130 |
prefer 2 |
|
131 |
apply (rule l_zero) |
|
132 |
prefer 2 |
|
133 |
apply (rule l_zero) |
|
134 |
apply (rule_tac a1 = a in l_neg [THEN subst]) |
|
135 |
apply (simp add: a_assoc) |
|
136 |
done |
|
137 |
||
138 |
lemma minus_add: "-((a::'a::ring) + b) = (-a) + (-b)" |
|
139 |
apply (rule_tac a = "a + b" in a_lcancel) |
|
140 |
apply (simp add: r_neg l_neg l_zero a_assoc a_comm a_lcomm) |
|
141 |
done |
|
142 |
||
143 |
lemma minus_minus: "-(-(a::'a::ring)) = a" |
|
144 |
apply (rule a_lcancel) |
|
145 |
apply (rule r_neg [THEN trans]) |
|
146 |
apply (rule l_neg [symmetric]) |
|
147 |
done |
|
148 |
||
149 |
lemma minus0: "- 0 = (0::'a::ring)" |
|
150 |
apply (rule a_lcancel) |
|
151 |
apply (rule r_neg [THEN trans]) |
|
152 |
apply (rule l_zero [symmetric]) |
|
153 |
done |
|
154 |
||
155 |
||
156 |
(* derived rules for multiplication *) |
|
157 |
||
158 |
lemma m_lcomm: "(a::'a::ring)*(b*c) = b*(a*c)" |
|
159 |
apply (rule m_comm [THEN trans]) |
|
160 |
apply (rule m_assoc [THEN trans]) |
|
161 |
apply (rule m_comm [THEN arg_cong]) |
|
162 |
done |
|
163 |
||
164 |
lemma r_one: "(a::'a::ring) * 1 = a" |
|
165 |
apply (rule m_comm [THEN trans]) |
|
166 |
apply (rule l_one) |
|
167 |
done |
|
168 |
||
169 |
lemma r_distr: "(a::'a::ring) * (b + c) = a * b + a * c" |
|
170 |
apply (rule m_comm [THEN trans]) |
|
171 |
apply (rule l_distr [THEN trans]) |
|
172 |
apply (simp add: m_comm) |
|
173 |
done |
|
174 |
||
175 |
||
176 |
(* the following proof is from Jacobson, Basic Algebra I, pp. 88-89 *) |
|
177 |
lemma l_null: "0 * (a::'a::ring) = 0" |
|
178 |
apply (rule a_lcancel) |
|
179 |
apply (rule l_distr [symmetric, THEN trans]) |
|
180 |
apply (simp add: r_zero) |
|
181 |
done |
|
182 |
||
183 |
lemma r_null: "(a::'a::ring) * 0 = 0" |
|
184 |
apply (rule m_comm [THEN trans]) |
|
185 |
apply (rule l_null) |
|
186 |
done |
|
187 |
||
188 |
lemma l_minus: "(-(a::'a::ring)) * b = - (a * b)" |
|
189 |
apply (rule a_lcancel) |
|
190 |
apply (rule r_neg [symmetric, THEN [2] trans]) |
|
191 |
apply (rule l_distr [symmetric, THEN trans]) |
|
192 |
apply (simp add: l_null r_neg) |
|
193 |
done |
|
194 |
||
195 |
lemma r_minus: "(a::'a::ring) * (-b) = - (a * b)" |
|
196 |
apply (rule a_lcancel) |
|
197 |
apply (rule r_neg [symmetric, THEN [2] trans]) |
|
198 |
apply (rule r_distr [symmetric, THEN trans]) |
|
199 |
apply (simp add: r_null r_neg) |
|
200 |
done |
|
201 |
||
202 |
(*** Term order for commutative rings ***) |
|
203 |
||
204 |
ML {* |
|
205 |
fun ring_ord (Const (a, _)) = |
|
206 |
find_index (fn a' => a = a') |
|
35267
8dfd816713c6
moved remaning class operations from Algebras.thy to Groups.thy
haftmann
parents:
34974
diff
changeset
|
207 |
[@{const_name Groups.zero}, @{const_name Groups.plus}, @{const_name Groups.uminus}, |
8dfd816713c6
moved remaning class operations from Algebras.thy to Groups.thy
haftmann
parents:
34974
diff
changeset
|
208 |
@{const_name Groups.minus}, @{const_name Groups.one}, @{const_name Groups.times}] |
21423 | 209 |
| ring_ord _ = ~1; |
210 |
||
35408 | 211 |
fun termless_ring (a, b) = (Term_Ord.term_lpo ring_ord (a, b) = LESS); |
21423 | 212 |
|
213 |
val ring_ss = HOL_basic_ss settermless termless_ring addsimps |
|
39159 | 214 |
[@{thm a_assoc}, @{thm l_zero}, @{thm l_neg}, @{thm a_comm}, @{thm m_assoc}, |
215 |
@{thm l_one}, @{thm l_distr}, @{thm m_comm}, @{thm minus_def}, |
|
216 |
@{thm r_zero}, @{thm r_neg}, @{thm r_neg2}, @{thm r_neg1}, @{thm minus_add}, |
|
217 |
@{thm minus_minus}, @{thm minus0}, @{thm a_lcomm}, @{thm m_lcomm}, (*@{thm r_one},*) |
|
218 |
@{thm r_distr}, @{thm l_null}, @{thm r_null}, @{thm l_minus}, @{thm r_minus}]; |
|
21423 | 219 |
*} (* Note: r_one is not necessary in ring_ss *) |
20318
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
220 |
|
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
221 |
method_setup ring = |
30549 | 222 |
{* Scan.succeed (K (SIMPLE_METHOD' (full_simp_tac ring_ss))) *} |
20318
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
223 |
{* computes distributive normal form in rings *} |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
224 |
|
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
225 |
|
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
226 |
subsection {* Rings and the summation operator *} |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
227 |
|
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
228 |
(* Basic facts --- move to HOL!!! *) |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
229 |
|
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
230 |
(* needed because natsum_cong (below) disables atMost_0 *) |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
231 |
lemma natsum_0 [simp]: "setsum f {..(0::nat)} = (f 0::'a::comm_monoid_add)" |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
232 |
by simp |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
233 |
(* |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
234 |
lemma natsum_Suc [simp]: |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
235 |
"setsum f {..Suc n} = (f (Suc n) + setsum f {..n}::'a::comm_monoid_add)" |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
236 |
by (simp add: atMost_Suc) |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
237 |
*) |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
238 |
lemma natsum_Suc2: |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
239 |
"setsum f {..Suc n} = (f 0::'a::comm_monoid_add) + (setsum (%i. f (Suc i)) {..n})" |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
240 |
proof (induct n) |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
241 |
case 0 show ?case by simp |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
242 |
next |
32449 | 243 |
case Suc thus ?case by (simp add: add_assoc) |
20318
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
244 |
qed |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
245 |
|
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
246 |
lemma natsum_cong [cong]: |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
247 |
"!!k. [| j = k; !!i::nat. i <= k ==> f i = (g i::'a::comm_monoid_add) |] ==> |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
248 |
setsum f {..j} = setsum g {..k}" |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
249 |
by (induct j) auto |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
250 |
|
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
251 |
lemma natsum_zero [simp]: "setsum (%i. 0) {..n::nat} = (0::'a::comm_monoid_add)" |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
252 |
by (induct n) simp_all |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
253 |
|
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
254 |
lemma natsum_add [simp]: |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
255 |
"!!f::nat=>'a::comm_monoid_add. |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
256 |
setsum (%i. f i + g i) {..n::nat} = setsum f {..n} + setsum g {..n}" |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
257 |
by (induct n) (simp_all add: add_ac) |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
258 |
|
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
259 |
(* Facts specific to rings *) |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
260 |
|
27542 | 261 |
subclass (in ring) comm_monoid_add |
20318
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
262 |
proof |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
263 |
fix x y z |
27542 | 264 |
show "x + y = y + x" by (rule a_comm) |
265 |
show "(x + y) + z = x + (y + z)" by (rule a_assoc) |
|
266 |
show "0 + x = x" by (rule l_zero) |
|
20318
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
267 |
qed |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
268 |
|
42768 | 269 |
simproc_setup |
270 |
ring ("t + u::'a::ring" | "t - u::'a::ring" | "t * u::'a::ring" | "- t::'a::ring") = |
|
271 |
{* |
|
272 |
fn _ => fn ss => fn ct => |
|
273 |
let |
|
274 |
val ctxt = Simplifier.the_context ss; |
|
275 |
val {t, T, maxidx, ...} = Thm.rep_cterm ct; |
|
276 |
val rew = |
|
277 |
Goal.prove ctxt [] [] |
|
278 |
(HOLogic.mk_Trueprop (HOLogic.mk_eq (t, Var (("x", maxidx + 1), T)))) |
|
279 |
(fn _ => simp_tac (Simplifier.inherit_context ss ring_ss) 1) |
|
280 |
|> mk_meta_eq; |
|
281 |
val (t', u) = Logic.dest_equals (Thm.prop_of rew); |
|
282 |
in if t' aconv u then NONE else SOME rew end |
|
20318
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
283 |
*} |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
284 |
|
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
285 |
lemma natsum_ldistr: |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
286 |
"!!a::'a::ring. setsum f {..n::nat} * a = setsum (%i. f i * a) {..n}" |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
287 |
by (induct n) simp_all |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
288 |
|
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
289 |
lemma natsum_rdistr: |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
290 |
"!!a::'a::ring. a * setsum f {..n::nat} = setsum (%i. a * f i) {..n}" |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
291 |
by (induct n) simp_all |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
292 |
|
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
293 |
subsection {* Integral Domains *} |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
294 |
|
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
295 |
declare one_not_zero [simp] |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
296 |
|
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
297 |
lemma zero_not_one [simp]: |
32449 | 298 |
"0 ~= (1::'a::domain)" |
20318
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
299 |
by (rule not_sym) simp |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
300 |
|
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
301 |
lemma integral_iff: (* not by default a simp rule! *) |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
302 |
"(a * b = (0::'a::domain)) = (a = 0 | b = 0)" |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
303 |
proof |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
304 |
assume "a * b = 0" then show "a = 0 | b = 0" by (simp add: integral) |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
305 |
next |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
306 |
assume "a = 0 | b = 0" then show "a * b = 0" by auto |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
307 |
qed |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
308 |
|
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
309 |
(* |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
310 |
lemma "(a::'a::ring) - (a - b) = b" apply simp |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
311 |
simproc seems to fail on this example (fixed with new term order) |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
312 |
*) |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
313 |
(* |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
314 |
lemma bug: "(b::'a::ring) - (b - a) = a" by simp |
32449 | 315 |
simproc for rings cannot prove "(a::'a::ring) - (a - b) = b" |
20318
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
316 |
*) |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
317 |
lemma m_lcancel: |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
318 |
assumes prem: "(a::'a::domain) ~= 0" shows conc: "(a * b = a * c) = (b = c)" |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
319 |
proof |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
320 |
assume eq: "a * b = a * c" |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
321 |
then have "a * (b - c) = 0" by simp |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
322 |
then have "a = 0 | (b - c) = 0" by (simp only: integral_iff) |
32449 | 323 |
with prem have "b - c = 0" by auto |
324 |
then have "b = b - (b - c)" by simp |
|
20318
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
325 |
also have "b - (b - c) = c" by simp |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
326 |
finally show "b = c" . |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
327 |
next |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
328 |
assume "b = c" then show "a * b = a * c" by simp |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
329 |
qed |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
330 |
|
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
331 |
lemma m_rcancel: |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
332 |
"(a::'a::domain) ~= 0 ==> (b * a = c * a) = (b = c)" |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
333 |
by (simp add: m_lcancel) |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
334 |
|
27542 | 335 |
declare power_Suc [simp] |
21416 | 336 |
|
337 |
lemma power_one [simp]: |
|
338 |
"1 ^ n = (1::'a::ring)" by (induct n) simp_all |
|
339 |
||
340 |
lemma power_zero [simp]: |
|
341 |
"n \<noteq> 0 \<Longrightarrow> 0 ^ n = (0::'a::ring)" by (induct n) simp_all |
|
342 |
||
343 |
lemma power_mult [simp]: |
|
344 |
"(a::'a::ring) ^ m * a ^ n = a ^ (m + n)" |
|
345 |
by (induct m) simp_all |
|
346 |
||
347 |
||
348 |
section "Divisibility" |
|
349 |
||
350 |
lemma dvd_zero_right [simp]: |
|
351 |
"(a::'a::ring) dvd 0" |
|
352 |
proof |
|
353 |
show "0 = a * 0" by simp |
|
354 |
qed |
|
355 |
||
356 |
lemma dvd_zero_left: |
|
357 |
"0 dvd (a::'a::ring) \<Longrightarrow> a = 0" unfolding dvd_def by simp |
|
358 |
||
359 |
lemma dvd_refl_ring [simp]: |
|
360 |
"(a::'a::ring) dvd a" |
|
361 |
proof |
|
362 |
show "a = a * 1" by simp |
|
363 |
qed |
|
364 |
||
365 |
lemma dvd_trans_ring: |
|
366 |
fixes a b c :: "'a::ring" |
|
367 |
assumes a_dvd_b: "a dvd b" |
|
368 |
and b_dvd_c: "b dvd c" |
|
369 |
shows "a dvd c" |
|
370 |
proof - |
|
371 |
from a_dvd_b obtain l where "b = a * l" using dvd_def by blast |
|
372 |
moreover from b_dvd_c obtain j where "c = b * j" using dvd_def by blast |
|
373 |
ultimately have "c = a * (l * j)" by simp |
|
374 |
then have "\<exists>k. c = a * k" .. |
|
375 |
then show ?thesis using dvd_def by blast |
|
376 |
qed |
|
377 |
||
21423 | 378 |
|
32449 | 379 |
lemma unit_mult: |
21423 | 380 |
"!!a::'a::ring. [| a dvd 1; b dvd 1 |] ==> a * b dvd 1" |
381 |
apply (unfold dvd_def) |
|
382 |
apply clarify |
|
383 |
apply (rule_tac x = "k * ka" in exI) |
|
384 |
apply simp |
|
385 |
done |
|
386 |
||
387 |
lemma unit_power: "!!a::'a::ring. a dvd 1 ==> a^n dvd 1" |
|
388 |
apply (induct_tac n) |
|
389 |
apply simp |
|
390 |
apply (simp add: unit_mult) |
|
391 |
done |
|
392 |
||
393 |
lemma dvd_add_right [simp]: |
|
394 |
"!! a::'a::ring. [| a dvd b; a dvd c |] ==> a dvd b + c" |
|
395 |
apply (unfold dvd_def) |
|
396 |
apply clarify |
|
397 |
apply (rule_tac x = "k + ka" in exI) |
|
398 |
apply (simp add: r_distr) |
|
399 |
done |
|
400 |
||
401 |
lemma dvd_uminus_right [simp]: |
|
402 |
"!! a::'a::ring. a dvd b ==> a dvd -b" |
|
403 |
apply (unfold dvd_def) |
|
404 |
apply clarify |
|
405 |
apply (rule_tac x = "-k" in exI) |
|
406 |
apply (simp add: r_minus) |
|
407 |
done |
|
408 |
||
409 |
lemma dvd_l_mult_right [simp]: |
|
410 |
"!! a::'a::ring. a dvd b ==> a dvd c*b" |
|
411 |
apply (unfold dvd_def) |
|
412 |
apply clarify |
|
413 |
apply (rule_tac x = "c * k" in exI) |
|
414 |
apply simp |
|
415 |
done |
|
416 |
||
417 |
lemma dvd_r_mult_right [simp]: |
|
418 |
"!! a::'a::ring. a dvd b ==> a dvd b*c" |
|
419 |
apply (unfold dvd_def) |
|
420 |
apply clarify |
|
421 |
apply (rule_tac x = "k * c" in exI) |
|
422 |
apply simp |
|
423 |
done |
|
424 |
||
425 |
||
426 |
(* Inverse of multiplication *) |
|
427 |
||
428 |
section "inverse" |
|
429 |
||
430 |
lemma inverse_unique: "!! a::'a::ring. [| a * x = 1; a * y = 1 |] ==> x = y" |
|
431 |
apply (rule_tac a = "(a*y) * x" and b = "y * (a*x)" in box_equals) |
|
432 |
apply (simp (no_asm)) |
|
433 |
apply auto |
|
434 |
done |
|
435 |
||
436 |
lemma r_inverse_ring: "!! a::'a::ring. a dvd 1 ==> a * inverse a = 1" |
|
437 |
apply (unfold inverse_def dvd_def) |
|
42768 | 438 |
using [[simproc del: ring]] |
439 |
apply simp |
|
21423 | 440 |
apply clarify |
441 |
apply (rule theI) |
|
442 |
apply assumption |
|
443 |
apply (rule inverse_unique) |
|
444 |
apply assumption |
|
445 |
apply assumption |
|
446 |
done |
|
447 |
||
448 |
lemma l_inverse_ring: "!! a::'a::ring. a dvd 1 ==> inverse a * a = 1" |
|
449 |
by (simp add: r_inverse_ring) |
|
450 |
||
451 |
||
452 |
(* Fields *) |
|
453 |
||
454 |
section "Fields" |
|
455 |
||
456 |
lemma field_unit [simp]: "!! a::'a::field. (a dvd 1) = (a ~= 0)" |
|
457 |
by (auto dest: field_ax dvd_zero_left simp add: field_one_not_zero) |
|
458 |
||
459 |
lemma r_inverse [simp]: "!! a::'a::field. a ~= 0 ==> a * inverse a = 1" |
|
460 |
by (simp add: r_inverse_ring) |
|
461 |
||
462 |
lemma l_inverse [simp]: "!! a::'a::field. a ~= 0 ==> inverse a * a= 1" |
|
463 |
by (simp add: l_inverse_ring) |
|
464 |
||
465 |
||
466 |
(* fields are integral domains *) |
|
467 |
||
468 |
lemma field_integral: "!! a::'a::field. a * b = 0 ==> a = 0 | b = 0" |
|
23894
1a4167d761ac
tactics: avoid dynamic reference to accidental theory context (via ML_Context.the_context etc.);
wenzelm
parents:
22997
diff
changeset
|
469 |
apply (tactic "step_tac @{claset} 1") |
21423 | 470 |
apply (rule_tac a = " (a*b) * inverse b" in box_equals) |
471 |
apply (rule_tac [3] refl) |
|
472 |
prefer 2 |
|
473 |
apply (simp (no_asm)) |
|
474 |
apply auto |
|
475 |
done |
|
476 |
||
477 |
||
478 |
(* fields are factorial domains *) |
|
479 |
||
480 |
lemma field_fact_prime: "!! a::'a::field. irred a ==> prime a" |
|
481 |
unfolding prime_def irred_def by (blast intro: field_ax) |
|
21416 | 482 |
|
20318
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff
changeset
|
483 |
end |