Skip to content

HMath.API.Algebra

Module index · Numerical conventions

Description

Small law-oriented numeric interfaces. Ring operations obey the usual associative/distributive laws for exact instances; IEEE instances approximate them and retain ordinary rounding/overflow. Field inversion is checked. Instances are open, so custom exact domains can use the same generic Horner and inner-product algorithms without pretending to be RealFloat.

On this page

API Purpose
Ring Implement zero, one, additive inverse, addition, multiplication and integer embedding.
zero Additive identity of this ring.
one Additive identity of this ring.
plus Additive identity of this ring.
times Additive identity of this ring.
negative Additive identity of this ring.
integer Additive identity of this ring.
Field Ring supporting checked multiplicative inversion.
invert Return multiplicative inverse of a nonzero domain element, or Left MathError for zeroinvalidnonrepresentable inverse.
Scalar Ring with conjugation,used by Hermitian inner-product algorithms.
conjugateScalar Return scalar conjugate; real/exact instances use identity and complex instances conjugate imaginary components.
FloatingPoint Scalar domain exposing precision epsilon and finite-value classification,including complex component checks.
machineEpsilon Given a type proxy, return floating precision epsilon as Double (2^-52 for Double,2^-23 for Float).
finiteScalar Given a type proxy, return floating precision epsilon as Double (2^-52 for Double,2^-23 for Float).
Numeric A numeric domain's conversion from a rational may fail, for example when an exact ring cannot represent a non-integral value.
rational Convert exact Rational into the domain, returning Left MathError if it cannot be represented under the instance contract.
MatrixLike Container interface for matrix dimensions,row-major elements,and checked construction.
matrixDimensions Return logical (rows,columns) of a matrix-like container.
matrixElements Return logical (rows,columns) of a matrix-like container.
matrixConstruct Return logical (rows,columns) of a matrix-like container.
TensorLike Container interface for tensor dimensions,row-major logical elements,and checked construction.
tensorDimensions Return tensor-like dimensions in axis order; [] denotes scalar.
tensorElements Return tensor-like dimensions in axis order; [] denotes scalar.
tensorConstruct Return tensor-like dimensions in axis order; [] denotes scalar.
VectorSpace Container interface for checked shape-compatible addition and scalar multiplication.
vectorPlus Add identically shaped vector-space values, returning checked dimension errors on mismatch.
vectorScale Add identically shaped vector-space values, returning checked dimension errors on mismatch.
Differentiable Differential extraction reuses the existing nested forward-mode Dual type.
Differential Differential extraction reuses the existing nested forward-mode Dual type.
differential Extract associated differential; the Dual instance returns its tangent component.
horner Coefficients are highest degree first; an empty polynomial is zero.
innerProduct Return sum(conjugate a[i] * b[i]) using the Scalar and Ring operations.
Exact An example user-definable domain, exact rationals with the explicit algebra contracts.
Exact Declaration and type contract below.
getExact Extract the exact Rational stored in the example Exact algebra domain.

Documentation

Ring

class Eq a => Ring a where Source #

Implement zero, one, additive inverse, addition, multiplication and integer embedding. No ordering or approximate division is imposed on exact rings.

Methods

zero :: a Source #

Additive identity of this ring.

one :: a Source #

Multiplicative identity of this ring.

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

Add two ring elements; exact instances obey ring laws and IEEE instances retain host rounding.

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

Multiply two ring elements using the instance arithmetic.

negative :: a -> a Source #

Return the additive inverse of a ring element.

integer :: Integer -> a Source #

Embed an unbounded Integer into the domain; instance representation/rounding rules apply.

Instances

Instances details
Ring Rational Source # 
Instance details

Defined in HMath.API.Algebra

Ring Exact Source # 
Instance details

Defined in HMath.API.Algebra

Ring Integer Source # 
Instance details

Defined in HMath.API.Algebra

Ring Double Source # 
Instance details

Defined in HMath.API.Algebra

