Add `AlmostRightCancellative` proof to ` IsCancellativeCommutativeSemiring`
mechvel opened this issue · comments
In lib-2.0, the module Algebra.Structures
has
record IsCancellativeCommutativeSemiring (+ * : Op₂ A) (0# 1# : A) : ...
where
field
isCommutativeSemiring : IsCommutativeSemiring + * 0# 1#
*-cancelˡ-nonZero : AlmostLeftCancellative 0# *
Due to isCommutativeSemiring
axiom, the users would like to also use the right-cancellation.
So, it is better to add there in-place a proof for
*-cancelʳ-nonZero : AlmostRightCancellative _≈_ 0# _*_
The implementation can be
*-cancelʳ-nonZero = *Cancellativeˡ-nz⇒*Cancellativeʳ-nz *-cancelˡ-nonZero
, where *Cancellativeˡ-nz⇒*Cancellativeʳ-nz
can be proved under the condition of CommutativeSemiring
:
*Cancellativeˡ-nz⇒*Cancellativeʳ-nz : AlmostLeftCancellative _≈_ 0# _*_ →
AlmostRightCancellative _≈_ 0# _*_
*Cancellativeˡ-nz⇒*Cancellativeʳ-nz
lCanc x y z x≉0 yx≈zx = lCanc x y z x≉0 xy≈xz
where
xy≈xz = begin⟨ setoid ⟩ x * y ≈⟨ *-comm x y ⟩
y * x ≈⟨ yx≈zx ⟩
z * x ≈⟨ *-comm z x ⟩
x * z
∎
Alternatively, the body of this proof can be set directly, because it uses only *-comm
,
which can be extracted from the axiom isCommutativeSemiring
.
Well, may be it is in /Algebra.Consequences...
.
But as the user imports from CancellativeCommutativeSemiring the law *-cancelˡ-nonZero
,
it is also natural to also import *-cancelʳ-nonZero
from this very place.
Generally, it is difficult to find that there are also Consequences
and to set the import from there separately.
I wonder about this. May be some items in Consequences need to be imported and used in Structures , to enable the users to import more items from Structures and Bundles.
In this particular case, it can be imported from Consequences to CancellativeCommutativeSemiring , but if this makes a loop, then it can be set in-place.
There are too many different places to import items from.
I agree, we should have the right version exported by the IsCancellativeCommutativeSemiring
structure.