symbolic_poly(matrix) : bug report in linear algebra quickref!

29 views
Skip to first unread message

William Stein

unread,
May 4, 2016, 3:10:07 PM5/4/16
to beezer, sage-devel
It (column 2 of [1]) says this should work (see [2] below also), but it doesn't:

A = matrix(QQ, [[1,2],[3,4]])
f(x) = x^3 - 2*x + 1
f(A) # FAIL -- this is maybe a bug though (the quickref says it should work)

Making f an actual polynomial (not symbolic) works.

[1] https://wiki.sagemath.org/quickref?action=AttachFile&do=get&target=quickref-linalg.pdf
[2] Complete session in latest sage:

~$ sage-develop
┌────────────────────────────────────────────────────────────────────┐
│ SageMath version 7.2.beta6, Release Date: 2016-04-28 │
│ Type "notebook()" for the browser-based notebook interface. │
│ Type "help()" for help. │
└────────────────────────────────────────────────────────────────────┘
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Warning: this is a prerelease version, and it may be unstable. ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
sage: A = random_matrix(QQ,2)
sage: f(x) = x^2
sage: f(A)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-3-0dfcaf9a93c0> in <module>()
----> 1 f(A)

/projects/sage/sage-develop/src/sage/symbolic/expression.pyx in
sage.symbolic.expression.Expression.__call__
(/projects/sage/sage-develop/src/
build/cythonized/sage/symbolic/expression.cpp:28249)()

/projects/sage/sage-develop/local/lib/python2.7/site-packages/sage/symbolic/callable.pyc
in _call_element_(self, _the_element, *args, **kwds)
485 d = dict(zip([repr(_) for _ in self.arguments()], args))
486 d.update(kwds)
--> 487 return SR(_the_element.substitute(**d))
488
489

/projects/sage/sage-develop/src/sage/symbolic/expression.pyx in
sage.symbolic.expression.Expression.substitute
(/projects/sage/sage-develop/sr
c/build/cythonized/sage/symbolic/expression.cpp:27754)()

/projects/sage/sage-develop/src/sage/symbolic/expression.pyx in
sage.symbolic.expression.Expression.coerce_in
(/projects/sage/sage-develop/src
/build/cythonized/sage/symbolic/expression.cpp:20144)()

/projects/sage/sage-develop/src/sage/structure/parent_old.pyx in
sage.structure.parent_old.Parent._coerce_
(/projects/sage/sage-develop/src/bu
ild/cythonized/sage/structure/parent_old.c:4547)()
237 def _coerce_(self, x): # Call this from Python
(do not override!)
238 if self._element_constructor is not None:
--> 239 return self.coerce(x)
240 check_old_coerce(self)
241 return self._coerce_c(x)

/projects/sage/sage-develop/src/sage/structure/parent.pyx in
sage.structure.parent.Parent.coerce
(/projects/sage/sage-develop/src/build/cython
ized/sage/structure/parent.c:11111)()

TypeError: no canonical coercion from Full MatrixSpace of 2 by 2 dense
matrices over Rational Field to Callable function ring with argument x
sage:

--
William (http://wstein.org)

Rob Beezer

unread,
May 4, 2016, 3:41:10 PM5/4/16
to sage-devel
Well, it might have worked in 2011!  ;-)

I guess this QuickRef could use a review and update.  Even better would be a way to doctest these and have them routinely tested as part of the usual development process.  I'll give the later some thought if/when I tackle the former.

Rob
Reply all
Reply to author
Forward
0 new messages