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

Safe HaskellSafe
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) Source # 

Methods

fmap :: (a -> b) -> Transition x a -> Transition x b #

(<$) :: a -> Transition x b -> Transition x a #

(Eq y, Eq x) => Eq (Transition x y) Source # 

Methods

(==) :: Transition x y -> Transition x y -> Bool #

(/=) :: Transition x y -> Transition x y -> Bool #

(Ord x, Eq y) => Ord (Transition x y) Source # 

Methods

compare :: Transition x y -> Transition x y -> Ordering #

(<) :: Transition x y -> Transition x y -> Bool #

(<=) :: Transition x y -> Transition x y -> Bool #

(>) :: Transition x y -> Transition x y -> Bool #

(>=) :: Transition x y -> Transition x y -> Bool #

max :: Transition x y -> Transition x y -> Transition x y #

min :: Transition x y -> Transition x y -> Transition x y #

(Show y, Show x) => Show (Transition x y) Source # 

Methods

showsPrec :: Int -> Transition x y -> ShowS #

show :: Transition x y -> String #

showList :: [Transition x y] -> ShowS #

data StepFunction x y Source #

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

Instances

Functor (StepFunction x) Source # 

Methods

fmap :: (a -> b) -> StepFunction x a -> StepFunction x b #

(<$) :: a -> StepFunction x b -> StepFunction x a #

(Eq x, Eq y) => Eq (StepFunction x y) Source # 

Methods

(==) :: StepFunction x y -> StepFunction x y -> Bool #

(/=) :: StepFunction x y -> StepFunction x y -> Bool #

(Show x, Show y) => Show (StepFunction x y) Source # 

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.