module Rings.Macro where

import           Types

import           Macro.Math
import           Macro.MetaMacro
import           Macro.Tuple

import           NumberTheory.Macro

-- * Rings

-- | Ring
rng :: Note -- ^ Set
    -> Note -- ^ Additive operation
    -> Note -- ^ Multiplicative operation
    -> Note
rng = triple

-- | Concrete ring set
rngs_ :: Note
rngs_ = "R"

-- | Concrete ring additive operation
rngaop_ :: Note
rngaop_ = "+"

-- | Infix version of the above
(.+) :: Note -> Note -> Note
(.+) = binop rngaop_

-- | Concrete ring multiplicative operation
rngmop_ :: Note
rngmop_ = "*"

-- | Infix version of the above
(.*) :: Note -> Note -> Note
(.*) = binop rngmop_

-- | Concrete ring
rng_ :: Note
rng_ = rng rngs_ rngaop_ rngmop_

-- | Ring Neutral
rnt_ :: Note
rnt_ = "e"

-- | Ring Identity
rid_ :: Note
rid_ = "i"

-- | Inverse element (for the multiplicative operation) in a ring
rinv :: Note -> Note
rinv = (^ "-1")

-- | Inverse element (for the additive operation) in a ring
rmin :: Note -> Note
rmin = ("-" <>)

-- | Inverse element in a given ring
rinvm :: Note -> Note -> Note
rinvm r n = "" !: r <> n ^ "-1"

-- | Integer ring modulo n
intring :: Note -> Note
intring n = rng (intmod n) ("" + "") cdot_

 * Rings
 | Ring
 ^ Set
 ^ Additive operation
 ^ Multiplicative operation
 | Concrete ring set
 | Concrete ring additive operation
 | Infix version of the above
 | Concrete ring multiplicative operation
 | Infix version of the above
 | Concrete ring
 | Ring Neutral
 | Ring Identity
 | Inverse element (for the multiplicative operation) in a ring
 | Inverse element (for the additive operation) in a ring
 | Inverse element in a given ring
 | Integer ring modulo n
module Rings.Macro where

import           Types

import           Macro.Math
import           Macro.MetaMacro
import           Macro.Tuple

import           NumberTheory.Macro


    -> Note
rng = triple

rngs_ :: Note
rngs_ = "R"

rngaop_ :: Note
rngaop_ = "+"

(.+) :: Note -> Note -> Note
(.+) = binop rngaop_

rngmop_ :: Note
rngmop_ = "*"

(.*) :: Note -> Note -> Note
(.*) = binop rngmop_

rng_ :: Note
rng_ = rng rngs_ rngaop_ rngmop_

rnt_ :: Note
rnt_ = "e"

rid_ :: Note
rid_ = "i"

rinv :: Note -> Note
rinv = (^ "-1")

rmin :: Note -> Note
rmin = ("-" <>)

rinvm :: Note -> Note -> Note
rinvm r n = "" !: r <> n ^ "-1"

intring :: Note -> Note
intring n = rng (intmod n) ("" + "") cdot_