Ring Float Source # 
Instance details

Defined in HMath.API.Algebra

Ring (Complex Double) Source # 
Instance details

Defined in HMath.API.Algebra

Field

class Ring a => Field a where Source #

Ring supporting checked multiplicative inversion. Invalid zero/domain or unrepresentable inverse returns MathError.

Methods

invert :: a -> Either MathError a Source #

Return multiplicative inverse of a nonzero domain element, or Left MathError for zeroinvalidnonrepresentable inverse.

Instances

Instances details
Field Rational Source # 
Instance details

Defined in HMath.API.Algebra

Field Exact Source # 
Instance details

Defined in HMath.API.Algebra

Field Double Source # 
Instance details

Defined in HMath.API.Algebra

Field Float Source # 
Instance details

Defined in HMath.API.Algebra

Field (Complex Double) Source # 
Instance details

Defined in HMath.API.Algebra

Scalar

class Ring a => Scalar a where Source #

Ring with conjugation,used by Hermitian inner-product algorithms.

Methods

conjugateScalar :: a -> a Source #

Return scalar conjugate; real/exact instances use identity and complex instances conjugate imaginary components.

Instances

Instances details
Scalar Rational Source # 
Instance details

Defined in HMath.API.Algebra

Scalar Exact Source # 
Instance details

Defined in HMath.API.Algebra

Scalar Integer Source # 
Instance details

Defined in HMath.API.Algebra

Scalar Double Source # 
Instance details

Defined in HMath.API.Algebra

Scalar Float Source # 
Instance details

Defined in HMath.API.Algebra

Scalar (Complex Double) Source # 
Instance details

Defined in HMath.API.Algebra

FloatingPoint

class Scalar a => FloatingPoint a where Source #

Scalar domain exposing precision epsilon and finite-value classification,including complex component checks.

Methods

machineEpsilon :: proxy a -> Double Source #

Given a type proxy, return floating precision epsilon as Double (2^-52 for Double,2^-23 for Float).

finiteScalar :: a -> Bool Source #

Test whether all real/complex components are finite for this instance.

Instances

Instances details
FloatingPoint Double Source # 
Instance details

Defined in HMath.API.Algebra

FloatingPoint Float Source # 
Instance details

Defined in HMath.API.Algebra

FloatingPoint (Complex Double) Source # 
Instance details

Defined in HMath.API.Algebra

Numeric

class Ring a => Numeric a where Source #

A numeric domain's conversion from a rational may fail, for example when an exact ring cannot represent a non-integral value.

Methods

rational :: Rational -> Either MathError a Source #

Convert exact Rational into the domain, returning Left MathError if it cannot be represented under the instance contract.

Instances

Instances details
Numeric Rational Source # 
Instance details

Defined in HMath.API.Algebra

Numeric Exact Source # 
Instance details

Defined in HMath.API.Algebra

Numeric Integer Source # 
Instance details

Defined in HMath.API.Algebra

Numeric Double Source # 
Instance details

Defined in HMath.API.Algebra

Numeric Float Source # 
Instance details

Defined in HMath.API.Algebra

Numeric (Complex Double) Source # 
Instance details

Defined in HMath.API.Algebra

MatrixLike

class MatrixLike (m :: Type -> Type) where Source #

Container interface for matrix dimensions,row-major elements,and checked construction.

Methods

matrixDimensions :: m a -> (Int, Int) Source #

Return logical (rows,columns) of a matrix-like container.

matrixElements :: m a -> [a] Source #

Return matrix elements in logical row-major order.

matrixConstruct :: Int -> Int -> [a] -> Either MathError (m a) Source #

Given rows,columns,flat row-major elements, construct a matrix-like value or return checked shape/count failure.

Instances

Instances details
MatrixLike Matrix Source # 
Instance details

Defined in HMath.API.Algebra

TensorLike

class TensorLike (t :: Type -> Type) where Source #

Container interface for tensor dimensions,row-major logical elements,and checked construction.

