Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Matrix-scalar and vector-scalar operations

Consider :

sage: b=vector([var("b_{}".format(u)) for u in (1..3)])
sage: B=matrix(b).transpose()*matrix(b)

Unsurprisingly :

sage: B*x
[  b_1^2*x b_1*b_2*x b_1*b_3*x]
[b_1*b_2*x   b_2^2*x b_2*b_3*x]
[b_1*b_3*x b_2*b_3*x   b_3^2*x]

This is less obvious (but intuitively compatible with associativity) :

sage: B+x
[b_1^2 + x   b_1*b_2   b_1*b_3]
[  b_1*b_2 b_2^2 + x   b_2*b_3]
[  b_1*b_3   b_2*b_3 b_3^2 + x]

This also is unsurprising :

sage: b*x
(b_1*x, b_2*x, b_3*x)

But there is nothing "obviously expectable" from this :

sage: b+x
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-29-58bd66da7aa5> in <module>
----> 1 b+x

/usr/local/sage-9/local/lib/python3.9/site-packages/sage/structure/element.pyx in sage.structure.element.Element.__add__ (build/cythonized/sage/structure/element.c:10988)()
   1230         # Left and right are Sage elements => use coercion model
   1231         if BOTH_ARE_ELEMENT(cl):
-> 1232             return coercion_model.bin_op(left, right, add)
   1233 
   1234         cdef long value

/usr/local/sage-9/local/lib/python3.9/site-packages/sage/structure/coerce.pyx in sage.structure.coerce.CoercionModel.bin_op (build/cythonized/sage/structure/coerce.c:11708)()
   1248         # We should really include the underlying error.
   1249         # This causes so much headache.
-> 1250         raise bin_op_exception(op, x, y)
   1251 
   1252     cpdef canonical_coercion(self, x, y):

TypeError: unsupported operand parent(s) for +: 'Vector space of dimension 3 over Symbolic Ring' and 'Symbolic Ring'

However,

sage: vector([u+x for u in b])
(b_1 + x, b_2 + x, b_3 + x)

would be a possible candidate, but I have trouble visualizing the consequences in the rest of algebraic computation rules in Sage. Is this documented ?