# User talk:PaoloMartini

From HaskellWiki

Revision as of 20:41, 15 September 2006 by PaoloMartini (talk | contribs)

```
{-# 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
```