Question: Polynomial Class Create a Python class that can implement a univariate polynomial with degree at least one (Polynomial) over the field of integers (only!) with

 Polynomial Class Create a Python class that can implement a univariate

Polynomial Class Create a Python class that can implement a univariate polynomial with degree at least one (Polynomial) over the field of integers (only!) with the following operations and interfaces. >>> p=Polynomial({0:8, 1:2, 3:4}) # keys are powers, values are coefficients >>> q=Polynomial({0:8,1:2,2:8,4:4}) >>> repr(p) 8 + 2 x + 4 x^(3) >>> p 3 # integer multiply 24 + 6 x + 12 x^(3) >>> 3*p # multiplication is commutative! 24 + 6 x + 12 x^(3) >>> p+q # add two polynomials 16 + 4 X + 8 X^(2) + 4 X^(3) + 4 x^(4) >>> p*4 + 5 - 3*p - 1 # compose operations and add/ subtract constants 12 + 2 x + 4 x^(3) >>> type(p-p) # zero requires special handling but is still a Polynomial Polynomial >>> p*q # polynomial by polynomial multiplication works as usual 64 + 32 x + 68 x^(2) + 48 x^(3) + 40 x^(4) + 40 x^(5) + 16 x^(7) >>> p.subs (10) # substitute in integers and evaluate 4028 >>> (P-p) == 0 True >>> p == 9 False >>> p=Polynomial({0:8,1:0,3:4}) # keys are powers, values are coefficients >>> repr(p) '8 + 4 X^(3)' >>> p = Polynomial({2:1,0:-1}) >>> q = Polynomial({1:1, 0:-1}) >>> p/a 1 + x >>> p / Polynomial({1:1,0:-3}) # raises Not ImplementedError Polynomial Class Create a Python class that can implement a univariate polynomial with degree at least one (Polynomial) over the field of integers (only!) with the following operations and interfaces. >>> p=Polynomial({0:8, 1:2, 3:4}) # keys are powers, values are coefficients >>> q=Polynomial({0:8,1:2,2:8,4:4}) >>> repr(p) 8 + 2 x + 4 x^(3) >>> p 3 # integer multiply 24 + 6 x + 12 x^(3) >>> 3*p # multiplication is commutative! 24 + 6 x + 12 x^(3) >>> p+q # add two polynomials 16 + 4 X + 8 X^(2) + 4 X^(3) + 4 x^(4) >>> p*4 + 5 - 3*p - 1 # compose operations and add/ subtract constants 12 + 2 x + 4 x^(3) >>> type(p-p) # zero requires special handling but is still a Polynomial Polynomial >>> p*q # polynomial by polynomial multiplication works as usual 64 + 32 x + 68 x^(2) + 48 x^(3) + 40 x^(4) + 40 x^(5) + 16 x^(7) >>> p.subs (10) # substitute in integers and evaluate 4028 >>> (P-p) == 0 True >>> p == 9 False >>> p=Polynomial({0:8,1:0,3:4}) # keys are powers, values are coefficients >>> repr(p) '8 + 4 X^(3)' >>> p = Polynomial({2:1,0:-1}) >>> q = Polynomial({1:1, 0:-1}) >>> p/a 1 + x >>> p / Polynomial({1:1,0:-3}) # raises Not ImplementedError

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!