Ask Your Question
1

Bug when testing if a matrix is in SR

asked 2019-11-02 11:09:26 -0600

Florentin Jaffredo gravatar image

On sagemath 8.9, I find the behavior of SR with matrix a bit strange.

sage: M = matrix([[0, -1], [1, 0]])
sage: print(SR(M)+M)
[[ 0 -1]
[ 1  0]              -1]
[              1 [ 0 -1]
[ 1  0]]

What is the use of coercing a matrix to the symbolic ring if it cannot be used as a matrix afterward?

These two lines of code also both raise an attribute error:

sage: SR(M) == M
sage: M in SR
AttributeError: 'ComplexIntervalField_class_with_category' object has no attribute 'complex_field'

By itself, it is not very relevant, but some element constructors (e.g. lie_algebra) contain a line

if x in self.base_ring():
    do something

which means SR cannot be used as a base ring.

Is this a known bug?

A workaround would be to add a single line in SR.__contains__ to return false when x is matrix (or maybe there are case when a matrix is considered in SR, I don't know), but this would not solve the underlying issues.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2019-11-02 12:28:30 -0600

Use M.change_ring(SR) to change the entries of M to lie in the symbolic ring. Note that M.change_ring(SR) will still be a matrix. On the other hand, SR(M) is not a matrix. For most uses, I think that M.change_ring(SR) is the right choice.

sage: M = matrix([[0, -1], [1, 0]])
sage: type(SR(M))
<class 'sage.symbolic.expression.Expression'>
sage: type(M.change_ring(SR))
<class 'sage.matrix.matrix_symbolic_dense.Matrix_symbolic_dense'>
sage: M.change_ring(SR) == M
True
sage: M.change_ring(SR) + M
[ 0 -2]
[ 2  0]
edit flag offensive delete link more

Comments

1

I am even surprised that SR(M) does not throw any error. What kind of beast is this matrix in the Symbolic RIng?

eric_g gravatar imageeric_g ( 2019-11-02 12:47:04 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2019-11-02 11:09:26 -0600

Seen: 41 times

Last updated: Nov 02