-----------------------------------------------------------------------------
--
-- Module      :  Math.Series
-- Copyright   :  (c) 2014-16 Brian W Bush
-- License     :  MIT
--
-- Maintainer  :  Brian W Bush <consult@brianwbush.info>
-- Stability   :  Stable
-- Portability :  Portable
--
-- | Numerical functions for lists.
--
-----------------------------------------------------------------------------


{-# LANGUAGE Safe #-}


module Math.Series (
-- * Functions
  deltas
, sums
) where


-- | Difference between values in a list.
deltas :: Num a => [a] -> [a]
deltas [] = []
deltas x = head x : zipWith (-) (tail x) (init x)


-- | Summ of adjacent values in a list.
sums :: Num a => [a] -> [a]
sums [] = []
sums [x] = [x]
sums (x : x' : xs) = x : sums (x + x' : xs)