Methods

tensorDimensions :: t a -> [Int] Source #

Return tensor-like dimensions in axis order; [] denotes scalar.

tensorElements :: t a -> [a] Source #

Return tensor-like elements in logical row-major coordinate order.

tensorConstruct :: [Int] -> [a] -> Either MathError (t a) Source #

Given dimensions then flat values, construct a tensor-like value or return shape/count failure.

Instances

Instances details
TensorLike Tensor Source # 
Instance details

Defined in HMath.API.Algebra

VectorSpace

class VectorSpace (v :: Type -> Type) where Source #

Container interface for checked shape-compatible addition and scalar multiplication.

Methods

vectorPlus :: Num a => v a -> v a -> Either MathError (v a) Source #

Add identically shaped vector-space values, returning checked dimension errors on mismatch.

vectorScale :: Num a => a -> v a -> v a Source #

Given scalar then vector-space value, return its coordinatewise scalar multiple.

Instances

Instances details
VectorSpace Matrix Source # 
Instance details

Defined in HMath.API.Algebra

Methods

vectorPlus :: Num a => Matrix a -> Matrix a -> Either MathError (Matrix a) Source #

vectorScale :: Num a => a -> Matrix a -> Matrix a Source #

VectorSpace Vector Source # 
Instance details

Defined in HMath.API.Algebra

Methods

vectorPlus :: Num a => Vector a -> Vector a -> Either MathError (Vector a) Source #

vectorScale :: Num a => a -> Vector a -> Vector a Source #

Differentiable

class Differentiable a where Source #

Differential extraction reuses the existing nested forward-mode Dual type.

Associated Types

type Differential a Source #

Methods

differential :: a -> Differential a Source #

Extract associated differential; the Dual instance returns its tangent component.

Instances

Instances details
Differentiable (Dual a) Source # 
Instance details

Defined in HMath.API.Algebra

Associated Types

type Differential (Dual a) 
Instance details

Defined in HMath.API.Algebra

type Differential (Dual a) = a

horner

horner :: Ring a => [a] -> a -> a Source #

Coefficients are highest degree first; an empty polynomial is zero.

innerProduct

innerProduct :: Scalar a => [a] -> [a] -> Either MathError a Source #

Return sum(conjugate a[i] * b[i]) using the Scalar and Ring operations. Equal list lengths are required; mismatch returns VectorLengthMismatch. Empty lists give the ring zero; instance arithmetic controls precision/overflow.

Exact

newtype Exact Source #

An example user-definable domain, exact rationals with the explicit algebra contracts. It deliberately does not need a Num or RealFloat instance.

Constructors

Exact 

Fields

  • getExact :: Rational

    Extract the exact Rational stored in the example Exact algebra domain.

Instances

Instances details
Show Exact Source # 
Instance details

Defined in HMath.API.Algebra

Methods

showsPrec :: Int -> Exact -> ShowS #

show :: Exact -> String #

showList :: [Exact] -> ShowS #

Eq Exact Source # 
Instance details

Defined in HMath.API.Algebra

Methods

(==) :: Exact -> Exact -> Bool #

(/=) :: Exact -> Exact -> Bool #

Ord Exact Source # 
Instance details

Defined in HMath.API.Algebra

Methods

compare :: Exact -> Exact -> Ordering #

(<) :: Exact -> Exact -> Bool #

(<=) :: Exact -> Exact -> Bool #

(>) :: Exact -> Exact -> Bool #

(>=) :: Exact -> Exact -> Bool #

max :: Exact -> Exact -> Exact #

min :: Exact -> Exact -> Exact #

Field Exact Source # 
Instance details

Defined in HMath.API.Algebra

Numeric Exact Source # 
Instance details

Defined in HMath.API.Algebra

Ring Exact Source # 
Instance details

Defined in HMath.API.Algebra

Scalar Exact Source # 
Instance details

Defined in HMath.API.Algebra