#15835: Smith Normal Form Integers Mod 2 TypeError: submatrix() takes exactly 4
positional arguments(2 given)
-------------------------------------+-------------------------------------
Reporter: andrewsilver | Owner:
Type: defect | Status: needs_review
Priority: minor | Milestone: sage-6.2
Component: linear algebra | Resolution:
Keywords: | Merged in:
Authors: | Reviewers:
Report Upstream: N/A | Work issues:
Branch: | Commit:
u/andrewsilver/ticket/15835 | f636d4b3e4d006437edd0da6295ce8d516db6247
Dependencies: | Stopgaps:
-------------------------------------+-------------------------------------
Description changed by jhpalmieri:
Old description:
> Try the following (Mac OS X Mavericks, Sage 6.11 Master Branch):
>
> A = Matrix(IntegerModRing(2),[[1,0,2],[1,0,1]])
> A.smith_form()
>
> You get the error:
> > TypeError Traceback (most recent call
> > last) <ipython-input-6-23e95c6be019> in <module>() ----> 1
> > A.smith_form()
> > /Users/.../builds/sage-6.1.1/local/lib/python2.7/site-
> packages/sage/matrix/matrix2.so
> > in sage.matrix.matrix2.Matrix.smith_form
> > (sage/matrix/matrix2.c:60007)()
> > /Users/.../builds/sage-6.1.1/local/lib/python2.7/site-
> packages/sage/matrix/matrix_mod2_dense.so
> > in sage.matrix.matrix_mod2_dense.Matrix_mod2_dense.submatrix
> > (sage/matrix/matrix_mod2_dense.c:10429)()
> > TypeError: submatrix() takes exactly 4 positional arguments (2
> > given)
>
> This error does not appear for calculations over the integers mod 3
>
> With the advice from https://groups.google.com/forum/#!topic/sage-
> devel/7F5xUQFcfXE, I went ahead and created what looks like a patch (to
> me, anyway):
>
> Inside the smith_form() function in matrix2.pyx:
>
> We have: mm = t.submatrix(1,1) on line 12413.
>
> The sub matrix function takes five parameters (self, starting row,
> starting col, # sub matrix rows, # sub matrix columns). From observation,
> the 1,1 is the starting row/col respectively. Somehow the function is
> unable to determine ncols and nrows when using the integers mod 2, but
> after some trial and error I discovered a potential patch:
>
> submatrix_rows = t.rows -1
> submatrix_cols = t.cols - 1
> mm = t.submatrix(1,1, submatrix_rows, submatrix,cols)
>
> The above modification gives the same answers as all the examples in the
> source code. I tested a couple of other things:
>
> Mod 3 Example:
> A = Matrix(Integers(3),[[1,0,2],[1,0,1],[1,1,1]])
> [1 0 0] [1 0 0] [1 0 1]
> [0 1 0] [2 0 1] [0 1 1]
> [0 0 1], [1 2 0], [0 0 1]
> (same for mod 3 in current master and modified version)
>
> Example mod 2 (not computable in current version of Sage - checked with
> hand computation - good luck checking it!) -
>
> sage: C =
> Matrix(IntegerModRing(2),[[1,0,1,0],[1,1,0,0],[0,1,1,0],[1,0,0,1],[0,0,1,1],[0,1,0,1]])
> sage: C.smith_form()
> (
> [1 0 0 0] [1 0 0 0 0 0]
> [0 1 0 0] [1 1 0 0 0 0]
> [0 0 1 0] [1 0 0 1 0 0] [1 0 1 1]
> [0 0 0 0] [1 1 1 0 0 0] [0 1 1 1]
> [0 0 0 0] [1 0 0 1 1 0] [0 0 1 1]
> [0 0 0 0], [0 1 0 1 0 1], [0 0 0 1]
> )
> sage: t,u,v=C.smith_form()
> sage: u.inverse()
> [1 0 0 0 0 0]
> [1 1 0 0 0 0]
> [0 1 0 1 0 0]
> [1 0 1 0 0 0]
> [0 0 1 0 1 0]
> [0 1 1 0 0 1]
New description:
Try the following (Mac OS X Mavericks, Sage 6.11 Master Branch):
{{{
A = Matrix(IntegerModRing(2),[[1,0,2],[1,0,1]])
A.smith_form()
}}}
You get the error:
{{{
> TypeError Traceback (most recent call
> last) <ipython-input-6-23e95c6be019> in <module>() ----> 1
> A.smith_form()
> /Users/.../builds/sage-6.1.1/local/lib/python2.7/site-
packages/sage/matrix/matrix2.so
> in sage.matrix.matrix2.Matrix.smith_form
> (sage/matrix/matrix2.c:60007)()
> /Users/.../builds/sage-6.1.1/local/lib/python2.7/site-
packages/sage/matrix/matrix_mod2_dense.so
> in sage.matrix.matrix_mod2_dense.Matrix_mod2_dense.submatrix
> (sage/matrix/matrix_mod2_dense.c:10429)()
> TypeError: submatrix() takes exactly 4 positional arguments (2
> given)
}}}
This error does not appear for calculations over the integers mod 3
With the advice from https://groups.google.com/forum/#!topic/sage-
devel/7F5xUQFcfXE, I went ahead and created what looks like a patch (to
me, anyway):
Inside the smith_form() function in matrix2.pyx:
We have: `mm = t.submatrix(1,1)` on line 12413.
The sub matrix function takes five parameters (self, starting row,
starting col, # sub matrix rows, # sub matrix columns). From observation,
the 1,1 is the starting row/col respectively. Somehow the function is
unable to determine ncols and nrows when using the integers mod 2, but
after some trial and error I discovered a potential patch:
{{{
submatrix_rows = t.rows -1
submatrix_cols = t.cols - 1
mm = t.submatrix(1,1, submatrix_rows, submatrix,cols)
}}}
The above modification gives the same answers as all the examples in the
source code. I tested a couple of other things:
{{{
Mod 3 Example:
A = Matrix(Integers(3),[[1,0,2],[1,0,1],[1,1,1]])
[1 0 0] [1 0 0] [1 0 1]
[0 1 0] [2 0 1] [0 1 1]
[0 0 1], [1 2 0], [0 0 1]
}}}
(same for mod 3 in current master and modified version)
Example mod 2 (not computable in current version of Sage - checked with
hand computation - good luck checking it!) -
{{{
sage: C =
Matrix(IntegerModRing(2),[[1,0,1,0],[1,1,0,0],[0,1,1,0],[1,0,0,1],[0,0,1,1],[0,1,0,1]])
sage: C.smith_form()
(
[1 0 0 0] [1 0 0 0 0 0]
[0 1 0 0] [1 1 0 0 0 0]
[0 0 1 0] [1 0 0 1 0 0] [1 0 1 1]
[0 0 0 0] [1 1 1 0 0 0] [0 1 1 1]
[0 0 0 0] [1 0 0 1 1 0] [0 0 1 1]
[0 0 0 0], [0 1 0 1 0 1], [0 0 0 1]
)
sage: t,u,v=C.smith_form()
sage: u.inverse()
[1 0 0 0 0 0]
[1 1 0 0 0 0]
[0 1 0 1 0 0]
[1 0 1 0 0 0]
[0 0 1 0 1 0]
[0 1 1 0 0 1]
}}}
--
--
Ticket URL: <http://trac.sagemath.org/ticket/15835#comment:5>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/groups/opt_out.