Opened 5 years ago

Closed 5 years ago

# change_ring broken on polynomials

Reported by: Owned by: Vincent Delecroix major sage-8.2 commutative algebra Ralf Stephan Vincent Delecroix Julian Rüth N/A 319bb43 319bb43a70dd8ddfd9637cbc310230579a643fe6

### Description

If the polynomial can be coerced in the new base ring, the result of `change_ring` is a constant

```sage: p = ZZ['x']([1,2,3])
sage: p.change_ring(QQ['x']).degree()
0
sage: p.change_ring(SR).degree()
0
```

### comment:1 Changed 5 years ago by Nils Bruin

Note that `change_ring` is supposed to change the base ring. For instance, we have:

```sage: p.change_ring(QQ['y']).degree()
2
sage: p.change_ring(QQ['y']).parent()
Univariate Polynomial Ring in x over Univariate Polynomial Ring in y over Rational Field
```

In your case, you basically end up with

```sage: QQ['x']['x'](p)
3*x^2 + 2*x + 1
```

and as it goes with coercion, the `x` of `p` coerces as low in the tower as possible.

Perhaps you'd prefer the result

```sage: QQ['x']['x'](p)
3*x^2 + 2*x + 1
```

There's some work to be done, though:

```sage: R.<x,y>=ZZ[]
sage: f=x^2+y^2
sage: f.change_ring(QQ['x','y']).monomials()
[1]
sage: f.change_ring(QQ['x']).monomials()
[x^2, y^2]
sage: f.change_ring(QQ['y']).monomials()
[x^2, y^2]
```

which does match

```sage: QQ['x']['x','y'](f).monomials()
[x^2, y^2]
sage: QQ['x','y']['x','y'](f).monomials()
[1]
```

but doesn't seem to fit the pattern of "coerce 'x' as low as possible. But then, following that rule consistently might not be such a good idea.

```sage: QQ['x']['x'](QQ['x']['x'].0).degree()
1
```

### comment:2 Changed 5 years ago by Vincent Delecroix

I think that `change_ring` on elements should uniformly be

```def change_ring(self, R):
return self.parent().change_ring(R)(list(self))
```

I don't plan to change anything to the `_element_constructor_` which is definitely allowed to behave differently.

### comment:3 Changed 5 years ago by Vincent Delecroix

Authors: → Vincent Delecroix → u/vdelecroix/25022 → 319bb43a70dd8ddfd9637cbc310230579a643fe6 new → needs_review

New commits:

 ​319bb43 `fix change_ring for polynomials`

### comment:4 Changed 5 years ago by Julian Rüth

Reviewers: → Julian Rüth

Changes look good to me. nbruin, do you agree?

### comment:5 Changed 5 years ago by Ralf Stephan

Patchbot is green, too.

ping

### comment:7 Changed 5 years ago by Julian Rüth

Status: needs_review → positive_review

Since nbruin has not reacted, let's assume that he does at least not strongly disagree…

### comment:8 Changed 5 years ago by Volker Braun

Branch: u/vdelecroix/25022 → 319bb43a70dd8ddfd9637cbc310230579a643fe6 → fixed positive_review → closed
Note: See TracTickets for help on using tickets.