Opened 5 years ago

Closed 2 years ago

# sorted variables in multivariate polynomial ring wrong order

Reported by: Owned by: dkrenn major sage-duplicate/invalid/wontfix algebra N/A

### Description

We have

```sage: R.<a,b> = QQ[]
sage: sorted([a,b])
[b, a]
```

which looks weird to me and is not what one would expect.

This is also inconsistent with

```sage: var('a, b')
(a, b)
sage: sorted([a,b])
[a, b]
```

(but in this case the ordering seems always to be alphabetically.)

However, in the multivariate polynomial ring this ordering depends on the definition:

```sage: R.<b,a> = QQ[]
sage: sorted([a,b])
[a, b]
```

### comment:1 Changed 5 years ago by dkrenn

Still there in 6.6

### comment:2 follow-up: ↓ 5 Changed 5 years ago by nbruin

Polynomial rings have a monomial order which should affect how monomials (and hence terms) compare:

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

### comment:3 follow-ups: ↓ 4 ↓ 6 Changed 5 years ago by lftabera

• Milestone changed from sage-6.5 to sage-duplicate/invalid/wontfix
• Status changed from new to needs_review

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.

I propose to resolve the ticket as wontfix.

### comment:4 in reply to: ↑ 3 ; follow-up: ↓ 7 Changed 5 years ago by bruno

• Status changed from needs_review to positive_review

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.

I propose to resolve the ticket as wontfix.

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.

### comment:5 in reply to: ↑ 2 Changed 5 years ago by dkrenn

• Status changed from positive_review to needs_info

Polynomial rings have a monomial order which should affect how monomials (and hence terms) compare:

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

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 `[1, a, ...]`.

### comment:6 in reply to: ↑ 3 Changed 5 years ago by dkrenn

• Work issues set to document this better

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.

Understood.

I propose to resolve the ticket as wontfix.

To get something out of it, e should at least mention this in the docstrings more explicitly.

### comment:7 in reply to: ↑ 4 ; follow-up: ↓ 8 Changed 5 years ago by dkrenn

[...] 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.

What do you mean by this. This should (IMHO) change...

Version 0, edited 5 years ago by dkrenn (next)

### comment:8 in reply to: ↑ 7 Changed 5 years ago by bruno

[...] 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.

What do you mean by this? This should (IMHO) change...

This is described in the reference manual http://doc.sagemath.org/html/en/reference/polynomial_rings/sage/rings/polynomial/term_order.html. The "two changes" I mentioned are the fact that in "degrevlex" one considers the last variable whose exponent is larger while in "deglex" one considers the first variable whose exponent is smaller. Thus, if you have as first variable `a` and second variable `b`, the comparison between the two monomials `a` and `b` is:

• degrevlex: `a > b` since both monomials have degree `1` and `b` is the last variable whose exponent is smaller in the monomial `a` (0) than in the monomial `b` (1);
• deglex: `a > b` since both monomials have degree `1` and `a` is the first variable whose exponent is larger in the monomial `a` (1) than in the monomial `b` (0).

Note that, unless I make a mistake, all orders defined in SageMath satisfy `a > b`.

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.

Last edited 5 years ago by bruno (previous) (diff)

### comment:9 Changed 3 years ago by chapoton

• Status changed from needs_info to positive_review
• Work issues document this better deleted

Let us close this as invalid.

### comment:10 Changed 2 years ago by embray

• Resolution set to wontfix
• Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.