diff --git a/src/sage/matroids/circuits_matroid.pxd b/src/sage/matroids/circuits_matroid.pxd index 0b79ea24044..2c876fa3a48 100644 --- a/src/sage/matroids/circuits_matroid.pxd +++ b/src/sage/matroids/circuits_matroid.pxd @@ -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) diff --git a/src/sage/matroids/circuits_matroid.pyx b/src/sage/matroids/circuits_matroid.pyx index 778591efbf4..e9c3a94f3af 100644 --- a/src/sage/matroids/circuits_matroid.pyx +++ b/src/sage/matroids/circuits_matroid.pyx @@ -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 @@ -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]: @@ -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]: @@ -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: @@ -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() @@ -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 diff --git a/src/sage/matroids/matroid.pyx b/src/sage/matroids/matroid.pyx index 2c395309088..a274df52180 100644 --- a/src/sage/matroids/matroid.pyx +++ b/src/sage/matroids/matroid.pyx @@ -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:: @@ -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): ...