Module docstring
{"# 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:
CovariantClassmodels the implicationa ≤ b → c * a ≤ c * b(multiplication is monotone),ContravariantClassmodels the implicationa * 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.
"}