# Can't do simple algebraic division

Why can't I do a simple division with Sage? All I get out is what I put in. I can do this by hand easily but no matter what method or option I try I get the same answer.

In: (3*x^3+x^2-3*x+5)/(x+1)
Out: (3*x^3 + x^2 - 3*x + 5)/(x + 1)

edit retag close merge delete

Please indicate what answer you are expecting. Especially since you can do this by hand easily!

Regarding "no matter what method or option I try", please list the methods and options you tried.

Then we can comment on why any particular method or option should have behaved the way it did or any other way. Maybe we can fix some bugs. But we need to see exactly what is going wrong.

Sort by » oldest newest most voted

Try using polynomials a polynomial ring.

Then you can define

• two polynomials in it,
• the rational fraction obtained by dividing one by the other
• the quotient and remainder

Define a polynomial ring:

sage: R.<x> = QQ[]


Or just a polynomial ring generator:

sage: x = polygen(QQ)


Define two polynomials:

sage: a = 3*x^3 + x^2 - 3*x + 5
sage: b = x + 1


Divide:

sage: c = a / b
sage: c
3*x^3 + x^2 - 3*x + 5)/(x + 1)


Quotient and remainder

sage: q = a // b
sage: q
3*x^2 - 2*x - 1

sage: r = a % b
sage: r
6


Both at once

sage: q, r = a.quo_rem(b)
sage: q
3*x^2 - 2*x - 1
sage: r
6


Check:

sage: q + r/b
(3*x^3 + x^2 - 3*x + 5)/(x + 1)

more