-
Notifications
You must be signed in to change notification settings - Fork 0
/
ordered_rings.v
562 lines (472 loc) · 15.4 KB
/
ordered_rings.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
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
Set Warnings "-notation-overridden,-ambiguous-paths".
Require Export ssreflect ssrbool ssrfun integral_domains.
Record ordered_ring :=
mkOR {
ring :> rings.ring where
"a + b" :=
(add ring a b)
and "a * b" :=
(mul ring a b)
and "0" :=
(zero ring)
and "1" :=
(one ring);
lt : elts ring → elts ring → Prop
where "a < b" := (lt a b);
lt_trans : ∀ a b c, a < b → b < c → a < c;
T : ∀ a b, (a < b ∧ a ≠ b ∧ ¬ b < a) ∨
(¬ a < b ∧ a = b ∧ ¬ b < a) ∨
(¬ a < b ∧ a ≠ b ∧ b < a);
O1 : ∀ a b c, b < c → a + b < a + c;
O2 : ∀ a b, 0 < a → 0 < b → 0 < a * b;
nontriviality : 1 ≠ 0;
}.
Section Ordered_ring_theorems.
Variable OR : ordered_ring.
Notation Ring := (ring OR).
Notation R := (elts Ring).
Notation "0" := (zero Ring).
Notation "1" := (one Ring).
Infix "+" := (add Ring).
Notation "2" := (1 + 1).
Infix "*" := (mul Ring).
Notation "- a" := (neg Ring a).
Notation "- 1" := (neg Ring 1).
Infix "-" := (sub Ring).
Infix "^" := (pow Ring).
Infix "<" := (lt OR).
Notation lt_trans := (lt_trans OR).
Notation O1 := (O1 OR).
Notation O2 := (O2 OR).
Notation T := (T OR).
Notation "a > b" := (b < a) (only parsing).
Definition le a b := a < b ∨ a = b.
Infix "≤" := le.
Notation "x < y < z" := (x < y ∧ y < z).
Notation "a ≥ b" := (b ≤ a) (only parsing).
Notation "a ≤ b < c" := (a ≤ b ∧ b < c) (at level 70, b at next level).
Notation "a < b ≤ c" := (a < b ∧ b ≤ c) (at level 70, b at next level).
Notation "a ≤ b ≤ c" := (a ≤ b ∧ b ≤ c) (at level 70, b at next level).
Add Ring generic_ordered_ring : (ringify Ring).
Theorem trichotomy : ∀ a b, a < b ∨ a = b ∨ b < a.
Proof.
move: T => /[swap] a /[swap] b /(_ a b); intuition.
Qed.
Theorem O1_r : ∀ a b c, b < c → b + a < c + a.
Proof.
move=> a b c H.
rewrite ? (A1 _ _ a).
auto using O1.
Qed.
Theorem add_le_r : ∀ a b c, b ≤ c → b + a ≤ c + a.
Proof.
move=> a b c [H | H].
- left.
auto using O1_r.
- right.
ring [H].
Qed.
Theorem add_le_l : ∀ a b c, b ≤ c → a + b ≤ a + c.
Proof.
move=> a b c.
rewrite ? (A1 _ a) => /add_le_r //.
Qed.
Theorem O0 : ∀ a b, 0 < a → 0 < b → 0 < a + b.
Proof.
move=> a b /(O1 0) /[swap] /(O1 a).
rewrite A3 A1 => /[swap] /lt_trans /[apply] //.
Qed.
Theorem lt_shift : ∀ a b, a < b ↔ 0 < b + -a.
Proof.
split => [/(O1_r (-a)) | /(O1_r a)];
by rewrite ? A4 ? A3 -? A2 ? A4_l ? A3_r.
Qed.
Theorem le_shift : ∀ a b, a ≤ b ↔ 0 ≤ b + -a.
Proof.
split => [/(add_le_r (-a)) | /(add_le_r a)];
by rewrite ? A4 ? A3 -? A2 ? A4_l ? A3_r.
Qed.
Theorem O3 : ∀ a b c, 0 < a → b < c → a * b < a * c.
Proof.
move=> a b c /lt_shift /[swap] /lt_shift /O2 /[apply].
(have ->: (c + -b) * (a + -0) = a * c + -(a * b) by ring) =>
/(iffRL (lt_shift _ _)) //.
Qed.
Theorem O3_r : ∀ a b c, 0 < a → b < c → b * a < c * a.
Proof.
move=> a b c.
rewrite ? (M1 _ _ a) => /O3 /[apply] //.
Qed.
Definition mul_lt_l := O3.
Definition mul_lt_r := O3_r.
Theorem neg_lt_0 : ∀ a, 0 < a ↔ -a < 0.
Proof.
move: lt_shift => /[swap] a /(_ (-a)) ->.
by have ->: 0 + --a = a by ring.
Qed.
Theorem lt_neg_0 : ∀ a, a < 0 ↔ 0 < -a.
Proof.
move: lt_shift => /[swap] a /(_ a) ->.
by have ->: 0 + -a = -a by ring.
Qed.
Theorem neg_le_0 : ∀ a, 0 ≤ a ↔ -a ≤ 0.
Proof.
split => [/le_shift | /le_shift].
- (have ->: a + -0 = 0 + --a by ring) => /(iffRL (le_shift _ _)) //.
- have ->: 0 + --a = a => //; ring.
Qed.
Theorem le_neg_0 : ∀ a, a ≤ 0 ↔ 0 ≤ -a.
Proof.
move=> a.
rewrite neg_le_0.
have ->: --a = a => //; ring.
Qed.
Definition mul_pos_pos := O2.
Theorem mul_pos_neg : ∀ a b, 0 < a → b < 0 → a * b < 0.
Proof.
move=> a b /[swap] /lt_neg_0 /O2 /[apply].
(have ->: -b * a = -(a * b) by ring) => /lt_neg_0 //.
Qed.
Theorem mul_neg_pos : ∀ a b, a < 0 → 0 < b → a * b < 0.
Proof.
move=> a b /mul_pos_neg /[apply].
by rewrite M1.
Qed.
Theorem mul_neg_neg : ∀ a b, a < 0 → b < 0 → 0 < a * b.
Proof.
move=> a b /lt_neg_0 /[swap] /lt_neg_0 /O2 /[apply].
have ->: -b * -a = a * b => //; ring.
Qed.
Theorem pos_mul : ∀ a b, 0 < a * b → (0 < a ∧ 0 < b) ∨ (a < 0 ∧ b < 0).
Proof.
move=> a b H.
case (T (a*b) 0), (T a 0), (T b 0); intuition; subst;
rewrite -> ? mul_0_r, ? mul_0_l in *; auto; exfalso;
eauto using mul_neg_pos, mul_pos_neg.
Qed.
Theorem pos_mul_iff : ∀ a b, 0 < a * b ↔ (0 < a ∧ 0 < b) ∨ (a < 0 ∧ b < 0).
Proof.
(split; auto using pos_mul) =>
[[[] /mul_pos_pos /[apply] | [] /mul_neg_neg /[apply]]] //.
Qed.
Theorem neg_mul : ∀ a b, a * b < 0 → (0 < a ∧ b < 0) ∨ (a < 0 ∧ 0 < b).
Proof.
move=> a b H.
case (T (a*b) 0), (T a 0), (T b 0); intuition; subst;
rewrite -> ? mul_0_r, ? mul_0_l in *; exfalso;
eauto using mul_neg_neg, mul_pos_pos.
Qed.
Theorem cancellation_0_mul : ∀ a b, a * b = 0 → a = 0 ∨ b = 0.
Proof.
move=> a b H.
case (T (a*b) 0), (T a 0), (T b 0); intuition;
eauto using pos_mul, neg_mul; exfalso;
eauto using mul_neg_neg, mul_neg_pos, mul_pos_neg, mul_pos_pos.
Qed.
Definition integral_domain := mkID Ring cancellation_0_mul (nontriviality OR).
Lemma zero_lt_1 : 0 < 1.
Proof.
elim (T 0 1) => [ | [[] /[swap] [[]] * |
[] /[swap] [[]] /[swap] /(O1_r (-1))]]; try tauto.
- by contradiction (nontriviality OR).
- rewrite A4 A3 -(M3 _ 1) -(rings.mul_neg_neg _ 1 1) => *.
apply mul_pos_pos; refine (@eq_rect _ _ _ _ _ _); eauto; ring.
Qed.
Lemma lt_succ : ∀ m, m < m + 1.
Proof.
move=> m.
rewrite -{1}(A3 _ m) A1.
eauto using O1, zero_lt_1.
Qed.
Lemma succ_lt : ∀ n m, n < m → n < m + 1.
Proof.
eauto using lt_succ, lt_trans.
Qed.
Theorem lt_irrefl : ∀ a, ¬ a < a.
Proof.
move: T => /[swap] a /(_ a a); intuition.
Qed.
Theorem lt_antisym : ∀ a b, a < b → ¬ b < a.
Proof.
move: T => /[swap] a /[swap] b /(_ a b); intuition.
Qed.
Theorem O3_iff : ∀ a b c, 0 < a → b < c ↔ a * b < a * c.
Proof.
split => [H0 | ]; eauto using O3.
elim (T b c) => [[H1 _] | [[_ [-> _] /lt_irrefl] |
[_ [_ /(O3 a _ _ H) /lt_antisym H1]]]] => //.
Qed.
Theorem le_antisymm : ∀ a b, a ≤ b → b ≤ a → a = b.
Proof.
move=> a b [/lt_antisym H | ->] // => [[H0 | ->]] //.
Qed.
Lemma square_ne0 : ∀ a, a ≠ 0 → a * a > 0.
Proof.
move: T => /[swap] a /(_ a 0) H H0; intuition; subst;
auto using mul_pos_pos, mul_neg_neg.
Qed.
Theorem le_trans : ∀ a b c, a ≤ b → b ≤ c → a ≤ c.
Proof.
move=> a b c [H | H] [H0 | H0]; subst; rewrite /le; eauto using lt_trans.
Qed.
Lemma pos_div_l : ∀ a b, 0 < a → 0 < a * b → 0 < b.
Proof.
move: pos_mul => /[swap] a /[swap] b /(_ a b) H H0.
case (T 0 a), (T 0 b); intuition.
Qed.
Lemma pos_div_r : ∀ a b, 0 < a → 0 < b * a → 0 < b.
Proof.
move=> a b.
by rewrite M1 => /pos_div_l /[apply].
Qed.
Lemma neg_div_l : ∀ a b, a < 0 → 0 < a * b → b < 0.
Proof.
move: pos_mul => /[swap] a /[swap] b /(_ a b) H H0.
case (T 0 a), (T 0 b); intuition.
Qed.
Lemma neg_div_r : ∀ a b, a < 0 → 0 < b * a → b < 0.
Proof.
move=> a b.
by rewrite M1 => /neg_div_l /[apply].
Qed.
Lemma pos_neg_div_l : ∀ a b, 0 < a → a * b < 0 → b < 0.
Proof.
move: neg_mul => /[swap] a /[swap] b /(_ a b) H H0.
case (T 0 a), (T 0 b); intuition.
Qed.
Lemma pos_neg_div_r : ∀ a b, 0 < a → b * a < 0 → b < 0.
Proof.
move=> a b.
by rewrite M1 => /pos_neg_div_l /[apply].
Qed.
Lemma neg_pos_div_l : ∀ a b, a < 0 → a * b < 0 → 0 < b.
Proof.
move: neg_mul => /[swap] a /[swap] b /(_ a b) H H0.
case (T 0 a), (T 0 b); intuition.
Qed.
Lemma neg_pos_div_r : ∀ a b, a < 0 → b * a < 0 → 0 < b.
Proof.
move=> a b.
by rewrite M1 => /neg_pos_div_l /[apply].
Qed.
Lemma one_lt : ∀ a, 1 < a → 0 < a.
Proof.
eauto using lt_trans, zero_lt_1.
Qed.
Theorem mul_le_l : ∀ a b c, 0 < a → b ≤ c → a * b ≤ a * c.
Proof.
move=> a b c H [/(mul_lt_l a _ _ H) | ->]; [left | right] => //.
Qed.
Theorem mul_le_r : ∀ a b c, a ≤ b → 0 < c → a * c ≤ b * c.
Proof.
move=> a b c.
by rewrite ? (M1 _ _ c) => /mul_le_l /[apply].
Qed.
Theorem neg_neg_lt : ∀ a b, a < b → -b < -a.
Proof.
move=> a b /(O1 (-a+-b)) => H.
by ring_simplify in H.
Qed.
Theorem lt_neq : ∀ a b, a < b → b ≠ a.
Proof.
move=> a b /[swap] -> /lt_irrefl //.
Qed.
Theorem lt_sub_pos : ∀ a b, 0 < b → a - b < a.
Proof.
move=> a b H.
rewrite lt_shift.
now ring_simplify.
Qed.
Theorem lt_cross_mul : ∀ a b c d,
0 < a → 0 < c → a < b → c < d → a * c < b * d.
Proof.
move=> a b c d H H0 /[dup] H1 /(O3 c) => /(_ H0) /[swap] /[dup] H3 /(O3 b).
rewrite ? (M1 _ c).
eauto using lt_trans.
Qed.
Theorem lt_le_cross_mul : ∀ a b c d,
0 < a → 0 < c → a < b → c ≤ d → a * c < b * d.
Proof.
move=> a b c d ? /[swap] ? /[swap] [[ | ->]]; auto using lt_cross_mul, O3_r.
Qed.
Theorem le_lt_cross_mul : ∀ a b c d,
0 < a → 0 < c → a ≤ b → c < d → a * c < b * d.
Proof.
move=> a b c d /[swap] ? /[swap] [[? | ->]] *; auto using lt_cross_mul, O3.
Qed.
Theorem lt_or_ge : ∀ a b, a < b ∨ b ≤ a.
Proof.
move: T => /[swap] a /[swap] b /(_ a b) [[H _] | [[_ [H _]] | [_ [_ H]]]];
rewrite /le; intuition.
Qed.
Theorem lt_not_ge : ∀ a b, a < b ↔ ¬ b ≤ a.
Proof.
move: T => /[swap] a /[swap] b /(_ b a); rewrite /le; tauto.
Qed.
Theorem le_not_gt : ∀ a b, a ≤ b ↔ ¬ b < a.
Proof.
move: T => /[swap] a /[swap] b /(_ a b); rewrite /le; tauto.
Qed.
Theorem mul_le_l_iff : ∀ a b c, 0 < a → b ≤ c ↔ a * b ≤ a * c.
Proof.
split => H0; auto using mul_le_l.
apply le_not_gt => /(O3 a) => /(_ H) /lt_not_ge [] //.
Qed.
Theorem mul_le_r_iff : ∀ a b c, 0 < a → b ≤ c ↔ b * a ≤ c * a.
Proof.
move=> a b c /mul_le_l_iff.
by rewrite ? (M1 _ _ a).
Qed.
Theorem O0_opp : ∀ a b, 0 < a + b → 0 < a ∨ 0 < b.
Proof.
move: T => /[swap] a /(_ 0 a)
[[H0 _] b | [[_ [<- _] b] | [_ [_ H0]] b /(lt_trans a 0 _ H0)
/lt_shift H1]]; auto.
- rewrite A3 => /or_intror //.
- ring_simplify in H1.
right => //.
Qed.
Theorem pow_pos : ∀ a b, 0 < a → 0 < a^b.
Proof.
induction b using Induction.
- move: pow_0_r zero_lt_1 -> => //.
- move: pow_succ_r -> => /[dup] /IHb /O2 /[apply] //.
Qed.
Theorem pow_ge_1 : ∀ a n, 1 < a → 1 ≤ a^n.
Proof.
induction n using Induction.
- move: pow_0_r (eq_refl 1) -> => /or_intror => /(_ (1 < 1)) //.
- rewrite pow_succ_r -{2}(M3 _ 1) =>
/[dup] /IHn /le_lt_cross_mul /[apply] /(_ zero_lt_1) /(_ zero_lt_1)
=> /or_introl => /(_ (1 * 1 = (a^n * a))) //.
Qed.
Theorem pow_gt_1 : ∀ a n, 1 < a → (0 < n)%N → 1 < a^n.
Proof.
induction n using Induction => [H /naturals.lt_irrefl | H H0] //.
move: pow_succ_r (classic (n = 0%N)) -> => [[-> | /succ_0 [m H1]]].
+ rewrite pow_0_r M3 //.
+ move: (M3 _ 1) H1 IHn H0 => {3}<- =>
-> /(_ H) /(_ (naturals.lt_succ m)) /(lt_cross_mul 1 (a^(S m)) 1 a) =>
/(_ zero_lt_1) /(_ zero_lt_1) /(_ H) //.
Qed.
Theorem one_lt_2 : 1 < 1 + 1.
Proof.
rewrite -{1}(A3_r _ 1).
apply /O1 /zero_lt_1.
Qed.
Definition min (a b : R) := If (a < b) then a else b.
Theorem min_le_l : ∀ a b, min a b ≤ a.
Proof.
rewrite /min /le => a b.
(case excluded_middle_informative; first by right) => /le_not_gt //.
Qed.
Theorem min_le_r : ∀ a b, min a b ≤ b.
Proof.
rewrite /min /le => a b.
case excluded_middle_informative; intuition.
Qed.
Theorem min_eq : ∀ a b, min a b = a ∨ min a b = b.
Proof.
rewrite /min /le => a b.
case excluded_middle_informative; intuition.
Qed.
Definition max (a b : R) := If (a < b) then b else a.
Theorem max_le_l : ∀ a b, a ≤ max a b.
Proof.
rewrite /max /le => a b.
case excluded_middle_informative; intuition.
Qed.
Theorem max_le_r : ∀ a b, b ≤ max a b.
Proof.
rewrite /max => a b.
(case excluded_middle_informative; first by right) => /le_not_gt //.
Qed.
Theorem max_eq : ∀ a b, max a b = a ∨ max a b = b.
Proof.
rewrite /max /le => a b.
case excluded_middle_informative; intuition.
Qed.
Theorem lt_cross_add : ∀ a b c d, a < b → c < d → a + c < b + d.
Proof.
move=> a b c d /(O1_r c) /[swap] /(O1 b) /[swap] /lt_trans /[apply] //.
Qed.
Theorem le_cross_add : ∀ a b c d, a ≤ b → c ≤ d → a + c ≤ b + d.
Proof.
move=> a b c d /(add_le_r c) /[swap] /(add_le_l b) /[swap]
/le_trans /[apply] //.
Qed.
Lemma square_ge_1 : ∀ r, 0 < r → 1 < r * r → 1 < r.
Proof.
move: T => /[swap] r /(_ 1 r) =>
[[[H _] | [[_ [<- _]] | [_ [_ H]] H0 /lt_antisym []]]];
try tauto; first by rewrite M3.
rewrite -(M3 _ 1).
by apply lt_cross_mul.
Qed.
Theorem zero_lt_2 : 0 < 2.
Proof.
move: zero_lt_1 => /[dup] /(O1_r 1).
rewrite A3 => /[swap] /lt_trans /[apply] //.
Qed.
Theorem zero_ne_2 : 2 ≠ 0.
Proof.
move: zero_lt_2 => /[swap] -> /lt_irrefl //.
Qed.
Theorem le_lt_trans : ∀ a b c, a ≤ b → b < c → a < c.
Proof.
move=> a b c [/lt_trans /[apply] | ->] //.
Qed.
Theorem lt_le_trans : ∀ a b c, a < b → b ≤ c → a < c.
Proof.
move=> a b c /[swap] [[/[swap] /lt_trans /[apply] | <-]] //.
Qed.
Theorem le_refl : ∀ a, a ≤ a.
Proof.
right => //.
Qed.
Theorem mul_le_l_nonneg : ∀ a b c, 0 ≤ a → b ≤ c → a * b ≤ a * c.
Proof.
move=> a b c [/[swap] /mul_le_l /[apply] | <-] //.
move: (mul_0_l _ b) (mul_0_l _ c) (le_refl 0) -> => -> //.
Qed.
Theorem mul_le_r_nonneg : ∀ a b c, a ≤ b → 0 ≤ c → a * c ≤ b * c.
Proof.
move=> a b c H [/(mul_le_r _ _ _ H) | <-] //.
move: (mul_0_r _ a) (mul_0_r _ b) (le_refl 0) -> => -> //.
Qed.
Theorem mul_nonneg_nonneg : ∀ a b, 0 ≤ a → 0 ≤ b → 0 ≤ a * b.
Proof.
move=> a b /mul_le_l_nonneg /[apply].
rewrite mul_0_r //.
Qed.
Theorem add_nonneg_nonneg : ∀ a b, 0 ≤ a → 0 ≤ b → 0 ≤ a + b.
Proof.
move=> a b /[dup] H [/(O1_r 0) /lt_trans /[swap]
[[/(O1 a) /[swap] /[apply] | <-]] | <-];
rewrite ? (A1 _ a) A3 // => /or_introl => /(_ (0 = b + a)) //.
Qed.
Theorem pos_ne_0 : ∀ a, 0 < a → a ≠ 0.
Proof.
move=> a /[swap] -> /lt_irrefl //.
Qed.
Theorem one_ne_minus_one : 1 ≠ -1.
Proof.
move: zero_ne_2 => /[swap] {2}-> [].
apply A4.
Qed.
Theorem pos_mul_nonneg : ∀ a b, 0 < a → 0 ≤ a * b → 0 ≤ b.
Proof.
move=> a b /mul_pos_neg H /le_not_gt.
rewrite le_not_gt => /[swap] /H //.
Qed.
Theorem le_sym : ∀ a b, a ≤ b ∨ b ≤ a.
Proof.
rewrite /le => a b.
case (T a b); tauto.
Qed.
Theorem ne0_lt_gt : ∀ a, a ≠ 0 → 0 < a ∨ a < 0.
Proof.
move=> a /neq_sym H.
case (T 0 a); intuition.
Qed.
End Ordered_ring_theorems.