probability-polynomial-1.0.0.0: Probability distributions via piecewise polynomials
CopyrightPredictable Network Solutions Ltd. 2020-2024
LicenseBSD-3-Clause
Safe HaskellSafe-Inferred
LanguageHaskell2010

Numeric.Function.Piecewise

Description

 
Synopsis

Type

data Piecewise o Source #

A function defined piecewise on numerical intervals.

  • o = type of function on every piece e.g. polynomials or other specialized representations of functions
  • Domain o = numerical type for the number line, e.g. Rational or Double

A value f :: Piecewise o represents a function

eval f x = { 0           if -∞ <  x < x1
           { eval o1 x   if x1 <= x < x2
           { eval o2 x   if x2 <= x < x3
           { …
           { eval on x   if xn <= x < +∞

where x1, …, xn are points on the real number line (in strictly increasing order) and where o1, …, on are specialized representations functions, e.g. polynomials.

In other words, the value f represents a function that is defined piecewise on half-open intervals.

The function intervals returns the half-open intervals in the middle:

intervals f = [(x1,x2), (x2,x3), …, (xn-1, xn)]

No attempt is made to merge intervals if the piecewise objects are equal, e.g. the situation o1 == o2 may occur.

Instances

Instances details
Generic (Piecewise o) Source # 
Instance details

Defined in Numeric.Function.Piecewise

Associated Types

type Rep (Piecewise o) :: Type -> Type #

Methods

from :: Piecewise o -> Rep (Piecewise o) x #

to :: Rep (Piecewise o) x -> Piecewise o #

(Ord (Domain o), Num o) => Num (Piecewise o) Source #

Algebraic operations (+), (*) and negate on piecewise functions.

The functions abs and signum are defined using abs and signum for every piece.

TODO: fromInteger is undefined

Instance details

Defined in Numeric.Function.Piecewise

(Show (Domain o), Show o) => Show (Piecewise o) Source # 
Instance details

Defined in Numeric.Function.Piecewise

(NFData (Domain o), NFData o) => NFData (Piecewise o) Source # 
Instance details

Defined in Numeric.Function.Piecewise

Methods

rnf :: Piecewise o -> () #

(Function o, Num o, Ord (Domain o), Num (Codomain o)) => Function (Piecewise o) Source #

Evaluate a piecewise function at a point.

Instance details

Defined in Numeric.Function.Piecewise

Associated Types

type Domain (Piecewise o) Source #

type Codomain (Piecewise o) Source #

type Rep (Piecewise o) Source # 
Instance details

Defined in Numeric.Function.Piecewise

type Rep (Piecewise o)
type Codomain (Piecewise o) Source # 
Instance details

Defined in Numeric.Function.Piecewise

type Domain (Piecewise o) Source # 
Instance details

Defined in Numeric.Function.Piecewise

type Domain (Piecewise o) = Domain o

Basic operations

zero :: Piecewise o Source #

The function which is zero everywhere.

fromInterval :: (Ord (Domain o), Num o) => (Domain o, Domain o) -> o -> Piecewise o Source #

fromInterval (x1,x2) o creates a Piecewise function from a single function o by restricting it to the to half-open interval x1 <= x < x2. The result is zero outside this interval.

fromAscPieces :: Ord (Domain o) => [(Domain o, o)] -> Piecewise o Source #

Build a piecewise function from an ascending list of contiguous pieces.

The precondition (`map fst` of input list is ascending) is not checked.

toAscPieces :: Ord (Domain o) => Piecewise o -> [(Domain o, o)] Source #

Convert the piecewise function to a list of contiguous pieces where the starting points of the pieces are in ascending order.

intervals :: Piecewise o -> [(Domain o, Domain o)] Source #

Intervals on which the piecewise function is defined, in sequence. The last half-open interval, xn <= x < +∞, is omitted.

Structure

mapPieces :: Domain o ~ Domain o' => (o -> o') -> Piecewise o -> Piecewise o' Source #

Map the objects of pieces.

mergeBy :: Num o => (o -> o -> Bool) -> Piecewise o -> Piecewise o Source #

Merge all adjacent pieces whose functions are considered equal by the given predicate.

trim :: (Eq o, Num o) => Piecewise o -> Piecewise o Source #

Merge all adjacent pieces whose functions are equal according to (==).

Numerical

evaluate :: (Function o, Num o, Ord (Domain o), Num (Codomain o)) => Piecewise o -> Domain o -> Codomain o Source #

Evaluate the piecewise function at a point. See Piecewise for the semantics.

translateWith :: (Ord (Domain o), Num (Domain o), Num o) => (Domain o -> o -> o) -> Domain o -> Piecewise o -> Piecewise o Source #

Translate a piecewise function, given a way to translate each piece.

 eval (translate' y o) = eval o (x - y)
   implies
   eval (translateWith translate' y p) = eval p (x - y)

Zip

zipPointwise Source #

Arguments

:: (Ord (Domain o), Num o) 
=> (o -> o -> o)
f
-> Piecewise o 
-> Piecewise o 
-> Piecewise o 

Combine two piecewise functions by combining the pieces with a pointwise operation that preserves 0.

For example, (+) and (*) are pointwise operations on functions, but convolution is not a pointwise operation.

Preconditions on the argument f:

  • f 0 0 = 0
  • f is a pointwise operations on functions, e.g. commutes with pointwise evaluation.

The preconditions are not checked!