Possible bug? Matroid contraction when creating a matroid from Matroid() by giving flats.
Here's the code I'm using as a minimal example:
from sage.matroids.constructor import Matroid
flats = [frozenset(), frozenset([1]), frozenset([2]), frozenset([3]), frozenset([1,2,3])]
M = Matroid(flats=flats)
print(M.groundset())
print(2 in M.groundset())
M.contract({2})
This is the corresponding output:
frozenset({1, 2, 3})
True
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[5], line 6
4 print(M.groundset())
5 print(Integer(2) in M.groundset())
----> 6 M.contract({Integer(2)})
File /ext/sage/10.6/src/sage/matroids/matroid.pyx:4131, in sage.matroids.matroid.Matroid.contract()
4129 return self._minor(conset, delset)
4130
-> 4131 cpdef contract(self, X):
4132 r"""
4133 Contract elements.
File /ext/sage/10.6/src/sage/matroids/matroid.pyx:4195, in sage.matroids.matroid.Matroid.contract()
4193 ['a', 'b', 'c']
4194 """
-> 4195 return self.minor(contractions=X)
4196
4197 def __truediv__(self, X):
File /ext/sage/10.6/src/sage/matroids/matroid.pyx:4128, in sage.matroids.matroid.Matroid.minor()
4126 if (not isinstance(deletions, (str, Iterable)) and deletions is not None):
4127 deletions = [deletions]
-> 4128 conset, delset = sanitize_contractions_deletions(self, contractions, deletions)
4129 return self._minor(conset, delset)
4130
File /ext/sage/10.6/src/sage/matroids/utilities.py:236, in sanitize_contractions_deletions(matroid, contractions, deletions)
233 if not contractions.isdisjoint(deletions):
234 raise ValueError("contraction and deletion sets are not disjoint.")
--> 236 conset = matroid._max_independent(contractions)
237 delset = matroid._max_coindependent(deletions)
239 return conset.union(deletions.difference(delset)), delset.union(contractions.difference(conset))
File /ext/sage/10.6/src/sage/matroids/matroid.pyx:621, in sage.matroids.matroid.Matroid._max_independent()
619 # each derived class
620
--> 621 cpdef frozenset _max_independent(self, frozenset X):
622 """
623 Compute a maximal independent subset.
File /ext/sage/10.6/src/sage/matroids/matroid.pyx:645, in sage.matroids.matroid.Matroid._max_independent()
643 for e in X:
644 res.append(e)
--> 645 if self._rank(res) > r:
646 r += 1
647 else:
TypeError: Expected frozenset, got list
I've tried changing the contract command to all sorts of other variations and they all throw the same error. After attempting to debug using AI, I finally gave up and came here.