Skip to content

Commit

Permalink
Suggestions by tscrim
Browse files Browse the repository at this point in the history
Store sorted circuit lengths and other minor edits.
  • Loading branch information
gmou3 committed May 6, 2024
1 parent d565827 commit ac338d5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
5 changes: 3 additions & 2 deletions src/sage/matroids/circuits_matroid.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ from sage.matroids.matroid cimport Matroid
from sage.matroids.set_system cimport SetSystem

cdef class CircuitsMatroid(Matroid):
cdef frozenset _groundset # _E
cdef int _matroid_rank # _R
cdef frozenset _groundset
cdef int _matroid_rank
cdef set _C # circuits
cdef dict _k_C # k-circuits (k=len)
cdef list _sorted_C_lens
cdef bint _nsc_defined
cpdef groundset(self)
cpdef _rank(self, X)
Expand Down
14 changes: 8 additions & 6 deletions src/sage/matroids/circuits_matroid.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ cdef class CircuitsMatroid(Matroid):
except KeyError:
self._k_C[len(C)] = set()
self._k_C[len(C)].add(C)
self._sorted_C_lens = sorted(self._k_C)
self._matroid_rank = self.rank(self._groundset)
self._nsc_defined = nsc_defined

Expand Down Expand Up @@ -160,7 +161,7 @@ cdef class CircuitsMatroid(Matroid):
"""
cdef set XX = set(X)
cdef int i, l = len(XX)
for i in sorted(self._k_C):
for i in self._sorted_C_lens:
if i > l:
break
for C in self._k_C[i]:
Expand Down Expand Up @@ -220,7 +221,7 @@ cdef class CircuitsMatroid(Matroid):
"""
cdef set XX = set(X)
cdef int i, l = len(XX)
for i in sorted(self._k_C):
for i in self._sorted_C_lens:
if i > l:
break
for C in self._k_C[i]:
Expand Down Expand Up @@ -249,8 +250,9 @@ cdef class CircuitsMatroid(Matroid):
cdef set XX = set(X)
cdef frozenset S
cdef int i
for i in sorted(self._k_C):
if i > len(XX) + 1: break
for i in self._sorted_C_lens:
if i > len(XX) + 1:
break
for C in self._k_C[i]:
S = C - XX
if len(S) == 1:
Expand Down Expand Up @@ -569,7 +571,7 @@ cdef class CircuitsMatroid(Matroid):
SetSystem of 0 sets over 8 elements
sage: sorted([sorted(X) for X in M.dependent_r_sets(4)])
[['a', 'b', 'c', 'd'], ['a', 'b', 'e', 'f'], ['a', 'b', 'g', 'h'],
['c', 'd', 'e', 'f'], ['e', 'f', 'g', 'h']]
['c', 'd', 'e', 'f'], ['e', 'f', 'g', 'h']]
"""
cdef int i
cdef set NB = set()
Expand Down Expand Up @@ -924,7 +926,7 @@ cdef class CircuitsMatroid(Matroid):
cdef int i, j, k
cdef frozenset C1, C2, C3, I12, U12
cdef bint flag
for (i, j) in combinations_with_replacement(sorted(self._k_C), 2):
for (i, j) in combinations_with_replacement(self._sorted_C_lens, 2):
# loop through all circuit length pairs (i, j) with i <= j
for C1 in self._k_C[i]:
if not C1: # the empty set can't be a circuit
Expand Down
6 changes: 3 additions & 3 deletions src/sage/matroids/matroid.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2855,9 +2855,9 @@ cdef class Matroid(SageObject):
sage: M = matroids.catalog.Pappus()
sage: M.independent_r_sets(4)
SetSystem of 0 sets over 9 elements
sage: M.independent_r_sets(3)
sage: S = M.independent_r_sets(3); S
SetSystem of 75 sets over 9 elements
sage: frozenset({'a', 'c', 'e'}) in _
sage: frozenset({'a', 'c', 'e'}) in S
True
.. SEEALSO::
Expand Down Expand Up @@ -8296,7 +8296,7 @@ cdef class Matroid(SageObject):
For a matroid with loops, the broken circuit complex is not defined,
and the method yields an error::
sage: M = Matroid(flats={0:['a'], 1:['ab', 'ac'], 2:['abc']})
sage: M = Matroid(flats={0: ['a'], 1: ['ab', 'ac'], 2: ['abc']})
sage: M.broken_circuit_complex()
Traceback (most recent call last):
...
Expand Down

0 comments on commit ac338d5

Please sign in to comment.