module Qtest where 

open import Data.Nat
open import Data.Nat.Properties as Nat
open import Relation.Binary 
open import Quotient
open import Data.Product
open import Relation.Binary.PropositionalEquality hiding ( [_] )
open ≡-Reasoning
open Nat.SemiringSolver

Int : Setoid _ _
Int = record
  { Carrier       =  × 
  ; _≈_           = λ { (x+ , x-) (y+ , y-)  x+ + y-  y+ + x- }
  ; isEquivalence = record
    { refl  = λ {_}  refl
    ; sym   = λ p  sym p
    ; trans = λ { {x+ , x-}{y+ , y-}{z+ , z-} p q 
        cancel-+-left (y- + y+) (begin
          (y- + y+) + (x+ + z-)  ≡⟨ solve 4  y- y+ x+ z-  (y- :+ y+) :+ (x+ :+ z-) :=
                                                             x+ :+ y- :+ (y+ :+ z-))
                                            refl y- y+ x+ z- 
          x+ + y- + (y+ + z-)    ≡⟨ cong₂ _+_ p q 
          y+ + x- + (z+ + y-)    ≡⟨ solve 4  y+ x- z+ y-  y+ :+ x- :+ (z+ :+ y-) :=
                                                             (y- :+ y+) :+ (z+ :+ x-))
                                            refl y+ x- z+ y- 
          (y- + y+) + (z+ + x-)  ) }
    }
  }

 : Set
 = Quotient Int

zeroℤ : 
zeroℤ = [ 0 , 0 ]

open import Algebra
module CS = CommutativeSemiring Nat.commutativeSemiring

minus :    
minus x = rec {A = Int} 
               
               {(x+ , x-)  [ x- , x+ ]}) 
               { {x+ , x-} {y+ , y-} x≈y  [ sym (trans (CS.+-comm y- x+) 
                                                          (trans x≈y 
                                                                 (CS.+-comm y+ x-))) ]-cong})
              x

minus-lem : (x : )  minus (minus x)  x
minus-lem x = elim {A = Int}  x  minus (minus x)  x) 
   { (x+ , x-)  refl})  x≈y  proof-irrelevance _ _) x