Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

def addpolyp1 p2 poly1 nppoly1dp... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modeling the Dynamics of Life Calculus and Probability for Life Scientists

Authors: Frederick R. Adler

3rd edition

840064187, 978-1285225975, 128522597X, 978-0840064189

More Books

Students also viewed these Programming questions

Question

2. Follow through with fair consequences.

Answered: 1 week ago