module Algebra.Ring.Reasoning {β„“} (R : Ring β„“) where

Reasoning combinators for ringsπŸ”—

*-zerol : 0r * x ≑ 0r
*-zerol {x} =
  0r * x                       β‰‘βŸ¨ a.introl a.inversel βŸ©β‰‘
  (- 0r * x) + 0r * x + 0r * x β‰‘βŸ¨ a.pullr (sym *-distribr) βŸ©β‰‘
  (- 0r * x) + (0r + 0r) * x   β‰‘βŸ¨ apβ‚‚ _+_ refl (ap (_* x) a.idl) βŸ©β‰‘
  (- 0r * x) + 0r * x          β‰‘βŸ¨ a.inversel βŸ©β‰‘
  0r                           ∎

*-zeror : x * 0r ≑ 0r
*-zeror {x} =
  x * 0r                     β‰‘βŸ¨ a.intror a.inverser βŸ©β‰‘
  x * 0r + (x * 0r - x * 0r) β‰‘βŸ¨ a.pulll (sym *-distribl) βŸ©β‰‘
  x * (0r + 0r) - x * 0r     β‰‘βŸ¨ apβ‚‚ _-_ (ap (x *_) a.idl) refl βŸ©β‰‘
  x * 0r - x * 0r            β‰‘βŸ¨ a.inverser βŸ©β‰‘
  0r                         ∎

*-negatel : (- x) * y ≑ - (x * y)
*-negatel {x} {y} = monoid-inverse-unique a.has-is-monoid (x * y) ((- x) * y) (- (x * y))
  (sym *-distribr Β·Β· ap (_* y) a.inversel Β·Β· *-zerol)
  a.inverser

*-negater : x * (- y) ≑ - (x * y)
*-negater {x} {y} = monoid-inverse-unique a.has-is-monoid (x * y) (x * (- y)) (- (x * y))
  (sym *-distribl Β·Β· ap (x *_) a.inversel Β·Β· *-zeror)
  a.inverser