-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRing2.v
335 lines (287 loc) · 7.29 KB
/
Ring2.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
(* Ring2.v *)
Require Import Utf8.
Class ring A :=
{ rng_zero : A;
rng_one : A;
rng_add : A → A → A;
rng_mul : A → A → A;
rng_opp : A → A;
rng_1_neq_0 : rng_one ≠ rng_zero;
rng_eq_dec : ∀ a b : A, {a = b} + {a ≠ b};
rng_add_comm : ∀ a b, rng_add a b = rng_add b a;
rng_add_assoc : ∀ a b c,
rng_add a (rng_add b c) = rng_add (rng_add a b) c;
rng_add_0_l : ∀ a, rng_add rng_zero a = a;
rng_add_opp_l : ∀ a, rng_add (rng_opp a) a = rng_zero;
rng_mul_comm : ∀ a b, rng_mul a b = rng_mul b a;
rng_mul_assoc : ∀ a b c,
rng_mul a (rng_mul b c) = rng_mul (rng_mul a b) c;
rng_mul_1_l : ∀ a, rng_mul rng_one a = a;
rng_mul_add_distr_l : ∀ a b c,
rng_mul a (rng_add b c) = rng_add (rng_mul a b) (rng_mul a c) }.
Definition rng_sub {A} {R : ring A} a b := rng_add a (rng_opp b).
Declare Scope ring_scope.
Delimit Scope ring_scope with Rng.
Bind Scope ring_scope with ring.
Notation "a + b" := (rng_add a b) : ring_scope.
Notation "a - b" := (rng_sub a b) : ring_scope.
Notation "a * b" := (rng_mul a b) : ring_scope.
Notation "- a" := (rng_opp a) : ring_scope.
Notation "0" := rng_zero : ring_scope.
Notation "1" := rng_one : ring_scope.
Arguments rng_eq_dec {_} {_} _%Rng _%Rng.
Fixpoint rng_power {A} {R : ring A} a n :=
match n with
| O => 1%Rng
| S m => (a * rng_power a m)%Rng
end.
Notation "a ^ b" := (rng_power a b) : ring_scope.
Section ring_theorems.
Context {A : Type}.
Context {r : ring A}.
Theorem rng_add_opp_r : ∀ x, (x - x = 0)%Rng.
Proof.
intros x; unfold rng_sub; rewrite rng_add_comm.
apply rng_add_opp_l.
Qed.
Theorem rng_mul_1_r : ∀ a, (a * 1 = a)%Rng.
Proof.
intros a; simpl.
rewrite rng_mul_comm, rng_mul_1_l.
reflexivity.
Qed.
Theorem rng_add_compat_l : ∀ a b c,
(a = b)%Rng → (c + a = c + b)%Rng.
Proof.
intros a b c Hab.
rewrite Hab; reflexivity.
Qed.
Theorem rng_add_compat_r : ∀ a b c,
(a = b)%Rng → (a + c = b + c)%Rng.
Proof.
intros a b c Hab.
rewrite Hab; reflexivity.
Qed.
Theorem rng_add_compat : ∀ a b c d,
(a = b)%Rng
→ (c = d)%Rng
→ (a + c = b + d)%Rng.
Proof.
intros a b c d Hab Hcd.
rewrite Hab, Hcd; reflexivity.
Qed.
Theorem rng_sub_compat_l : ∀ a b c,
(a = b)%Rng → (a - c = b - c)%Rng.
Proof.
intros a b c Hab.
now rewrite Hab.
Qed.
Theorem rng_sub_compat_r : ∀ a b c,
(b = c)%Rng → (a - b = a - c)%Rng.
Proof.
intros a b c Hbc.
now rewrite Hbc.
Qed.
Theorem rng_mul_compat_r : ∀ a b c,
(a = b)%Rng
→ (a * c = b * c)%Rng.
Proof.
intros a b c Hab; simpl in Hab |- *.
rewrite Hab; reflexivity.
Qed.
Theorem rng_mul_compat : ∀ a b c d,
(a = b)%Rng
→ (c = d)%Rng
→ (a * c = b * d)%Rng.
Proof.
intros a b c d Hab Hcd.
rewrite Hab, Hcd; reflexivity.
Qed.
Theorem rng_add_0_r : ∀ a, (a + 0 = a)%Rng.
Proof.
intros a; simpl.
rewrite rng_add_comm.
apply rng_add_0_l.
Qed.
Theorem fold_rng_sub : ∀ a b, (a + - b)%Rng = (a - b)%Rng.
Proof. intros; easy. Qed.
Theorem rng_add_sub : ∀ a b, (a + b - b = a)%Rng.
Proof.
intros.
unfold rng_sub.
rewrite <- rng_add_assoc.
rewrite fold_rng_sub.
rewrite rng_add_opp_r.
apply rng_add_0_r.
Qed.
Theorem rng_sub_add : ∀ a b, (a - b + b = a)%Rng.
Proof.
intros.
unfold rng_sub.
rewrite <- rng_add_assoc.
rewrite rng_add_opp_l.
apply rng_add_0_r.
Qed.
Theorem rng_add_reg_r : ∀ a b c, (a + c = b + c)%Rng → (a = b)%Rng.
Proof.
intros a b c Habc; simpl in Habc; simpl.
eapply rng_sub_compat_l with (c := c) in Habc.
now do 2 rewrite rng_add_sub in Habc.
Qed.
Theorem rng_add_reg_l : ∀ a b c, (c + a = c + b)%Rng → (a = b)%Rng.
Proof.
intros a b c Habc; simpl in Habc; simpl.
apply rng_add_reg_r with (c := c).
rewrite rng_add_comm; symmetry.
rewrite rng_add_comm; symmetry.
assumption.
Qed.
Theorem rng_opp_add_distr : ∀ a b,
(- (a + b) = - a - b)%Rng.
Proof.
intros.
apply (rng_add_reg_l _ _ (b + a)%Rng).
unfold rng_sub.
rewrite rng_add_assoc.
do 3 rewrite fold_rng_sub.
rewrite rng_add_sub.
rewrite rng_add_comm.
now do 2 rewrite rng_add_opp_r.
Qed.
Theorem rng_sub_add_distr : ∀ a b c, (a - (b + c) = a - b - c)%Rng.
Proof.
intros.
unfold rng_sub.
rewrite rng_opp_add_distr.
apply rng_add_assoc.
Qed.
Theorem rng_mul_add_distr_r : ∀ x y z,
((x + y) * z = x * z + y * z)%Rng.
Proof.
intros x y z; simpl.
rewrite rng_mul_comm.
rewrite rng_mul_add_distr_l.
rewrite rng_mul_comm.
assert (rng_mul z y = rng_mul y z) as H.
apply rng_mul_comm.
rewrite H; reflexivity.
Qed.
Theorem rng_mul_0_l : ∀ a, (0 * a = 0)%Rng.
Proof.
intros a.
assert ((0 * a + a = a)%Rng) as H.
transitivity ((0 * a + 1 * a)%Rng).
rewrite rng_mul_1_l; reflexivity.
rewrite <- rng_mul_add_distr_r.
rewrite rng_add_0_l, rng_mul_1_l.
reflexivity.
apply rng_add_reg_r with (c := a).
rewrite rng_add_0_l; assumption.
Qed.
Theorem rng_mul_0_r : ∀ a, (a * 0 = 0)%Rng.
Proof.
intros a; simpl.
rewrite rng_mul_comm, rng_mul_0_l.
reflexivity.
Qed.
Theorem rng_mul_opp_l : ∀ a b, ((- a) * b = - (a * b))%Rng.
Proof.
intros a b; simpl.
apply rng_add_reg_l with (c := (a * b)%Rng).
rewrite fold_rng_sub.
rewrite rng_add_opp_r.
rewrite <- rng_mul_add_distr_r.
rewrite fold_rng_sub.
rewrite rng_add_opp_r, rng_mul_0_l.
reflexivity.
Qed.
Theorem rng_mul_opp_r : ∀ a b, (a * (- b) = - (a * b))%Rng.
Proof.
intros a b; simpl.
rewrite rng_mul_comm; symmetry.
rewrite rng_mul_comm; symmetry.
apply rng_mul_opp_l.
Qed.
Theorem rng_mul_sub_distr_l : ∀ x y z,
(x * (y - z) = x * y - x * z)%Rng.
Proof.
intros.
unfold rng_sub.
rewrite rng_mul_add_distr_l.
now rewrite <- rng_mul_opp_r.
Qed.
Theorem rng_mul_sub_distr_r : ∀ x y z,
((x - y) * z = x * z - y * z)%Rng.
Proof.
intros.
rewrite rng_mul_comm.
rewrite rng_mul_sub_distr_l.
rewrite (rng_mul_comm _ x).
rewrite (rng_mul_comm _ y).
easy.
Qed.
Theorem rng_opp_0 : (- 0 = 0)%Rng.
Proof.
simpl; etransitivity; [ symmetry; apply rng_add_0_l | idtac ].
apply rng_add_opp_r.
Qed.
Theorem rng_sub_0_r : ∀ a, (a - 0 = a)%Rng.
Proof.
intros.
unfold rng_sub.
rewrite rng_opp_0.
apply rng_add_0_r.
Qed.
Theorem rng_add_move_0_r : ∀ a b, (a + b = 0)%Rng ↔ (a = - b)%Rng.
Proof.
intros a b.
split; intros H.
apply rng_sub_compat_l with (c := b) in H.
rewrite rng_add_sub in H.
unfold rng_sub in H.
now rewrite rng_add_0_l in H.
rewrite H.
rewrite rng_add_opp_l; reflexivity.
Qed.
Theorem rng_opp_inj_wd : ∀ a b, (- a = - b)%Rng ↔ (a = b)%Rng.
Proof.
intros a b; split; intros H.
apply rng_add_move_0_r in H.
rewrite rng_add_comm in H.
apply rng_add_move_0_r in H.
rewrite H.
apply rng_add_move_0_r.
apply rng_add_opp_r.
rewrite H; reflexivity.
Qed.
Theorem rng_opp_involutive : ∀ x, (- - x)%Rng = x.
Proof.
intros.
symmetry.
apply rng_add_move_0_r.
apply rng_add_opp_r.
Qed.
Theorem rng_add_add_swap : ∀ n m p, (n + m + p = n + p + m)%Rng.
Proof.
intros n m p; simpl.
do 2 rewrite <- rng_add_assoc.
assert (m + p = p + m)%Rng as H by apply rng_add_comm.
rewrite H; reflexivity.
Qed.
Theorem rng_mul_mul_swap : ∀ n m p, (n * m * p = n * p * m)%Rng.
Proof.
intros n m p.
do 2 rewrite <- rng_mul_assoc.
assert (m * p = p * m)%Rng as H by apply rng_mul_comm.
rewrite H; reflexivity.
Qed.
Theorem rng_mul_eq_0 : ∀ n m,
(n = 0)%Rng ∨ (m = 0)%Rng
→ (n * m = 0)%Rng.
Proof.
intros n m H; simpl in H; simpl.
destruct H as [H| H]; rewrite H; [ apply rng_mul_0_l | apply rng_mul_0_r ].
Qed.
Theorem rng_pow_1_r : ∀ a, (a ^ 1 = a)%Rng.
Proof. now intros; cbn; rewrite rng_mul_1_r. Qed.
End ring_theorems.