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 :: a -> v a -> a
evaluatePolynomial a
x v a
v
| v a -> Bool
forall (v :: * -> *) a. Vector v a => v a -> Bool
G.null v a
v = a
0
| Bool
otherwise = (a -> a -> a) -> v a -> a
forall (v :: * -> *) a. Vector v a => (a -> a -> a) -> v a -> a
G.foldr1 (\a
a a
r -> a
a a -> a -> a
forall a. Num a => a -> a -> a
+ a
ra -> a -> a
forall a. Num a => a -> a -> a
*a
x) v a
v
evaluateEvenPolynomial :: (Vector v a, Num a)
=> a
-> v a
-> a
{-# INLINE evaluateEvenPolynomial #-}
evaluateEvenPolynomial :: a -> v a -> a
evaluateEvenPolynomial a
x
= a -> v a -> a
forall (v :: * -> *) a. (Vector v a, Num a) => a -> v a -> a
evaluatePolynomial (a
xa -> a -> a
forall a. Num a => a -> a -> a
*a
x)
evaluateOddPolynomial :: (Vector v a, Num a)
=> a
-> v a
-> a
{-# INLINE evaluateOddPolynomial #-}
evaluateOddPolynomial :: a -> v a -> a
evaluateOddPolynomial a
x v a
coefs
= a
x a -> a -> a
forall a. Num a => a -> a -> a
* a -> v a -> a
forall (v :: * -> *) a. (Vector v a, Num a) => a -> v a -> a
evaluatePolynomial (a
xa -> a -> a
forall a. Num a => a -> a -> a
*a
x) v a
coefs
evaluatePolynomialL :: (Num a) => a -> [a] -> a
evaluatePolynomialL :: a -> [a] -> a
evaluatePolynomialL a
x = a -> Vector a -> a
forall (v :: * -> *) a. (Vector v a, Num a) => a -> v a -> a
evaluatePolynomial a
x (Vector a -> a) -> ([a] -> Vector a) -> [a] -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [a] -> Vector a
forall a. [a] -> Vector a
V.fromList
{-# INLINE evaluatePolynomialL #-}
evaluateEvenPolynomialL :: (Num a) => a -> [a] -> a
evaluateEvenPolynomialL :: a -> [a] -> a
evaluateEvenPolynomialL a
x = a -> Vector a -> a
forall (v :: * -> *) a. (Vector v a, Num a) => a -> v a -> a
evaluateEvenPolynomial a
x (Vector a -> a) -> ([a] -> Vector a) -> [a] -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [a] -> Vector a
forall a. [a] -> Vector a
V.fromList
{-# INLINE evaluateEvenPolynomialL #-}
evaluateOddPolynomialL :: (Num a) => a -> [a] -> a
evaluateOddPolynomialL :: a -> [a] -> a
evaluateOddPolynomialL a
x = a -> Vector a -> a
forall (v :: * -> *) a. (Vector v a, Num a) => a -> v a -> a
evaluateOddPolynomial a
x (Vector a -> a) -> ([a] -> Vector a) -> [a] -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [a] -> Vector a
forall a. [a] -> Vector a
V.fromList
{-# INLINE evaluateOddPolynomialL #-}