Question: Write Python functions for the following operations: addpoly(p1,p2) multpoly(p1,p2) that add and multiply two polynomials, respectively. Let us consider polynomials in a single variable x

Write Python functions for the following operations: addpoly(p1,p2) multpoly(p1,p2) that add and multiply two polynomials, respectively.

Let us consider polynomials in a single variable x with integer coefficients: for instance, 3x^4 - 17x^2 - 3x + 5. Each term of the polynomial can be represented as a pair of integers (coefficient,exponent). The polynomial itself is then a list of such pairs.

We have the following constraints to guarantee that each polynomial has a unique representation:

-- Terms are sorted in descending order of exponent

-- No term has a zero cofficient

-- No two terms have the same exponent

-- Exponents are always nonnegative

For example, the polynomial introduced earlier is represented as

[(3,4),(-17,2),(-3,1),(5,0)]

The zero polynomial, 0, is represented as the empty list [], since it has no terms with nonzero coefficients.

You may assume that the inputs to these functions follow the representation given above. Correspondingly, the outputs from these functions should also obey the same constraints.

Step by Step Solution

3.44 Rating (147 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

To implement the required functions addpoly and multpoly to add and multiply two polynomials we will represent each polynomial as a list of tuples whe... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!