Opened 7 years ago

Last modified 6 years ago

#15248 new defect

Calling a lazy power series ring twice summons demons from hell

Reported by: darij Owned by:
Priority: major Milestone: sage-6.4
Component: coercion Keywords: coercion, LazyPowerSeries
Cc: SimonKing, mantepse Merged in:
Authors: Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Description (last modified by darij)

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.

Change History (10)

comment:1 Changed 7 years ago by darij

  • Description modified (diff)

comment:2 Changed 7 years ago by nbruin

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 7 years ago by darij

Great job tracing this to its origins in 15 minutes!

comment:4 Changed 7 years ago by jdemeyer

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

comment:5 Changed 7 years ago by mantepse

  • Cc mantepse added
  • Keywords LazyPowerSeries added; lazy-power-series removed

comment:6 Changed 7 years ago by mhansen

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

comment:7 Changed 7 years ago by mhansen

A fix is in #15673

comment:8 Changed 7 years ago by vbraun_spam

  • Milestone changed from sage-6.1 to sage-6.2

comment:9 Changed 7 years ago by vbraun_spam

  • Milestone changed from sage-6.2 to sage-6.3

comment:10 Changed 6 years ago by vbraun_spam

  • Milestone changed from sage-6.3 to sage-6.4
Note: See TracTickets for help on using tickets.