#๐Ÿ”’ sympy

13 messages ยท Page 1 of 1 (latest)

hoary zodiac
#
from sympy import symbols, gcd

x = symbols('x')

p1 = x**4 + 2*x**3 + 3*x**2 + 2*x + 1
p2 = x**4 - 2*x**2 - 3*x - 2


print(gcd(p2, p1))

when i do this in python i get x**2 + x + 1 as the result but if i do this using Euclidian's algorithm by hand i get that the answer is 1 and when i do this using a calculator (symbolab) i get that the answer is also 1 so what am i missing here?

warped yarrowBOT
#

@hoary zodiac

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

hoary zodiac
#

!eval ```py
from sympy import symbols, gcd

x = symbols('x')

p1 = x4 + 2*x3 + 3x**2 + 2x + 1
p2 = x4 - 2*x2 - 3*x - 2

print(gcd(p2, p1))

warped yarrowBOT
tight summit
#

Get sympy to factorise both quartics.

#
from sympy import symbols, factor

# Define the variable
x = symbols('x')

# Define the quartic polynomial
p1 = x**4 + 2*x**3 + 3*x**2 + 2*x + 1
p2 = x**4 - 2*x**2 - 3*x - 2

print(factor(p1))
print(factor(p2))
#
(x**2 + x + 1)**2
(x - 2)*(x + 1)*(x**2 + x + 1)
#

I think there was a mistake in the hand calculation.

civic sinew
#

and symbolab fails to factor for some reason

#

wolfram alpha does it fine

tight summit
#

Is symbolab thrown off by complex roots?

warped yarrowBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.