| Safe Haskell | None |
|---|---|
| Language | GHC2024 |
NumHask
Description
Numeric classes.
Synopsis
- class Additive a where
- sum :: (Additive a, Foldable f) => f a -> a
- accsum :: (Additive a, Traversable f) => f a -> f a
- class Additive a => Subtractive a where
- class Multiplicative a where
- product :: (Multiplicative a, Foldable f) => f a -> a
- accproduct :: (Multiplicative a, Traversable f) => f a -> f a
- class Multiplicative a => Divisive a where
- type Distributive a = (Additive a, Multiplicative a)
- type Ring a = (Distributive a, Subtractive a)
- class Distributive a => StarSemiring a where
- class (StarSemiring a, Idempotent a) => KleeneAlgebra a
- class Distributive a => InvolutiveRing a where
- adj :: a -> a
- two :: (Multiplicative a, Additive a) => a
- newtype MinPlus a = MinPlus {
- getMinPlus :: a
- newtype Warshall = Warshall Bool
- type Field a = (Ring a, Divisive a)
- class Field a => ExpField a where
- class SemiField a => QuotientField a where
- data Quotient w a = Quotient {}
- toQuotient :: QuotientField a => a -> Quotient (Whole a) a
- fromQuotient :: QuotientField a => Quotient (Whole a) a -> a
- mulQuotient :: QuotientField a => Quotient (Whole a) a -> Quotient (Whole a) a -> Quotient (Whole a) a
- class Field a => TrigField a where
- infinity :: SemiField a => a
- negInfinity :: Field a => a
- nan :: SemiField a => a
- half :: (Additive a, Divisive a) => a
- modF :: (Eq a, Field a, FromIntegral a (Whole a), QuotientField a) => a -> a -> a
- divF :: (Eq a, Field a, FromIntegral a (Whole a), QuotientField a) => a -> a -> a
- divModF :: (Eq a, Field a, FromIntegral a (Whole a), QuotientField a) => a -> a -> DivMod a
- class Eq a => JoinSemiLattice a where
- (\/) :: a -> a -> a
- joinLeq :: JoinSemiLattice a => a -> a -> Bool
- (<\) :: JoinSemiLattice a => a -> a -> Bool
- class Eq a => MeetSemiLattice a where
- (/\) :: a -> a -> a
- meetLeq :: MeetSemiLattice a => a -> a -> Bool
- (</) :: MeetSemiLattice a => a -> a -> Bool
- class JoinSemiLattice a => LowerBounded a where
- bottom :: a
- class MeetSemiLattice a => UpperBounded a where
- top :: a
- class LowerBounded a => CompleteJoinSemiLattice a where
- class (CompleteJoinSemiLattice a, Multiplicative a) => Quantale a
- class Quantale a => Residuated a where
- class Quantale a => StarAutonomous a where
- class Copyable a where
- class Mergeable a where
- class Additive (AdditiveScalar m) => AdditiveAction m where
- type AdditiveScalar m
- (|+) :: m -> AdditiveScalar m -> m
- (+|) :: AdditiveAction m => AdditiveScalar m -> m -> m
- class (AdditiveAction m, Subtractive (AdditiveScalar m)) => SubtractiveAction m where
- (|-) :: m -> AdditiveScalar m -> m
- (-|) :: (AdditiveAction m, Subtractive m) => AdditiveScalar m -> m -> m
- class Multiplicative (Scalar m) => MultiplicativeAction m where
- (*|) :: MultiplicativeAction m => Scalar m -> m -> m
- class (Divisive (Scalar m), MultiplicativeAction m) => DivisiveAction m where
- (/|) :: (MultiplicativeAction m, Divisive m) => Scalar m -> m -> m
- type Module m = (Distributive (Scalar m), MultiplicativeAction m)
- newtype TrivialAction a = TrivialAction {
- getTrivialAction :: a
- class Distributive (Mag a) => Basis a where
- type Absolute a = (Basis a, Mag a ~ a)
- type Sign a = (Basis a, Base a ~ a)
- type EndoBased a = (Basis a, Mag a ~ a, Base a ~ a)
- abs :: Absolute a => a -> a
- signum :: Sign a => a -> a
- distance :: (Basis a, Subtractive a) => a -> a -> Mag a
- class (Distributive coord, Distributive (Dir coord)) => Direction coord where
- data Polar a = Polar {}
- polar :: (Dir (Base a) ~ Mag a, Basis a, Direction (Base a)) => a -> Polar (Mag a)
- coord :: (Scalar m ~ Dir m, MultiplicativeAction m, Direction m) => Polar (Scalar m) -> m
- class (Eq a, Additive a) => Epsilon a where
- epsilon :: a
- aboutEqual :: (Epsilon a, Lattice a, Subtractive a) => a -> a -> Bool
- nearZero :: (Epsilon a, Lattice a, Subtractive a) => a -> Bool
- (~=) :: (Epsilon a, Lattice a, Subtractive a) => a -> a -> Bool
- newtype Complex a = Complex {
- complexPair :: (a, a)
- (+:) :: a -> a -> Complex a
- realPart :: Complex a -> a
- imagPart :: Complex a -> a
- normSquared :: Distributive a => Complex a -> a
- class Distributive a => Integral a where
- data DivMod a = DivMod {}
- data QuotRem a = QuotRem {}
- class ToIntegral a b where
- toIntegral :: a -> b
- type ToInt a = ToIntegral a Int
- class FromIntegral a b where
- fromIntegral :: b -> a
- class FromInteger a where
- fromInteger :: Integer -> a
- type FromInt a = FromIntegral a Int
- even :: (Eq a, Integral a) => a -> Bool
- odd :: (Eq a, Integral a) => a -> Bool
- (^^) :: (Ord b, Divisive a, Subtractive b, Integral b) => a -> b -> a
- (^) :: Divisive a => a -> Int -> a
- (^+) :: Multiplicative a => a -> Natural -> a
- data Ratio a = !a :% !a
- type Rational = Ratio Integer
- class ToRatio a b where
- class FromRatio a b where
- class FromRational a where
- fromRational :: Rational -> a
- reduce :: (Ord a, Subtractive a, EndoBased a, Integral a) => a -> a -> Ratio a
- gcd :: (Eq a, EndoBased a, Integral a) => a -> a -> a
- newtype NumHaskException = NumHaskException {}
- throw :: forall a e. (HasCallStack, Exception e) => e -> a
Usage
>>>:m -Prelude>>>:set -XRebindableSyntax>>>import NumHask.Prelude>>>1+12
Overview
numhask is largely a set of classes that can replace the Num class and it's descendents.
Principles that have guided design include:
- balanced class density. The numeric hierarchy begins with addition and multiplication, choosing not to build from a Magma base. Whilst not being as principled as other approaches, this circumvents the instance explosion problems of Haskell whilst maintaining clarity of class purpose.
- operator-first. In all cases, a class exists to define useful operators.
Major class groupings, such as
Distributive,RingandFieldare type synonyms. - lawful. All classes have laws associated with them that serve to relate class operators together in a meaningful way.
- low-impact. The library attempts to fit in with the rest of the Haskell ecosystem.
It provides instances for common numbers:
Int,Integer,Double,Float,Natural, and the Word classes. It avoids name (or idea) clashes with other popular libraries and adopts conventions in the current prelude where they make sense. - proof-of-concept. The library may be below industrial-strength depending on a definition of this term. At the same time, correspondence around improving the library is most welcome.
The class heirarchy looks somewhat like this:
Prelude Mappings
Num is a very old part of haskell, and is virtually unchanged since its specification in
haskell98.
A deconstruction of Num and mapping to numhask.
-- | Basic numeric class.
class Num a where
{-# MINIMAL (+), (*), abs, signum, fromInteger, (negate | (-)) #-}
(+), (-), (*) :: a -> a -> a
-- | Unary negation.
negate :: a -> a(+) is an operator of the Additive class
(-) & negate are functions in the Subtractive class, and
(*) is an operator of the Multiplicative class.
zero and one are also introduced to the numeric hierarchy.
-- | 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
The concept of an absolute value and the sign of a number can include situations where the domain type is different to the absolute and sign codomain types.
A new class, Basis is supplied to handle these situations:
abs and signum are specialisations of these methods.
-- | 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 -> aFromInteger becomes its own class and FromIntegral is introduced to polymorphise the covariant.
Mappings from other areas of prelude include:
IntegralbecomesIntegraland a polymorphicToIntegralis introduced.Fractionalis roughly synonymous toFieldtogether with a polymorphicFromRatio.RealFracbecomesQuotientFieldwith a polymorphicWholetype using Type Families.Floatingis split intoExpFieldandTrigFieldRealFloatis not attempted. Life is too short.- Complex is resupplied in
Complexbut with some functionality deriving viaEuclideanPair. The underlying representation has also been switched to a newtype-wrapped tuple.
In addition to base changes, alternatives to sum and product from Foldable are also supplied.
Extensions
RebindableSyntax is recommended for use with numhask.
As a replacement for the numerical classes, numhask clashes significantly with an
unqualified import of the Prelude. Either numhask modules should be qualified,
or prelude turned off with the NoImplicitPrelude extension, or with RebindableSyntax,
which implies NoImplicitPrelude.
defaulting
Without RebindableSyntax, numeric literals default as follows:
>>>:set -XNoRebindableSyntax>>>:t 11 :: Num a => a
>>>:t 1.01.0 :: Fractional a => a
With RebindableSyntax (which also switches NoImplicitPrelude on) literal numbers change to the numhask types, FromInteger and FromRational:
>>>:set -XRebindableSyntax>>>:t 11 :: FromInteger a => a
>>>:t 1.01.0 :: FromRational a => a
>>>11
>>>1.01.0
RebindableSyntax is a tradeoff, however, and usage comes attached with other non-numeric changes that NumHask.Prelude attempts to counteract.
See haskell2010 Section 4.3.4 for the nuts and bolts to defaulting.
The effect of ExtendedDefaultRules
in ghci or switched on as an extension also need to be understood.
It can lead to unusual interactions with numerics and strange error messages at times because
it adds () and [] to the start of the type defaulting list.
Additive
class Additive a where Source #
or Addition
For practical reasons, we begin the class tree with Additive. Starting with Associative and Unital, or using Semigroup and Monoid from base tends to confuse the interface once you start having to disinguish between (say) monoidal addition and monoidal multiplication.
zero + a == a a + zero == a (a + b) + c == a + (b + c) a + b == b + a
By convention, (+) is regarded as commutative, but this is not universal, and the introduction of another symbol which means non-commutative addition seems a bit dogmatic.
>>>zero + 11
>>>1 + 12
>>>2 + zero == (2 :: Int)True
>>>(1 + 2) + 3 == 1 + (2 + 3)True
>>>2 + 3 == 3 + 2True
Instances
sum :: (Additive a, Foldable f) => f a -> a Source #
Compute the sum of a Foldable.
>>>sum [0..10]55
accsum :: (Additive a, Traversable f) => f a -> f a Source #
Compute the accumulating sum of a Traversable.
>>>accsum [0..10][0,1,3,6,10,15,21,28,36,45,55]
class Additive a => Subtractive a where Source #
or Subtraction
a - a == zero negate a == zero - a negate a + a == zero a + negate a == zero
>>>negate 1-1
>>>1 - 2-1
>>>2 - 2 == (zero :: Int)True
>>>negate 2 == zero - (2 :: Int)True
>>>negate 2 + 2 == (zero :: Int)True
>>>2 + negate 2 == (zero :: Int)True
Instances
Multiplicative
class Multiplicative a where Source #
For practical reasons, we begin the class tree with Additive and Multiplicative. Starting with Associative and Unital, or using Semigroup and Monoid from base tends to confuse the interface once you start having to disinguish between (say) monoidal addition and monoidal multiplication.
one * a == a a * one == a (a * b) * c == a * (b * c)
By convention, (*) is regarded as not necessarily commutative, but this is not universal, and the introduction of another symbol which means commutative multiplication seems a bit dogmatic.
>>>one * 22
>>>2 * 36
>>>2 * one == (2 :: Int)True
>>>(2 * 3) * 4 == 2 * (3 * 4)True
Instances
product :: (Multiplicative a, Foldable f) => f a -> a Source #
Compute the product of a Foldable.
>>>product [1..5]120
accproduct :: (Multiplicative a, Traversable f) => f a -> f a Source #
Compute the accumulating product of a Traversable.
>>>accproduct [1..5][1,2,6,24,120]
class Multiplicative a => Divisive a where Source #
or Division
Though unusual, the term Divisive usefully fits in with the grammer of other classes and avoids name clashes that occur with some popular libraries.
a / a ~= one || a == zero recip a ~= one / a || a == zero recip a * a ~= one || a == zero a * recip a ~= one || a == zero
>>>recip 2.00.5
>>>1 / 20.5
>>>let a = 4.0 in a / a ~= oneTrue
>>>let a = 4.0 in recip a ~= one / aTrue
>>>let a = 4.0 in recip a * a ~= oneTrue
>>>let a = 4.0 in a * recip a ~= oneTrue
Instances
| Divisive Double Source # | |
| Divisive Float Source # | |
| Divisive a => Divisive (TrivialAction a) Source # | |
Defined in NumHask.Algebra.Action Methods recip :: TrivialAction a -> TrivialAction a Source # (/) :: TrivialAction a -> TrivialAction a -> TrivialAction a Source # | |
| Divisive a => Divisive (EuclideanPair a) Source # | |
Defined in NumHask.Algebra.Metric Methods recip :: EuclideanPair a -> EuclideanPair a Source # (/) :: EuclideanPair a -> EuclideanPair a -> EuclideanPair a Source # | |
| (Subtractive a, Divisive a) => Divisive (Complex a) Source # | |
| Divisive a => Divisive (Positive a) Source # | |
| (Ord a, EndoBased a, Integral a, Ring a) => Divisive (Ratio a) Source # | |
| Divisive a => Divisive (Wrapped a) Source # | |
| Divisive b => Divisive (a -> b) Source # | |
Ring
type Distributive a = (Additive a, Multiplicative a) Source #
a * (b + c) == a * b + a * c (a + b) * c == a * c + b * c zero * a == zero a * zero == zero
>>>2 * (3 + 4) == 2 * 3 + 2 * 4True
>>>(2 + 3) * 4 == 2 * 4 + 3 * 4True
>>>zero * 2 == (zero :: Int)True
>>>2 * zero == (zero :: Int)True
The sneaking in of the Absorption laws here glosses over the possibility that the multiplicative zero element does not have to correspond with the additive unital zero.
type Ring a = (Distributive a, Subtractive a) Source #
A Ring is an abelian group under addition (Unital, Associative, Commutative, Invertible) and monoidal under multiplication (Unital, Associative), and where multiplication distributes over addition.
\a -> zero + a == a \a -> a + zero == a \a b c -> (a + b) + c == a + (b + c) \a b -> a + b == b + a \a -> a - a == zero \a -> negate a == zero - a \a -> negate a + a == zero \a -> a + negate a == zero \a -> one * a == a \a -> a * one == a \a b c -> (a * b) * c == a * (b * c) \a b c -> a * (b + c) == a * b + a * c \a b c -> (a + b) * c == a * c + b * c \a -> zero * a == zero \a -> a * zero == zero
class Distributive a => StarSemiring a where Source #
A StarSemiring is a semiring with a unary star operator satisfying the Conway equations:
\a -> star a == one + a * star a -- fixpoint \a b -> star (a * b) == one + a * star (b * a) * b -- product-star (sliding) \a b -> star (a + b) == star (star a * b) * star a -- sum-star (vanishing)
These three equations are the doctestable core; they are exactly the sliding and vanishing axioms of a traced category in semiring clothing.
Instances
| StarSemiring FieldStar Source # | |
| StarSemiring Warshall Source # | Boolean star is constantly true.
|
| StarSemiring Bool Source # | |
| StarSemiring a => StarSemiring (Wrapped a) Source # | |
| StarSemiring (MinPlus Double) Source # | Star is zero in a min-plus semiring: the cheapest repeated traversal is to stay put.
Conway equations for 'MinPlus Double'.
|
| StarSemiring (Viterbi Double) Source # | |
| StarSemiring (StarSemiring a) Source # | |
Defined in NumHask.Free.StarSemiring Methods star :: StarSemiring a -> StarSemiring a Source # plus :: StarSemiring a -> StarSemiring a Source # | |
class (StarSemiring a, Idempotent a) => KleeneAlgebra a Source #
A Kleene Algebra is a Star Semiring with idempotent addition.
Idempotent addition gives a natural order a <= b ⟺ a + b == b. In that order, Kozen's induction laws hold as derived facts:
a * x + x <= x ==> star a * x + x <= x x * a + x <= x ==> x * star a + x <= x
They are stated here as prose rather than class laws because they involve a partial order and Horn clauses, which do not fit the equational/doctest style of the Conway core.
Instances
| KleeneAlgebra Warshall Source # | |
Defined in NumHask.Free.Carriers | |
| KleeneAlgebra Bool Source # | |
Defined in NumHask.Algebra.Ring | |
| KleeneAlgebra (MinPlus Double) Source # | |
Defined in NumHask.Free.Carriers | |
| KleeneAlgebra (Viterbi Double) Source # | |
Defined in NumHask.Free.Carriers | |
class Distributive a => InvolutiveRing a where Source #
Conway equations for Bool.
>>>let a = False; b = True in star (a * b) == one + a * star (b * a) * bTrue
>>>let a = False; b = True in star (a + b) == star (star a * b) * star aTrue
Involutive Ring
adj (a + b) ==> adj a + adj b adj (a * b) ==> adj a * adj b adj one ==> one adj (adj a) ==> a
Note: elements for which adj a == a are called "self-adjoint".
Minimal complete definition
Nothing
Instances
two :: (Multiplicative a, Additive a) => a Source #
Tropical
Tropical (min-plus) semiring for Floyd–Warshall shortest paths.
Addition is min, multiplication is ordinary addition, the additive unit
is positive infinity, and the multiplicative unit is zero.
>>>MinPlus 3 + MinPlus 2 :: MinPlus DoubleMinPlus {getMinPlus = 2.0}
>>>MinPlus 3 * MinPlus 2 :: MinPlus DoubleMinPlus {getMinPlus = 5.0}
Constructors
| MinPlus | |
Fields
| |
Instances
| Eq a => Eq (MinPlus a) Source # | |
| Ord a => Ord (MinPlus a) Source # | |
| Show a => Show (MinPlus a) Source # | |
| Additive (MinPlus Double) Source # | |
| Idempotent (MinPlus Double) Source # | |
Defined in NumHask.Free.Carriers | |
| Magma (MinPlus Double) Source # | |
| CompleteJoinSemiLattice (MinPlus Double) Source # | |
| Ord a => JoinSemiLattice (MinPlus a) Source # | Tropical join-semilattice structure: join is |
| LowerBounded (MinPlus Double) Source # | |
| Multiplicative (MinPlus Double) Source # | |
| Quantale (MinPlus Double) Source # | Tropical (min-plus) quantale: join is minimum, bottom is positive infinity, multiplication is addition. |
Defined in NumHask.Algebra.Quantale | |
| Residuated (MinPlus Double) Source # | Tropical residual is truncated subtraction.
|
| StarAutonomous (MinPlus Double) Source # | Tropical linear negation is additive inverse; |
| KleeneAlgebra (MinPlus Double) Source # | |
Defined in NumHask.Free.Carriers | |
| StarSemiring (MinPlus Double) Source # | Star is zero in a min-plus semiring: the cheapest repeated traversal is to stay put.
Conway equations for 'MinPlus Double'.
|
Boolean semiring for Warshall's transitive closure.
plus is ||, times is &&, star is constantly True.
>>>Warshall True + Warshall FalseWarshall True
Instances
| Eq Warshall Source # | |
| Ord Warshall Source # | |
Defined in NumHask.Free.Carriers | |
| Show Warshall Source # | |
| Additive Warshall Source # | |
| Idempotent Warshall Source # | |
Defined in NumHask.Free.Carriers | |
| Magma Warshall Source # | |
| CompleteJoinSemiLattice Warshall Source # | |
| JoinSemiLattice Warshall Source # | Boolean join-semilattice structure: join is |
| LowerBounded Warshall Source # | |
Defined in NumHask.Free.Carriers | |
| Multiplicative Warshall Source # | |
| Quantale Warshall Source # | Boolean quantale: join is disjunction, multiplication is conjunction. |
Defined in NumHask.Algebra.Quantale | |
| Residuated Warshall Source # | Boolean implication as the residual of conjunction.
|
| StarAutonomous Warshall Source # | Boolean negation as complement; |
| KleeneAlgebra Warshall Source # | |
Defined in NumHask.Free.Carriers | |
| StarSemiring Warshall Source # | Boolean star is constantly true.
|
Field
type Field a = (Ring a, Divisive a) Source #
A Field is a set on which addition, subtraction, multiplication, and division are defined. It is also assumed that multiplication is distributive over addition.
A summary of the rules inherited from super-classes of Field:
zero + a == a a + zero == a ((a + b) + c) (a + (b + c)) a + b == b + a a - a == zero negate a == zero - a negate a + a == zero a + negate a == zero one * a == a a * one == a ((a * b) * c) == (a * (b * c)) (a * (b + c)) == (a * b + a * c) ((a + b) * c) == (a * c + b * c) a * zero == zero zero * a == zero a / a == one || a == zero recip a == one / a || a == zero recip a * a == one || a == zero a * recip a == one || a == zero
class Field a => ExpField a where Source #
A hyperbolic field class
a < zero || (sqrt . (**2)) a == a a < zero || (log . exp) a ~= a b < zero || a <= zero || a == 1 || abs (a ** logBase a b - b) < 10 * epsilon
>>>(sqrt . (**2)) (4.0 :: Double) == 4.0True
>>>(log . exp) (1.0 :: Double) ~= 1.0True
>>>2 ** logBase 2 8 ~= (8 :: Double)True
Methods
logBase :: a -> a -> a Source #
log to the base of
>>>logBase 2 82.9999999999999996
square root
>>>sqrt 42.0
Instances
| ExpField Double Source # | |
| ExpField Float Source # | |
| (TrigField a, ExpField a) => ExpField (EuclideanPair a) Source # | |
Defined in NumHask.Algebra.Metric Methods exp :: EuclideanPair a -> EuclideanPair a Source # log :: EuclideanPair a -> EuclideanPair a Source # (**) :: EuclideanPair a -> EuclideanPair a -> EuclideanPair a Source # logBase :: EuclideanPair a -> EuclideanPair a -> EuclideanPair a Source # sqrt :: EuclideanPair a -> EuclideanPair a Source # | |
| (TrigField a, ExpField a) => ExpField (Complex a) Source # | |
| ExpField a => ExpField (Wrapped a) Source # | |
| ExpField b => ExpField (a -> b) Source # | |
class SemiField a => QuotientField a where Source #
Quotienting of a Field into a Ring
\a -> a - one < floor a <= a <= ceiling a < a + one
>>>properFraction (1.5 :: Double)Quotient {whole = 1, fraction = 0.5}
>>>fromQuotient (properFraction (1.5 :: Double))1.5
Minimal complete definition
Methods
properFraction :: a -> Quotient (Whole a) a Source #
Split into a whole part and a fractional tail in the canonical range
0 <= fraction < one.
The floor decomposition, not Prelude's toward-zero split: the fraction
is never negative, so properFraction (-1.5) =
Quotient {whole = -2, fraction = 0.5}. Deliberate departure from
Prelude — the floor basis keeps the sign in whole, a clean
change-of-basis to compute with, instead of compounding sign into the
fraction.
>>>properFraction (-1.5 :: Double)Quotient {whole = -2, fraction = 0.5}
fromWhole :: Whole a -> a Source #
Embed the whole-number type back into the field.
The recombination inverse of properFraction. Scalar fields default to
fromIntegral; compound fields override it (e.g. Whole (Complex a) =
Complex (Whole a) lifts component-wise).
round :: a -> Whole a Source #
round to the nearest Int
Exact ties are managed by rounding down ties if the whole component is even.
>>>round (1.5 :: Double)2
>>>round (2.5 :: Double)2
ceiling :: a -> Whole a Source #
supply the next upper whole component
>>>ceiling (1.001 :: Double)2
floor :: a -> Whole a Source #
supply the previous lower whole component
>>>floor (1.001 :: Double)1
truncate :: a -> Whole a Source #
supply the whole component closest to zero
>>>floor (-1.001 :: Double)-2
>>>truncate (-1.001 :: Double)-1
Instances
Whole-and-fraction pair. properFraction is the normalizer (Prelude
toward-zero). The constructor is raw; the range is not enforced.
toQuotient :: QuotientField a => a -> Quotient (Whole a) a Source #
properFraction as the named normalizer into Quotient.
The canonical range is the Prelude toward-zero split: fraction ∈ (-1, 1)
with the sign of the input, and fromQuotient (toQuotient a) == a.
fromQuotient :: QuotientField a => Quotient (Whole a) a -> a Source #
Recombine a Quotient. Law: fromQuotient (toQuotient a) == a.
mulQuotient :: QuotientField a => Quotient (Whole a) a -> Quotient (Whole a) a -> Quotient (Whole a) a Source #
Bilinear multiplication of quotients: recombine, multiply, re-split.
(w1 + f1) * (w2 + f2) expands to the four terms
w1*w2 + w1*f2 + f1*w2 + f1*f2, and toQuotient pushes any overflow back
into whole. The same bilinear-then-normalize pattern as complex
multiplication.
>>>mulQuotient (toQuotient (0.5 :: Double)) (toQuotient (3.0 :: Double))Quotient {whole = 1, fraction = 0.5}
>>>mulQuotient (toQuotient (1.5 :: Double)) (toQuotient (2.0 :: Double)) == toQuotient (1.5 * 2.0 :: Double)True
class Field a => TrigField a where Source #
Trigonometric Field
The list of laws is quite long: trigonometric identities
Methods
Instances
| TrigField Double Source # | |
Defined in NumHask.Algebra.Field Methods sin :: Double -> Double Source # cos :: Double -> Double Source # tan :: Double -> Double Source # asin :: Double -> Double Source # acos :: Double -> Double Source # atan :: Double -> Double Source # atan2 :: Double -> Double -> Double Source # sinh :: Double -> Double Source # cosh :: Double -> Double Source # tanh :: Double -> Double Source # asinh :: Double -> Double Source # | |
| TrigField Float Source # | |
Defined in NumHask.Algebra.Field Methods sin :: Float -> Float Source # cos :: Float -> Float Source # tan :: Float -> Float Source # asin :: Float -> Float Source # acos :: Float -> Float Source # atan :: Float -> Float Source # atan2 :: Float -> Float -> Float Source # sinh :: Float -> Float Source # cosh :: Float -> Float Source # tanh :: Float -> Float Source # asinh :: Float -> Float Source # | |
| TrigField a => TrigField (Wrapped a) Source # | |
Defined in NumHask.Data.Wrapped Methods sin :: Wrapped a -> Wrapped a Source # cos :: Wrapped a -> Wrapped a Source # tan :: Wrapped a -> Wrapped a Source # asin :: Wrapped a -> Wrapped a Source # acos :: Wrapped a -> Wrapped a Source # atan :: Wrapped a -> Wrapped a Source # atan2 :: Wrapped a -> Wrapped a -> Wrapped a Source # sinh :: Wrapped a -> Wrapped a Source # cosh :: Wrapped a -> Wrapped a Source # tanh :: Wrapped a -> Wrapped a Source # asinh :: Wrapped a -> Wrapped a Source # | |
| TrigField b => TrigField (a -> b) Source # | |
Defined in NumHask.Algebra.Field Methods sin :: (a -> b) -> a -> b Source # cos :: (a -> b) -> a -> b Source # tan :: (a -> b) -> a -> b Source # asin :: (a -> b) -> a -> b Source # acos :: (a -> b) -> a -> b Source # atan :: (a -> b) -> a -> b Source # atan2 :: (a -> b) -> (a -> b) -> a -> b Source # sinh :: (a -> b) -> a -> b Source # cosh :: (a -> b) -> a -> b Source # tanh :: (a -> b) -> a -> b Source # asinh :: (a -> b) -> a -> b Source # | |
negInfinity :: Field a => a Source #
negative infinity
>>>negInfinity + infinityNaN
nan :: SemiField a => a Source #
nan is defined as zero/zero
but note the (social) law:
>>>nan == zero / zeroFalse
modF :: (Eq a, Field a, FromIntegral a (Whole a), QuotientField a) => a -> a -> a Source #
Approximate modulo for fields
>>>modF 1.5 1.20.30000000000000004
Since: 0.13
divF :: (Eq a, Field a, FromIntegral a (Whole a), QuotientField a) => a -> a -> a Source #
divModF :: (Eq a, Field a, FromIntegral a (Whole a), QuotientField a) => a -> a -> DivMod a Source #
Approximate divMod for fields.
>>>divModF 1.5 1.2DivMod {div_ = 1.0, mod_ = 0.30000000000000004}
Since: 0.13
Lattice
class Eq a => JoinSemiLattice a where Source #
A algebraic structure with element joins: See Semilattice
Associativity: x \/ (y \/ z) == (x \/ y) \/ z Commutativity: x \/ y == y \/ x Idempotency: x \/ x == x
Instances
| JoinSemiLattice Int16 Source # | |
| JoinSemiLattice Int32 Source # | |
| JoinSemiLattice Int64 Source # | |
| JoinSemiLattice Int8 Source # | |
| JoinSemiLattice Word16 Source # | |
| JoinSemiLattice Word32 Source # | |
| JoinSemiLattice Word64 Source # | |
| JoinSemiLattice Word8 Source # | |
| JoinSemiLattice Warshall Source # | Boolean join-semilattice structure: join is |
| JoinSemiLattice Integer Source # | |
| JoinSemiLattice Natural Source # | |
| JoinSemiLattice Bool Source # | |
| JoinSemiLattice Double Source # | |
| JoinSemiLattice Float Source # | |
| JoinSemiLattice Int Source # | |
| JoinSemiLattice Word Source # | |
| Ord a => JoinSemiLattice (Set a) Source # | |
| JoinSemiLattice a => JoinSemiLattice (EuclideanPair a) Source # | |
Defined in NumHask.Algebra.Metric Methods (\/) :: EuclideanPair a -> EuclideanPair a -> EuclideanPair a Source # | |
| JoinSemiLattice a => JoinSemiLattice (Complex a) Source # | |
| JoinSemiLattice a => JoinSemiLattice (Positive a) Source # | |
| (Ord a, Integral a, EndoBased a, Subtractive a) => JoinSemiLattice (Ratio a) Source # | |
| JoinSemiLattice a => JoinSemiLattice (Wrapped a) Source # | |
| Ord a => JoinSemiLattice (MinPlus a) Source # | Tropical join-semilattice structure: join is |
joinLeq :: JoinSemiLattice a => a -> a -> Bool Source #
The partial ordering induced by the join-semilattice structure
(<\) :: JoinSemiLattice a => a -> a -> Bool infixr 6 Source #
The partial ordering induced by the join-semilattice structure
class Eq a => MeetSemiLattice a where Source #
A algebraic structure with element meets: See Semilattice
Associativity: x /\ (y /\ z) == (x /\ y) /\ z Commutativity: x /\ y == y /\ x Idempotency: x /\ x == x
Instances
| MeetSemiLattice Int16 Source # | |
| MeetSemiLattice Int32 Source # | |
| MeetSemiLattice Int64 Source # | |
| MeetSemiLattice Int8 Source # | |
| MeetSemiLattice Word16 Source # | |
| MeetSemiLattice Word32 Source # | |
| MeetSemiLattice Word64 Source # | |
| MeetSemiLattice Word8 Source # | |
| MeetSemiLattice Integer Source # | |
| MeetSemiLattice Natural Source # | |
| MeetSemiLattice Bool Source # | |
| MeetSemiLattice Double Source # | |
| MeetSemiLattice Float Source # | |
| MeetSemiLattice Int Source # | |
| MeetSemiLattice Word Source # | |
| MeetSemiLattice a => MeetSemiLattice (EuclideanPair a) Source # | |
Defined in NumHask.Algebra.Metric Methods (/\) :: EuclideanPair a -> EuclideanPair a -> EuclideanPair a Source # | |
| MeetSemiLattice a => MeetSemiLattice (Complex a) Source # | |
| MeetSemiLattice a => MeetSemiLattice (Positive a) Source # | |
| (Ord a, Integral a, EndoBased a, Subtractive a) => MeetSemiLattice (Ratio a) Source # | |
| MeetSemiLattice a => MeetSemiLattice (Wrapped a) Source # | |
meetLeq :: MeetSemiLattice a => a -> a -> Bool Source #
The partial ordering induced by the meet-semilattice structure
(</) :: MeetSemiLattice a => a -> a -> Bool infixr 6 Source #
The partial ordering induced by the meet-semilattice structure
class JoinSemiLattice a => LowerBounded a where Source #
Instances
| LowerBounded Int16 Source # | |
Defined in NumHask.Algebra.Lattice | |
| LowerBounded Int32 Source # | |
Defined in NumHask.Algebra.Lattice | |
| LowerBounded Int64 Source # | |
Defined in NumHask.Algebra.Lattice | |
| LowerBounded Int8 Source # | |
Defined in NumHask.Algebra.Lattice | |
| LowerBounded Word16 Source # | |
Defined in NumHask.Algebra.Lattice | |
| LowerBounded Word32 Source # | |
Defined in NumHask.Algebra.Lattice | |
| LowerBounded Word64 Source # | |
Defined in NumHask.Algebra.Lattice | |
| LowerBounded Word8 Source # | |
Defined in NumHask.Algebra.Lattice | |
| LowerBounded Warshall Source # | |
Defined in NumHask.Free.Carriers | |
| LowerBounded Natural Source # | |
Defined in NumHask.Algebra.Lattice | |
| LowerBounded Bool Source # | |
Defined in NumHask.Algebra.Lattice | |
| LowerBounded Double Source # | |
Defined in NumHask.Algebra.Lattice | |
| LowerBounded Float Source # | |
Defined in NumHask.Algebra.Lattice | |
| LowerBounded Int Source # | |
Defined in NumHask.Algebra.Lattice | |
| LowerBounded Word Source # | |
Defined in NumHask.Algebra.Lattice | |
| Ord a => LowerBounded (Set a) Source # | |
Defined in NumHask.Algebra.Lattice | |
| LowerBounded a => LowerBounded (EuclideanPair a) Source # | |
Defined in NumHask.Algebra.Metric Methods bottom :: EuclideanPair a Source # | |
| LowerBounded a => LowerBounded (Complex a) Source # | |
Defined in NumHask.Data.Complex | |
| (Additive a, JoinSemiLattice a) => LowerBounded (Positive a) Source # | |
Defined in NumHask.Data.Positive | |
| LowerBounded a => LowerBounded (Wrapped a) Source # | |
Defined in NumHask.Data.Wrapped | |
| LowerBounded (MinPlus Double) Source # | |
class MeetSemiLattice a => UpperBounded a where Source #
Instances
| UpperBounded Int16 Source # | |
Defined in NumHask.Algebra.Lattice | |
| UpperBounded Int32 Source # | |
Defined in NumHask.Algebra.Lattice | |
| UpperBounded Int64 Source # | |
Defined in NumHask.Algebra.Lattice | |
| UpperBounded Int8 Source # | |
Defined in NumHask.Algebra.Lattice | |
| UpperBounded Word16 Source # | |
Defined in NumHask.Algebra.Lattice | |
| UpperBounded Word32 Source # | |
Defined in NumHask.Algebra.Lattice | |
| UpperBounded Word64 Source # | |
Defined in NumHask.Algebra.Lattice | |
| UpperBounded Word8 Source # | |
Defined in NumHask.Algebra.Lattice | |
| UpperBounded Bool Source # | |
Defined in NumHask.Algebra.Lattice | |
| UpperBounded Double Source # | |
Defined in NumHask.Algebra.Lattice | |
| UpperBounded Float Source # | |
Defined in NumHask.Algebra.Lattice | |
| UpperBounded Int Source # | |
Defined in NumHask.Algebra.Lattice | |
| UpperBounded Word Source # | |
Defined in NumHask.Algebra.Lattice | |
| UpperBounded a => UpperBounded (EuclideanPair a) Source # | |
Defined in NumHask.Algebra.Metric Methods top :: EuclideanPair a Source # | |
| UpperBounded a => UpperBounded (Complex a) Source # | |
Defined in NumHask.Data.Complex | |
| UpperBounded a => UpperBounded (Positive a) Source # | |
Defined in NumHask.Data.Positive | |
| UpperBounded a => UpperBounded (Wrapped a) Source # | |
Defined in NumHask.Data.Wrapped | |
class LowerBounded a => CompleteJoinSemiLattice a where Source #
A join-semilattice that admits arbitrary joins (least upper bounds).
x \/ joins xs == joins (x : xs) joins [] == bottom
Minimal complete definition
Nothing
Instances
Quantale
class (CompleteJoinSemiLattice a, Multiplicative a) => Quantale a Source #
A quantale is a monoid in complete join-semilattices: a complete
join-semilattice equipped with an associative multiplication (*) and unit
(one) that distributes over arbitrary joins.
a * joins xs == joins (fmap (a *) xs) joins xs * a == joins (fmap (* a) xs) a * bottom == bottom bottom * a == bottom
Instances
| Quantale Warshall Source # | Boolean quantale: join is disjunction, multiplication is conjunction. |
Defined in NumHask.Algebra.Quantale | |
| Quantale Bool Source # | Boolean quantale: join is disjunction, multiplication is conjunction. |
Defined in NumHask.Algebra.Quantale | |
| (Ord a, Multiplicative a) => Quantale (Set a) Source # | |
Defined in NumHask.Algebra.Quantale | |
| Quantale (MinPlus Double) Source # | Tropical (min-plus) quantale: join is minimum, bottom is positive infinity, multiplication is addition. |
Defined in NumHask.Algebra.Quantale | |
class Quantale a => Residuated a where Source #
If a quantale is also a StarSemiring, then star
is the least fixed point, equivalently the join of the geometric series:
star a == joins (iterate (a *) one)
A KleeneAlgebra is therefore the fragment of a
(commutative) quantale that only needs these iterative joins, while a
quantale admits arbitrary joins.
A residuated quantale: a quantale equipped with the left and right residuals of multiplication.
In any quantale, multiplication by a fixed element preserves joins, so it has both left and right adjoints. These adjoints are the residuals:
a * lres a b <= b lres a b == joins [ x | a * x <= b ]
rres a b * a <= b rres a b == joins [ x | x * a <= b ]
The order <= is the one induced by the join-semilattice:
x <= y iff x / y == y.
For commutative quantales the two residuals coincide: lres = rres.
Methods
Left residual of multiplication: the greatest x with a * x <= b.
Right residual of multiplication: the greatest x with x * a <= b.
Instances
| Residuated Warshall Source # | Boolean implication as the residual of conjunction.
|
| Residuated Bool Source # | Boolean implication as the residual of conjunction. |
| Residuated (MinPlus Double) Source # | Tropical residual is truncated subtraction.
|
class Quantale a => StarAutonomous a where Source #
A star-autonomous quantale: a quantale with an involutive, order-reversing linear negation.
The negation is an anti-automorphism of the underlying quantale:
neg (neg a) == a joinLeq a b == joinLeq (neg b) (neg a) neg (a * b) == neg b * neg a
Multiplicative disjunction (par) and its unit (bot) are the duals of
(*) and one:
par a b == neg (neg a * neg b) bot == neg one
This is the missing connective that turns a quantale into a model of classical linear logic.
Minimal complete definition
Methods
Linear negation.
Multiplicative disjunction (par), dual to multiplication.
Instances
| StarAutonomous Warshall Source # | Boolean negation as complement; |
| StarAutonomous Bool Source # | Boolean negation is complement; |
| StarAutonomous (MinPlus Double) Source # | Tropical linear negation is additive inverse; |
Bimonoid
class Copyable a where Source #
A cocommutative comonoid in the category of Haskell functions.
This is the value-level content of the linear-logic exponential !A:
the value may be copied (contraction) and discarded (weakening).
class Mergeable a where Source #
A commutative monoid in the category of Haskell functions.
This is the value-level content of the linear-logic exponential ?A:
values may be merged (cocontraction) and introduced from nothing
(coweakening).
Methods
Combine two values.
The unit value, introduced from the terminal object ().
Instances
| Mergeable () Source # | Unit merges trivially. |
| Mergeable Bool Source # | Booleans merge by disjunction. |
| Additive a => Mergeable a Source # | Numeric types merge by addition. This generic instance covers every |
| Ord a => Mergeable (Set a) Source # | Sets merge by union. |
| Mergeable b => Mergeable (a -> b) Source # | Function merging is pointwise. |
Action
class Additive (AdditiveScalar m) => AdditiveAction m where Source #
Additive Action
m |+ zero == m
Associated Types
type AdditiveScalar m Source #
Methods
(|+) :: m -> AdditiveScalar m -> m infixl 6 Source #
Instances
| Additive a => AdditiveAction (TrivialAction a) Source # | |||||
Defined in NumHask.Algebra.Action Associated Types
Methods (|+) :: TrivialAction a -> AdditiveScalar (TrivialAction a) -> TrivialAction a Source # | |||||
| AdditiveAction a => AdditiveAction (Positive a) Source # | |||||
Defined in NumHask.Data.Positive Associated Types
| |||||
| AdditiveAction a => AdditiveAction (Wrapped a) Source # | |||||
Defined in NumHask.Data.Wrapped Associated Types
| |||||
(+|) :: AdditiveAction m => AdditiveScalar m -> m -> m infixl 6 Source #
flipped additive action
(+|) == flip (|+) zero +| m = m
class (AdditiveAction m, Subtractive (AdditiveScalar m)) => SubtractiveAction m where Source #
Subtractive Action
m |- zero = m
Methods
(|-) :: m -> AdditiveScalar m -> m infixl 6 Source #
Instances
| Subtractive a => SubtractiveAction (TrivialAction a) Source # | |
Defined in NumHask.Algebra.Action Methods (|-) :: TrivialAction a -> AdditiveScalar (TrivialAction a) -> TrivialAction a Source # | |
| SubtractiveAction a => SubtractiveAction (Positive a) Source # | |
Defined in NumHask.Data.Positive | |
| SubtractiveAction a => SubtractiveAction (Wrapped a) Source # | |
Defined in NumHask.Data.Wrapped | |
(-|) :: (AdditiveAction m, Subtractive m) => AdditiveScalar m -> m -> m infixl 6 Source #
Subtraction with the scalar on the left
(-|) == (+|) . negate zero -| m = negate m
class Multiplicative (Scalar m) => MultiplicativeAction m where Source #
Multiplicative Action
m |* one = m m |* zero = zero
Instances
| MultiplicativeAction Double Source # | Scalar self-action for This used to live as an orphan in | ||||
| MultiplicativeAction Float Source # | Scalar self-action for | ||||
| Multiplicative a => MultiplicativeAction (TrivialAction a) Source # | |||||
Defined in NumHask.Algebra.Action Associated Types
Methods (|*) :: TrivialAction a -> Scalar (TrivialAction a) -> TrivialAction a Source # | |||||
| Multiplicative a => MultiplicativeAction (EuclideanPair a) Source # | |||||
Defined in NumHask.Algebra.Metric Associated Types
Methods (|*) :: EuclideanPair a -> Scalar (EuclideanPair a) -> EuclideanPair a Source # | |||||
| MultiplicativeAction a => MultiplicativeAction (Positive a) Source # | |||||
| MultiplicativeAction a => MultiplicativeAction (Wrapped a) Source # | |||||
(*|) :: MultiplicativeAction m => Scalar m -> m -> m infixl 7 Source #
flipped multiplicative action
(*|) == flip (|*) one *| m = one zero *| m = zero
class (Divisive (Scalar m), MultiplicativeAction m) => DivisiveAction m where Source #
Divisive Action
m |/ one = m
Instances
| DivisiveAction Double Source # | |
| DivisiveAction Float Source # | |
| Divisive a => DivisiveAction (TrivialAction a) Source # | |
Defined in NumHask.Algebra.Action Methods (|/) :: TrivialAction a -> Scalar (TrivialAction a) -> TrivialAction a Source # | |
| Divisive a => DivisiveAction (EuclideanPair a) Source # | |
Defined in NumHask.Algebra.Metric Methods (|/) :: EuclideanPair a -> Scalar (EuclideanPair a) -> EuclideanPair a Source # | |
| DivisiveAction a => DivisiveAction (Positive a) Source # | |
| DivisiveAction a => DivisiveAction (Wrapped a) Source # | |
(/|) :: (MultiplicativeAction m, Divisive m) => Scalar m -> m -> m Source #
left scalar division
(/|) == (*|) . recip one |/ m = recip m
type Module m = (Distributive (Scalar m), MultiplicativeAction m) Source #
A Module
a *| one == a (a + b) *| c == (a *| c) + (b *| c) c |* (a + b) == (c |* a) + (c |* b) a *| zero == zero a *| b == b |* a
newtype TrivialAction a Source #
An action of a set of numbers on itself
Constructors
| TrivialAction | |
Fields
| |
Instances
| Eq a => Eq (TrivialAction a) Source # | |||||
Defined in NumHask.Algebra.Action Methods (==) :: TrivialAction a -> TrivialAction a -> Bool # (/=) :: TrivialAction a -> TrivialAction a -> Bool # | |||||
| Ord a => Ord (TrivialAction a) Source # | |||||
Defined in NumHask.Algebra.Action Methods compare :: TrivialAction a -> TrivialAction a -> Ordering # (<) :: TrivialAction a -> TrivialAction a -> Bool # (<=) :: TrivialAction a -> TrivialAction a -> Bool # (>) :: TrivialAction a -> TrivialAction a -> Bool # (>=) :: TrivialAction a -> TrivialAction a -> Bool # max :: TrivialAction a -> TrivialAction a -> TrivialAction a # min :: TrivialAction a -> TrivialAction a -> TrivialAction a # | |||||
| Additive a => AdditiveAction (TrivialAction a) Source # | |||||
Defined in NumHask.Algebra.Action Associated Types
Methods (|+) :: TrivialAction a -> AdditiveScalar (TrivialAction a) -> TrivialAction a Source # | |||||
| Divisive a => DivisiveAction (TrivialAction a) Source # | |||||
Defined in NumHask.Algebra.Action Methods (|/) :: TrivialAction a -> Scalar (TrivialAction a) -> TrivialAction a Source # | |||||
| Multiplicative a => MultiplicativeAction (TrivialAction a) Source # | |||||
Defined in NumHask.Algebra.Action Associated Types
Methods (|*) :: TrivialAction a -> Scalar (TrivialAction a) -> TrivialAction a Source # | |||||
| Subtractive a => SubtractiveAction (TrivialAction a) Source # | |||||
Defined in NumHask.Algebra.Action Methods (|-) :: TrivialAction a -> AdditiveScalar (TrivialAction a) -> TrivialAction a Source # | |||||
| Additive a => Additive (TrivialAction a) Source # | |||||
Defined in NumHask.Algebra.Action Methods (+) :: TrivialAction a -> TrivialAction a -> TrivialAction a Source # zero :: TrivialAction a Source # | |||||
| Subtractive a => Subtractive (TrivialAction a) Source # | |||||
Defined in NumHask.Algebra.Action Methods negate :: TrivialAction a -> TrivialAction a Source # (-) :: TrivialAction a -> TrivialAction a -> TrivialAction a Source # | |||||
| Divisive a => Divisive (TrivialAction a) Source # | |||||
Defined in NumHask.Algebra.Action Methods recip :: TrivialAction a -> TrivialAction a Source # (/) :: TrivialAction a -> TrivialAction a -> TrivialAction a Source # | |||||
| Multiplicative a => Multiplicative (TrivialAction a) Source # | |||||
Defined in NumHask.Algebra.Action Methods (*) :: TrivialAction a -> TrivialAction a -> TrivialAction a Source # one :: TrivialAction a Source # | |||||
| type AdditiveScalar (TrivialAction a) Source # | |||||
Defined in NumHask.Algebra.Action | |||||
| type Scalar (TrivialAction a) Source # | |||||
Defined in NumHask.Algebra.Action | |||||
Metric
class Distributive (Mag a) => Basis a where Source #
Basis encapsulates the notion of magnitude (intuitively the quotienting of a higher-kinded number to a scalar one) and the basis on which the magnitude quotienting was performed. An instance needs to satisfy these laws:
\a -> magnitude a >= zero \a -> magnitude zero == zero \a -> a == magnitude a *| basis a \a -> magnitude (basis a) == one
The names chosen are meant to represent the spiritual idea of a basis rather than a specific mathematics. See https://en.wikipedia.org/wiki/Basis_(linear_algebra) & https://en.wikipedia.org/wiki/Norm_(mathematics) for some mathematical motivations.
>>>magnitude (-0.5 :: Double)0.5
>>>basis (-0.5 :: Double)-1.0
Since: 0.11
Instances
| Basis Int16 Source # | |||||||||
| Basis Int32 Source # | |||||||||
| Basis Int64 Source # | |||||||||
| Basis Int8 Source # | |||||||||
| Basis Word16 Source # | |||||||||
| Basis Word32 Source # | |||||||||
| Basis Word64 Source # | |||||||||
| Basis Word8 Source # | |||||||||
| Basis Integer Source # | |||||||||
Defined in NumHask.Algebra.Metric Associated Types
| |||||||||
| Basis Natural Source # | |||||||||
Defined in NumHask.Algebra.Metric Associated Types
| |||||||||
| Basis Double Source # | |||||||||
| Basis Float Source # | |||||||||
| Basis Int Source # | |||||||||
| Basis Word Source # | |||||||||
| (ExpField a, Eq a) => Basis (EuclideanPair a) Source # | |||||||||
Defined in NumHask.Algebra.Metric Associated Types
Methods magnitude :: EuclideanPair a -> Mag (EuclideanPair a) Source # basis :: EuclideanPair a -> Base (EuclideanPair a) Source # | |||||||||
| (Additive a, Multiplicative a) => Basis (Polar a) Source # | |||||||||
Defined in NumHask.Algebra.Metric Associated Types
| |||||||||
| (ExpField a, Eq a) => Basis (Complex a) Source # | |||||||||
Defined in NumHask.Data.Complex Associated Types
| |||||||||
| Basis a => Basis (Positive a) Source # | |||||||||
Defined in NumHask.Data.Positive Associated Types
| |||||||||
| (Ord a, EndoBased a, Integral a, Ring a) => Basis (Ratio a) Source # | |||||||||
Defined in NumHask.Data.Rational Associated Types
| |||||||||
| Basis a => Basis (Wrapped a) Source # | |||||||||
Defined in NumHask.Data.Wrapped Associated Types
| |||||||||
type Absolute a = (Basis a, Mag a ~ a) Source #
Basis where the domain and magnitude codomain are the same.
Since: 0.11
type Sign a = (Basis a, Base a ~ a) Source #
Basis where the domain and basis codomain are the same.
Since: 0.11
type EndoBased a = (Basis a, Mag a ~ a, Base a ~ a) Source #
Basis where the domain, magnitude codomain and basis codomain are the same.
Since: 0.11
abs :: Absolute a => a -> a Source #
The absolute value of a number.
abs a * signum a ~= a
>>>abs (-1)1
>>>abs (-2) * signum (-2) == (-2 :: Int)True
>>>abs 2 * signum 2 == (2 :: Int)True
signum :: Sign a => a -> a Source #
The sign of a number.
>>>signum (-1)-1
abs zero == zero, so any value for signum zero is ok. We choose lawful neutral:
>>>signum zero == zeroTrue
Since: 0.11
distance :: (Basis a, Subtractive a) => a -> a -> Mag a Source #
Distance, which combines the Subtractive notion of difference, with Basis.
distance a b >= zero distance a a == zero distance a b *| basis (a - b) == a - b
class (Distributive coord, Distributive (Dir coord)) => Direction coord where Source #
Convert between a "co-ordinated" or "higher-kinded" number and a direction.
ray . angle == basis magnitude (ray x) == one
Since: 0.7
Instances
| TrigField a => Direction (EuclideanPair a) Source # | |||||
Defined in NumHask.Algebra.Metric Associated Types
Methods angle :: EuclideanPair a -> Dir (EuclideanPair a) Source # ray :: Dir (EuclideanPair a) -> EuclideanPair a Source # | |||||
| TrigField a => Direction (Complex a) Source # | |||||
| Direction a => Direction (Positive a) Source # | |||||
| Direction a => Direction (Wrapped a) Source # | |||||
Something that has a magnitude and a direction, with both expressed as the same type.
Since: 0.7
Instances
| Eq a => Eq (Polar a) Source # | |||||||||
| Data a => Data (Polar a) Source # | |||||||||
Defined in NumHask.Algebra.Metric Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Polar a -> c (Polar a) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Polar a) # toConstr :: Polar a -> Constr # dataTypeOf :: Polar a -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Polar a)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Polar a)) # gmapT :: (forall b. Data b => b -> b) -> Polar a -> Polar a # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Polar a -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Polar a -> r # gmapQ :: (forall d. Data d => d -> u) -> Polar a -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Polar a -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Polar a -> m (Polar a) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Polar a -> m (Polar a) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Polar a -> m (Polar a) # | |||||||||
| Generic (Polar a) Source # | |||||||||
Defined in NumHask.Algebra.Metric Associated Types
| |||||||||
| Read a => Read (Polar a) Source # | |||||||||
| Show a => Show (Polar a) Source # | |||||||||
| (Additive a, Multiplicative a) => Basis (Polar a) Source # | |||||||||
Defined in NumHask.Algebra.Metric Associated Types
| |||||||||
| type Rep (Polar a) Source # | |||||||||
Defined in NumHask.Algebra.Metric type Rep (Polar a) = D1 ('MetaData "Polar" "NumHask.Algebra.Metric" "numhask-0.14.0.0-inplace" 'False) (C1 ('MetaCons "Polar" 'PrefixI 'True) (S1 ('MetaSel ('Just "radial") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a) :*: S1 ('MetaSel ('Just "azimuth") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a))) | |||||||||
| type Base (Polar a) Source # | |||||||||
Defined in NumHask.Algebra.Metric | |||||||||
| type Mag (Polar a) Source # | |||||||||
Defined in NumHask.Algebra.Metric | |||||||||
polar :: (Dir (Base a) ~ Mag a, Basis a, Direction (Base a)) => a -> Polar (Mag a) Source #
Convert a higher-kinded number that has direction, to a Polar
Since: 0.7
coord :: (Scalar m ~ Dir m, MultiplicativeAction m, Direction m) => Polar (Scalar m) -> m Source #
Convert a Polar to a (higher-kinded) number that has a direction.
Since: 0.7
class (Eq a, Additive a) => Epsilon a where Source #
A small number, especially useful for approximate equality.
Minimal complete definition
Nothing
Instances
| Epsilon Int16 Source # | |
Defined in NumHask.Algebra.Metric | |
| Epsilon Int32 Source # | |
Defined in NumHask.Algebra.Metric | |
| Epsilon Int64 Source # | |
Defined in NumHask.Algebra.Metric | |
| Epsilon Int8 Source # | |
Defined in NumHask.Algebra.Metric | |
| Epsilon Word16 Source # | |
Defined in NumHask.Algebra.Metric | |
| Epsilon Word32 Source # | |
Defined in NumHask.Algebra.Metric | |
| Epsilon Word64 Source # | |
Defined in NumHask.Algebra.Metric | |
| Epsilon Word8 Source # | |
Defined in NumHask.Algebra.Metric | |
| Epsilon Integer Source # | |
Defined in NumHask.Algebra.Metric | |
| Epsilon Double Source # | 1e-14 |
Defined in NumHask.Algebra.Metric | |
| Epsilon Float Source # | 1e-6 |
Defined in NumHask.Algebra.Metric | |
| Epsilon Int Source # | 0 |
Defined in NumHask.Algebra.Metric | |
| Epsilon Word Source # | |
Defined in NumHask.Algebra.Metric | |
| Epsilon a => Epsilon (EuclideanPair a) Source # | |
Defined in NumHask.Algebra.Metric Methods epsilon :: EuclideanPair a Source # | |
| Epsilon a => Epsilon (Complex a) Source # | |
Defined in NumHask.Data.Complex | |
| Epsilon a => Epsilon (Positive a) Source # | |
Defined in NumHask.Data.Positive | |
| (Ord a, EndoBased a, Integral a, Ring a) => Epsilon (Ratio a) Source # | |
Defined in NumHask.Data.Rational | |
| Epsilon a => Epsilon (Wrapped a) Source # | |
Defined in NumHask.Data.Wrapped | |
aboutEqual :: (Epsilon a, Lattice a, Subtractive a) => a -> a -> Bool Source #
Approximate equality
>>>aboutEqual zero (epsilon :: Double)True
nearZero :: (Epsilon a, Lattice a, Subtractive a) => a -> Bool Source #
Note that the constraint is Lattice rather than Ord allowing broader usage.
>>>nearZero (epsilon :: Double)True
>>>nearZero (epsilon :: EuclideanPair Double)True
(~=) :: (Epsilon a, Lattice a, Subtractive a) => a -> a -> Bool infixl 4 Source #
About equal operator.
>>>(1.0 + epsilon) ~= (1.0 :: Double)True
Complex
The underlying representation is a newtype-wrapped tuple, compared with the base datatype. This was chosen to facilitate the use of DerivingVia.
Constructors
| Complex | |
Fields
| |
Instances
| Functor Complex Source # | |||||||||
| Eq a => Eq (Complex a) Source # | |||||||||
| Data a => Data (Complex a) Source # | |||||||||
Defined in NumHask.Data.Complex Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Complex a -> c (Complex a) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Complex a) # toConstr :: Complex a -> Constr # dataTypeOf :: Complex a -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Complex a)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Complex a)) # gmapT :: (forall b. Data b => b -> b) -> Complex a -> Complex a # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Complex a -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Complex a -> r # gmapQ :: (forall d. Data d => d -> u) -> Complex a -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Complex a -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Complex a -> m (Complex a) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Complex a -> m (Complex a) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Complex a -> m (Complex a) # | |||||||||
| Generic (Complex a) Source # | |||||||||
Defined in NumHask.Data.Complex Associated Types
| |||||||||
| Read a => Read (Complex a) Source # | |||||||||
| Show a => Show (Complex a) Source # | |||||||||
| Additive a => Additive (Complex a) Source # | |||||||||
| Subtractive a => Subtractive (Complex a) Source # | |||||||||
| (TrigField a, ExpField a) => ExpField (Complex a) Source # | |||||||||
| (Subtractive a, QuotientField a) => QuotientField (Complex a) Source # | A complex field quotients and recombines component-wise.
Can't use DerivingVia due to extra Whole constraints. | ||||||||
Defined in NumHask.Data.Complex Associated Types
| |||||||||
| JoinSemiLattice a => JoinSemiLattice (Complex a) Source # | |||||||||
| LowerBounded a => LowerBounded (Complex a) Source # | |||||||||
Defined in NumHask.Data.Complex | |||||||||
| MeetSemiLattice a => MeetSemiLattice (Complex a) Source # | |||||||||
| UpperBounded a => UpperBounded (Complex a) Source # | |||||||||
Defined in NumHask.Data.Complex | |||||||||
| (ExpField a, Eq a) => Basis (Complex a) Source # | |||||||||
Defined in NumHask.Data.Complex Associated Types
| |||||||||
| TrigField a => Direction (Complex a) Source # | |||||||||
| Epsilon a => Epsilon (Complex a) Source # | |||||||||
Defined in NumHask.Data.Complex | |||||||||
| (Subtractive a, Divisive a) => Divisive (Complex a) Source # | |||||||||
| (Subtractive a, Multiplicative a) => Multiplicative (Complex a) Source # | |||||||||
| (Distributive a, Subtractive a) => InvolutiveRing (Complex a) Source # | |||||||||
| (Additive a, FromIntegral a b) => FromIntegral (Complex a) b Source # | |||||||||
Defined in NumHask.Data.Complex Methods fromIntegral :: b -> Complex a Source # | |||||||||
| type Rep (Complex a) Source # | |||||||||
Defined in NumHask.Data.Complex | |||||||||
| type Whole (Complex a) Source # | |||||||||
Defined in NumHask.Data.Complex | |||||||||
| type Base (Complex a) Source # | |||||||||
Defined in NumHask.Data.Complex | |||||||||
| type Dir (Complex a) Source # | |||||||||
Defined in NumHask.Data.Complex | |||||||||
| type Mag (Complex a) Source # | |||||||||
Defined in NumHask.Data.Complex | |||||||||
(+:) :: a -> a -> Complex a infixl 6 Source #
Complex number constructor.
Internally, Complex derives most instances via EuclideanPair. For instance,
>>>sqrt (1.0 +: (-1.0)) :: Complex DoubleComplex {complexPair = (1.0986841134678098,-0.45508986056222733)}
>>>sqrt ((-1.0) +: 0.0) :: Complex DoubleComplex {complexPair = (6.123233995736766e-17,1.0)}
normSquared :: Distributive a => Complex a -> a Source #
The squared norm: frequently useful, and doesn't require the ability to take square roots.
Integral
class Distributive a => Integral a where Source #
An Integral is anything that satisfies the law:
b == zero || b * (a `div` b) + (a `mod` b) == a
>>>3 `divMod` 2DivMod {div_ = 1, mod_ = 1}
>>>(-3) `divMod` 2DivMod {div_ = -2, mod_ = 1}
>>>(-3) `quotRem` 2QuotRem {quot_ = -1, rem_ = -1}
>>>2 * (3 `div` 2) + (3 `mod` 2) == (3 :: Int)True
>>>2 * ((-3) `div` 2) + ((-3) `mod` 2) == (-3 :: Int)True
Methods
div :: a -> a -> a infixl 7 Source #
mod :: a -> a -> a infixl 7 Source #
Instances
| Integral Int16 Source # | |
| Integral Int32 Source # | |
| Integral Int64 Source # | |
| Integral Int8 Source # | |
| Integral Word16 Source # | |
Defined in NumHask.Data.Integral | |
| Integral Word32 Source # | |
Defined in NumHask.Data.Integral | |
| Integral Word64 Source # | |
Defined in NumHask.Data.Integral | |
| Integral Word8 Source # | |
| Integral Integer Source # | |
| Integral Natural Source # | |
| Integral Int Source # | |
| Integral Word Source # | |
| Integral a => Integral (Positive a) Source # | |
Defined in NumHask.Data.Positive Methods div :: Positive a -> Positive a -> Positive a Source # mod :: Positive a -> Positive a -> Positive a Source # divMod :: Positive a -> Positive a -> DivMod (Positive a) Source # quot :: Positive a -> Positive a -> Positive a Source # rem :: Positive a -> Positive a -> Positive a Source # quotRem :: Positive a -> Positive a -> QuotRem (Positive a) Source # | |
| Integral a => Integral (Wrapped a) Source # | |
Defined in NumHask.Data.Wrapped Methods div :: Wrapped a -> Wrapped a -> Wrapped a Source # mod :: Wrapped a -> Wrapped a -> Wrapped a Source # divMod :: Wrapped a -> Wrapped a -> DivMod (Wrapped a) Source # quot :: Wrapped a -> Wrapped a -> Wrapped a Source # rem :: Wrapped a -> Wrapped a -> Wrapped a Source # quotRem :: Wrapped a -> Wrapped a -> QuotRem (Wrapped a) Source # | |
| Integral b => Integral (a -> b) Source # | |
Defined in NumHask.Data.Integral Methods div :: (a -> b) -> (a -> b) -> a -> b Source # mod :: (a -> b) -> (a -> b) -> a -> b Source # divMod :: (a -> b) -> (a -> b) -> DivMod (a -> b) Source # quot :: (a -> b) -> (a -> b) -> a -> b Source # rem :: (a -> b) -> (a -> b) -> a -> b Source # quotRem :: (a -> b) -> (a -> b) -> QuotRem (a -> b) Source # | |
Floor-division pair. Distinct from QuotRem (toward-zero).
Toward-zero division pair. Distinct from DivMod (floor).
class ToIntegral a b where Source #
toIntegral is kept separate from Integral to help with compatability issues.
toIntegral a == a
Methods
toIntegral :: a -> b Source #
Instances
| ToIntegral Int16 Int16 Source # | |
Defined in NumHask.Data.Integral Methods toIntegral :: Int16 -> Int16 Source # | |
| ToIntegral Int16 Integer Source # | |
Defined in NumHask.Data.Integral Methods toIntegral :: Int16 -> Integer Source # | |
| ToIntegral Int16 Int Source # | |
Defined in NumHask.Data.Integral Methods toIntegral :: Int16 -> Int Source # | |
| ToIntegral Int32 Int32 Source # | |
Defined in NumHask.Data.Integral Methods toIntegral :: Int32 -> Int32 Source # | |
| ToIntegral Int32 Integer Source # | |
Defined in NumHask.Data.Integral Methods toIntegral :: Int32 -> Integer Source # | |
| ToIntegral Int32 Int Source # | |
Defined in NumHask.Data.Integral Methods toIntegral :: Int32 -> Int Source # | |
| ToIntegral Int64 Int64 Source # | |
Defined in NumHask.Data.Integral Methods toIntegral :: Int64 -> Int64 Source # | |
| ToIntegral Int64 Integer Source # | |
Defined in NumHask.Data.Integral Methods toIntegral :: Int64 -> Integer Source # | |
| ToIntegral Int64 Int Source # | |
Defined in NumHask.Data.Integral Methods toIntegral :: Int64 -> Int Source # | |
| ToIntegral Int8 Int8 Source # | |
Defined in NumHask.Data.Integral Methods toIntegral :: Int8 -> Int8 Source # | |
| ToIntegral Int8 Integer Source # | |
Defined in NumHask.Data.Integral Methods toIntegral :: Int8 -> Integer Source # | |
| ToIntegral Int8 Int Source # | |
Defined in NumHask.Data.Integral Methods toIntegral :: Int8 -> Int Source # | |
| ToIntegral Word16 Word16 Source # | |
Defined in NumHask.Data.Integral Methods toIntegral :: Word16 -> Word16 Source # | |
| ToIntegral Word16 Integer Source # | |
Defined in NumHask.Data.Integral Methods toIntegral :: Word16 -> Integer Source # | |
| ToIntegral Word16 Int Source # | |
Defined in NumHask.Data.Integral Methods toIntegral :: Word16 -> Int Source # | |
| ToIntegral Word32 Word32 Source # | |
Defined in NumHask.Data.Integral Methods toIntegral :: Word32 -> Word32 Source # | |
| ToIntegral Word32 Integer Source # | |
Defined in NumHask.Data.Integral Methods toIntegral :: Word32 -> Integer Source # | |
| ToIntegral Word32 Int Source # | |
Defined in NumHask.Data.Integral Methods toIntegral :: Word32 -> Int Source # | |
| ToIntegral Word64 Word64 Source # | |
Defined in NumHask.Data.Integral Methods toIntegral :: Word64 -> Word64 Source # | |
| ToIntegral Word64 Integer Source # | |
Defined in NumHask.Data.Integral Methods toIntegral :: Word64 -> Integer Source # | |
| ToIntegral Word64 Int Source # | |
Defined in NumHask.Data.Integral Methods toIntegral :: Word64 -> Int Source # | |
| ToIntegral Word8 Word8 Source # | |
Defined in NumHask.Data.Integral Methods toIntegral :: Word8 -> Word8 Source # | |
| ToIntegral Word8 Integer Source # | |
Defined in NumHask.Data.Integral Methods toIntegral :: Word8 -> Integer Source # | |
| ToIntegral Word8 Int Source # | |
Defined in NumHask.Data.Integral Methods toIntegral :: Word8 -> Int Source # | |
| ToIntegral Integer Integer Source # | |
Defined in NumHask.Data.Integral Methods toIntegral :: Integer -> Integer Source # | |
| ToIntegral Integer Int Source # | |
Defined in NumHask.Data.Integral Methods toIntegral :: Integer -> Int Source # | |
| ToIntegral Natural Integer Source # | |
Defined in NumHask.Data.Integral Methods toIntegral :: Natural -> Integer Source # | |
| ToIntegral Natural Natural Source # | |
Defined in NumHask.Data.Integral Methods toIntegral :: Natural -> Natural Source # | |
| ToIntegral Natural Int Source # | |
Defined in NumHask.Data.Integral Methods toIntegral :: Natural -> Int Source # | |
| ToIntegral Int Integer Source # | |
Defined in NumHask.Data.Integral Methods toIntegral :: Int -> Integer Source # | |
| ToIntegral Int Int Source # | |
Defined in NumHask.Data.Integral Methods toIntegral :: Int -> Int Source # | |
| ToIntegral Word Integer Source # | |
Defined in NumHask.Data.Integral Methods toIntegral :: Word -> Integer Source # | |
| ToIntegral Word Int Source # | |
Defined in NumHask.Data.Integral Methods toIntegral :: Word -> Int Source # | |
| ToIntegral Word Word Source # | |
Defined in NumHask.Data.Integral Methods toIntegral :: Word -> Word Source # | |
| ToIntegral a b => ToIntegral (Positive a) b Source # | |
Defined in NumHask.Data.Positive Methods toIntegral :: Positive a -> b Source # | |
| ToIntegral a b => ToIntegral (Wrapped a) b Source # | |
Defined in NumHask.Data.Wrapped Methods toIntegral :: Wrapped a -> b Source # | |
class FromIntegral a b where Source #
Polymorphic version of fromInteger
fromIntegral a == a
Methods
fromIntegral :: b -> a Source #
Instances
| FromIntegral Int16 Int16 Source # | |
Defined in NumHask.Data.Integral Methods fromIntegral :: Int16 -> Int16 Source # | |
| FromIntegral Int16 Integer Source # | |
Defined in NumHask.Data.Integral Methods fromIntegral :: Integer -> Int16 Source # | |
| FromIntegral Int16 Int Source # | |
Defined in NumHask.Data.Integral Methods fromIntegral :: Int -> Int16 Source # | |
| FromIntegral Int32 Int32 Source # | |
Defined in NumHask.Data.Integral Methods fromIntegral :: Int32 -> Int32 Source # | |
| FromIntegral Int32 Integer Source # | |
Defined in NumHask.Data.Integral Methods fromIntegral :: Integer -> Int32 Source # | |
| FromIntegral Int32 Int Source # | |
Defined in NumHask.Data.Integral Methods fromIntegral :: Int -> Int32 Source # | |
| FromIntegral Int64 Int64 Source # | |
Defined in NumHask.Data.Integral Methods fromIntegral :: Int64 -> Int64 Source # | |
| FromIntegral Int64 Integer Source # | |
Defined in NumHask.Data.Integral Methods fromIntegral :: Integer -> Int64 Source # | |
| FromIntegral Int64 Int Source # | |
Defined in NumHask.Data.Integral Methods fromIntegral :: Int -> Int64 Source # | |
| FromIntegral Int8 Int8 Source # | |
Defined in NumHask.Data.Integral Methods fromIntegral :: Int8 -> Int8 Source # | |
| FromIntegral Int8 Integer Source # | |
Defined in NumHask.Data.Integral Methods fromIntegral :: Integer -> Int8 Source # | |
| FromIntegral Int8 Int Source # | |
Defined in NumHask.Data.Integral Methods fromIntegral :: Int -> Int8 Source # | |
| FromIntegral Word16 Word16 Source # | |
Defined in NumHask.Data.Integral Methods fromIntegral :: Word16 -> Word16 Source # | |
| FromIntegral Word16 Integer Source # | |
Defined in NumHask.Data.Integral Methods fromIntegral :: Integer -> Word16 Source # | |
| FromIntegral Word16 Int Source # | |
Defined in NumHask.Data.Integral Methods fromIntegral :: Int -> Word16 Source # | |
| FromIntegral Word32 Word32 Source # | |
Defined in NumHask.Data.Integral Methods fromIntegral :: Word32 -> Word32 Source # | |
| FromIntegral Word32 Integer Source # | |
Defined in NumHask.Data.Integral Methods fromIntegral :: Integer -> Word32 Source # | |
| FromIntegral Word32 Int Source # | |
Defined in NumHask.Data.Integral Methods fromIntegral :: Int -> Word32 Source # | |
| FromIntegral Word64 Word64 Source # | |
Defined in NumHask.Data.Integral Methods fromIntegral :: Word64 -> Word64 Source # | |
| FromIntegral Word64 Integer Source # | |
Defined in NumHask.Data.Integral Methods fromIntegral :: Integer -> Word64 Source # | |
| FromIntegral Word64 Int Source # | |
Defined in NumHask.Data.Integral Methods fromIntegral :: Int -> Word64 Source # | |
| FromIntegral Word8 Word8 Source # | |
Defined in NumHask.Data.Integral Methods fromIntegral :: Word8 -> Word8 Source # | |
| FromIntegral Word8 Integer Source # | |
Defined in NumHask.Data.Integral Methods fromIntegral :: Integer -> Word8 Source # | |
| FromIntegral Word8 Int Source # | |
Defined in NumHask.Data.Integral Methods fromIntegral :: Int -> Word8 Source # | |
| FromIntegral Integer Integer Source # | |
Defined in NumHask.Data.Integral Methods fromIntegral :: Integer -> Integer Source # | |
| FromIntegral Integer Int Source # | |
Defined in NumHask.Data.Integral Methods fromIntegral :: Int -> Integer Source # | |
| FromIntegral Natural Integer Source # | |
Defined in NumHask.Data.Integral Methods fromIntegral :: Integer -> Natural Source # | |
| FromIntegral Natural Natural Source # | |
Defined in NumHask.Data.Integral Methods fromIntegral :: Natural -> Natural Source # | |
| FromIntegral Natural Int Source # | |
Defined in NumHask.Data.Integral Methods fromIntegral :: Int -> Natural Source # | |
| FromIntegral Double Integer Source # | |
Defined in NumHask.Data.Integral Methods fromIntegral :: Integer -> Double Source # | |
| FromIntegral Double Int Source # | |
Defined in NumHask.Data.Integral Methods fromIntegral :: Int -> Double Source # | |
| FromIntegral Float Integer Source # | |
Defined in NumHask.Data.Integral Methods fromIntegral :: Integer -> Float Source # | |
| FromIntegral Float Int Source # | |
Defined in NumHask.Data.Integral Methods fromIntegral :: Int -> Float Source # | |
| FromIntegral Int Integer Source # | |
Defined in NumHask.Data.Integral Methods fromIntegral :: Integer -> Int Source # | |
| FromIntegral Int Int Source # | |
Defined in NumHask.Data.Integral Methods fromIntegral :: Int -> Int Source # | |
| FromIntegral Word Integer Source # | |
Defined in NumHask.Data.Integral Methods fromIntegral :: Integer -> Word Source # | |
| FromIntegral Word Int Source # | |
Defined in NumHask.Data.Integral Methods fromIntegral :: Int -> Word Source # | |
| FromIntegral Word Word Source # | |
Defined in NumHask.Data.Integral Methods fromIntegral :: Word -> Word Source # | |
| (Additive a, FromIntegral a b) => FromIntegral (Complex a) b Source # | |
Defined in NumHask.Data.Complex Methods fromIntegral :: b -> Complex a Source # | |
| (JoinSemiLattice a, Integral a) => FromIntegral (Positive a) a Source # | |
Defined in NumHask.Data.Positive Methods fromIntegral :: a -> Positive a Source # | |
| FromIntegral a b => FromIntegral (Positive a) b Source # | |
Defined in NumHask.Data.Positive Methods fromIntegral :: b -> Positive a Source # | |
| (FromIntegral a b, Multiplicative a) => FromIntegral (Ratio a) b Source # | |
Defined in NumHask.Data.Rational Methods fromIntegral :: b -> Ratio a Source # | |
| FromIntegral a b => FromIntegral (Wrapped a) b Source # | |
Defined in NumHask.Data.Wrapped Methods fromIntegral :: b -> Wrapped a Source # | |
| FromIntegral a b => FromIntegral (c -> a) b Source # | |
Defined in NumHask.Data.Integral Methods fromIntegral :: b -> c -> a Source # | |
class FromInteger a where Source #
fromInteger is special in two ways:
- numeric integral literals (like "42") are interpreted specifically as "fromInteger (42 :: GHC.Num.Integer)". The prelude version is used as default (or whatever fromInteger is in scope if RebindableSyntax is set).
- The default rules in haskell2010 specify that constraints on
fromIntegerneed to be in a formC v, where v is a Num or a subclass of Num.
So a type synonym such as type FromInteger a = FromIntegral a Integer doesn't work well with type defaulting; hence the need for a separate class.
Methods
fromInteger :: Integer -> a Source #
Instances
| FromInteger Int16 Source # | |
Defined in NumHask.Data.Integral Methods fromInteger :: Integer -> Int16 Source # | |
| FromInteger Int32 Source # | |
Defined in NumHask.Data.Integral Methods fromInteger :: Integer -> Int32 Source # | |
| FromInteger Int64 Source # | |
Defined in NumHask.Data.Integral Methods fromInteger :: Integer -> Int64 Source # | |
| FromInteger Int8 Source # | |
Defined in NumHask.Data.Integral Methods fromInteger :: Integer -> Int8 Source # | |
| FromInteger Word16 Source # | |
Defined in NumHask.Data.Integral Methods fromInteger :: Integer -> Word16 Source # | |
| FromInteger Word32 Source # | |
Defined in NumHask.Data.Integral Methods fromInteger :: Integer -> Word32 Source # | |
| FromInteger Word64 Source # | |
Defined in NumHask.Data.Integral Methods fromInteger :: Integer -> Word64 Source # | |
| FromInteger Word8 Source # | |
Defined in NumHask.Data.Integral Methods fromInteger :: Integer -> Word8 Source # | |
| FromInteger Integer Source # | |
Defined in NumHask.Data.Integral Methods fromInteger :: Integer -> Integer Source # | |
| FromInteger Natural Source # | |
Defined in NumHask.Data.Integral Methods fromInteger :: Integer -> Natural Source # | |
| FromInteger Double Source # | |
Defined in NumHask.Data.Integral Methods fromInteger :: Integer -> Double Source # | |
| FromInteger Float Source # | |
Defined in NumHask.Data.Integral Methods fromInteger :: Integer -> Float Source # | |
| FromInteger Int Source # | |
Defined in NumHask.Data.Integral Methods fromInteger :: Integer -> Int Source # | |
| FromInteger Word Source # | |
Defined in NumHask.Data.Integral Methods fromInteger :: Integer -> Word Source # | |
| FromInteger a => FromInteger (Sum a) Source # | |
Defined in NumHask.Data.Integral Methods fromInteger :: Integer -> Sum a Source # | |
| FromInteger a => FromInteger (Product a) Source # | |
Defined in NumHask.Data.Integral Methods fromInteger :: Integer -> Product a Source # | |
| FromInteger a => FromInteger (Positive a) Source # | |
Defined in NumHask.Data.Positive Methods fromInteger :: Integer -> Positive a Source # | |
| (FromInteger a, Multiplicative a) => FromInteger (Ratio a) Source # | |
Defined in NumHask.Data.Rational Methods fromInteger :: Integer -> Ratio a Source # | |
| FromInteger a => FromInteger (Wrapped a) Source # | |
Defined in NumHask.Data.Wrapped Methods fromInteger :: Integer -> Wrapped a Source # | |
(^+) :: Multiplicative a => a -> Natural -> a infixr 8 Source #
Rational
A rational number, represented as the ratio of two Integral numbers.
Constructors
| !a :% !a |
Instances
| FromRatio Rational Integer Source # | |||||||||
| (Eq a, Ord a, Subtractive a, EndoBased a, Absolute a, Integral a) => Eq (Ratio a) Source # | |||||||||
| (Ord a, Integral a, EndoBased a, Subtractive a) => Ord (Ratio a) Source # | |||||||||
Defined in NumHask.Data.Rational | |||||||||
| Show a => Show (Ratio a) Source # | |||||||||
| (Ord a, EndoBased a, Integral a, Ring a) => Additive (Ratio a) Source # | |||||||||
| (Ord a, EndoBased a, Integral a, Ring a) => Subtractive (Ratio a) Source # | |||||||||
| (Ord a, EndoBased a, Absolute a, ToInt a, FromIntegral a Int, Integral a, Ring a) => QuotientField (Ratio a) Source # | |||||||||
| (Ord a, Integral a, EndoBased a, Subtractive a) => JoinSemiLattice (Ratio a) Source # | |||||||||
| (Ord a, Integral a, EndoBased a, Subtractive a) => MeetSemiLattice (Ratio a) Source # | |||||||||
| (Ord a, EndoBased a, Integral a, Ring a) => Basis (Ratio a) Source # | |||||||||
Defined in NumHask.Data.Rational Associated Types
| |||||||||
| (Ord a, EndoBased a, Integral a, Ring a) => Epsilon (Ratio a) Source # | |||||||||
Defined in NumHask.Data.Rational | |||||||||
| (Ord a, EndoBased a, Integral a, Ring a) => Divisive (Ratio a) Source # | |||||||||
| (Ord a, EndoBased a, Integral a, Ring a) => Multiplicative (Ratio a) Source # | |||||||||
| (FromInteger a, Multiplicative a) => FromInteger (Ratio a) Source # | |||||||||
Defined in NumHask.Data.Rational Methods fromInteger :: Integer -> Ratio a Source # | |||||||||
| FromRational (Ratio Integer) Source # | |||||||||
Defined in NumHask.Data.Rational | |||||||||
| (FromIntegral a b, Multiplicative a) => FromIntegral (Ratio a) b Source # | |||||||||
Defined in NumHask.Data.Rational Methods fromIntegral :: b -> Ratio a Source # | |||||||||
| ToRatio (Ratio Integer) Integer Source # | |||||||||
| type Whole (Ratio a) Source # | |||||||||
Defined in NumHask.Data.Rational | |||||||||
| type Base (Ratio a) Source # | |||||||||
Defined in NumHask.Data.Rational | |||||||||
| type Mag (Ratio a) Source # | |||||||||
Defined in NumHask.Data.Rational | |||||||||
class ToRatio a b where Source #
toRatio is equivalent to Real in base, but is polymorphic in the Integral type.
>>>toRatio (3.1415927 :: Float) :: Ratio Integer13176795 :% 4194304
Instances
| ToRatio Int16 Integer Source # | |
| ToRatio Int32 Integer Source # | |
| ToRatio Int64 Integer Source # | |
| ToRatio Int8 Integer Source # | |
| ToRatio Word16 Integer Source # | |
| ToRatio Word32 Integer Source # | |
| ToRatio Word64 Integer Source # | |
| ToRatio Word8 Integer Source # | |
| ToRatio Integer Integer Source # | |
| ToRatio Natural Integer Source # | |
| ToRatio Double Integer Source # | |
| ToRatio Float Integer Source # | |
| ToRatio Int Integer Source # | |
| ToRatio Word Integer Source # | |
| ToRatio a b => ToRatio (Positive a) b Source # | |
| ToRatio (Ratio Integer) Integer Source # | |
| ToRatio a b => ToRatio (Wrapped a) b Source # | |
class FromRatio a b where Source #
Fractional in base splits into fromRatio and Field
>>>fromRatio (5 :% 2 :: Ratio Integer) :: Double2.5
class FromRational a where Source #
fromRational is special in two ways:
- numeric decimal literals (like "53.66") are interpreted as exactly "fromRational (53.66 :: GHC.Real.Ratio Integer)". The prelude version, GHC.Real.fromRational is used as default (or whatever is in scope if RebindableSyntax is set).
- The default rules in haskell2010 specify that contraints on
fromRationalneed to be in a formC v, where v is a Num or a subclass of Num.
So a type synonym of `type FromRational a = FromRatio a Integer` doesn't work well with type defaulting; hence the need for a separate class.
Methods
fromRational :: Rational -> a Source #
Instances
| FromRational Double Source # | |
Defined in NumHask.Data.Rational Methods fromRational :: Rational -> Double Source # | |
| FromRational Float Source # | |
Defined in NumHask.Data.Rational Methods fromRational :: Rational -> Float Source # | |
| FromRational a => FromRational (Positive a) Source # | |
Defined in NumHask.Data.Positive Methods fromRational :: Rational -> Positive a Source # | |
| FromRational (Ratio Integer) Source # | |
Defined in NumHask.Data.Rational | |
| FromRational a => FromRational (Wrapped a) Source # | |
Defined in NumHask.Data.Wrapped Methods fromRational :: Rational -> Wrapped a Source # | |
reduce :: (Ord a, Subtractive a, EndoBased a, Integral a) => a -> a -> Ratio a Source #
reduce normalises a ratio by dividing both numerator and denominator by
their greatest common divisor.
>>>reduce 72 606 :% 5
reduce a b == a :% b || b == zero
>>>reduce 72 60 == 72 :% 60True
>>>reduce (-4) 6 == (-4) :% 6True
gcd :: (Eq a, EndoBased a, Integral a) => a -> a -> a Source #
is the non-negative factor of both gcd x yx and y of which
every common factor of x and y is also a factor; for example
, gcd 4 2 = 2, gcd (-4) 6 = 2 = gcd 0 44. = gcd 0 00.
(That is, the common divisor that is "greatest" in the divisibility
preordering.)
Note: Since for signed fixed-width integer types, ,
the result may be negative if one of the arguments is abs minBound < 0 (and
necessarily is if the other is minBound0 or ) for such types.minBound
>>>gcd 72 6012
Exceptions
newtype NumHaskException Source #
A numhask exception.
Constructors
| NumHaskException | |
Fields | |
Instances
| Exception NumHaskException Source # | |
Defined in NumHask.Exception Methods toException :: NumHaskException -> SomeException # fromException :: SomeException -> Maybe NumHaskException # | |
| Show NumHaskException Source # | |
Defined in NumHask.Exception Methods showsPrec :: Int -> NumHaskException -> ShowS # show :: NumHaskException -> String # showList :: [NumHaskException] -> ShowS # | |
throw :: forall a e. (HasCallStack, Exception e) => e -> a #
Throw an exception. Exceptions may be thrown from purely
functional code, but may only be caught within the IO monad.
WARNING: You may want to use throwIO instead so that your pure code
stays exception-free.