18 done |
19 done |
19 |
20 |
20 |
21 |
21 subsection {* @{text "\<Z>"}: The Set of Integers as Algebraic Structure *} |
22 subsection {* @{text "\<Z>"}: The Set of Integers as Algebraic Structure *} |
22 |
23 |
23 definition |
24 abbreviation |
24 int_ring :: "int ring" ("\<Z>") where |
25 int_ring :: "int ring" ("\<Z>") where |
25 "int_ring = \<lparr>carrier = UNIV, mult = op *, one = 1, zero = 0, add = op +\<rparr>" |
26 "int_ring == (| carrier = UNIV, mult = op *, one = 1, zero = 0, add = op + |)" |
26 |
27 |
27 lemma int_Zcarr [intro!, simp]: |
28 lemma int_Zcarr [intro!, simp]: |
28 "k \<in> carrier \<Z>" |
29 "k \<in> carrier \<Z>" |
29 by (simp add: int_ring_def) |
30 by simp |
30 |
31 |
31 lemma int_is_cring: |
32 lemma int_is_cring: |
32 "cring \<Z>" |
33 "cring \<Z>" |
33 unfolding int_ring_def |
|
34 apply (rule cringI) |
34 apply (rule cringI) |
35 apply (rule abelian_groupI, simp_all) |
35 apply (rule abelian_groupI, simp_all) |
36 defer 1 |
36 defer 1 |
37 apply (rule comm_monoidI, simp_all) |
37 apply (rule comm_monoidI, simp_all) |
38 apply (rule zadd_zmult_distrib) |
38 apply (rule zadd_zmult_distrib) |
60 and "mult \<Z> x y = x * y" |
60 and "mult \<Z> x y = x * y" |
61 and "one \<Z> = 1" |
61 and "one \<Z> = 1" |
62 and "pow \<Z> x n = x^n" |
62 and "pow \<Z> x n = x^n" |
63 proof - |
63 proof - |
64 -- "Specification" |
64 -- "Specification" |
65 show "monoid \<Z>" proof qed (auto simp: int_ring_def) |
65 show "monoid \<Z>" proof qed auto |
66 then interpret int: monoid \<Z> . |
66 then interpret int: monoid \<Z> . |
67 |
67 |
68 -- "Carrier" |
68 -- "Carrier" |
69 show "carrier \<Z> = UNIV" by (simp add: int_ring_def) |
69 show "carrier \<Z> = UNIV" by simp |
70 |
70 |
71 -- "Operations" |
71 -- "Operations" |
72 { fix x y show "mult \<Z> x y = x * y" by (simp add: int_ring_def) } |
72 { fix x y show "mult \<Z> x y = x * y" by simp } |
73 note mult = this |
73 note mult = this |
74 show one: "one \<Z> = 1" by (simp add: int_ring_def) |
74 show one: "one \<Z> = 1" by simp |
75 show "pow \<Z> x n = x^n" by (induct n) (simp, simp add: int_ring_def)+ |
75 show "pow \<Z> x n = x^n" by (induct n) simp_all |
76 qed |
76 qed |
77 |
77 |
78 interpretation int: comm_monoid \<Z> |
78 interpretation int: comm_monoid \<Z> |
79 where "finprod \<Z> f A = (if finite A then setprod f A else undefined)" |
79 where "finprod \<Z> f A = (if finite A then setprod f A else undefined)" |
80 proof - |
80 proof - |
81 -- "Specification" |
81 -- "Specification" |
82 show "comm_monoid \<Z>" proof qed (auto simp: int_ring_def) |
82 show "comm_monoid \<Z>" proof qed auto |
83 then interpret int: comm_monoid \<Z> . |
83 then interpret int: comm_monoid \<Z> . |
84 |
84 |
85 -- "Operations" |
85 -- "Operations" |
86 { fix x y have "mult \<Z> x y = x * y" by (simp add: int_ring_def) } |
86 { fix x y have "mult \<Z> x y = x * y" by simp } |
87 note mult = this |
87 note mult = this |
88 have one: "one \<Z> = 1" by (simp add: int_ring_def) |
88 have one: "one \<Z> = 1" by simp |
89 show "finprod \<Z> f A = (if finite A then setprod f A else undefined)" |
89 show "finprod \<Z> f A = (if finite A then setprod f A else undefined)" |
90 proof (cases "finite A") |
90 proof (cases "finite A") |
91 case True then show ?thesis proof induct |
91 case True then show ?thesis proof induct |
92 case empty show ?case by (simp add: one) |
92 case empty show ?case by (simp add: one) |
93 next |
93 next |
97 case False then show ?thesis by (simp add: finprod_def) |
97 case False then show ?thesis by (simp add: finprod_def) |
98 qed |
98 qed |
99 qed |
99 qed |
100 |
100 |
101 interpretation int: abelian_monoid \<Z> |
101 interpretation int: abelian_monoid \<Z> |
102 where "zero \<Z> = 0" |
102 where int_carrier_eq: "carrier \<Z> = UNIV" |
103 and "add \<Z> x y = x + y" |
103 and int_zero_eq: "zero \<Z> = 0" |
104 and "finsum \<Z> f A = (if finite A then setsum f A else undefined)" |
104 and int_add_eq: "add \<Z> x y = x + y" |
|
105 and int_finsum_eq: "finsum \<Z> f A = (if finite A then setsum f A else undefined)" |
105 proof - |
106 proof - |
106 -- "Specification" |
107 -- "Specification" |
107 show "abelian_monoid \<Z>" proof qed (auto simp: int_ring_def) |
108 show "abelian_monoid \<Z>" proof qed auto |
108 then interpret int: abelian_monoid \<Z> . |
109 then interpret int: abelian_monoid \<Z> . |
109 |
110 |
|
111 -- "Carrier" |
|
112 show "carrier \<Z> = UNIV" by simp |
|
113 |
110 -- "Operations" |
114 -- "Operations" |
111 { fix x y show "add \<Z> x y = x + y" by (simp add: int_ring_def) } |
115 { fix x y show "add \<Z> x y = x + y" by simp } |
112 note add = this |
116 note add = this |
113 show zero: "zero \<Z> = 0" by (simp add: int_ring_def) |
117 show zero: "zero \<Z> = 0" by simp |
114 show "finsum \<Z> f A = (if finite A then setsum f A else undefined)" |
118 show "finsum \<Z> f A = (if finite A then setsum f A else undefined)" |
115 proof (cases "finite A") |
119 proof (cases "finite A") |
116 case True then show ?thesis proof induct |
120 case True then show ?thesis proof induct |
117 case empty show ?case by (simp add: zero) |
121 case empty show ?case by (simp add: zero) |
118 next |
122 next |
122 case False then show ?thesis by (simp add: finsum_def finprod_def) |
126 case False then show ?thesis by (simp add: finsum_def finprod_def) |
123 qed |
127 qed |
124 qed |
128 qed |
125 |
129 |
126 interpretation int: abelian_group \<Z> |
130 interpretation int: abelian_group \<Z> |
127 where "a_inv \<Z> x = - x" |
131 (* The equations from the interpretation of abelian_monoid need to be repeated. |
128 and "a_minus \<Z> x y = x - y" |
132 Since the morphisms through which the abelian structures are interpreted are |
|
133 not the identity, the equations of these interpretations are not inherited. *) |
|
134 (* FIXME *) |
|
135 where "carrier \<Z> = UNIV" |
|
136 and "zero \<Z> = 0" |
|
137 and "add \<Z> x y = x + y" |
|
138 and "finsum \<Z> f A = (if finite A then setsum f A else undefined)" |
|
139 and int_a_inv_eq: "a_inv \<Z> x = - x" |
|
140 and int_a_minus_eq: "a_minus \<Z> x y = x - y" |
129 proof - |
141 proof - |
130 -- "Specification" |
142 -- "Specification" |
131 show "abelian_group \<Z>" |
143 show "abelian_group \<Z>" |
132 proof (rule abelian_groupI) |
144 proof (rule abelian_groupI) |
133 show "!!x. x \<in> carrier \<Z> ==> EX y : carrier \<Z>. y \<oplus>\<^bsub>\<Z>\<^esub> x = \<zero>\<^bsub>\<Z>\<^esub>" |
145 show "!!x. x \<in> carrier \<Z> ==> EX y : carrier \<Z>. y \<oplus>\<^bsub>\<Z>\<^esub> x = \<zero>\<^bsub>\<Z>\<^esub>" |
134 by (simp add: int_ring_def) arith |
146 by simp arith |
135 qed (auto simp: int_ring_def) |
147 qed auto |
136 then interpret int: abelian_group \<Z> . |
148 then interpret int: abelian_group \<Z> . |
137 |
|
138 -- "Operations" |
149 -- "Operations" |
139 { fix x y have "add \<Z> x y = x + y" by (simp add: int_ring_def) } |
150 { fix x y have "add \<Z> x y = x + y" by simp } |
140 note add = this |
151 note add = this |
141 have zero: "zero \<Z> = 0" by (simp add: int_ring_def) |
152 have zero: "zero \<Z> = 0" by simp |
142 { fix x |
153 { fix x |
143 have "add \<Z> (-x) x = zero \<Z>" by (simp add: add zero) |
154 have "add \<Z> (-x) x = zero \<Z>" by (simp add: add zero) |
144 then show "a_inv \<Z> x = - x" by (simp add: int.minus_equality) } |
155 then show "a_inv \<Z> x = - x" by (simp add: int.minus_equality) } |
145 note a_inv = this |
156 note a_inv = this |
146 show "a_minus \<Z> x y = x - y" by (simp add: int.minus_eq add a_inv) |
157 show "a_minus \<Z> x y = x - y" by (simp add: int.minus_eq add a_inv) |
147 qed |
158 qed (simp add: int_carrier_eq int_zero_eq int_add_eq int_finsum_eq)+ |
148 |
159 |
149 interpretation int: "domain" \<Z> |
160 interpretation int: "domain" \<Z> |
150 proof qed (auto simp: int_ring_def left_distrib right_distrib) |
161 where "carrier \<Z> = UNIV" |
|
162 and "zero \<Z> = 0" |
|
163 and "add \<Z> x y = x + y" |
|
164 and "finsum \<Z> f A = (if finite A then setsum f A else undefined)" |
|
165 and "a_inv \<Z> x = - x" |
|
166 and "a_minus \<Z> x y = x - y" |
|
167 proof - |
|
168 show "domain \<Z>" by unfold_locales (auto simp: left_distrib right_distrib) |
|
169 qed (simp |
|
170 add: int_carrier_eq int_zero_eq int_add_eq int_finsum_eq int_a_inv_eq int_a_minus_eq)+ |
151 |
171 |
152 |
172 |
153 text {* Removal of occurrences of @{term UNIV} in interpretation result |
173 text {* Removal of occurrences of @{term UNIV} in interpretation result |
154 --- experimental. *} |
174 --- experimental. *} |
155 |
175 |
211 |
231 |
212 subsection {* Generated Ideals of @{text "\<Z>"} *} |
232 subsection {* Generated Ideals of @{text "\<Z>"} *} |
213 |
233 |
214 lemma int_Idl: |
234 lemma int_Idl: |
215 "Idl\<^bsub>\<Z>\<^esub> {a} = {x * a | x. True}" |
235 "Idl\<^bsub>\<Z>\<^esub> {a} = {x * a | x. True}" |
216 apply (subst int.cgenideal_eq_genideal[symmetric]) apply (simp add: int_ring_def) |
236 apply (subst int.cgenideal_eq_genideal[symmetric]) apply simp |
217 apply (simp add: cgenideal_def int_ring_def) |
237 apply (simp add: cgenideal_def) |
218 done |
238 done |
219 |
239 |
220 lemma multiples_principalideal: |
240 lemma multiples_principalideal: |
221 "principalideal {x * a | x. True } \<Z>" |
241 "principalideal {x * a | x. True } \<Z>" |
222 apply (subst int_Idl[symmetric], rule principalidealI) |
242 apply (subst int_Idl[symmetric], rule principalidealI) |
230 shows "primeideal (Idl\<^bsub>\<Z>\<^esub> {p}) \<Z>" |
250 shows "primeideal (Idl\<^bsub>\<Z>\<^esub> {p}) \<Z>" |
231 apply (rule primeidealI) |
251 apply (rule primeidealI) |
232 apply (rule int.genideal_ideal, simp) |
252 apply (rule int.genideal_ideal, simp) |
233 apply (rule int_is_cring) |
253 apply (rule int_is_cring) |
234 apply (simp add: int.cgenideal_eq_genideal[symmetric] cgenideal_def) |
254 apply (simp add: int.cgenideal_eq_genideal[symmetric] cgenideal_def) |
235 apply (simp add: int_ring_def) |
|
236 apply clarsimp defer 1 |
255 apply clarsimp defer 1 |
237 apply (simp add: int.cgenideal_eq_genideal[symmetric] cgenideal_def) |
256 apply (simp add: int.cgenideal_eq_genideal[symmetric] cgenideal_def) |
238 apply (simp add: int_ring_def) |
|
239 apply (elim exE) |
257 apply (elim exE) |
240 proof - |
258 proof - |
241 fix a b x |
259 fix a b x |
242 |
260 |
243 from prime |
261 from prime |
334 lemma rcos_zfact: |
352 lemma rcos_zfact: |
335 assumes kIl: "k \<in> ZMod l r" |
353 assumes kIl: "k \<in> ZMod l r" |
336 shows "EX x. k = x * l + r" |
354 shows "EX x. k = x * l + r" |
337 proof - |
355 proof - |
338 from kIl[unfolded ZMod_def] |
356 from kIl[unfolded ZMod_def] |
339 have "\<exists>xl\<in>Idl\<^bsub>\<Z>\<^esub> {l}. k = xl + r" by (simp add: a_r_coset_defs int_ring_def) |
357 have "\<exists>xl\<in>Idl\<^bsub>\<Z>\<^esub> {l}. k = xl + r" by (simp add: a_r_coset_defs) |
340 from this obtain xl |
358 from this obtain xl |
341 where xl: "xl \<in> Idl\<^bsub>\<Z>\<^esub> {l}" |
359 where xl: "xl \<in> Idl\<^bsub>\<Z>\<^esub> {l}" |
342 and k: "k = xl + r" |
360 and k: "k = xl + r" |
343 by auto |
361 by auto |
344 from xl obtain x |
362 from xl obtain x |
380 interpret ideal "Idl\<^bsub>\<Z>\<^esub> {m}" \<Z> by (rule int.genideal_ideal, fast) |
398 interpret ideal "Idl\<^bsub>\<Z>\<^esub> {m}" \<Z> by (rule int.genideal_ideal, fast) |
381 show ?thesis |
399 show ?thesis |
382 unfolding ZMod_def |
400 unfolding ZMod_def |
383 apply (rule a_repr_independence'[symmetric]) |
401 apply (rule a_repr_independence'[symmetric]) |
384 apply (simp add: int_Idl a_r_coset_defs) |
402 apply (simp add: int_Idl a_r_coset_defs) |
385 apply (simp add: int_ring_def) |
|
386 proof - |
403 proof - |
387 have "a = m * (a div m) + (a mod m)" by (simp add: zmod_zdiv_equality) |
404 have "a = m * (a div m) + (a mod m)" by (simp add: zmod_zdiv_equality) |
388 hence "a = (a div m) * m + (a mod m)" by simp |
405 hence "a = (a div m) * m + (a mod m)" by simp |
389 thus "\<exists>h. (\<exists>x. h = x * m) \<and> a = h + a mod m" by fast |
406 thus "\<exists>h. (\<exists>x. h = x * m) \<and> a = h + a mod m" by fast |
390 qed simp |
407 qed simp |
424 done |
441 done |
425 |
442 |
426 lemma ZFact_zero: |
443 lemma ZFact_zero: |
427 "carrier (ZFact 0) = (\<Union>a. {{a}})" |
444 "carrier (ZFact 0) = (\<Union>a. {{a}})" |
428 apply (insert int.genideal_zero) |
445 apply (insert int.genideal_zero) |
429 apply (simp add: ZFact_defs A_RCOSETS_defs r_coset_def int_ring_def ring_record_simps) |
446 apply (simp add: ZFact_defs A_RCOSETS_defs r_coset_def ring_record_simps) |
430 done |
447 done |
431 |
448 |
432 lemma ZFact_one: |
449 lemma ZFact_one: |
433 "carrier (ZFact 1) = {UNIV}" |
450 "carrier (ZFact 1) = {UNIV}" |
434 apply (simp only: ZFact_defs A_RCOSETS_defs r_coset_def int_ring_def ring_record_simps) |
451 apply (simp only: ZFact_defs A_RCOSETS_defs r_coset_def ring_record_simps) |
435 apply (subst int.genideal_one[unfolded int_ring_def, simplified ring_record_simps]) |
452 apply (subst int.genideal_one) |
436 apply (rule, rule, clarsimp) |
453 apply (rule, rule, clarsimp) |
437 apply (rule, rule, clarsimp) |
454 apply (rule, rule, clarsimp) |
438 apply (rule, clarsimp, arith) |
455 apply (rule, clarsimp, arith) |
439 apply (rule, clarsimp) |
456 apply (rule, clarsimp) |
440 apply (rule exI[of _ "0"], clarsimp) |
457 apply (rule exI[of _ "0"], clarsimp) |