ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sat, 01 Aug 2020 07:48:39 +0200Can't do simple algebraic divisionhttps://ask.sagemath.org/question/52792/cant-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)Sat, 01 Aug 2020 05:01:46 +0200https://ask.sagemath.org/question/52792/cant-do-simple-algebraic-division/Comment by slelievre for <p>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.</p>
<pre><code>In: (3*x^3+x^2-3*x+5)/(x+1)
Out: (3*x^3 + x^2 - 3*x + 5)/(x + 1)
</code></pre>
https://ask.sagemath.org/question/52792/cant-do-simple-algebraic-division/?comment=52793#post-id-52793Please indicate what answer you are expecting. Especially since you can do this by hand easily!
Then we might know how to help you attain the same answer with Sage.
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.Sat, 01 Aug 2020 05:45:26 +0200https://ask.sagemath.org/question/52792/cant-do-simple-algebraic-division/?comment=52793#post-id-52793Answer by slelievre for <p>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.</p>
<pre><code>In: (3*x^3+x^2-3*x+5)/(x+1)
Out: (3*x^3 + x^2 - 3*x + 5)/(x + 1)
</code></pre>
https://ask.sagemath.org/question/52792/cant-do-simple-algebraic-division/?answer=52794#post-id-52794Try 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)
Sat, 01 Aug 2020 07:48:39 +0200https://ask.sagemath.org/question/52792/cant-do-simple-algebraic-division/?answer=52794#post-id-52794