Order of Variables of Polynomial Matters

56 views
Skip to first unread message

Animesh Shree

unread,
Jul 27, 2024, 4:59:26 PM7/27/24
to sage-support
I saw this behavior

sage: R1.<x,y,z> = QQ[]
sage: R2.<z,x,y> = QQ[]  # Rearrange variables of R1
sage: R1
Multivariate Polynomial Ring in x, y, z over Rational Field
sage: R2
Multivariate Polynomial Ring in z, x, y over Rational Field
sage: R1 is R2
False
sage: print(R1.gens(), R1.variable_names())
(x, y, z) ('x', 'y', 'z')
sage: print(R2.gens(), R2.variable_names())
(z, x, y) ('z', 'x', 'y')
sage:


It looks like the order in which we initiate the polynomials leads to different polynomial spaces. I thought this should not be the case.
I got confused. Is it right or bug or intentional?

Dima Pasechnik

unread,
Jul 27, 2024, 6:12:28 PM7/27/24
to sage-s...@googlegroups.com
It is by design. Multivariate polynomial rings come with monomial
orders (https://en.wikipedia.org/wiki/Monomial_order)
and in this case R1 and R1 have different monomial orders.
Monomial orders are crucial for many algorithms operating on
multivariate polynomial rings, their ideals, etc.

Dima

>
> --
> You received this message because you are subscribed to the Google Groups "sage-support" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sage-support...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/sage-support/30b4f982-9b1a-434f-a512-7690b6c16e6bn%40googlegroups.com.

Animesh Shree

unread,
Jul 28, 2024, 1:51:52 AM7/28/24
to sage-support
I was looking into this issue

This throws error:
-----------------------------------------------------------------------------------------
sage: R1.<x,y,z> = QQ[]
sage: p = (x^2 - y^2) * (x + y + z)
sage: S = QQ['z']['x,y']
sage: try:
....:     S(p)
....: except Exception as e:
....:     print(e)
x^3 + x^2*y - x*y^2 - y^3 is not a constant polynomial


But this passes
--------------------------------------------------------------------------------------------
sage: R2.<z,x,y> = QQ[]
sage: p = (x^2 - y^2) * (x + y + z)
sage: S(p)
x^3 + x^2*y - x*y^2 - y^3 + z*x^2 + (-z)*y^2
sage:


So the output of 
        p = R1.random_element()
        S(p) and S(R2(p))
should they be same or different ?

One reason to this behavior is the ordering of monomial. Ref1
The 1st one hits the Ref1 but 2nd one don't. That leads to ConstantPolynomial Error.

Dima Pasechnik

unread,
Jul 28, 2024, 6:10:12 AM7/28/24
to sage-s...@googlegroups.com
On Sun, Jul 28, 2024 at 6:51 AM 'Animesh Shree' via sage-support
<sage-s...@googlegroups.com> wrote:
>
> I was looking into this issue
>
> This throws error:
> -----------------------------------------------------------------------------------------
> sage: R1.<x,y,z> = QQ[]
> sage: p = (x^2 - y^2) * (x + y + z)
> sage: S = QQ['z']['x,y']
> sage: try:
> ....: S(p)
> ....: except Exception as e:
> ....: print(e)
> x^3 + x^2*y - x*y^2 - y^3 is not a constant polynomial
>
>
> But this passes
> --------------------------------------------------------------------------------------------
> sage: R2.<z,x,y> = QQ[]
> sage: p = (x^2 - y^2) * (x + y + z)
> sage: S(p)
> x^3 + x^2*y - x*y^2 - y^3 + z*x^2 + (-z)*y^2
> sage:
>
>
> So the output of
> p = R1.random_element()
> S(p) and S(R2(p))
> should they be same or different ?

I don't know whether S(p), i.e. coersion of p into the ring S, should work for
different monomial order, or one should explicitly use R1.change_ring

You get lucky with S and R2, as this is the same order.

I'd also be vary of using the same variable names for different rings:
if you declare
two rings, R1 amd R2, using the same variable, say, y, how does Sage
supposed to know whether
y is a member of R1, or a member of R2 (you can still use R1(y) and
R2(y) to be explicit)

HTH,
Dima
> To view this discussion on the web visit https://groups.google.com/d/msgid/sage-support/f25ed01f-2b98-47bd-bb56-52a42ed19149n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages