module Numeric.Polynomial (
evaluatePolynomial
, evaluateEvenPolynomial
, evaluateOddPolynomial
, evaluatePolynomialL
, evaluateEvenPolynomialL
, evaluateOddPolynomialL
) where
import qualified Data.Vector.Generic as G
import qualified Data.Vector as V
import Data.Vector.Generic (Vector)
evaluatePolynomial :: (Vector v a, Num a)
=> a
-> v a
-> a
{-# INLINE evaluatePolynomial #-}
evaluatePolynomial x v
| G.null v = 0
| otherwise = G.foldr1 (\a r -> a + r*x) v
evaluateEvenPolynomial :: (Vector v a, Num a)
=> a
-> v a
-> a
{-# INLINE evaluateEvenPolynomial #-}
evaluateEvenPolynomial x
= evaluatePolynomial (x*x)
evaluateOddPolynomial :: (Vector v a, Num a)
=> a
-> v a
-> a
{-# INLINE evaluateOddPolynomial #-}
evaluateOddPolynomial x coefs
= x * evaluatePolynomial (x*x) coefs
evaluatePolynomialL :: (Num a) => a -> [a] -> a
evaluatePolynomialL x = evaluatePolynomial x . V.fromList
{-# INLINE evaluatePolynomialL #-}
evaluateEvenPolynomialL :: (Num a) => a -> [a] -> a
evaluateEvenPolynomialL x = evaluateEvenPolynomial x . V.fromList
{-# INLINE evaluateEvenPolynomialL #-}
evaluateOddPolynomialL :: (Num a) => a -> [a] -> a
evaluateOddPolynomialL x = evaluateOddPolynomial x . V.fromList
{-# INLINE evaluateOddPolynomialL #-}