Here's what mod 3 et all do: sage: A = random_matrix(GF(3),10,10) sage: A.submatrix?
Definition: A.submatrix(self, row=0, col=0, nrows=-1, ncols=-1)
Docstring:
Return the matrix constructed from self using the specified range
of rows and columns.
INPUT:
* "row", "col" - index of the starting row and column. Indices
start at zero.
* "nrows", "ncols" - (optional) number of rows and columns to take.
If not provided, take all rows below and all columns to the right
of the starting entry.
mod 2 should do the same.
I think the bug is in matrices mod 2. Your workaround in smith forms is
fine, but it's still a bug in mod 2 matrices (which likely I introduced)
On 19/02/14 03:04, [email protected] wrote:
> I spent a while running print statements. I'm not sure how this even worked
> previously (was it figuring out the rows and cols based on the "self"
> passed as a parameter?)
>
> There isn't really a sensible default to pass to the sub matrix function,
> in my opinion, because there isn't a sensible default - it is expecting the
> rows/cols of the sub matrix to be a parameter, so I figured out the
> problem is with the smith_form() function still (mm = t.submatrix(1,1) in
> current version of Sage). I'm not sure how the submatrix() function
> interprets the rows and cols with mod 3/integer coefficients, but if I give
> the other two parameters to the sub matrix() call,
>
> i.e.
>
> inr = t.nrows() - 1
> inc = t.ncols() - 1
> mm = t.submatrix(1,1,inr,inc)
>
> it appears to fix the issue. From a few examples, I achieved the same
> results as the current master branch (6.11) of Sage.
>
> Examples of my own:
>
> 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 and modified version)
>
> here's an example that I already new the answer to by hand computation (and
> ran this through sage w/ the modified version, this does not work in
> current version of master)
>
> 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]
>
> I was skimming through
> http://sagemath.github.io/git-developer-guide/walk_through.html and
> http://sagemath.github.io/git-developer-guide/trac.html#section-trac-account
>
> should I open a ticket...? or fork sagemath/Sage and make a PR?
>
> On Tuesday, February 18, 2014 2:07:53 PM UTC-5, Martin R. Albrecht wrote:
>>
>> Looks like a bug to me, i.e. the mod2 submatrix command should assume
>> default parameters when less than four parameters are given.
>>
>> I am happy to review your patch ;)
>>
>> On 18/02/14 18:38, [email protected] <javascript:> wrote:
>>> I'm trying to compute some homology stuff by finding the smith normal
>>> form of (fairly) large matrices.
>>>
>>> I do the following:
>>>
>>> A = Matrix(IntegerModRing(2),[[1,0,2],[1,0,1]]) A.smith_form()
>>>
>>> and I get the following 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)
>>>
>>> Looking at the code, line 12413 (mm = t.submatrix(1,1) ) only passes
>>> two arguments while the actual sub matrix function takes 5 arguments
>>> (itself, which doesn't count, lowr, lowc, nrows, ncols).
>>>
>>> Since the integers mod 2 are a field, this "should" be working in
>>> theory. The integers mod 3 and the integers both work. Any thoughts?
>>>
>>
>>
signature.asc
Description: OpenPGP digital signature
