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