User talk:PaoloMartini
Jump to navigation
Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
{-# OPTIONS_GHC -fglasgow-exts #-}
module Polynomial where
import Test.QuickCheck
-- *f*actorial
f :: Integer -> Integer
f n = product [1..n]
-- *c*hoose -- binomial coefficient
c :: Integer -> Integer -> Integer
n `c` k = f n `div` (f k * f (n-k))
-- *p*olynomial
p, q :: [Integer] -> Integer -> Integer
p a x = sum [(a!!fromIntegral i)*(x^i) | i <- [0..n]] where n = length a - 1
q a x = ((a!!n) * ((x+1)^n))
+ ((a!!n) * sum [(fromIntegral n `c` fromIntegral k)*((x+1)^(n-k))*((-1)^k) | k <- [1..n]])
+ sum [(a!!fromIntegral i)*(x^i) | i <- [0..n-1]] where n = length a - 1
-- *t*est
t = quickCheck $ \(x::Integer) (xs::[Integer]) ->
not (null xs) && last xs /= 0 ==> p xs x == q xs x