numhask
Safe HaskellNone
LanguageGHC2024

NumHask.Free.Ring

Description

Free ring — the initial encoding of Ring.

Synopsis

Documentation

data Ring a Source #

Free ring over a carrier type.

The initial encoding of Ring. Combines additive and multiplicative structure with the antipode. Distributivity is enforced by eval, not by the term structure — Times over Plus is not reduced automatically. Use eval to project into a lawful ring.

Constructors

Zero 
One 
Plus (Ring a) (Ring a) 
Negate (Ring a) 
Times (Ring a) (Ring a) 
Embed a 

Instances

Instances details
Eq a => Eq (Ring a) Source # 
Instance details

Defined in NumHask.Free.Ring

Methods

(==) :: Ring a -> Ring a -> Bool #

(/=) :: Ring a -> Ring a -> Bool #

Show a => Show (Ring a) Source # 
Instance details

Defined in NumHask.Free.Ring

Methods

showsPrec :: Int -> Ring a -> ShowS #

show :: Ring a -> String #

showList :: [Ring a] -> ShowS #

zero :: Ring a Source #

Additive identity.

one :: Ring a Source #

Multiplicative identity.

plus :: Ring a -> Ring a -> Ring a Source #

Addition with identity absorption.

negate :: Ring a -> Ring a Source #

Antipode with involution cancellation.

minus :: Ring a -> Ring a -> Ring a Source #

Subtraction as addition of the antipode.

times :: Ring a -> Ring a -> Ring a Source #

Multiplication with identity absorption.

embed :: a -> Ring a Source #

Embed a carrier value as an atomic generator.

lift :: (Eq a, Ring a) => a -> Ring a Source #

Lift a carrier value, absorbing additive and multiplicative identities.

>>> lift 0
Zero
>>> lift 1
One

normalize :: (Eq a, Ring a) => Ring a -> Ring a Source #

Normalize a term with respect to ring laws: identity absorption and antipode involution. Distributivity is left to eval.

>>> normalize (embed 0)
Zero

eval :: Ring a => Ring a -> a Source #

Evaluate a term into any Ring.

This is the unique homomorphism out of the free ring.

foldRing :: b -> b -> (b -> b -> b) -> (b -> b) -> (b -> b -> b) -> (a -> b) -> Ring a -> b Source #

Universal property: fold with a target ring.

fromAdditive :: Additive a -> Ring a Source #

Inject an additive term into the free ring.

fromMultiplicative :: Multiplicative a -> Ring a Source #

Inject a multiplicative term into the free ring.

fromSubtractive :: Subtractive a -> Ring a Source #

Inject a subtractive term into the free ring.