| Safe Haskell | None |
|---|---|
| Language | GHC2024 |
NumHask.Algebra.Field
Description
field classes
Synopsis
- type SemiField a = (Distributive a, Divisive a)
- 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
- infinity :: SemiField a => a
- negInfinity :: Field a => a
- nan :: SemiField a => a
- class Field a => TrigField a where
- 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
Documentation
type SemiField a = (Distributive a, Divisive a) Source #
A Semifield is a field with no subtraction.
Since: 0.12
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
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
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 # | |
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