module Math.Polynomial.Newton where

import Math.Polynomial
import Data.List

-- |Returns the Newton basis set of polynomials associated with a set of 
-- abscissas.  This is the set of monic polynomials each of which is @0@ 
-- at all previous points in the input list.
newtonBasis :: (Num a, Eq a) => [a] -> [Poly a]
newtonBasis :: [a] -> [Poly a]
newtonBasis xs :: [a]
xs = 
    [ (Poly a -> Poly a -> Poly a) -> Poly a -> [Poly a] -> Poly a
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl Poly a -> Poly a -> Poly a
forall a. (Num a, Eq a) => Poly a -> Poly a -> Poly a
multPoly (Endianness -> [a] -> Poly a
forall a. (Num a, Eq a) => Endianness -> [a] -> Poly a
poly Endianness
LE [1]) 
        [ Endianness -> [a] -> Poly a
forall a. (Num a, Eq a) => Endianness -> [a] -> Poly a
poly Endianness
LE [-a
x_i, 1]
        | a
x_i <- [a]
xs'
        ]
    | [a]
xs' <- [a] -> [[a]]
forall a. [a] -> [[a]]
inits [a]
xs
    ]