    -- | The 'Data.Number.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.
    --
    module Data.Number.Dif(Dif, val, df, mkDif, dCon, dVar, deriv, unDif) where

    -- |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.
    data Dif a = D !a (Dif a) | C !a

    -- |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.
    dCon :: (Num a) => a -> Dif a
    dCon :: forall a. Num a => a -> Dif a
    dCon a
    x = a -> Dif a
    forall a. a -> Dif a
    C a
    x

    -- |The 'dVar' function turns a number into a variable
    -- number.  This is the number with with respect to which
    -- the derivaticve is computed.
    dVar :: (Num a, Eq a) => a -> Dif a
    dVar :: forall a. (Num a, Eq a) => a -> Dif a
    dVar a
    x = a -> Dif a -> Dif a
    forall a. a -> Dif a -> Dif a
    D a
    x Dif a
    1

    -- |The 'df' takes a 'Dif' number and returns its first
    -- derivative.  The function can be iterated to to get
    -- higher derivaties.
    df :: (Num a, Eq a) => Dif a -> Dif a
    df :: forall a. (Num a, Eq a) => Dif a -> Dif a
    df (D a
    _ Dif a
    x') = Dif a
    x'
    df (C a
    _   ) = Dif a
    0

    -- |The 'val' function takes a 'Dif' number back to a normal
    -- number, thus forgetting about all the derivatives.
    val :: Dif a -> a
    val :: forall a. Dif a -> a
    val (D a
    x Dif a
    _) = a
    x
    val (C a
    x  ) = a
    x

    -- |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.
    mkDif :: a -> Dif a -> Dif a
    mkDif :: forall a. a -> Dif a -> Dif a
    mkDif = a -> Dif a -> Dif a
    forall a. a -> Dif a -> Dif a
    D

    -- |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
    --
    deriv :: (Num a, Num b, Eq a, Eq b) => (Dif a -> Dif b) -> (a -> b)
    deriv :: forall a b.
    (Num a, Num b, Eq a, Eq b) =>
    (Dif a -> Dif b) -> a -> b
    deriv Dif a -> Dif b
    f = Dif b -> b
    forall a. Dif a -> a
    val (Dif b -> b) -> (a -> Dif b) -> a -> b
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Dif b -> Dif b
    forall a. (Num a, Eq a) => Dif a -> Dif a
    df (Dif b -> Dif b) -> (a -> Dif b) -> a -> Dif b
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Dif a -> Dif b
    f (Dif a -> Dif b) -> (a -> Dif a) -> a -> Dif b
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . a -> Dif a
    forall a. (Num a, Eq a) => a -> Dif a
    dVar

    -- |Convert a 'Dif' function to an ordinary function.
    unDif :: (Num a, Eq a) => (Dif a -> Dif b) -> (a -> b)
    unDif :: forall a b. (Num a, Eq a) => (Dif a -> Dif b) -> a -> b
    unDif Dif a -> Dif b
    f = Dif b -> b
    forall a. Dif a -> a
    val (Dif b -> b) -> (a -> Dif b) -> a -> b
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Dif a -> Dif b
    f (Dif a -> Dif b) -> (a -> Dif a) -> a -> Dif b
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . a -> Dif a
    forall a. (Num a, Eq a) => a -> Dif a
    dVar

    instance (Show a) => Show (Dif a) where
        show :: Dif a -> String
    show Dif a
    x = a -> String
    forall a. Show a => a -> String
    show (Dif a -> a
    forall a. Dif a -> a
    val Dif a
    x) String -> ShowS
    forall a. [a] -> [a] -> [a]
    ++ String
    "~~"

    instance (Read a) => Read (Dif a) where
        readsPrec :: Int -> ReadS (Dif a)
    readsPrec Int
    p String
    s = [(a -> Dif a
    forall a. a -> Dif a
    C a
    x, String
    s') | (a
    x, String
    s') <- Int -> ReadS a
    forall a. Read a => Int -> ReadS a
    readsPrec Int
    p String
    s]

    instance (Eq a) => Eq (Dif a) where
        Dif a
    x == :: Dif a -> Dif a -> Bool
    == Dif a
    y  =  Dif a -> a
    forall a. Dif a -> a
    val Dif a
    x a -> a -> Bool
    forall a. Eq a => a -> a -> Bool
    == Dif a -> a
    forall a. Dif a -> a
    val Dif a
    y

    instance (Ord a) => Ord (Dif a) where
        Dif a
    x compare :: Dif a -> Dif a -> Ordering
    `compare` Dif a
    y  =  Dif a -> a
    forall a. Dif a -> a
    val Dif a
    x a -> a -> Ordering
    forall a. Ord a => a -> a -> Ordering
    `compare` Dif a -> a
    forall a. Dif a -> a
    val Dif a
    y

    instance (Num a, Eq a) => Num (Dif a) where
        (C a
    x)    + :: Dif a -> Dif a -> Dif a
    + (C a
    y)         =  a -> Dif a
    forall a. a -> Dif a
    C (a
    x a -> a -> a
    forall a. Num a => a -> a -> a
    + a
    y)
        (C a
    x)    + (D a
    y Dif a
    y')      =  a -> Dif a -> Dif a
    forall a. a -> Dif a -> Dif a
    D (a
    x a -> a -> a
    forall a. Num a => a -> a -> a
    + a
    y) Dif a
    y'
        (D a
    x Dif a
    x') + (C a
    y)         =  a -> Dif a -> Dif a
    forall a. a -> Dif a -> Dif a
    D (a
    x a -> a -> a
    forall a. Num a => a -> a -> a
    + a
    y) Dif a
    x'
        (D a
    x Dif a
    x') + (D a
    y Dif a
    y')      =  a -> Dif a -> Dif a
    forall a. a -> Dif a -> Dif a
    D (a
    x a -> a -> a
    forall a. Num a => a -> a -> a
    + a
    y) (Dif a
    x' Dif a -> Dif a -> Dif a
    forall a. Num a => a -> a -> a
    + Dif a
    y')

        (C a
    x)    - :: Dif a -> Dif a -> Dif a
    - (C a
    y)         =  a -> Dif a
    forall a. a -> Dif a
    C (a
    x a -> a -> a
    forall a. Num a => a -> a -> a
    - a
    y)
        (C a
    x)    - (D a
    y Dif a
    y')      =  a -> Dif a -> Dif a
    forall a. a -> Dif a -> Dif a
    D (a
    x a -> a -> a
    forall a. Num a => a -> a -> a
    - a
    y) (-Dif a
    y')
        (D a
    x Dif a
    x') - (C a
    y)         =  a -> Dif a -> Dif a
    forall a. a -> Dif a -> Dif a
    D (a
    x a -> a -> a
    forall a. Num a => a -> a -> a
    - a
    y) Dif a
    x'
        (D a
    x Dif a
    x') - (D a
    y Dif a
    y')      =  a -> Dif a -> Dif a
    forall a. a -> Dif a -> Dif a
    D (a
    x a -> a -> a
    forall a. Num a => a -> a -> a
    - a
    y) (Dif a
    x' Dif a -> Dif a -> Dif a
    forall a. Num a => a -> a -> a
    - Dif a
    y')

        (C a
    0)      * :: Dif a -> Dif a -> Dif a
    * Dif a
    _           =  a -> Dif a
    forall a. a -> Dif a
    C a
    0
        Dif a
    _          * (C a
    0)       =  a -> Dif a
    forall a. a -> Dif a
    C a
    0
        (C a
    x)      * (C a
    y)       =  a -> Dif a
    forall a. a -> Dif a
    C (a
    x a -> a -> a
    forall a. Num a => a -> a -> a
    * a
    y)
        p :: Dif a
    p@(C a
    x)    * (D a
    y Dif a
    y')    =  a -> Dif a -> Dif a
    forall a. a -> Dif a -> Dif a
    D (a
    x a -> a -> a
    forall a. Num a => a -> a -> a
    * a
    y) (Dif a
    p Dif a -> Dif a -> Dif a
    forall a. Num a => a -> a -> a
    * Dif a
    y')
        (D a
    x Dif a
    x')   * q :: Dif a
    q@(C a
    y)     =  a -> Dif a -> Dif a
    forall a. a -> Dif a -> Dif a
    D (a
    x a -> a -> a
    forall a. Num a => a -> a -> a
    * a
    y) (Dif a
    x' Dif a -> Dif a -> Dif a
    forall a. Num a => a -> a -> a
    * Dif a
    q)
        p :: Dif a
    p@(D a
    x Dif a
    x') * q :: Dif a
    q@(D a
    y Dif a
    y')  =  a -> Dif a -> Dif a
    forall a. a -> Dif a -> Dif a
    D (a
    x a -> a -> a
    forall a. Num a => a -> a -> a
    * a
    y) (Dif a
    x' Dif a -> Dif a -> Dif a
    forall a. Num a => a -> a -> a
    * Dif a
    q Dif a -> Dif a -> Dif a
    forall a. Num a => a -> a -> a
    + Dif a
    p Dif a -> Dif a -> Dif a
    forall a. Num a => a -> a -> a
    * Dif a
    y')

        negate :: Dif a -> Dif a
    negate (C a
    x)             =  a -> Dif a
    forall a. a -> Dif a
    C (a -> a
    forall a. Num a => a -> a
    negate a
    x)
        negate (D a
    x Dif a
    x')          =  a -> Dif a -> Dif a
    forall a. a -> Dif a -> Dif a
    D (a -> a
    forall a. Num a => a -> a
    negate a
    x) (Dif a -> Dif a
    forall a. Num a => a -> a
    negate Dif a
    x')

        fromInteger :: Integer -> Dif a
    fromInteger Integer
    i            =  a -> Dif a
    forall a. a -> Dif a
    C (Integer -> a
    forall a. Num a => Integer -> a
    fromInteger Integer
    i)

        abs :: Dif a -> Dif a
    abs (C a
    x)                =  a -> Dif a
    forall a. a -> Dif a
    C (a -> a
    forall a. Num a => a -> a
    abs a
    x)
        abs p :: Dif a
    p@(D a
    x Dif a
    x')           =  a -> Dif a -> Dif a
    forall a. a -> Dif a -> Dif a
    D (a -> a
    forall a. Num a => a -> a
    abs a
    x) (Dif a -> Dif a
    forall a. Num a => a -> a
    signum Dif a
    p Dif a -> Dif a -> Dif a
    forall a. Num a => a -> a -> a
    * Dif a
    x')

        -- The derivative of the signum function is (2*) the Dirac impulse,
        -- but there's not really any good way to encode this.
        -- We could do it by +Infinity (1/0) at 0.
        signum :: Dif a -> Dif a
    signum (C a
    x)             =  a -> Dif a
    forall a. a -> Dif a
    C (a -> a
    forall a. Num a => a -> a
    signum a
    x)
        signum (D a
    x Dif a
    _)           =  a -> Dif a
    forall a. a -> Dif a
    C (a -> a
    forall a. Num a => a -> a
    signum a
    x)

    instance (Fractional a, Eq a) => Fractional (Dif a) where
        recip :: Dif a -> Dif a
    recip (C a
    x)    = a -> Dif a
    forall a. a -> Dif a
    C (a -> a
    forall a. Fractional a => a -> a
    recip a
    x)
        recip (D a
    x Dif a
    x') = Dif a
    ip
            where ip :: Dif a
    ip = a -> Dif a -> Dif a
    forall a. a -> Dif a -> Dif a
    D (a -> a
    forall a. Fractional a => a -> a
    recip a
    x) (-Dif a
    x' Dif a -> Dif a -> Dif a
    forall a. Num a => a -> a -> a
    * Dif a
    ip Dif a -> Dif a -> Dif a
    forall a. Num a => a -> a -> a
    * Dif a
    ip)
        fromRational :: Rational -> Dif a
    fromRational Rational
    r = a -> Dif a
    forall a. a -> Dif a
    C (Rational -> a
    forall a. Fractional a => Rational -> a
    fromRational Rational
    r)

    lift :: (Num a, Eq a) => [a -> a] -> Dif a -> Dif a
    lift :: forall a. (Num a, Eq a) => [a -> a] -> Dif a -> Dif a
    lift (a -> a
    f : [a -> a]
    _) (C a
    x) = a -> Dif a
    forall a. a -> Dif a
    C (a -> a
    f a
    x)
    lift (a -> a
    f : [a -> a]
    f') p :: Dif a
    p@(D a
    x Dif a
    x') = a -> Dif a -> Dif a
    forall a. a -> Dif a -> Dif a
    D (a -> a
    f a
    x) (Dif a
    x' Dif a -> Dif a -> Dif a
    forall a. Num a => a -> a -> a
    * [a -> a] -> Dif a -> Dif a
    forall a. (Num a, Eq a) => [a -> a] -> Dif a -> Dif a
    lift [a -> a]
    f' Dif a
    p)
    lift [a -> a]
    _ Dif a
    _ = String -> Dif a
    forall a. HasCallStack => String -> a
    error String
    "lift"

    instance (Floating a, Eq a) => Floating (Dif a) where
        pi :: Dif a
    pi               = a -> Dif a
    forall a. a -> Dif a
    C a
    forall a. Floating a => a
    pi

        exp :: Dif a -> Dif a
    exp (C a
    x)        = a -> Dif a
    forall a. a -> Dif a
    C (a -> a
    forall a. Floating a => a -> a
    exp a
    x)
        exp (D a
    x Dif a
    x')     = Dif a
    r where r :: Dif a
    r = a -> Dif a -> Dif a
    forall a. a -> Dif a -> Dif a
    D (a -> a
    forall a. Floating a => a -> a
    exp a
    x) (Dif a
    x' Dif a -> Dif a -> Dif a
    forall a. Num a => a -> a -> a
    * Dif a
    r)

        log :: Dif a -> Dif a
    log (C a
    x)        = a -> Dif a
    forall a. a -> Dif a
    C (a -> a
    forall a. Floating a => a -> a
    log a
    x)
        log p :: Dif a
    p@(D a
    x Dif a
    x')   = a -> Dif a -> Dif a
    forall a. a -> Dif a -> Dif a
    D (a -> a
    forall a. Floating a => a -> a
    log a
    x) (Dif a
    x' Dif a -> Dif a -> Dif a
    forall a. Fractional a => a -> a -> a
    / Dif a
    p)

        sqrt :: Dif a -> Dif a
    sqrt (C a
    x)       = a -> Dif a
    forall a. a -> Dif a
    C (a -> a
    forall a. Floating a => a -> a
    sqrt a
    x)
        sqrt (D a
    x Dif a
    x')    = Dif a
    r where r :: Dif a
    r = a -> Dif a -> Dif a
    forall a. a -> Dif a -> Dif a
    D (a -> a
    forall a. Floating a => a -> a
    sqrt a
    x) (Dif a
    x' Dif a -> Dif a -> Dif a
    forall a. Fractional a => a -> a -> a
    / (Dif a
    2 Dif a -> Dif a -> Dif a
    forall a. Num a => a -> a -> a
    * Dif a
    r))

        sin :: Dif a -> Dif a
    sin              = [a -> a] -> Dif a -> Dif a
    forall a. (Num a, Eq a) => [a -> a] -> Dif a -> Dif a
    lift ([a -> a] -> [a -> a]
    forall a. HasCallStack => [a] -> [a]
    cycle [a -> a
    forall a. Floating a => a -> a
    sin, a -> a
    forall a. Floating a => a -> a
    cos, a -> a
    forall a. Num a => a -> a
    negate (a -> a) -> (a -> a) -> a -> a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . a -> a
    forall a. Floating a => a -> a
    sin, a -> a
    forall a. Num a => a -> a
    negate (a -> a) -> (a -> a) -> a -> a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . a -> a
    forall a. Floating a => a -> a
    cos])
        cos :: Dif a -> Dif a
    cos              = [a -> a] -> Dif a -> Dif a
    forall a. (Num a, Eq a) => [a -> a] -> Dif a -> Dif a
    lift ([a -> a] -> [a -> a]
    forall a. HasCallStack => [a] -> [a]
    cycle [a -> a
    forall a. Floating a => a -> a
    cos, a -> a
    forall a. Num a => a -> a
    negate (a -> a) -> (a -> a) -> a -> a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . a -> a
    forall a. Floating a => a -> a
    sin, a -> a
    forall a. Num a => a -> a
    negate (a -> a) -> (a -> a) -> a -> a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . a -> a
    forall a. Floating a => a -> a
    cos, a -> a
    forall a. Floating a => a -> a
    sin])

        acos :: Dif a -> Dif a
    acos (C a
    x)       = a -> Dif a
    forall a. a -> Dif a
    C (a -> a
    forall a. Floating a => a -> a
    acos a
    x)
        acos p :: Dif a
    p@(D a
    x Dif a
    x')  = a -> Dif a -> Dif a
    forall a. a -> Dif a -> Dif a
    D (a -> a
    forall a. Floating a => a -> a
    acos a
    x) (-Dif a
    x' Dif a -> Dif a -> Dif a
    forall a. Fractional a => a -> a -> a
    / Dif a -> Dif a
    forall a. Floating a => a -> a
    sqrt(Dif a
    1 Dif a -> Dif a -> Dif a
    forall a. Num a => a -> a -> a
    - Dif a
    pDif a -> Dif a -> Dif a
    forall a. Num a => a -> a -> a
    *Dif a
    p))
        asin :: Dif a -> Dif a
    asin (C a
    x)       = a -> Dif a
    forall a. a -> Dif a
    C (a -> a
    forall a. Floating a => a -> a
    asin a
    x)
        asin p :: Dif a
    p@(D a
    x Dif a
    x')  = a -> Dif a -> Dif a
    forall a. a -> Dif a -> Dif a
    D (a -> a
    forall a. Floating a => a -> a
    asin a
    x) ( Dif a
    x' Dif a -> Dif a -> Dif a
    forall a. Fractional a => a -> a -> a
    / Dif a -> Dif a
    forall a. Floating a => a -> a
    sqrt(Dif a
    1 Dif a -> Dif a -> Dif a
    forall a. Num a => a -> a -> a
    - Dif a
    pDif a -> Dif a -> Dif a
    forall a. Num a => a -> a -> a
    *Dif a
    p))
        atan :: Dif a -> Dif a
    atan (C a
    x)       = a -> Dif a
    forall a. a -> Dif a
    C (a -> a
    forall a. Floating a => a -> a
    atan a
    x)
        atan p :: Dif a
    p@(D a
    x Dif a
    x')  = a -> Dif a -> Dif a
    forall a. a -> Dif a -> Dif a
    D (a -> a
    forall a. Floating a => a -> a
    atan a
    x) ( Dif a
    x' Dif a -> Dif a -> Dif a
    forall a. Fractional a => a -> a -> a
    / (Dif a
    pDif a -> Dif a -> Dif a
    forall a. Num a => a -> a -> a
    *Dif a
    p Dif a -> Dif a -> Dif a
    forall a. Num a => a -> a -> a
    - Dif a
    1))

        sinh :: Dif a -> Dif a
    sinh Dif a
    x           = (Dif a -> Dif a
    forall a. Floating a => a -> a
    exp Dif a
    x Dif a -> Dif a -> Dif a
    forall a. Num a => a -> a -> a
    - Dif a -> Dif a
    forall a. Floating a => a -> a
    exp (-Dif a
    x)) Dif a -> Dif a -> Dif a
    forall a. Fractional a => a -> a -> a
    / Dif a
    2
        cosh :: Dif a -> Dif a
    cosh Dif a
    x           = (Dif a -> Dif a
    forall a. Floating a => a -> a
    exp Dif a
    x Dif a -> Dif a -> Dif a
    forall a. Num a => a -> a -> a
    + Dif a -> Dif a
    forall a. Floating a => a -> a
    exp (-Dif a
    x)) Dif a -> Dif a -> Dif a
    forall a. Fractional a => a -> a -> a
    / Dif a
    2
        asinh :: Dif a -> Dif a
    asinh Dif a
    x          = Dif a -> Dif a
    forall a. Floating a => a -> a
    log (Dif a
    x Dif a -> Dif a -> Dif a
    forall a. Num a => a -> a -> a
    + Dif a -> Dif a
    forall a. Floating a => a -> a
    sqrt (Dif a
    xDif a -> Dif a -> Dif a
    forall a. Num a => a -> a -> a
    *Dif a
    x Dif a -> Dif a -> Dif a
    forall a. Num a => a -> a -> a
    + Dif a
    1))
        acosh :: Dif a -> Dif a
    acosh Dif a
    x          = Dif a -> Dif a
    forall a. Floating a => a -> a
    log (Dif a
    x Dif a -> Dif a -> Dif a
    forall a. Num a => a -> a -> a
    + Dif a -> Dif a
    forall a. Floating a => a -> a
    sqrt (Dif a
    xDif a -> Dif a -> Dif a
    forall a. Num a => a -> a -> a
    *Dif a
    x Dif a -> Dif a -> Dif a
    forall a. Num a => a -> a -> a
    - Dif a
    1))
        atanh :: Dif a -> Dif a
    atanh Dif a
    x          = (Dif a -> Dif a
    forall a. Floating a => a -> a
    log (Dif a
    1 Dif a -> Dif a -> Dif a
    forall a. Num a => a -> a -> a
    + Dif a
    x) Dif a -> Dif a -> Dif a
    forall a. Num a => a -> a -> a
    - Dif a -> Dif a
    forall a. Floating a => a -> a
    log (Dif a
    1 Dif a -> Dif a -> Dif a
    forall a. Num a => a -> a -> a
    - Dif a
    x)) Dif a -> Dif a -> Dif a
    forall a. Fractional a => a -> a -> a
    / Dif a
    2

    instance (Real a) => Real (Dif a) where
        toRational :: Dif a -> Rational
    toRational = a -> Rational
    forall a. Real a => a -> Rational
    toRational (a -> Rational) -> (Dif a -> a) -> Dif a -> Rational
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Dif a -> a
    forall a. Dif a -> a
    val

    instance (RealFrac a) => RealFrac (Dif a) where
        -- Second component should have an impulse derivative.
        properFraction :: forall b. Integral b => Dif a -> (b, Dif a)
    properFraction Dif a
    x = (b
    i, Dif a
    x Dif a -> Dif a -> Dif a
    forall a. Num a => a -> a -> a
    - b -> Dif a
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral b
    i) where (b
    i, a
    _) = a -> (b, a)
    forall b. Integral b => a -> (b, a)
    forall a b. (RealFrac a, Integral b) => a -> (b, a)
    properFraction (Dif a -> a
    forall a. Dif a -> a
    val Dif a
    x)
        truncate :: forall b. Integral b => Dif a -> b
    truncate = a -> b
    forall b. Integral b => a -> b
    forall a b. (RealFrac a, Integral b) => a -> b
    truncate (a -> b) -> (Dif a -> a) -> Dif a -> b
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Dif a -> a
    forall a. Dif a -> a
    val
        round :: forall b. Integral b => Dif a -> b
    round    = a -> b
    forall b. Integral b => a -> b
    forall a b. (RealFrac a, Integral b) => a -> b
    round    (a -> b) -> (Dif a -> a) -> Dif a -> b
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Dif a -> a
    forall a. Dif a -> a
    val
        ceiling :: forall b. Integral b => Dif a -> b
    ceiling  = a -> b
    forall b. Integral b => a -> b
    forall a b. (RealFrac a, Integral b) => a -> b
    ceiling  (a -> b) -> (Dif a -> a) -> Dif a -> b
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Dif a -> a
    forall a. Dif a -> a
    val
        floor :: forall b. Integral b => Dif a -> b
    floor    = a -> b
    forall b. Integral b => a -> b
    forall a b. (RealFrac a, Integral b) => a -> b
    floor    (a -> b) -> (Dif a -> a) -> Dif a -> b
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Dif a -> a
    forall a. Dif a -> a
    val

    -- Partial definition on purpose, more could be defined.
    instance (RealFloat a) => RealFloat (Dif a) where
        floatRadix :: Dif a -> Integer
    floatRadix = a -> Integer
    forall a. RealFloat a => a -> Integer
    floatRadix (a -> Integer) -> (Dif a -> a) -> Dif a -> Integer
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Dif a -> a
    forall a. Dif a -> a
    val
        floatDigits :: Dif a -> Int
    floatDigits = a -> Int
    forall a. RealFloat a => a -> Int
    floatDigits (a -> Int) -> (Dif a -> a) -> Dif a -> Int
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Dif a -> a
    forall a. Dif a -> a
    val
        floatRange :: Dif a -> (Int, Int)
    floatRange  = a -> (Int, Int)
    forall a. RealFloat a => a -> (Int, Int)
    floatRange (a -> (Int, Int)) -> (Dif a -> a) -> Dif a -> (Int, Int)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Dif a -> a
    forall a. Dif a -> a
    val
        exponent :: Dif a -> Int
    exponent Dif a
    _ = Int
    0
        scaleFloat :: Int -> Dif a -> Dif a
    scaleFloat Int
    0 Dif a
    x = Dif a
    x
        isNaN :: Dif a -> Bool
    isNaN = a -> Bool
    forall a. RealFloat a => a -> Bool
    isNaN (a -> Bool) -> (Dif a -> a) -> Dif a -> Bool
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Dif a -> a
    forall a. Dif a -> a
    val
        isInfinite :: Dif a -> Bool
    isInfinite = a -> Bool
    forall a. RealFloat a => a -> Bool
    isInfinite (a -> Bool) -> (Dif a -> a) -> Dif a -> Bool
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Dif a -> a
    forall a. Dif a -> a
    val
        isDenormalized :: Dif a -> Bool
    isDenormalized = a -> Bool
    forall a. RealFloat a => a -> Bool
    isDenormalized (a -> Bool) -> (Dif a -> a) -> Dif a -> Bool
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Dif a -> a
    forall a. Dif a -> a
    val
        isNegativeZero :: Dif a -> Bool
    isNegativeZero = a -> Bool
    forall a. RealFloat a => a -> Bool
    isNegativeZero (a -> Bool) -> (Dif a -> a) -> Dif a -> Bool
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Dif a -> a
    forall a. Dif a -> a
    val
        isIEEE :: Dif a -> Bool
    isIEEE = a -> Bool
    forall a. RealFloat a => a -> Bool
    isIEEE (a -> Bool) -> (Dif a -> a) -> Dif a -> Bool
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Dif a -> a
    forall a. Dif a -> a
    val
        -- Set these to undefined rather than omit them to avoid compiler
        -- warnings.
        decodeFloat :: Dif a -> (Integer, Int)
    decodeFloat = Dif a -> (Integer, Int)
    forall a. HasCallStack => a
    undefined
        encodeFloat :: Integer -> Int -> Dif a
    encodeFloat = Integer -> Int -> Dif a
    forall a. HasCallStack => a
    undefined