method .polynomial() gives unexpected answer

24 views
Skip to first unread message

rafaeldleon

unread,
Jul 25, 2011, 3:31:29 PM7/25/11
to sage-support
Hello all,

I don´t know if the following is an error in the implementation of the
method polynomial
or if I am using it in a way that is not intended, but it seems that
the use of the method
polynomial changes when I am in a polynomial ring with 2 or with 3
variables.

pol and pol2 are the "same" polynomial in rings with 3 or 2 variables
resp. and
the method pol.polynomial(q) and pol2.polynomial(q) return different
answers.


sage: R.<p,q,t>=ZZ[]
sage: pol=2+3*q+4*q^3;pol
4*q^3 + 3*q + 2
sage: parent(pol)
Multivariate Polynomial Ring in p, q, t over Integer Ring
sage: pol2=pol.polynomial(t).coefficients()[0];pol2
4*q^3 + 3*q + 2
sage: parent(pol2)
Multivariate Polynomial Ring in p, q over Integer Ring
sage: pol2.polynomial(q)
2
sage: pol.polynomial(q)
4*q^3 + 3*q + 2

Can anyone give me some insight about why I am getting these
different answers?

Thanks!

Rafael

Julian Rüth

unread,
Jul 25, 2011, 4:42:09 PM7/25/11
to sage-s...@googlegroups.com
Apparently, this is caused by a problem in degree() which is used in
polynomial(). In your example:

sage: pol2.degree(q)
0
sage: pol2.degree(p)
3

You get the expected behavior if you bring q into pol2.parent()
explicitly:

sage: q=pol2.parent()(q)
sage: pol2.degree(q),pol2.polynomial(q)
(3, 4*q^3 + 3*q + 2)

So, this seems like an error to me. In the implementation of degree()
the line reading

return singular_polynomial_deg(p, (<MPolynomial_libsingular>x)._poly, r)

should probably be changed (x is the generator passed to the method).
But maybe somebody who knows more about the singular/sage connection can
say more about this.

cheers,
julian


* rafaeldleon <rafae...@gmail.com> [2011-07-25 12:31:29 -0700]:

> --
> 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

rafaeldleon

unread,
Jul 28, 2011, 9:00:25 PM7/28/11
to sage-support
Dear Julian,

Thank you very much for your help. It seems like an error to me too.
I am using your solution in my code and is working nicely.

Should we report this error in any other place?

Thank you again,

Rafael

On Jul 25, 4:42 pm, Julian Rüth <julian.ru...@gmail.com> wrote:
> Apparently, this is caused by a problem in degree() which is used in
> polynomial(). In your example:
>
> sage: pol2.degree(q)
> 0
> sage: pol2.degree(p)
> 3
>
> You get the expected behavior if you bring q into pol2.parent()
> explicitly:
>
> sage: q=pol2.parent()(q)
> sage: pol2.degree(q),pol2.polynomial(q)
> (3, 4*q^3 + 3*q + 2)
>
> So, this seems like an error to me. In the implementation of degree()
> the line reading
>
> return singular_polynomial_deg(p, (<MPolynomial_libsingular>x)._poly, r)
>
> should probably be changed (x is the generator passed to the method).
> But maybe somebody who knows more about the singular/sage connection can
> say more about this.
>
> cheers,
> julian
>
> * rafaeldleon <rafaeldl...@gmail.com> [2011-07-25 12:31:29 -0700]:

Julian Rüth

unread,
Aug 5, 2011, 1:12:58 PM8/5/11
to sage-s...@googlegroups.com
I opened a ticket on trac regarding this problem:

http://trac.sagemath.org/sage_trac/ticket/11652

* rafaeldleon <rafae...@gmail.com> [2011-07-28 18:00:25 -0700]:

> Dear Julian,
>
> Thank you very much for your help. It seems like an error to me too.
> I am using your solution in my code and is working nicely.
>
> Should we report this error in any other place?
>
> Thank you again,
>
> Rafael
>

Reply all
Reply to author
Forward
0 new messages