úÎz¿uiX      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWSafe345-2Bound operations less-than, <less-than-or-equal, "d.NStep function. Piecewise constant function, having finitely many pieces. See  +https://en.wikipedia.org/wiki/Step_function. (fromList [( k1, v1), ( k2, v2)]) v3 ::  k v) describes a piecewise constant function  f : k \to v:} f\,x = \begin{cases} v_1, \quad x < k_1 \newline v_2, \quad k_1 \le x \le k_2 \newline v_3, \quad k_2 < x \end{cases}  or as you would write in Haskell ?f x | x < k1 = v1 | x <= k2 = v2 | otherwise = v3 Note:  Khttps://hackage.haskell.org/package/total-map-0.0.6/docs/Data-TotalMap.html total-map package, which provides function with finite support.9Constructor is exposed as you cannot construct non-valid .Merging You can use X instance to merge .,putSF $ liftA2 (+) (step 0 0 1) (step 1 0 1)\x -> if | x < 0 -> 0 | x < 1 -> 1 | otherwise -> 2Following property holds, i.e.  and ordinary function X instances are compatible (and  is a homomorphism).*liftA2 f g h ! x == liftA2 f (g !) (h !) x#Recall that for ordinary functions Y f g h x = f (g x) (h x).Dense?"This dense variant is useful with  )https://en.wikipedia.org/wiki/Dense_order dense ordered domains, e.g. Z. [ is not dense, so you could use Data.Function.Step.Discrete variant instead.Blet s = fromList [(Open 0, -1),(Closed 0, 0)] 1 :: SF Rational IntputSF s\x -> if | x < 0 % 1 -> -1 | x <= 0 % 1 -> 0 | otherwise -> 1import Data.Ratio ((%))map (s !) [-1, -0.5, 0, 0.5, 1] [-1,-1,0,1,1]Apply . heaviside ! 21Constant functionputSF $ constant 1\_ -> 1Step function.* k v1 v2 = \ x -> if x < k then v1 else v2.putSF $ step 1 2 3\x -> if | x < 1 -> 2 | otherwise -> 35Create function from list of cases and default value.7let f = fromList [(Open 1,2),(Closed 3,4),(Open 4,5)] 6putSF f\x -> if | x < 1 -> 2 | x <= 3 -> 4 | x < 4 -> 5 | otherwise -> 6map (f !) [0..10][2,4,4,4,6,6,6,6,6,6,6] Possible values of values heaviside[-1,1] (Merge adjustent pieces with same values.Note: A isn't normalised on construction. Values don't necessarily are \.putSF $ normalise heaviside\x -> if | x < 0 -> -1 | otherwise -> 1putSF $ normalise $ step 0 1 1\_ -> 1Bnormalise (liftA2 (+) p (fmap negate p)) == (pure 0 :: SF Int Int) Show  as Haskell code ] .  Order is like  k = (k, False),  k = (k, True). Piecewise ^.(putSF $ step 0 "a" "b" <> step 1 "c" "d"\x -> if | x < 0 -> "ac" | x < 1 -> "bc" | otherwise -> "bd"_ is a constant function.    9 Safe345PÐ $NStep function. Piecewise constant function, having finitely many pieces. See  +https://en.wikipedia.org/wiki/Step_function.Note:= this variant has discrete domain. It's enough to have only < $, without "d, as there is a next( element without any others in between.$' (fromList [(k1, v1), (k2, v2)]) v3 :: $ k v) describes a piecewise constant function  f : k \to v:} f\,x = \begin{cases} v_1, \quad x \le k_1 \newline v_2, \quad k_1 < x \le k_2 \newline v_3, \quad k_2 < x \end{cases}  or as you would write in Haskell Af x | x <= k1 = v1 | x <= k2 = v2 | otherwise = v3 9Constructor is exposed as you cannot construct non-valid $.&Apply $. heaviside ! 21'Constant functionputSF $ constant 1\_ -> 1(Step function.(* k v1 v2 = \ x -> if x < k then v1 else v2.putSF $ step 1 2 3\x -> if | x <= 1 -> 2 | otherwise -> 3)5Create function from list of cases and default value. let f = fromList [(1,2),(3,4)] 5putSF f\x -> if | x <= 1 -> 2 | x <= 3 -> 4 | otherwise -> 5map (f !) [0..10][2,2,4,4,5,5,5,5,5,5,5]*Possible values of $values heaviside[-1,1]+(Merge adjustent pieces with same values.Note: $A isn't normalised on construction. Values don't necessarily are \.putSF $ normalise heaviside\x -> if | x <= 0 -> -1 | otherwise -> 1putSF $ normalise $ step 0 1 1\_ -> 1Bnormalise (liftA2 (+) p (fmap negate p)) == (pure 0 :: SF Int Int),-Convert from discrete variant to more "dense"-SF.putSF $ toDense $ fromList [(1,2),(3,4)] 5\x -> if | x <= 1 -> 2 | x <= 3 -> 4 | otherwise -> 5-Convert from "dense" variant. <= k pieces will be converted to < ` k-. There might be less pieces in the ressult $, than in the original.Clet f = SF.fromList [(SF.Open 1,2),(SF.Closed 3,4),(SF.Open 4,5)] 6 SF.putSF f\x -> if | x < 1 -> 2 | x <= 3 -> 4 | x < 4 -> 5 | otherwise -> 6!putSF $ fromDense (Just . pred) f\x -> if | x <= 0 -> 2 | x <= 3 -> 4 | otherwise -> 6.Show $ as Haskell code/ ] . .6 Piecewise ^.(putSF $ step 0 "a" "b" <> step 1 "c" "d"\x -> if | x <= 0 -> "ac" | x <= 1 -> "bc" | otherwise -> "bd"8_ is a constant function.-previous key, if exists $%&'()*+,-./ $%'()+&*,-./$%&9 Safe345t >NStep function. Piecewise constant function, having finitely many pieces. See  +https://en.wikipedia.org/wiki/Step_function.Note:= this variant has discrete domain. It's enough to have only < $, without "d, as there is a next( element without any others in between.>' (fromList [(k1, v1), (k2, v2)]) v3 :: > k v) describes a piecewise constant function  f : k \to v:} f\,x = \begin{cases} v_1, \quad x < k_1 \newline v_2, \quad k_1 \le x < k_2 \newline v_3, \quad k_2 \le x \end{cases}  or as you would write in Haskell ?f x | x < k1 = v1 | x < k2 = v2 | otherwise = v3 9Constructor is exposed as you cannot construct non-valid >.@Apply >. heaviside ! 21AConstant functionputSF $ constant 1\_ -> 1BStep function.B* k v1 v2 = \ x -> if x < k then v1 else v2.putSF $ step 1 2 3\x -> if | x < 1 -> 2 | otherwise -> 3C5Create function from list of cases and default value. putSF $ fromList [(1,2),(3,4)] 5\x -> if | x < 1 -> 2 | x < 3 -> 4 | otherwise -> 5(map (fromList [(1,2),(3,4)] 5 !) [0..10][2,4,4,5,5,5,5,5,5,5,5]DPossible values of >values heaviside[-1,1]E(Merge adjustent pieces with same values.Note: >A isn't normalised on construction. Values don't necessarily are \.putSF $ normalise heaviside\x -> if | x < 0 -> -1 | otherwise -> 1putSF $ normalise $ step 0 1 1\_ -> 1Bnormalise (liftA2 (+) p (fmap negate p)) == (pure 0 :: SF Int Int)F-Convert from discrete variant to more "dense"-SF.putSF $ toDense $ fromList [(1,2),(3,4)] 5\x -> if | x < 1 -> 2 | x < 3 -> 4 | otherwise -> 5GConvert from "dense" variant. <= k pieces will be converted to < ` k-. There might be less pieces in the ressult >, than in the original.Clet f = SF.fromList [(SF.Open 1,2),(SF.Closed 3,4),(SF.Open 4,5)] 6 SF.putSF f\x -> if | x < 1 -> 2 | x <= 3 -> 4 | x < 4 -> 5 | otherwise -> 6!putSF $ fromDense (Just . succ) f\x -> if | x < 1 -> 2 | x < 4 -> 4 | otherwise -> 6HShow > as Haskell codeI ] . HP Piecewise ^.(putSF $ step 0 "a" "b" <> step 1 "c" "d"\x -> if | x < 0 -> "ac" | x < 1 -> "bc" | otherwise -> "bd"R_ is a constant function.Gnext key, if exists >?@ABCDEFGHI >?ABCE@DFGHI>?@9 Safeu3 >?@ABCDEFGHIa      !"#$%&'     ()#$%&'     ()#$%&'*+,*+-*./012345*67*89*+:*;<='step-function-0.2-2Qsv5imVwn4Z15hTtssmSData.Function.Step"Data.Function.Step.Discrete.Closed Data.Function.Step.Discrete.OpenData.Function.Step.DiscreteBoundOpenClosedSF!constantstepfromListvalues normaliseshowSFputSF $fShow1Bound $fNFDataBound$fArbitraryBound $fOrdBound$fShowSF $fShow1SF $fShow2SF $fNFDataSF $fArbitrarySF $fMonoidSF $fSemigroupSF $fMonadSF$fApplicativeSF $fEqBound $fShowBound$fFunctorBound$fFoldableBound$fTraversableBound$fEqSF$fOrdSF $fFunctorSF $fFoldableSF$fTraversableSFtoDense fromDensebaseGHC.Base ApplicativeliftA2GHC.RealRational integer-gmpGHC.Integer.TypeIntegerghc-prim GHC.ClassesEq System.IOputStrLnData.Semigroup<>pureGHC.Enumsucc