numbers-3000.2.0.2: Various number types

Safe Haskell | Safe-Inferred
Language | Haskell98

Data.Number.Dif

Description

The `Dif` module contains a data type, `Dif`, that allows for automatic forward differentiation.

All the ideas are from Jerzy Karczmarczuk's work, see http://users.info.unicaen.fr/~karczma/arpap/diffalg.pdf.

A simple example, if we define

    foo x = x*x

then the function

    foo' = deriv foo

will behave as if its body was 2*x.

Synopsis

- data Dif a
- val :: Dif a -> a
- df :: (Num a, Eq a) => Dif a -> Dif a
- mkDif :: a -> Dif a -> Dif a
- dCon :: Num a => a -> Dif a
- dVar :: (Num a, Eq a) => a -> Dif a
- deriv :: (Num a, Num b, Eq a, Eq b) => (Dif a -> Dif b) -> a -> b
- unDif :: (Num a, Eq a) => (Dif a -> Dif b) -> a -> b

# Documentation

data Dif a Source #

The `Dif` type is the type of differentiable numbers. It's an instance of all the usual numeric classes. The computed derivative of a function is is correct except where the function is discontinuous, at these points the derivative should be a Dirac pulse, but it isn't.

The `Dif` numbers are printed with a trailing ~~ to indicate that there is a "tail" of derivatives.

#### Instances

Instances details

(Floating a, Eq a) => Floating (Dif a) Source # |

Instance details

Defined in Data.Number.Dif

Methods

pi :: Dif a Source #

exp :: Dif a -> Dif a Source #

log :: Dif a -> Dif a Source #

sqrt :: Dif a -> Dif a Source #

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

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

sin :: Dif a -> Dif a Source #

cos :: Dif a -> Dif a Source #

tan :: Dif a -> Dif a Source #

asin :: Dif a -> Dif a Source #

acos :: Dif a -> Dif a Source #

atan :: Dif a -> Dif a Source #

sinh :: Dif a -> Dif a Source #

cosh :: Dif a -> Dif a Source #

tanh :: Dif a -> Dif a Source #

asinh :: Dif a -> Dif a Source #

acosh :: Dif a -> Dif a Source #

atanh :: Dif a -> Dif a Source #

log1p :: Dif a -> Dif a Source #

expm1 :: Dif a -> Dif a Source #

log1pexp :: Dif a -> Dif a Source #

log1mexp :: Dif a -> Dif a Source #

RealFloat a => RealFloat (Dif a) Source # |

Instance details

Defined in Data.Number.Dif

Methods

floatRadix :: Dif a -> Integer Source #

floatDigits :: Dif a -> Int Source #

floatRange :: Dif a -> (Int, Int) Source #

decodeFloat :: Dif a -> (Integer, Int) Source #

encodeFloat :: Integer -> Int -> Dif a Source #

exponent :: Dif a -> Int Source #

significand :: Dif a -> Dif a Source #

scaleFloat :: Int -> Dif a -> Dif a Source #

isNaN :: Dif a -> Bool Source #

isInfinite :: Dif a -> Bool Source #

isDenormalized :: Dif a -> Bool Source #

isNegativeZero :: Dif a -> Bool Source #

isIEEE :: Dif a -> Bool Source #

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

(Num a, Eq a) => Num (Dif a) Source # |
Instance details Defined in Data.Number.Dif Methods (+) :: Dif a -> Dif a -> Dif a Source # (-) :: Dif a -> Dif a -> Dif a Source # (*) :: Dif a -> Dif a -> Dif a Source # negate :: Dif a -> Dif a Source # abs :: Dif a -> Dif a Source # signum :: Dif a -> Dif a Source # fromInteger :: Integer -> Dif a Source #
Read a => Read (Dif a) Source # |
Instance details Defined in Data.Number.Dif Methods readsPrec :: Int -> ReadS (Dif a) Source # readList :: ReadS [Dif a] Source # readPrec :: ReadPrec (Dif a) Source # readListPrec :: ReadPrec [Dif a] Source #
(Fractional a, Eq a) => Fractional (Dif a) Source # |
Instance details Defined in Data.Number.Dif Methods (/) :: Dif a -> Dif a -> Dif a Source # recip :: Dif a -> Dif a Source # fromRational :: Rational -> Dif a Source #
Real a => Real (Dif a) Source # |
Instance details Defined in Data.Number.Dif Methods toRational :: Dif a -> Rational Source #
RealFrac a => RealFrac (Dif a) Source # |
Instance details Defined in Data.Number.Dif Methods properFraction :: Integral b => Dif a -> (b, Dif a) Source # truncate :: Integral b => Dif a -> b Source # round :: Integral b => Dif a -> b Source # ceiling :: Integral b => Dif a -> b Source # floor :: Integral b => Dif a -> b Source #
Show a => Show (Dif a) Source # |
Instance details Defined in Data.Number.Dif Methods showsPrec :: Int -> Dif a -> ShowS Source # show :: Dif a -> String Source # showList :: [Dif a] -> ShowS Source #
Eq a => Eq (Dif a) Source # |
Instance details Defined in Data.Number.Dif Methods (==) :: Dif a -> Dif a -> Bool Source # (/=) :: Dif a -> Dif a -> Bool Source #
Ord a => Ord (Dif a) Source # |
Instance details Defined in Data.Number.Dif Methods compare :: Dif a -> Dif a -> Ordering Source # (<) :: Dif a -> Dif a -> Bool Source # (<=) :: Dif a -> Dif a -> Bool Source # (>) :: Dif a -> Dif a -> Bool Source # (>=) :: Dif a -> Dif a -> Bool Source # max :: Dif a -> Dif a -> Dif a Source # min :: Dif a -> Dif a -> Dif a Source #

val :: Dif a -> a Source #

The `val` function takes a `Dif` number back to a normal number, thus forgetting about all the derivatives.

df :: (Num a, Eq a) => Dif a -> Dif a Source #

The `df` takes a `Dif` number and returns its first derivative. The function can be iterated to to get higher derivaties.

mkDif :: a -> Dif a -> Dif a Source #

The `mkDif` takes a value and `Dif` value and makes a `Dif` number that has the given value as its normal value, and the `Dif` number as its derivatives.

dCon :: Num a => a -> Dif a Source #

The `dCon` function turns a normal number into a `Dif` number with the same value. Not that numeric literals do not need an explicit conversion due to the normal Haskell overloading of literals.

dVar :: (Num a, Eq a) => a -> Dif a Source #

The `dVar` function turns a number into a variable number. This is the number with with respect to which the derivaticve is computed.

deriv :: (Num a, Num b, Eq a, Eq b) => (Dif a -> Dif b) -> a -> b Source #

The `deriv` function is a simple utility to take the derivative of a (single argument) function. It is simply defined as

     deriv f = val . df . f . dVar

unDif :: (Num a, Eq a) => (Dif a -> Dif b) -> a -> b Source #

Convert a `Dif` function to an ordinary function.