Sage: Ticket #17550: sorted variables in multivariate polynomial ring wrong order
https://trac.sagemath.org/ticket/17550
<p>
We have
</p>
<pre class="wiki">sage: R.<a,b> = QQ[]
sage: sorted([a,b])
[b, a]
</pre><p>
which looks weird to me and is not what one would expect.
</p>
<p>
This is also inconsistent with
</p>
<pre class="wiki">sage: var('a, b')
(a, b)
sage: sorted([a,b])
[a, b]
</pre><p>
(but in this case the ordering seems always to be alphabetically.)
</p>
<p>
However, in the multivariate polynomial ring this ordering depends on the definition:
</p>
<pre class="wiki">sage: R.<b,a> = QQ[]
sage: sorted([a,b])
[a, b]
</pre>en-usSagehttps://trac.sagemath.org/chrome/site/logo_sagemath_trac.png
https://trac.sagemath.org/ticket/17550
Trac 1.1.6dkrennThu, 16 Apr 2015 21:22:20 GMT
https://trac.sagemath.org/ticket/17550#comment:1
https://trac.sagemath.org/ticket/17550#comment:1
<p>
Still there in 6.6
</p>
TicketnbruinThu, 16 Apr 2015 21:34:01 GMT
https://trac.sagemath.org/ticket/17550#comment:2
https://trac.sagemath.org/ticket/17550#comment:2
<p>
Polynomial rings have a monomial order which should affect how monomials (and hence terms) compare:
</p>
<pre class="wiki">sage: A.<a,b>=PolynomialRing(Rationals(),order="lex")
sage: sorted([a^i*b^j for i in [0..2] for j in [0..2]])
[1, b, b^2, a, a*b, a*b^2, a^2, a^2*b, a^2*b^2]
sage: A.<a,b>=PolynomialRing(Rationals(),order="deglex")
sage: sorted([a^i*b^j for i in [0..2] for j in [0..2]])
[1, b, a, b^2, a*b, a^2, a*b^2, a^2*b, a^2*b^2]
sage: A.<a,b>=PolynomialRing(Rationals(),order="degrevlex")
sage: sorted([a^i*b^j for i in [0..2] for j in [0..2]])
[1, b, a, b^2, a*b, a^2, a*b^2, a^2*b, a^2*b^2]
</pre>
TicketlftaberaFri, 05 Jun 2015 07:12:14 GMTstatus, milestone changed
https://trac.sagemath.org/ticket/17550#comment:3
https://trac.sagemath.org/ticket/17550#comment:3
<ul>
<li><strong>status</strong>
changed from <em>new</em> to <em>needs_review</em>
</li>
<li><strong>milestone</strong>
changed from <em>sage-6.5</em> to <em>sage-duplicate/invalid/wontfix</em>
</li>
</ul>
<p>
By default sage uses 'degrevlex' for term orders. This is somehow standard in multivariate polynomial rings. I would not change this default. If you want a>b I suggest you to use 'deglex' term order instead.
</p>
<p>
I propose to resolve the ticket as wontfix.
</p>
TicketbrunoFri, 05 Jun 2015 14:03:14 GMTstatus changed
https://trac.sagemath.org/ticket/17550#comment:4
https://trac.sagemath.org/ticket/17550#comment:4
<ul>
<li><strong>status</strong>
changed from <em>needs_review</em> to <em>positive_review</em>
</li>
</ul>
<p>
Replying to <a class="ticket" href="https://trac.sagemath.org/ticket/17550#comment:3" title="Comment 3">lftabera</a>:
</p>
<blockquote class="citation">
<p>
By default sage uses 'degrevlex' for term orders. This is somehow standard in multivariate polynomial rings. I would not change this default. If you want a>b I suggest you to use 'deglex' term order instead.
</p>
<p>
I propose to resolve the ticket as wontfix.
</p>
</blockquote>
<p>
I agree with you that this is related to the term orders. Yet, the order on the variables themselves doesn't change between "degrevlex" and "deglex". This is due to the fact that there are two distinct changes between these two orders.
</p>
TicketdkrennSat, 06 Jun 2015 14:24:23 GMTstatus changed
https://trac.sagemath.org/ticket/17550#comment:5
https://trac.sagemath.org/ticket/17550#comment:5
<ul>
<li><strong>status</strong>
changed from <em>positive_review</em> to <em>needs_info</em>
</li>
</ul>
<p>
Replying to <a class="ticket" href="https://trac.sagemath.org/ticket/17550#comment:2" title="Comment 2">nbruin</a>:
</p>
<blockquote class="citation">
<p>
Polynomial rings have a monomial order which should affect how monomials (and hence terms) compare:
</p>
<pre class="wiki">sage: A.<a,b>=PolynomialRing(Rationals(),order="lex")
sage: sorted([a^i*b^j for i in [0..2] for j in [0..2]])
[1, b, b^2, a, a*b, a*b^2, a^2, a^2*b, a^2*b^2]
sage: A.<a,b>=PolynomialRing(Rationals(),order="deglex")
sage: sorted([a^i*b^j for i in [0..2] for j in [0..2]])
[1, b, a, b^2, a*b, a^2, a*b^2, a^2*b, a^2*b^2]
sage: A.<a,b>=PolynomialRing(Rationals(),order="degrevlex")
sage: sorted([a^i*b^j for i in [0..2] for j in [0..2]])
[1, b, a, b^2, a*b, a^2, a*b^2, a^2*b, a^2*b^2]
</pre></blockquote>
<p>
I understand that the original posted "problem" is not one, since we use "degrevlex", but using "lex" or "deglex" the output of the lines above should definitely start with <code>[1, a, ...]</code>.
</p>
TicketdkrennSat, 06 Jun 2015 14:25:37 GMTwork_issues set
https://trac.sagemath.org/ticket/17550#comment:6
https://trac.sagemath.org/ticket/17550#comment:6
<ul>
<li><strong>work_issues</strong>
set to <em>document this better</em>
</li>
</ul>
<p>
Replying to <a class="ticket" href="https://trac.sagemath.org/ticket/17550#comment:3" title="Comment 3">lftabera</a>:
</p>
<blockquote class="citation">
<p>
By default sage uses 'degrevlex' for term orders. This is somehow standard in multivariate polynomial rings. I would not change this default. If you want a>b I suggest you to use 'deglex' term order instead.
</p>
</blockquote>
<p>
Understood.
</p>
<blockquote class="citation">
<p>
I propose to resolve the ticket as wontfix.
</p>
</blockquote>
<p>
To get something out of it, e should at least mention this in the docstrings more explicitly.
</p>
TicketdkrennSat, 06 Jun 2015 14:26:46 GMT
https://trac.sagemath.org/ticket/17550#comment:7
https://trac.sagemath.org/ticket/17550#comment:7
<p>
Replying to <a class="ticket" href="https://trac.sagemath.org/ticket/17550#comment:4" title="Comment 4">bruno</a>:
</p>
<blockquote class="citation">
<p>
[...] Yet, the order on the variables themselves doesn't change between "degrevlex" and "deglex". This is due to the fact that there are two distinct changes between these two orders.
</p>
</blockquote>
<p>
What do you mean by this? This should (IMHO) change...
</p>
TicketbrunoMon, 08 Jun 2015 09:15:07 GMT
https://trac.sagemath.org/ticket/17550#comment:8
https://trac.sagemath.org/ticket/17550#comment:8
<p>
Replying to <a class="ticket" href="https://trac.sagemath.org/ticket/17550#comment:7" title="Comment 7">dkrenn</a>:
</p>
<blockquote class="citation">
<p>
Replying to <a class="ticket" href="https://trac.sagemath.org/ticket/17550#comment:4" title="Comment 4">bruno</a>:
</p>
<blockquote class="citation">
<p>
[...] Yet, the order on the variables themselves doesn't change between "degrevlex" and "deglex". This is due to the fact that there are two distinct changes between these two orders.
</p>
</blockquote>
<p>
What do you mean by this? This should (IMHO) change...
</p>
</blockquote>
<p>
This is described in the reference manual <a class="ext-link" href="http://doc.sagemath.org/html/en/reference/polynomial_rings/sage/rings/polynomial/term_order.html"><span class="icon"></span>http://doc.sagemath.org/html/en/reference/polynomial_rings/sage/rings/polynomial/term_order.html</a>. The "two changes" I mentioned are the fact that in "degrevlex" one considers the <em><strong>last</strong> variable whose exponent is <strong>larger</strong></em> while in "deglex" one considers the <em><strong>first</strong> variable whose exponent is <strong>smaller</strong></em>. Thus, if you have as first variable <code>a</code> and second variable <code>b</code>, the comparison between the two monomials <code>a</code> and <code>b</code> is:
</p>
<ul><li>degrevlex: <code>a > b</code> since both monomials have degree <code>1</code> and <code>b</code> is the last variable whose exponent is smaller in the monomial <code>a</code> (0) than in the monomial <code>b</code> (1);
</li><li>deglex: <code>a > b</code> since both monomials have degree <code>1</code> and <code>a</code> is the first variable whose exponent is larger in the monomial <code>a</code> (1) than in the monomial <code>b</code> (0).
</li></ul><p>
Note that, unless I make a mistake, all orders defined in SageMath satisfy <code>a > b</code>.
</p>
<p>
I do not understand what you mean by "This should change". The way the orders are defined in SageMath seems consistent with the literature and the other softwares.
</p>
TicketchapotonTue, 25 Jul 2017 06:30:45 GMTstatus changed; work_issues deleted
https://trac.sagemath.org/ticket/17550#comment:9
https://trac.sagemath.org/ticket/17550#comment:9
<ul>
<li><strong>status</strong>
changed from <em>needs_info</em> to <em>positive_review</em>
</li>
<li><strong>work_issues</strong>
<em>document this better</em> deleted
</li>
</ul>
<p>
Let us close this as invalid.
</p>
TicketembrayTue, 12 Dec 2017 08:23:33 GMTstatus changed; resolution set
https://trac.sagemath.org/ticket/17550#comment:10
https://trac.sagemath.org/ticket/17550#comment:10
<ul>
<li><strong>status</strong>
changed from <em>positive_review</em> to <em>closed</em>
</li>
<li><strong>resolution</strong>
set to <em>wontfix</em>
</li>
</ul>
Ticket