0

I need to find product of two polynomials.

Input:

x+2; x^3-x^2+1

Output:

x^4+x^3-2x^2+x+2

I have two questions:

1) How to extract coeff. from polynomials.

2) How to build new polynomial using new coeff. (output form in example)

I'm not allowed to use additional libraries.

Seanny123
  • 8,776
  • 13
  • 68
  • 124
  • you can use sympy library for that. – Ramesh Kumar Jan 21 '19 at 16:02
  • I'm not allowed to use additional libraries, but i would be happy if you can give me an example of code to solve this problem using libraries – friendly_user Jan 21 '19 at 16:05
  • 3
    Can you please share what you have tried so far and what is failing in your current implementation? – ParvBanks Jan 21 '19 at 16:08
  • @ParvBanks i know how to solve this problem if input consists only of coeff. like [1,2] and [1,-1,1] but i dont know how to work with polynomials in python in their natural form, like in my example – friendly_user Jan 21 '19 at 16:14
  • Have you tried using `regex` to identify the coefficients? Once you have those, you can use your current solution to solve. It will also not need additional libraries (except `re`) – ParvBanks Jan 21 '19 at 16:16
  • @ParvBanks i will read documentation, because i've dealt with regex. Hope it will help. thank you – friendly_user Jan 21 '19 at 16:24
  • I have found a possible solution, you can check my answer. – ParvBanks Jan 21 '19 at 16:32
  • @friendly_user Please [edit] the question to mention that you can't use additional libraries, plus any other specific requirements. Also add anything you've tried so far and the results. – wjandrea Jan 21 '19 at 16:37
  • **You could use `regex` to identify the polynomials from your expressions.** I found a similar query [here](https://stackoverflow.com/questions/50914959/calculating-the-coefficients-of-a-differentiated-polynomial-using-re-compile-and). Please check if it works for you. **The result is a list of coefficients which is what you're looking to integrate with your solution.** – ParvBanks Jan 21 '19 at 16:32

0 Answers0