numhask
Safe HaskellNone
LanguageGHC2024

NumHask.Free.Subtractive

Description

Free abelian group — the initial encoding of Subtractive.

Synopsis

Documentation

data Subtractive a Source #

Free abelian group over a carrier type.

The initial encoding of Subtractive. Extends the free commutative monoid with an antipode.

Constructors

Zero 
Plus (Subtractive a) (Subtractive a) 
Negate (Subtractive a) 
Embed a 

Instances

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

Defined in NumHask.Free.Subtractive

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

Defined in NumHask.Free.Subtractive

zero :: Subtractive a Source #

Additive identity.

plus :: Subtractive a -> Subtractive a -> Subtractive a Source #

Addition with identity absorption.

negate :: Subtractive a -> Subtractive a Source #

Antipode with involution cancellation.

negate zero = zero
negate (negate a) = a

minus :: Subtractive a -> Subtractive a -> Subtractive a Source #

Subtraction as addition of the antipode.

embed :: a -> Subtractive a Source #

Embed a carrier value as an atomic generator.

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

Lift a carrier value, absorbing the additive identity.

>>> lift 0
Zero

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

Normalize a term with respect to abelian-group laws: identity absorption, antipode involution, and additive-inverse cancellation.

>>> normalize (plus (embed 3) (negate (embed 3)))
Zero

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

Evaluate a term into any Subtractive.

This is the unique homomorphism out of the free abelian group.

foldSubtractive :: b -> (b -> b -> b) -> (b -> b) -> (a -> b) -> Subtractive a -> b Source #

Universal property: fold with a target abelian group.