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
Additive identity of this ring.
Multiplicative identity of this ring.
Add two ring elements; exact instances obey ring laws and IEEE instances retain host rounding.
Multiply two ring elements using the instance arithmetic.
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
| Ring Rational Source # | |
| Ring Exact Source # | |
| Ring Integer Source # | |
| Ring Double Source # | |
| Ring Float Source # | |
| Ring (Complex Double) Source # | |
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.
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
| Scalar Rational Source # | |
Defined in HMath.API.Algebra Methods conjugateScalar :: Rational -> Rational Source # | |
| Scalar Exact Source # | |
Defined in HMath.API.Algebra Methods conjugateScalar :: Exact -> Exact Source # | |
| Scalar Integer Source # | |
Defined in HMath.API.Algebra Methods conjugateScalar :: Integer -> Integer Source # | |
| Scalar Double Source # | |
Defined in HMath.API.Algebra Methods conjugateScalar :: Double -> Double Source # | |
| Scalar Float Source # | |
Defined in HMath.API.Algebra Methods conjugateScalar :: Float -> Float Source # | |
| Scalar (Complex Double) Source # | |
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
| FloatingPoint Double Source # | |
Defined in HMath.API.Algebra | |
| FloatingPoint Float Source # | |
Defined in HMath.API.Algebra | |
| FloatingPoint (Complex Double) Source # | |
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.
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
| MatrixLike Matrix Source # | |
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
| TensorLike Tensor Source # | |
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
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
| Differentiable (Dual a) Source # | |||||
Defined in HMath.API.Algebra Associated Types
Methods differential :: Dual a -> Differential (Dual a) Source # | |||||
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
An example user-definable domain, exact rationals with the explicit algebra contracts. It deliberately does not need a Num or RealFloat instance.
Constructors
| Exact | |