1 | initial version |
Try using polynomials a polynomial ring.
Then you can define
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)