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)

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter15: Recursion
Section: Chapter Questions
Problem 8SA
icon
Related questions
Question

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)

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr