Skip to content

Commit

Permalink
Trac #33744: Compute bases/circuits in MatroidUnion
Browse files Browse the repository at this point in the history
It appears there is a bug computing the bases and circuits of a
`MatroidUnion`.

{{{
sage: k, h, n = 4, 3, 5
sage: M1 = matroids.Uniform(k-1, h)
sage: M2 = Matroid(bases = [frozenset({3}),frozenset({4})])
sage: M = M1.union(M2); M
Matroid of rank 4 on 5 elements as matroid union of
Matroid of rank 3 on 3 elements with circuit-closures
{}
Matroid of rank 1 on 2 elements with 2 bases
sage: M.bases()
sage: M.bases()
------------------------------------------------------------------------
---
TypeError                                 Traceback (most recent call
last)
<ipython-input-48-a32efdfad611> in <module>
----> 1 M.bases()

~/Applications/sage/local/var/lib/sage/venv-python3.9/lib/python3.9
/site-packages/sage/matroids/matroid.pyx in
sage.matroids.matroid.Matroid.bases
(build/cythonized/sage/matroids/matroid.c:21764)()
   2615         return res
   2616
-> 2617     cpdef bases(self):
   2618         r"""
   2619         Return the list of bases of the matroid.

~/Applications/sage/local/var/lib/sage/venv-python3.9/lib/python3.9
/site-packages/sage/matroids/matroid.pyx in
sage.matroids.matroid.Matroid.bases
(build/cythonized/sage/matroids/matroid.c:21661)()
   2643         res = SetSystem(list(self.groundset()))
   2644         for X in combinations(self.groundset(),
self.full_rank()):
-> 2645             if self._rank(X) == len(X):
   2646                 res.append(X)
   2647         return res

~/Applications/sage/local/var/lib/sage/venv-python3.9/lib/python3.9
/site-packages/sage/matroids/union_matroid.pyx in
sage.matroids.union_matroid.MatroidUnion._rank
(build/cythonized/sage/matroids/union_matroid.c:3080)()
     90         summands = []
     91         for e in self.matroids:
---> 92             summands.append(e.delete(e.groundset()-X))
     93         sum_matroid = MatroidSum(summands)
     94         d = {}

TypeError: unsupported operand type(s) for -: 'frozenset' and 'tuple'
sage: M.circuits()
------------------------------------------------------------------------
---
TypeError                                 Traceback (most recent call
last)
<ipython-input-47-8adfde621a57> in <module>
----> 1 M.circuits()

~/Applications/sage/local/var/lib/sage/venv-python3.9/lib/python3.9
/site-packages/sage/matroids/matroid.pyx in
sage.matroids.matroid.Matroid.circuits
(build/cythonized/sage/matroids/matroid.c:19192)()
   2370     # enumeration
   2371
-> 2372     cpdef circuits(self):
   2373         """
   2374         Return the list of circuits of the matroid.

~/Applications/sage/local/var/lib/sage/venv-python3.9/lib/python3.9
/site-packages/sage/matroids/matroid.pyx in
sage.matroids.matroid.Matroid.circuits
(build/cythonized/sage/matroids/matroid.c:18928)()
   2393         """
   2394         C = set()
-> 2395         for B in self.bases():
   2396             C.update([self._circuit(B.union(set([e])))
   2397                       for e in self.groundset().difference(B)])

~/Applications/sage/local/var/lib/sage/venv-python3.9/lib/python3.9
/site-packages/sage/matroids/matroid.pyx in
sage.matroids.matroid.Matroid.bases
(build/cythonized/sage/matroids/matroid.c:21661)()
   2643         res = SetSystem(list(self.groundset()))
   2644         for X in combinations(self.groundset(),
self.full_rank()):
-> 2645             if self._rank(X) == len(X):
   2646                 res.append(X)
   2647         return res

~/Applications/sage/local/var/lib/sage/venv-python3.9/lib/python3.9
/site-packages/sage/matroids/union_matroid.pyx in
sage.matroids.union_matroid.MatroidUnion._rank
(build/cythonized/sage/matroids/union_matroid.c:3080)()
     90         summands = []
     91         for e in self.matroids:
---> 92             summands.append(e.delete(e.groundset()-X))
     93         sum_matroid = MatroidSum(summands)
     94         d = {}

TypeError: unsupported operand type(s) for -: 'frozenset' and 'tuple'
}}}

URL: https://trac.sagemath.org/33744
Reported by: tkarn
Ticket author(s): Trevor K. Karn
Reviewer(s): Travis Scrimshaw
  • Loading branch information
Release Manager committed May 22, 2022
2 parents 8943dc0 + 8fffb1c commit f02236f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/sage/matroids/matroid.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2643,7 +2643,7 @@ cdef class Matroid(SageObject):
cdef SetSystem res
res = SetSystem(list(self.groundset()))
for X in combinations(self.groundset(), self.full_rank()):
if self._rank(X) == len(X):
if self._rank(frozenset(X)) == len(X):
res.append(X)
return res

Expand Down
14 changes: 14 additions & 0 deletions src/sage/matroids/union_matroid.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@ cdef class MatroidUnion(Matroid):
`I= \{\bigcup_{i=1}^n J_i | J_i \in I_i \}`.
EXAMPLES::
sage: M1 = matroids.Uniform(3,3)
sage: M2 = Matroid(bases = [frozenset({3}), frozenset({4})])
sage: M = M1.union(M2); M
Matroid of rank 4 on 5 elements as matroid union of
Matroid of rank 3 on 3 elements with circuit-closures
{}
Matroid of rank 1 on 2 elements with 2 bases
sage: M.bases()
Iterator over a system of subsets
sage: M.circuits()
[frozenset({3, 4})]
INPUT:
- ``matroids`` -- a iterator of matroids.
Expand Down

0 comments on commit f02236f

Please sign in to comment.