Opened 5 years ago
Last modified 2 months ago
#23576 new defect
Wrong results in vector matrix multiplication
Reported by:  Simon Brandhorst  Owned by:  

Priority:  major  Milestone:  sage9.8 
Component:  linear algebra  Keywords:  sd91 
Cc:  Travis Scrimshaw  Merged in:  
Authors:  Reviewers:  
Report Upstream:  N/A  Work issues:  
Branch:  u/roed/vmat_action (Commits, GitHub, GitLab)  Commit:  6021daa7081396ae0c418b8f34ad69dc96a682c7 
Dependencies:  Stopgaps: 
Description
sage: M = FreeModule(ZZ,1).span([vector([1/3])]) sage: x = M([1/3]) sage: x (1/3) sage: A = Matrix(QQ,[1]) sage: x*A , A*x ((1/3), (1/3))
This is good.
sage: B = Matrix(ZZ,[1]) sage: x*B , B*x ((1), (1/3))
The first entry is clearly wrong. Somehow the first product is carried out in a wrong basis representation for x.
Change History (14)
comment:1 Changed 5 years ago by
Keywords:  sd91 added 

comment:2 Changed 5 years ago by
comment:3 Changed 5 years ago by
There's maybe a separate issue in sage.matrix.action
, since it detects the base ring of the result by checking the base ring of the inputs. But here x
and B
both have base ring ZZ
, and indeed
sage: from sage.structure.element import coercion_model sage: from operator import mul sage: coercion_model.explain(x.parent(), B.parent(), mul) Action discovered. Right action by Full MatrixSpace of 1 by 1 dense matrices over Integer Ring on Free module of degree 1 and rank 1 over Integer Ring Echelon basis matrix: [1/3] Result lives in Ambient free module of rank 1 over the principal ideal domain Integer Ring Ambient free module of rank 1 over the principal ideal domain Integer Ring
The result should probably have rational entries....
comment:4 Changed 5 years ago by
Branch:  → u/roed/vmat_action 

comment:5 Changed 5 years ago by
Commit:  → 6021daa7081396ae0c418b8f34ad69dc96a682c7 

There are segfaults in the new implementation that multiplies a nonsquare integral matrix times a rational vector. Still working on them...
New commits:
6021daa  Correct base ring for matrices acting on submodules, implement multiplication for Vector_rational_dense times an integral matrix.

comment:6 Changed 5 years ago by
*ping* :) Maybe #24031 is related to this? After all that bug occurs for vectors as well. Does this one for matrices too?
comment:7 Changed 2 years ago by
Cc:  Travis Scrimshaw added 

Milestone:  sage8.1 → sage9.2 
Still unresolved as of 9.2.beta2
comment:8 Changed 2 years ago by
There is a possibility that #28544 will solve this, see comment 10 there.
comment:9 Changed 2 years ago by
Milestone:  sage9.2 → sage9.3 

comment:10 Changed 19 months ago by
Milestone:  sage9.3 → sage9.4 

Moving to 9.4, as 9.3 has been released.
comment:11 Changed 16 months ago by
Milestone:  sage9.4 → sage9.5 

comment:12 Changed 12 months ago by
Milestone:  sage9.5 → sage9.6 

comment:13 Changed 7 months ago by
Milestone:  sage9.6 → sage9.7 

comment:14 Changed 2 months ago by
Milestone:  sage9.7 → sage9.8 

The problem appears in line 1122 of
sage.matrix.matrix_integer_dense.pyx
, inside the functioncdef _vector_times_matrix_(self, Vector v)
:If you change that to
you'll get an error, because
v
is aVector_rational_dense
, and if you change it toyou get
(1/3)
.This function is replacing a more general implementation in
sage.matrix.matrix0
, but it only replaces_vector_times_matrix_
, not_matrix_times_vector_
, thus the disparity based on whetherB
is acting on the left or right.I don't know if the try/except block is the right answer. I'll think about it....