Copyright | Predictable Network Solutions Ltd. 2020-2024 |
---|---|
License | BSD-3-Clause |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Numeric.Function.Piecewise
Description
Synopsis
- data Piecewise o
- zero :: Piecewise o
- fromInterval :: (Ord (Domain o), Num o) => (Domain o, Domain o) -> o -> Piecewise o
- fromAscPieces :: Ord (Domain o) => [(Domain o, o)] -> Piecewise o
- toAscPieces :: Ord (Domain o) => Piecewise o -> [(Domain o, o)]
- intervals :: Piecewise o -> [(Domain o, Domain o)]
- mapPieces :: Domain o ~ Domain o' => (o -> o') -> Piecewise o -> Piecewise o'
- mergeBy :: Num o => (o -> o -> Bool) -> Piecewise o -> Piecewise o
- trim :: (Eq o, Num o) => Piecewise o -> Piecewise o
- evaluate :: (Function o, Num o, Ord (Domain o), Num (Codomain o)) => Piecewise o -> Domain o -> Codomain o
- translateWith :: (Ord (Domain o), Num (Domain o), Num o) => (Domain o -> o -> o) -> Domain o -> Piecewise o -> Piecewise o
- zipPointwise :: (Ord (Domain o), Num o) => (o -> o -> o) -> Piecewise o -> Piecewise o -> Piecewise o
Type
A function defined piecewise on numerical intervals.
o
= type of function on every piece e.g. polynomials or other specialized representations of functions
= numerical type for the number line, e.g.Domain
oRational
orDouble
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
Basic operations
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
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!