step-function-0.1.0.2: Step functions, staircase functions or piecewise constant functions

Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.StepFunction

Description

Functions for dealing with step functions.

Synopsis

Documentation

data Transition x y Source

A Transition, for a certain value on the x axis, there is a new y value.

Constructors

Transition 

Fields

x_val :: x

The x value where the transition happens.

y_val :: y

The new y value.

left_closed :: Bool

If True, y_val is for all x >= x_val, otherwise for all x > x_val.

Instances

Functor (Transition x) 
(Eq x, Eq y) => Eq (Transition x y) 
(Ord x, Eq y) => Ord (Transition x y) 
(Show x, Show y) => Show (Transition x y) 

data StepFunction x y Source

A StepFunction is implemented as a default value and a sorted list of Transitions.

Instances

(Eq x, Eq y) => Eq (StepFunction x y) 
(Show x, Show y) => Show (StepFunction x y) 

mkStepFunction :: (Ord x, Eq y) => y -> [Transition x y] -> StepFunction x y Source

Smart constructor sorts and simplifies the list of transitions.

valAt :: Ord x => x -> StepFunction x y -> y Source

Get the y value for a given x.

transitions :: StepFunction x y -> [Transition x y] Source

The transitions.

merge :: (Ord x, Eq c) => (a -> b -> c) -> StepFunction x a -> StepFunction x b -> StepFunction x c Source

Merge two step function, such that the following should be true:

valAt x (merge f sf1 sf2) == f (valAt x sf1) (valAt x sf2)

The resulting step function will be simplified, transitions that don't change the y value will be eliminated, and transitions that happen on the same x position will be eliminated.