Opened 9 years ago

# Calling a lazy power series ring twice summons demons from hell

Reported by: Owned by: Darij Grinberg major sage-duplicate/invalid/wontfix coercion coercion, LazyPowerSeries Simon King, Martin Rubey N/A

```sage: R = LazyPowerSeriesRing(QQ)
sage: x = R.gen()
sage: x
x
sage: M = Matrix(R, [[x, x], [1, x]])
sage: M.det()
Uninitialized lazy power series
```

Sounds good so far. Now let's do this all again, in the same session:

```sage: R = LazyPowerSeriesRing(QQ)
sage: x = R.gen()
sage: x
x
sage: M = Matrix(R, [[x, x], [1, x]])
sage: M.det()
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-10-90e0c7c30c91> in <module>()
----> 1 M.det()

/home/darij/sage-5.12.beta5/local/lib/python2.7/site-packages/sage/matrix/matrix2.so in sage.matrix.matrix2.Matrix.det (sage/matrix/matrix2.c:10774)()

/home/darij/sage-5.12.beta5/local/lib/python2.7/site-packages/sage/matrix/matrix2.so in sage.matrix.matrix2.Matrix.determinant (sage/matrix/matrix2.c:8701)()

/home/darij/sage-5.12.beta5/local/lib/python2.7/site-packages/sage/structure/element.so in sage.structure.element.RingElement.__mul__ (sage/structure/element.c:14531)()

/home/darij/sage-5.12.beta5/local/lib/python2.7/site-packages/sage/structure/coerce.so in sage.structure.coerce.CoercionModel_cache_maps.bin_op (sage/structure/coerce.c:7330)()

/home/darij/sage-5.12.beta5/local/lib/python2.7/site-packages/sage/structure/coerce.so in sage.structure.coerce.CoercionModel_cache_maps.canonical_coercion (sage/structure/coerce.c:8800)()

/home/darij/sage-5.12.beta5/local/lib/python2.7/site-packages/sage/structure/coerce.so in sage.structure.coerce.CoercionModel_cache_maps._coercion_error (sage/structure/coerce.c:14607)()

RuntimeError: There is a bug in the coercion code in Sage.
Both x (=1) and y (=x) are supposed to have identical parents but they don't.
In fact, x has parent 'Lazy Power Series Ring over Rational Field'
whereas y has parent 'Lazy Power Series Ring over Rational Field'
Original elements 1 (parent Lazy Power Series Ring over Rational Field) and x (parent Lazy Power Series Ring over Rational Field) and maps
<type 'NoneType'> None
<type 'sage.categories.morphism.CallMorphism'> Call morphism:
From: Lazy Power Series Ring over Rational Field
To:   Lazy Power Series Ring over Rational Field
```

This error does not persist if I set M to be `Matrix(R, [[x, x], [x, x]])` instead, so the coercion of 1 from integers to lazy power series seems to trigger the issue.

### comment:1 Changed 9 years ago by Darij Grinberg

Description: modified (diff)

### comment:2 Changed 9 years ago by Nils Bruin

Classic example of constructing "unique" objects over "non-identical-but-equal" bases. Excellent find! It's well-known this is bound to give problems, but I'm not sure we had such a clear example yet.

```sage: R.<x>=LazyPowerSeriesRing(QQ)
sage: S.<x>=LazyPowerSeriesRing(QQ)
sage: R is S
False
sage: R == S
True
```
```sage: MR=MatrixSpace(R,2,2)
sage: MS=MatrixSpace(S,2,2)
sage: MR is MS
True
```

Since `R==S`, the construction of `MS` will return MR again. So `MS` has `R` as a base, not `S`:

```sage: MS.base() is R, MS.base() is S
(True, False)
```

After this it's unavoidable:

```sage: S.0 + R.0
RuntimeError: There is a bug in the coercion code in Sage.
Both x (=x) and y (=x) are supposed to have identical parents but they don't.
```

and you're hitting a more insidious form with

```sage: MR(R.0)
[x 0]
[0 x]
sage: MS(S.0)
RuntimeError: There is a bug in the coercion code in Sage.
```

### comment:3 Changed 9 years ago by Darij Grinberg

Great job tracing this to its origins in 15 minutes!

### comment:4 Changed 9 years ago by Jeroen Demeyer

Just saw this ticket by chance: funniest title ever :-) I should try that to my own tickets too...

### comment:6 Changed 9 years ago by Mike Hansen

This can be fixed by moving LazyPowerSeriesRing? over to the new parent framework. I'll do this this evening.

### comment:7 Changed 9 years ago by Mike Hansen

A fix is in #15673

### comment:8 Changed 9 years ago by For batch modifications

Milestone: sage-6.1 → sage-6.2

### comment:9 Changed 9 years ago by For batch modifications

Milestone: sage-6.2 → sage-6.3

### comment:10 Changed 8 years ago by For batch modifications

Milestone: sage-6.3 → sage-6.4

### comment:11 Changed 2 months ago by Martin Rubey

Milestone: sage-6.4 → sage-duplicate/invalid/wontfix new → needs_review

This works now, since #32367.

### comment:12 Changed 5 weeks ago by Frédéric Chapoton

is this doctested ? where exactly ?

### comment:13 Changed 5 weeks ago by Travis Scrimshaw

Status: needs_review → needs_work

This isn't something specific to lazy power series, it is an issue for any ring where we can have equal-but-not-identical instances as per Nil's comment:2. We just need to find another instance of this with a different base ring.

Note: See TracTickets for help on using tickets.