Safe Haskell | None |
---|---|
Language | Haskell2010 |
The basic algebraic class structure of a number.
import NumHask.Algebra import Prelude hiding (Integral(..), (*), (**), (+), (-), (/), (^), (^^), abs, acos, acosh, asin, asinh, atan, atan2, atanh, ceiling, cos, cosh, exp, floor, fromInteger, fromIntegral, log, logBase, negate, pi, product, recip, round, sin, sinh, sqrt, sum, tan, tanh, toInteger, fromRational)
- module NumHask.Algebra.Additive
- module NumHask.Algebra.Basis
- module NumHask.Algebra.Distribution
- module NumHask.Algebra.Field
- module NumHask.Algebra.Integral
- module NumHask.Algebra.Magma
- module NumHask.Algebra.Metric
- module NumHask.Algebra.Module
- module NumHask.Algebra.Multiplicative
- module NumHask.Algebra.Rational
- module NumHask.Algebra.Ring
- data Complex a :: * -> * = !a :+ !a
Mapping from Num
Num
is a very old part of haskell, and a lot of different numeric concepts are tossed in there. The closest analogue in numhask is the Ring
class, which combines the classical +
, -
and *
, together with the distribution laws.
No attempt is made, however, to reconstruct the particular combination of laws and classes that represent the old Num
. A rough mapping of Num
to numhask classes follows:
-- | Basic numeric class. class Num a where {-# MINIMAL (+), (*), abs, signum, fromInteger, (negate | (-)) #-} (+), (-), (*) :: a -> a -> a -- | Unary negation. negate :: a -> a
+
is a function of the Additive
class,
-
is a function of the AdditiveGroup
class, and
*
is a function of the Multiplicative
class.
negate
is specifically in the AdditiveInvertible
class. There are many useful constructions between negate and (-), involving cancellative properties.
-- | Absolute value. abs :: a -> a -- | Sign of a number. -- The functions 'abs' and 'signum' should satisfy the law: -- -- > abs x * signum x == x -- -- For real numbers, the 'signum' is either @-1@ (negative), @0@ (zero) -- or @1@ (positive). signum :: a -> a
abs
is a function in the Signed
class. The concept of an absolute value of a number can include situations where the domain and codomain are different, and size
as a function in the Normed
class is supplied for these cases.
sign
replaces signum
, because signum is a heinous name.
-- | Conversion from an 'Integer'. -- An integer literal represents the application of the function -- 'fromInteger' to the appropriate value of type 'Integer', -- so such literals have type @('Num' a) => a@. fromInteger :: Integer -> a
fromInteger
is given its own class FromInteger
module NumHask.Algebra.Additive
module NumHask.Algebra.Basis
module NumHask.Algebra.Distribution
module NumHask.Algebra.Field
module NumHask.Algebra.Integral
module NumHask.Algebra.Magma
module NumHask.Algebra.Metric
module NumHask.Algebra.Module
module NumHask.Algebra.Rational
module NumHask.Algebra.Ring
Complex numbers are an algebraic type.
For a complex number z
,
is a number with the magnitude of abs
zz
,
but oriented in the positive real direction, whereas
has the phase of signum
zz
, but unit magnitude.
The Foldable
and Traversable
instances traverse the real part first.
!a :+ !a infix 6 | forms a complex number from its real and imaginary rectangular components. |