Write Python functions for the following operations: addpoly(p1,p2) multpoly(p1,p2) that add and multiply two polynomials, respectively. Let
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 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.
Modeling the Dynamics of Life Calculus and Probability for Life Scientists
ISBN: 978-0840064189
3rd edition
Authors: Frederick R. Adler