-
Notifications
You must be signed in to change notification settings - Fork 337
/
Defs.lean
559 lines (419 loc) · 22.8 KB
/
Defs.lean
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
/-
Copyright (c) 2021 Damiano Testa. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Damiano Testa
-/
import Mathlib.Algebra.Group.Basic
import Mathlib.Order.Basic
import Mathlib.Order.Monotone.Basic
/-!
# Covariants and contravariants
This file contains general lemmas and instances to work with the interactions between a relation and
an action on a Type.
The intended application is the splitting of the ordering from the algebraic assumptions on the
operations in the `Ordered[...]` hierarchy.
The strategy is to introduce two more flexible typeclasses, `CovariantClass` and
`ContravariantClass`:
* `CovariantClass` models the implication `a ≤ b → c * a ≤ c * b` (multiplication is monotone),
* `ContravariantClass` models the implication `a * b < a * c → b < c`.
Since `Co(ntra)variantClass` takes as input the operation (typically `(+)` or `(*)`) and the order
relation (typically `(≤)` or `(<)`), these are the only two typeclasses that I have used.
The general approach is to formulate the lemma that you are interested in and prove it, with the
`Ordered[...]` typeclass of your liking. After that, you convert the single typeclass,
say `[OrderedCancelMonoid M]`, into three typeclasses, e.g.
`[CancelMonoid M] [PartialOrder M] [CovariantClass M M (Function.swap (*)) (≤)]`
and have a go at seeing if the proof still works!
Note that it is possible to combine several `Co(ntra)variantClass` assumptions together.
Indeed, the usual ordered typeclasses arise from assuming the pair
`[CovariantClass M M (*) (≤)] [ContravariantClass M M (*) (<)]`
on top of order/algebraic assumptions.
A formal remark is that normally `CovariantClass` uses the `(≤)`-relation, while
`ContravariantClass` uses the `(<)`-relation. This need not be the case in general, but seems to be
the most common usage. In the opposite direction, the implication
```lean
[Semigroup α] [PartialOrder α] [ContravariantClass α α (*) (≤)] → LeftCancelSemigroup α
```
holds -- note the `Co*ntra*` assumption on the `(≤)`-relation.
# Formalization notes
We stick to the convention of using `Function.swap (*)` (or `Function.swap (+)`), for the
typeclass assumptions, since `Function.swap` is slightly better behaved than `flip`.
However, sometimes as a **non-typeclass** assumption, we prefer `flip (*)` (or `flip (+)`),
as it is easier to use.
-/
-- TODO: convert `ExistsMulOfLE`, `ExistsAddOfLE`?
-- TODO: relationship with `Con/AddCon`
-- TODO: include equivalence of `LeftCancelSemigroup` with
-- `Semigroup PartialOrder ContravariantClass α α (*) (≤)`?
-- TODO : use ⇒, as per Eric's suggestion? See
-- https://leanprover.zulipchat.com/#narrow/stream/116395-maths/topic/ordered.20stuff/near/236148738
-- for a discussion.
open Function
section Variants
variable {M N : Type*} (μ : M → N → N) (r : N → N → Prop)
variable (M N)
/-- `Covariant` is useful to formulate succinctly statements about the interactions between an
action of a Type on another one and a relation on the acted-upon Type.
See the `CovariantClass` doc-string for its meaning. -/
def Covariant : Prop :=
∀ (m) {n₁ n₂}, r n₁ n₂ → r (μ m n₁) (μ m n₂)
/-- `Contravariant` is useful to formulate succinctly statements about the interactions between an
action of a Type on another one and a relation on the acted-upon Type.
See the `ContravariantClass` doc-string for its meaning. -/
def Contravariant : Prop :=
∀ (m) {n₁ n₂}, r (μ m n₁) (μ m n₂) → r n₁ n₂
/-- Given an action `μ` of a Type `M` on a Type `N` and a relation `r` on `N`, informally, the
`CovariantClass` says that "the action `μ` preserves the relation `r`."
More precisely, the `CovariantClass` is a class taking two Types `M N`, together with an "action"
`μ : M → N → N` and a relation `r : N → N → Prop`. Its unique field `elim` is the assertion that
for all `m ∈ M` and all elements `n₁, n₂ ∈ N`, if the relation `r` holds for the pair
`(n₁, n₂)`, then, the relation `r` also holds for the pair `(μ m n₁, μ m n₂)`,
obtained from `(n₁, n₂)` by acting upon it by `m`.
If `m : M` and `h : r n₁ n₂`, then `CovariantClass.elim m h : r (μ m n₁) (μ m n₂)`.
-/
class CovariantClass : Prop where
/-- For all `m ∈ M` and all elements `n₁, n₂ ∈ N`, if the relation `r` holds for the pair
`(n₁, n₂)`, then, the relation `r` also holds for the pair `(μ m n₁, μ m n₂)` -/
protected elim : Covariant M N μ r
/-- Given an action `μ` of a Type `M` on a Type `N` and a relation `r` on `N`, informally, the
`ContravariantClass` says that "if the result of the action `μ` on a pair satisfies the
relation `r`, then the initial pair satisfied the relation `r`."
More precisely, the `ContravariantClass` is a class taking two Types `M N`, together with an
"action" `μ : M → N → N` and a relation `r : N → N → Prop`. Its unique field `elim` is the
assertion that for all `m ∈ M` and all elements `n₁, n₂ ∈ N`, if the relation `r` holds for the
pair `(μ m n₁, μ m n₂)` obtained from `(n₁, n₂)` by acting upon it by `m`, then, the relation
`r` also holds for the pair `(n₁, n₂)`.
If `m : M` and `h : r (μ m n₁) (μ m n₂)`, then `ContravariantClass.elim m h : r n₁ n₂`.
-/
class ContravariantClass : Prop where
/-- For all `m ∈ M` and all elements `n₁, n₂ ∈ N`, if the relation `r` holds for the
pair `(μ m n₁, μ m n₂)` obtained from `(n₁, n₂)` by acting upon it by `m`, then, the relation
`r` also holds for the pair `(n₁, n₂)`. -/
protected elim : Contravariant M N μ r
/-- Typeclass for monotonicity of multiplication on the left,
namely `b₁ ≤ b₂ → a * b₁ ≤ a * b₂`.
You should usually not use this very granular typeclass directly, but rather a typeclass like
`OrderedCommMonoid`. -/
abbrev MulLeftMono [Mul M] [LE M] : Prop :=
CovariantClass M M (· * ·) (· ≤ ·)
/-- Typeclass for monotonicity of multiplication on the right,
namely `a₁ ≤ a₂ → a₁ * b ≤ a₂ * b`.
You should usually not use this very granular typeclass directly, but rather a typeclass like
`OrderedCommMonoid`. -/
abbrev MulRightMono [Mul M] [LE M] : Prop :=
CovariantClass M M (swap (· * ·)) (· ≤ ·)
/-- Typeclass for monotonicity of addition on the left,
namely `b₁ ≤ b₂ → a + b₁ ≤ a + b₂`.
You should usually not use this very granular typeclass directly, but rather a typeclass like
`OrderedAddCommMonoid`. -/
abbrev AddLeftMono [Add M] [LE M] : Prop :=
CovariantClass M M (· + ·) (· ≤ ·)
/-- Typeclass for monotonicity of addition on the right,
namely `a₁ ≤ a₂ → a₁ + b ≤ a₂ + b`.
You should usually not use this very granular typeclass directly, but rather a typeclass like
`OrderedAddCommMonoid`. -/
abbrev AddRightMono [Add M] [LE M] : Prop :=
CovariantClass M M (swap (· + ·)) (· ≤ ·)
attribute [to_additive existing] MulLeftMono MulRightMono
/-- Typeclass for monotonicity of multiplication on the left,
namely `b₁ < b₂ → a * b₁ < a * b₂`.
You should usually not use this very granular typeclass directly, but rather a typeclass like
`OrderedCommGroup`. -/
abbrev MulLeftStrictMono [Mul M] [LT M] : Prop :=
CovariantClass M M (· * ·) (· < ·)
/-- Typeclass for monotonicity of multiplication on the right,
namely `a₁ < a₂ → a₁ * b < a₂ * b`.
You should usually not use this very granular typeclass directly, but rather a typeclass like
`OrderedCommGroup`. -/
abbrev MulRightStrictMono [Mul M] [LT M] : Prop :=
CovariantClass M M (swap (· * ·)) (· < ·)
/-- Typeclass for monotonicity of addition on the left,
namely `b₁ < b₂ → a + b₁ < a + b₂`.
You should usually not use this very granular typeclass directly, but rather a typeclass like
`OrderedAddCommGroup`. -/
abbrev AddLeftStrictMono [Add M] [LT M] : Prop :=
CovariantClass M M (· + ·) (· < ·)
/-- Typeclass for monotonicity of addition on the right,
namely `a₁ < a₂ → a₁ + b < a₂ + b`.
You should usually not use this very granular typeclass directly, but rather a typeclass like
`OrderedAddCommGroup`. -/
abbrev AddRightStrictMono [Add M] [LT M] : Prop :=
CovariantClass M M (swap (· + ·)) (· < ·)
attribute [to_additive existing] MulLeftStrictMono MulRightStrictMono
/-- Typeclass for strict reverse monotonicity of multiplication on the left,
namely `a * b₁ < a * b₂ → b₁ < b₂`.
You should usually not use this very granular typeclass directly, but rather a typeclass like
`OrderedCommGroup`. -/
abbrev MulLeftReflectLT [Mul M] [LT M] : Prop :=
ContravariantClass M M (· * ·) (· < ·)
/-- Typeclass for strict reverse monotonicity of multiplication on the right,
namely `a₁ * b < a₂ * b → a₁ < a₂`.
You should usually not use this very granular typeclass directly, but rather a typeclass like
`OrderedCommGroup`. -/
abbrev MulRightReflectLT [Mul M] [LT M] : Prop :=
ContravariantClass M M (swap (· * ·)) (· < ·)
/-- Typeclass for strict reverse monotonicity of addition on the left,
namely `a + b₁ < a + b₂ → b₁ < b₂`.
You should usually not use this very granular typeclass directly, but rather a typeclass like
`OrderedAddCommGroup`. -/
abbrev AddLeftReflectLT [Add M] [LT M] : Prop :=
ContravariantClass M M (· + ·) (· < ·)
/-- Typeclass for strict reverse monotonicity of addition on the right,
namely `a₁ * b < a₂ * b → a₁ < a₂`.
You should usually not use this very granular typeclass directly, but rather a typeclass like
`OrderedAddCommGroup`. -/
abbrev AddRightReflectLT [Add M] [LT M] : Prop :=
ContravariantClass M M (swap (· + ·)) (· < ·)
attribute [to_additive existing] MulLeftReflectLT MulRightReflectLT
/-- Typeclass for reverse monotonicity of multiplication on the left,
namely `a * b₁ ≤ a * b₂ → b₁ ≤ b₂`.
You should usually not use this very granular typeclass directly, but rather a typeclass like
`OrderedCancelCommMonoid`. -/
abbrev MulLeftReflectLE [Mul M] [LE M] : Prop :=
ContravariantClass M M (· * ·) (· ≤ ·)
/-- Typeclass for reverse monotonicity of multiplication on the right,
namely `a₁ * b ≤ a₂ * b → a₁ ≤ a₂`.
You should usually not use this very granular typeclass directly, but rather a typeclass like
`OrderedCancelCommMonoid`. -/
abbrev MulRightReflectLE [Mul M] [LE M] : Prop :=
ContravariantClass M M (swap (· * ·)) (· ≤ ·)
/-- Typeclass for reverse monotonicity of addition on the left,
namely `a + b₁ ≤ a + b₂ → b₁ ≤ b₂`.
You should usually not use this very granular typeclass directly, but rather a typeclass like
`OrderedCancelAddCommMonoid`. -/
abbrev AddLeftReflectLE [Add M] [LE M] : Prop :=
ContravariantClass M M (· + ·) (· ≤ ·)
/-- Typeclass for reverse monotonicity of addition on the right,
namely `a₁ + b ≤ a₂ + b → a₁ ≤ a₂`.
You should usually not use this very granular typeclass directly, but rather a typeclass like
`OrderedCancelAddCommMonoid`. -/
abbrev AddRightReflectLE [Add M] [LE M] : Prop :=
ContravariantClass M M (swap (· + ·)) (· ≤ ·)
attribute [to_additive existing] MulLeftReflectLE MulRightReflectLE
theorem rel_iff_cov [CovariantClass M N μ r] [ContravariantClass M N μ r] (m : M) {a b : N} :
r (μ m a) (μ m b) ↔ r a b :=
⟨ContravariantClass.elim _, CovariantClass.elim _⟩
section flip
variable {M N μ r}
theorem Covariant.flip (h : Covariant M N μ r) : Covariant M N μ (flip r) :=
fun a _ _ ↦ h a
theorem Contravariant.flip (h : Contravariant M N μ r) : Contravariant M N μ (flip r) :=
fun a _ _ ↦ h a
end flip
section Covariant
variable {M N μ r} [CovariantClass M N μ r]
theorem act_rel_act_of_rel (m : M) {a b : N} (ab : r a b) : r (μ m a) (μ m b) :=
CovariantClass.elim _ ab
@[to_additive]
theorem Group.covariant_iff_contravariant [Group N] :
Covariant N N (· * ·) r ↔ Contravariant N N (· * ·) r := by
refine ⟨fun h a b c bc ↦ ?_, fun h a b c bc ↦ ?_⟩
· rw [← inv_mul_cancel_left a b, ← inv_mul_cancel_left a c]
exact h a⁻¹ bc
· rw [← inv_mul_cancel_left a b, ← inv_mul_cancel_left a c] at bc
exact h a⁻¹ bc
@[to_additive]
instance (priority := 100) Group.covconv [Group N] [CovariantClass N N (· * ·) r] :
ContravariantClass N N (· * ·) r :=
⟨Group.covariant_iff_contravariant.mp CovariantClass.elim⟩
@[to_additive]
theorem Group.mulLeftReflectLE_of_mulLeftMono [Group N] [LE N]
[MulLeftMono N] : MulLeftReflectLE N :=
inferInstance
@[to_additive]
theorem Group.mulLeftReflectLT_of_mulLeftStrictMono [Group N] [LT N]
[MulLeftStrictMono N] : MulLeftReflectLT N :=
inferInstance
@[to_additive]
theorem Group.covariant_swap_iff_contravariant_swap [Group N] :
Covariant N N (swap (· * ·)) r ↔ Contravariant N N (swap (· * ·)) r := by
refine ⟨fun h a b c bc ↦ ?_, fun h a b c bc ↦ ?_⟩
· rw [← mul_inv_cancel_right b a, ← mul_inv_cancel_right c a]
exact h a⁻¹ bc
· rw [← mul_inv_cancel_right b a, ← mul_inv_cancel_right c a] at bc
exact h a⁻¹ bc
@[to_additive]
instance (priority := 100) Group.covconv_swap [Group N] [CovariantClass N N (swap (· * ·)) r] :
ContravariantClass N N (swap (· * ·)) r :=
⟨Group.covariant_swap_iff_contravariant_swap.mp CovariantClass.elim⟩
@[to_additive]
theorem Group.mulRightReflectLE_of_mulRightMono [Group N] [LE N]
[MulRightMono N] : MulRightReflectLE N :=
inferInstance
@[to_additive]
theorem Group.mulRightReflectLT_of_mulRightStrictMono [Group N] [LT N]
[MulRightStrictMono N] : MulRightReflectLT N :=
inferInstance
section Trans
variable [IsTrans N r] (m n : M) {a b c d : N}
-- Lemmas with 3 elements.
theorem act_rel_of_rel_of_act_rel (ab : r a b) (rl : r (μ m b) c) : r (μ m a) c :=
_root_.trans (act_rel_act_of_rel m ab) rl
theorem rel_act_of_rel_of_rel_act (ab : r a b) (rr : r c (μ m a)) : r c (μ m b) :=
_root_.trans rr (act_rel_act_of_rel _ ab)
end Trans
end Covariant
-- Lemma with 4 elements.
section MEqN
variable {M N μ r} {mu : N → N → N} [IsTrans N r] [i : CovariantClass N N mu r]
[i' : CovariantClass N N (swap mu) r] {a b c d : N}
theorem act_rel_act_of_rel_of_rel (ab : r a b) (cd : r c d) : r (mu a c) (mu b d) :=
_root_.trans (@act_rel_act_of_rel _ _ (swap mu) r _ c _ _ ab) (act_rel_act_of_rel b cd)
end MEqN
section Contravariant
variable {M N μ r} [ContravariantClass M N μ r]
theorem rel_of_act_rel_act (m : M) {a b : N} (ab : r (μ m a) (μ m b)) : r a b :=
ContravariantClass.elim _ ab
section Trans
variable [IsTrans N r] (m n : M) {a b c d : N}
-- Lemmas with 3 elements.
theorem act_rel_of_act_rel_of_rel_act_rel (ab : r (μ m a) b) (rl : r (μ m b) (μ m c)) :
r (μ m a) c :=
_root_.trans ab (rel_of_act_rel_act m rl)
theorem rel_act_of_act_rel_act_of_rel_act (ab : r (μ m a) (μ m b)) (rr : r b (μ m c)) :
r a (μ m c) :=
_root_.trans (rel_of_act_rel_act m ab) rr
end Trans
end Contravariant
section Monotone
variable {α : Type*} {M N μ} [Preorder α] [Preorder N]
variable {f : N → α}
/-- The partial application of a constant to a covariant operator is monotone. -/
theorem Covariant.monotone_of_const [CovariantClass M N μ (· ≤ ·)] (m : M) : Monotone (μ m) :=
fun _ _ ↦ CovariantClass.elim m
/-- A monotone function remains monotone when composed with the partial application
of a covariant operator. E.g., `∀ (m : ℕ), Monotone f → Monotone (fun n ↦ f (m + n))`. -/
theorem Monotone.covariant_of_const [CovariantClass M N μ (· ≤ ·)] (hf : Monotone f) (m : M) :
Monotone (f <| μ m ·) :=
hf.comp (Covariant.monotone_of_const m)
/-- Same as `Monotone.covariant_of_const`, but with the constant on the other side of
the operator. E.g., `∀ (m : ℕ), Monotone f → Monotone (fun n ↦ f (n + m))`. -/
theorem Monotone.covariant_of_const' {μ : N → N → N} [CovariantClass N N (swap μ) (· ≤ ·)]
(hf : Monotone f) (m : N) : Monotone (f <| μ · m) :=
Monotone.covariant_of_const (μ := swap μ) hf m
/-- Dual of `Monotone.covariant_of_const` -/
theorem Antitone.covariant_of_const [CovariantClass M N μ (· ≤ ·)] (hf : Antitone f) (m : M) :
Antitone (f <| μ m ·) :=
hf.comp_monotone <| Covariant.monotone_of_const m
/-- Dual of `Monotone.covariant_of_const'` -/
theorem Antitone.covariant_of_const' {μ : N → N → N} [CovariantClass N N (swap μ) (· ≤ ·)]
(hf : Antitone f) (m : N) : Antitone (f <| μ · m) :=
Antitone.covariant_of_const (μ := swap μ) hf m
end Monotone
theorem covariant_le_of_covariant_lt [PartialOrder N] :
Covariant M N μ (· < ·) → Covariant M N μ (· ≤ ·) := by
intro h a b c bc
rcases bc.eq_or_lt with (rfl | bc)
· exact le_rfl
· exact (h _ bc).le
theorem covariantClass_le_of_lt [PartialOrder N] [CovariantClass M N μ (· < ·)] :
CovariantClass M N μ (· ≤ ·) := ⟨covariant_le_of_covariant_lt _ _ _ CovariantClass.elim⟩
@[to_additive]
theorem mulLeftMono_of_mulLeftStrictMono (M) [Mul M] [PartialOrder M] [MulLeftStrictMono M] :
MulLeftMono M := covariantClass_le_of_lt _ _ _
@[to_additive]
theorem mulRightMono_of_mulRightStrictMono (M) [Mul M] [PartialOrder M] [MulRightStrictMono M] :
MulRightMono M := covariantClass_le_of_lt _ _ _
theorem contravariant_le_iff_contravariant_lt_and_eq [PartialOrder N] :
Contravariant M N μ (· ≤ ·) ↔ Contravariant M N μ (· < ·) ∧ Contravariant M N μ (· = ·) := by
refine ⟨fun h ↦ ⟨fun a b c bc ↦ ?_, fun a b c bc ↦ ?_⟩, fun h ↦ fun a b c bc ↦ ?_⟩
· exact (h a bc.le).lt_of_ne (by rintro rfl; exact lt_irrefl _ bc)
· exact (h a bc.le).antisymm (h a bc.ge)
· exact bc.lt_or_eq.elim (fun bc ↦ (h.1 a bc).le) (fun bc ↦ (h.2 a bc).le)
theorem contravariant_lt_of_contravariant_le [PartialOrder N] :
Contravariant M N μ (· ≤ ·) → Contravariant M N μ (· < ·) :=
And.left ∘ (contravariant_le_iff_contravariant_lt_and_eq M N μ).mp
theorem covariant_le_iff_contravariant_lt [LinearOrder N] :
Covariant M N μ (· ≤ ·) ↔ Contravariant M N μ (· < ·) :=
⟨fun h _ _ _ bc ↦ not_le.mp fun k ↦ bc.not_le (h _ k),
fun h _ _ _ bc ↦ not_lt.mp fun k ↦ bc.not_lt (h _ k)⟩
theorem covariant_lt_iff_contravariant_le [LinearOrder N] :
Covariant M N μ (· < ·) ↔ Contravariant M N μ (· ≤ ·) :=
⟨fun h _ _ _ bc ↦ not_lt.mp fun k ↦ bc.not_lt (h _ k),
fun h _ _ _ bc ↦ not_le.mp fun k ↦ bc.not_le (h _ k)⟩
variable (mu : N → N → N)
theorem covariant_flip_iff [h : Std.Commutative mu] :
Covariant N N (flip mu) r ↔ Covariant N N mu r := by unfold flip; simp_rw [h.comm]
theorem contravariant_flip_iff [h : Std.Commutative mu] :
Contravariant N N (flip mu) r ↔ Contravariant N N mu r := by unfold flip; simp_rw [h.comm]
instance contravariant_lt_of_covariant_le [LinearOrder N]
[CovariantClass N N mu (· ≤ ·)] : ContravariantClass N N mu (· < ·) where
elim := (covariant_le_iff_contravariant_lt N N mu).mp CovariantClass.elim
@[to_additive]
theorem mulLeftReflectLT_of_mulLeftMono [Mul N] [LinearOrder N] [MulLeftMono N] :
MulLeftReflectLT N :=
inferInstance
@[to_additive]
theorem mulRightReflectLT_of_mulRightMono [Mul N] [LinearOrder N] [MulRightMono N] :
MulRightReflectLT N :=
inferInstance
instance covariant_lt_of_contravariant_le [LinearOrder N]
[ContravariantClass N N mu (· ≤ ·)] : CovariantClass N N mu (· < ·) where
elim := (covariant_lt_iff_contravariant_le N N mu).mpr ContravariantClass.elim
@[to_additive]
theorem mulLeftStrictMono_of_mulLeftReflectLE [Mul N] [LinearOrder N] [MulLeftReflectLE N] :
MulLeftStrictMono N :=
inferInstance
@[to_additive]
theorem mulRightStrictMono_of_mulRightReflectLE [Mul N] [LinearOrder N] [MulRightReflectLE N] :
MulRightStrictMono N :=
inferInstance
@[to_additive]
instance covariant_swap_mul_of_covariant_mul [CommSemigroup N]
[CovariantClass N N (· * ·) r] : CovariantClass N N (swap (· * ·)) r where
elim := (covariant_flip_iff N r (· * ·)).mpr CovariantClass.elim
@[to_additive]
theorem mulRightMono_of_mulLeftMono [CommSemigroup N] [LE N] [MulLeftMono N] :
MulRightMono N :=
inferInstance
@[to_additive]
theorem mulRightStrictMono_of_mulLeftStrictMono [CommSemigroup N] [LT N] [MulLeftStrictMono N] :
MulRightStrictMono N :=
inferInstance
@[to_additive]
instance contravariant_swap_mul_of_contravariant_mul [CommSemigroup N]
[ContravariantClass N N (· * ·) r] : ContravariantClass N N (swap (· * ·)) r where
elim := (contravariant_flip_iff N r (· * ·)).mpr ContravariantClass.elim
@[to_additive]
theorem mulRightReflectLE_of_mulLeftReflectLE [CommSemigroup N] [LE N] [MulLeftReflectLE N] :
MulRightReflectLE N :=
inferInstance
@[to_additive]
theorem mulRightReflectLT_of_mulLeftReflectLT [CommSemigroup N] [LT N] [MulLeftReflectLT N] :
MulRightReflectLT N :=
inferInstance
theorem covariant_lt_of_covariant_le_of_contravariant_eq [ContravariantClass M N μ (· = ·)]
[PartialOrder N] [CovariantClass M N μ (· ≤ ·)] : CovariantClass M N μ (· < ·) where
elim a _ _ bc := (CovariantClass.elim a bc.le).lt_of_ne (bc.ne ∘ ContravariantClass.elim _)
theorem contravariant_le_of_contravariant_eq_and_lt [PartialOrder N]
[ContravariantClass M N μ (· = ·)] [ContravariantClass M N μ (· < ·)] :
ContravariantClass M N μ (· ≤ ·) where
elim := (contravariant_le_iff_contravariant_lt_and_eq M N μ).mpr
⟨ContravariantClass.elim, ContravariantClass.elim⟩
/- TODO:
redefine `IsLeftCancel N mu` as abbrev of `ContravariantClass N N mu (· = ·)`,
redefine `IsRightCancel N mu` as abbrev of `ContravariantClass N N (flip mu) (· = ·)`,
redefine `IsLeftCancelMul` as abbrev of `IsLeftCancel`,
then the following four instances (actually eight) can be removed in favor of the above two. -/
@[to_additive]
instance IsLeftCancelMul.covariant_mul_lt_of_covariant_mul_le [Mul N] [IsLeftCancelMul N]
[PartialOrder N] [CovariantClass N N (· * ·) (· ≤ ·)] :
CovariantClass N N (· * ·) (· < ·) where
elim a _ _ bc := (CovariantClass.elim a bc.le).lt_of_ne ((mul_ne_mul_right a).mpr bc.ne)
@[to_additive]
instance IsRightCancelMul.covariant_swap_mul_lt_of_covariant_swap_mul_le
[Mul N] [IsRightCancelMul N] [PartialOrder N] [CovariantClass N N (swap (· * ·)) (· ≤ ·)] :
CovariantClass N N (swap (· * ·)) (· < ·) where
elim a _ _ bc := (CovariantClass.elim a bc.le).lt_of_ne ((mul_ne_mul_left a).mpr bc.ne)
@[to_additive]
instance IsLeftCancelMul.contravariant_mul_le_of_contravariant_mul_lt [Mul N] [IsLeftCancelMul N]
[PartialOrder N] [ContravariantClass N N (· * ·) (· < ·)] :
ContravariantClass N N (· * ·) (· ≤ ·) where
elim := (contravariant_le_iff_contravariant_lt_and_eq N N _).mpr
⟨ContravariantClass.elim, fun _ ↦ mul_left_cancel⟩
@[to_additive]
instance IsRightCancelMul.contravariant_swap_mul_le_of_contravariant_swap_mul_lt
[Mul N] [IsRightCancelMul N] [PartialOrder N] [ContravariantClass N N (swap (· * ·)) (· < ·)] :
ContravariantClass N N (swap (· * ·)) (· ≤ ·) where
elim := (contravariant_le_iff_contravariant_lt_and_eq N N _).mpr
⟨ContravariantClass.elim, fun _ ↦ mul_right_cancel⟩
end Variants