Write a function that multiplies two polynomials in HASKELL multPoly :: (Num a, Eq a) => Poly a -> Poly a -> Poly a For example: > multPoly (P [-1,0,1]) (P [0,1]) P [0,-1,0,1] > multPoly (P [-1,0,1]) (P [2]) P [-2,0,2] > multPoly (P [1,1]) (P [-1,1]) P [-1,0,1] > multPoly (P [18,0,3]) (P []) P [] Before writing multPoly, you may find it helpful to write a function that increases the degree of a polynomial by multiplying it by x. E.g., mapping x^2−1 to ?^3−x. Seeing how this function, scale, and addPoly are written should give you a sense of how to construct multPoly. As with addPoly, multPoly is easier to write as a combination of simpler functions. Your implementation of multPoly should have this property: multPoly p q $$ x == (p $$ x) * (q $$ x)
Write a function that multiplies two polynomials in HASKELL
multPoly :: (Num a, Eq a) => Poly a -> Poly a -> Poly a
For example:
> multPoly (P [-1,0,1]) (P [0,1])
P [0,-1,0,1]
> multPoly (P [-1,0,1]) (P [2])
P [-2,0,2]
> multPoly (P [1,1]) (P [-1,1])
P [-1,0,1]
> multPoly (P [18,0,3]) (P [])
P []
Before writing multPoly, you may find it helpful to write a function that increases the degree of a polynomial by multiplying it by x. E.g., mapping x^2−1 to ?^3−x. Seeing how this function, scale, and addPoly are written should give you a sense of how to construct multPoly. As with addPoly, multPoly is easier to write as a combination of simpler functions.
Your implementation of multPoly should have this property: multPoly p q $$ x == (p $$ x) * (q $$ x)
Trending now
This is a popular solution!
Step by step
Solved in 2 steps