I expected it to be a method of the Polynomial class. I suspect my
difficulty lies in converting a symbolic expression to a polynomial.
In fact, if I knew how to do that properly I shouldn't even need
PolynomialRemainder. The plan is to create the ring Q(z) where
z is a primitive 18th root of 1, and then enter some expression such
as (z^5-1/z^5 )(z - 1/z) (but much longer) and see it expressed as
a polynomial of degree 5 in z. In Mathematica I just multiplied by a
sufficient power of z and then used PolynomialRemainder (I'm going to
set the result to zero so multiplying by a power of z is fine).
What is the right way to do this in Sage?
On Jan 3, 10:59 am, Michael Beeson <profbee...@gmail.com> wrote:
> I am just learning Sage. I tried to define a polynomial and then
> find the polynomial remainder upon division by the
> cyclotomic_polynomial(18), which is 1-x^3+x^6. This is easily
> accomplished in Mathematica using the PolynomialRemainder function.
> But I could not find the analog of that function in the Sage
> documentation.
> What is the right way to do this in Sage?
I think this is what you are trying to do:
sage: P.<x> = PolynomialRing(QQ)
sage: f = x^10+2*x^8+3*x+1
sage: f in P
True
sage: g = cyclotomic_polynomial(18); g
x^6 - x^3 + 1
sage: f.quo_rem(g)
(x^4 + 2*x^2 + x, 2*x^5 - 2*x^2 + 2*x + 1)
The first term is the quotient and the second is the remainder. See
sage: f.quo_rem?
for the description of the method.
Daniel Bump
See also
http://groups.google.com/group/sage-support/browse_thread/thread/c786de5c6d13b600/dd1594ca70590735
for a similar thread.
Thanks,
Jason
If there's an easy way that I should have been able to look this up
for myself I would like to know that even more than the specific
answer.
On another subject:
The documentation mentions the "ring" of symbolic expressions. To be
a ring one needs to know when two symbolic expressions are equal. Is
1/0 a symbolic expression and if so is it equal to oo ? How about x-
x and 0? x/x and 1? More generally has anything been written
about the or "a" semantics for Sage?
Michael
On 5 jan, 09:37, Michael Beeson <profbee...@gmail.com> wrote:
> Thanks, that's a start, but my polynomials have some parameters
> a,b,c,...
> in the coefficients. In Mathematica you say PolyomialRemainder[f,g,x]
> where the
> last 'x' names the polynomial variable, so all other variables are
> parameters. When
> I tried to modify your code by inserting a=var('a') and then
> f=a*x^10, it didn't work,
> because now f only belongs to sage.symbolic.expression.Expression, and
> not
> to P.
Is the following what you look for?
sage: R.<x>=PolynomialRing(SR)
sage: var('a')
a
sage: f = a*x^10+2*x^8+3*x+1
sage: g = cyclotomic_polynomial(18)(x)
sage: f.quo_rem(g)
(a*x^4 + 2*x^2 + a*x, 2*x^5 - 2*x^2 + (-a + 3)*x + 1)
Yann
1/0 is an error.
sage: 1/0
Traceback (most recent call last):
...
ZeroDivisionError: Rational division by zero
> How about x-
> x and 0?
sage: bool(x-x == 0)
True
> x/x and 1?
sage: bool(x/x == 1)
True
> More generally has anything been written
> about the or "a" semantics for Sage?
Maybe in the ginac documentation...
>
> Michael
>
>
> On Jan 3, 12:42 pm, bump <b...@match.stanford.edu> wrote:
>> On Jan 3, 10:59 am, Michael Beeson <profbee...@gmail.com> wrote:
>>
>> > I am just learning Sage. I tried to define a polynomial and then
>> > find the polynomial remainder upon division by the
>> > cyclotomic_polynomial(18), which is 1-x^3+x^6. This is easily
>> > accomplished in Mathematica using the PolynomialRemainder function.
>> > But I could not find the analog of that function in the Sage
>> > documentation.
>> > What is the right way to do this in Sage?
>>
>> I think this is what you are trying to do:
>>
>> sage: P.<x> = PolynomialRing(QQ)
>> sage: f = x^10+2*x^8+3*x+1
>> sage: f in P
>> True
>> sage: g = cyclotomic_polynomial(18); g
>> x^6 - x^3 + 1
>> sage: f.quo_rem(g)
>> (x^4 + 2*x^2 + x, 2*x^5 - 2*x^2 + 2*x + 1)
>>
>> The first term is the quotient and the second is the remainder. See
>> sage: f.quo_rem?
>>
>> for the description of the method.
>>
>> Daniel Bump
>
> --
> To post to this group, send email to sage-s...@googlegroups.com
> To unsubscribe from this group, send email to sage-support...@googlegroups.com
> For more options, visit this group at http://groups.google.com/group/sage-support
> URL: http://www.sagemath.org
>
--
William Stein
Associate Professor of Mathematics
University of Washington
http://wstein.org