Skip to content

Commit

Permalink
SeriesParallelReductionNode.core, SpecialLeafNode.rep_matrix: New; Ma…
Browse files Browse the repository at this point in the history
…trix_cmr_chr_sparse.three_sum: Add doc (#13)
  • Loading branch information
jsantillan3 committed Aug 30, 2023
1 parent d5cce9b commit ec229ef
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 6 deletions.
29 changes: 25 additions & 4 deletions src/sage/matrix/matrix_cmr_sparse.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -465,10 +465,31 @@ cdef class Matrix_cmr_chr_sparse(Matrix_cmr_sparse):

def three_sum(first_mat, second_mat, first_col_index1, first_col_index2, second_col_index1, second_col_index2):
r"""
Return the 3-sum matrix constructed from the given matrices ``first_mat`` and ``second_mat``, with 'first_col_index1'
and 'first_col_index2' being the indices of the column vectors of the matrix, which are identical except for one row
having a 0 in one column and the other a non-zero entry in that row. The method assumes the nonzero entry is one. The same assumptions
are made for 'second_mat' and its input index variables.
Return the 3-sum matrix constructed from the given matrices ``first_mat`` and ``second_mat``, with ``first_col_index1``
and ``first_col_index2`` being the indices of the column vectors of the matrix, which are identical except for one row
having a 0 in one column and the other a non-zero entry in that row. The method assumes the nonzero entry is one. The same goes
are made for ``second_mat``, ``second_col_index1``, and ``second_col_index2``.
The operation performed is effectively as in Schrijver:=
[first_submat first_subcol first_subcol] ___|___ [second_submat second_subcol second_suncol]
[ first_row 0 1 ] | 3 [ second_row 0 1 ]
----- [ first_submat first_subcol x second_row]
----- [second_subcol x first_row second_subcol ]
INPUT:
- ``first_mat`` -- integer matrix having two collumns which are identical in every entry except for one row in
which one is 0 and the other is 1
- ``second_mat`` -- integer matrix having two collumns which are identical in every entry except for one row in
which one is 0 and the other is 1
- ``first_col_index1`` -- index of a column in ``first_mat`` identical to some other column in every entry except for one row in
which one is 0 and the other is 1
- ``first_col_index2`` -- index of the other column which is identical to first_mat[first_col_index1] in every entry except for one
row in which one is 0 and the other is 1
- ``second_col_index1`` -- index of a column in ``second_mat`` identical to some other column in every entry except for one row in
which one is 0 and the other is 1
- ``first_col_index2`` -- index of the other column which is identical to second_mat[second_col_index1] in every entry except for one
row in which one is 0 and the other is 1
EXAMPLES::
Expand Down
37 changes: 35 additions & 2 deletions src/sage/matrix/seymour_decomposition.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,31 @@ cdef class PlanarNode(BaseGraphicNode):

cdef class SeriesParallelReductionNode(DecompositionNode):

pass
def core(self):
r"""
EXAMPLES::
sage: from sage.matrix.matrix_cmr_sparse import Matrix_cmr_chr_sparse
sage: M = Matrix_cmr_chr_sparse(MatrixSpace(ZZ, 5, 6, sparse=True),
....: [[1, 1, 1, 1, 1, 0], [1, 1, 1, 0,0, 0],
....: [1, 0, 1, 1, 0, 1] ,[1, 0,0, 1, 1, 0],
....: [1, 1, 0, 0, 1, 0]]); M
[1 1 1 1 1 0]
[1 1 1 0 0 0]
[1 0 1 1 0 1]
[1 0 0 1 1 0]
[1 1 0 0 1 0]
sage: result, certificate = M.is_totally_unimodular(certificate = True); result
....: , certificate
(True, SeriesParallelReductionNode (5×6))
sage: certificate.core()
[1 1 1 1 1]
[1 1 1 0 0]
[1 0 1 1 0]
[1 0 0 1 1]
[1 1 0 0 1]
"""
return self._children()[0].matrix()


cdef class SpecialLeafNode(DecompositionNode):
Expand Down Expand Up @@ -475,8 +499,17 @@ cdef class SpecialLeafNode(DecompositionNode):
assert False, 'special leaf node with unknown type'

def _repr_(self):
return f'Minor isomorphic to {self._matroid()}'
return f'Isomorphic to a minor of {self._matroid()}'

def rep_matrix(self):
r"""
WIP
"""
assert NotImplementedError

cdef int representation_matrix
cdef CMR_DEC_TYPE typ = CMRdecIsSpecialLeaf(self._dec, &representation_matrix)
return Matrix_cmr_chr_sparse._from_data(representation_matrix, immutable=False)

cdef _class(CMR_DEC *dec):
k = CMRdecIsSum(dec, NULL, NULL)
Expand Down

0 comments on commit ec229ef

Please sign in to comment.