numhask-0.10.1.1: A numeric class hierarchy.
Safe HaskellSafe-Inferred
LanguageHaskell2010

NumHask.Algebra.Field

Description

Field classes

Synopsis

Documentation

class (Distributive a, Subtractive a, Divisive a) => Field 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

Instances

Instances details
Field Double Source # 
Instance details

Defined in NumHask.Algebra.Field

Field Float Source # 
Instance details

Defined in NumHask.Algebra.Field

Field a => Field (Complex a) Source # 
Instance details

Defined in NumHask.Data.Complex

(Ord a, Signed a, Integral a, Ring a) => Field (Ratio a) Source # 
Instance details

Defined in NumHask.Data.Rational

Field b => Field (a -> b) Source # 
Instance details

Defined in NumHask.Algebra.Field

class Field a => ExpField a where Source #

A hyperbolic field class

\a -> a < zero || (sqrt . (**2)) a == a
\a -> a < zero || (log . exp) a ~= a
\a b -> (b < zero) || a <= zero || a == 1 || abs (a ** logBase a b - b) < 10 * epsilon

Minimal complete definition

exp, log

Methods

exp :: a -> a Source #

log :: a -> a Source #

(**) :: a -> a -> a Source #

logBase :: a -> a -> a Source #

log to the base of

>>> logBase 2 8
2.9999999999999996

sqrt :: a -> a Source #

square root

>>> sqrt 4
2.0

Instances

Instances details
ExpField Double Source # 
Instance details

Defined in NumHask.Algebra.Field

ExpField Float Source # 
Instance details

Defined in NumHask.Algebra.Field

(Ord a, TrigField a, ExpField a) => ExpField (Complex a) Source # 
Instance details

Defined in NumHask.Data.Complex

ExpField b => ExpField (a -> b) Source # 
Instance details

Defined in NumHask.Algebra.Field

Methods

exp :: (a -> b) -> a -> b Source #

log :: (a -> b) -> a -> b Source #

(**) :: (a -> b) -> (a -> b) -> a -> b Source #

logBase :: (a -> b) -> (a -> b) -> a -> b Source #

sqrt :: (a -> b) -> a -> b Source #

class (Field a, Multiplicative b, Additive b) => QuotientField a b where Source #

Conversion from a Field to a Ring

See Field of fractions

\a -> a - one < floor a <= a <= ceiling a < a + one
(\a -> a - one < fromIntegral (floor a :: Int) && fromIntegral (floor a :: Int) <= a && a <= fromIntegral (ceiling a :: Int) && fromIntegral (ceiling a :: Int) <= a + one) :: Double -> Bool
\a -> (round a :: Int) ~= (floor (a + half) :: Int)

Minimal complete definition

properFraction

Methods

properFraction :: a -> (b, a) Source #

round :: a -> b Source #

round to the nearest integral

Exact ties are managed by rounding down ties if the whole component is even.

>>> round (1.5 :: Double) :: Int
2
>>> round (2.5 :: Double) :: Int
2

default round :: (Ord a, Ord b, Subtractive b, Integral b) => a -> b Source #

ceiling :: a -> b Source #

supply the next upper whole component

>>> ceiling (1.001 :: Double) :: Int
2

default ceiling :: Ord a => a -> b Source #

floor :: a -> b Source #

supply the previous lower whole component

>>> floor (1.001 :: Double) :: Int
1

default floor :: (Ord a, Subtractive b) => a -> b Source #

truncate :: a -> b Source #

supply the whole component closest to zero

>>> floor (-1.001 :: Double) :: Int
-2
>>> truncate (-1.001 :: Double) :: Int
-1

default truncate :: Ord a => a -> b Source #

Instances

Instances details
QuotientField Double Integer Source # 
Instance details

Defined in NumHask.Algebra.Field

QuotientField Double Int Source # 
Instance details

Defined in NumHask.Algebra.Field

QuotientField Float Integer Source # 
Instance details

Defined in NumHask.Algebra.Field

QuotientField Float Int Source # 
Instance details

Defined in NumHask.Algebra.Field

(Ord a, Ord b, Signed a, Integral a, Ring a, Signed b, Subtractive b, Integral b, FromIntegral b a) => QuotientField (Ratio a) b Source # 
Instance details

Defined in NumHask.Data.Rational

Methods

properFraction :: Ratio a -> (b, Ratio a) Source #

round :: Ratio a -> b Source #

ceiling :: Ratio a -> b Source #

floor :: Ratio a -> b Source #

truncate :: Ratio a -> b Source #

QuotientField b c => QuotientField (a -> b) (a -> c) Source # 
Instance details

Defined in NumHask.Algebra.Field

Methods

properFraction :: (a -> b) -> (a -> c, a -> b) Source #

round :: (a -> b) -> a -> c Source #

ceiling :: (a -> b) -> a -> c Source #

floor :: (a -> b) -> a -> c Source #

truncate :: (a -> b) -> a -> c Source #

infinity :: Field a => a Source #

infinity is defined for any Field.

>>> one / zero + infinity
Infinity
>>> infinity + 1
Infinity

negInfinity :: Field a => a Source #

negative infinity

>>> negInfinity + infinity
NaN

nan :: Field a => a Source #

nan is defined as zero/zero

but note the (social) law:

>>> nan == zero / zero
False

class Field a => TrigField a where Source #

Trigonometric Field

The list of laws is quite long: trigonometric identities

Minimal complete definition

pi, sin, cos, asin, acos, atan, atan2, sinh, cosh, asinh, acosh, atanh

Methods

pi :: a Source #

sin :: a -> a Source #

cos :: a -> a Source #

tan :: a -> a Source #

asin :: a -> a Source #

acos :: a -> a Source #

atan :: a -> a Source #

atan2 :: a -> a -> a Source #

sinh :: a -> a Source #

cosh :: a -> a Source #

tanh :: a -> a Source #

asinh :: a -> a Source #

acosh :: a -> a Source #

atanh :: a -> a Source #

Instances

Instances details
TrigField Double Source # 
Instance details

Defined in NumHask.Algebra.Field

TrigField Float Source # 
Instance details

Defined in NumHask.Algebra.Field

TrigField b => TrigField (a -> b) Source # 
Instance details

Defined in NumHask.Algebra.Field

Methods

pi :: a -> b Source #

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 #

acosh :: (a -> b) -> a -> b Source #

atanh :: (a -> b) -> a -> b Source #

half :: Field a => a Source #

A half is a Field because it requires addition, multiplication and division.

>>> half :: Double
0.5