Rank function matroids#

The easiest way to define arbitrary matroids in Sage might be through the class RankMatroid. All that is required is a groundset and a function that computes the rank for each given subset.

Of course, since the rank function is used as black box, matroids so defined cannot take advantage of any extra structure your class might have, and rely on default implementations. Besides this, matroids in this class can’t be saved.

Constructions#

Any function can be used, but no checks are performed, so be careful.

EXAMPLES:

sage: def f(X):
....:     return min(len(X), 3)
sage: M = Matroid(groundset=range(6), rank_function=f)
sage: M.is_valid()
True
sage: M.is_isomorphic(matroids.Uniform(3, 6))
True

sage: def g(X):
....:     if len(X) >= 3:
....:         return 1
....:     else:
....:         return 0
sage: N = Matroid(groundset='abc', rank_function=g)
sage: N.is_valid()
False
>>> from sage.all import *
>>> def f(X):
...     return min(len(X), Integer(3))
>>> M = Matroid(groundset=range(Integer(6)), rank_function=f)
>>> M.is_valid()
True
>>> M.is_isomorphic(matroids.Uniform(Integer(3), Integer(6)))
True

>>> def g(X):
...     if len(X) >= Integer(3):
...         return Integer(1)
...     else:
...         return Integer(0)
>>> N = Matroid(groundset='abc', rank_function=g)
>>> N.is_valid()
False

See below for more. It is recommended to use the Matroid() function for easy construction of a RankMatroid. For direct access to the RankMatroid constructor, run:

sage: from sage.matroids.advanced import *
>>> from sage.all import *
>>> from sage.matroids.advanced import *

AUTHORS:

  • Rudi Pendavingh, Stefan van Zwam (2013-04-01): initial version

Methods#

class sage.matroids.rank_matroid.RankMatroid(groundset, rank_function)[source]#

Bases: Matroid

Matroid specified by its rank function.

INPUT:

  • groundset – the groundset of a matroid.

  • rank_function – a function mapping subsets of groundset to nonnegative integers.

OUTPUT:

A matroid on groundset whose rank function equals rank_function

EXAMPLES:

sage: from sage.matroids.advanced import *
sage: def f(X):
....:     return min(len(X), 3)
sage: M = RankMatroid(groundset=range(6), rank_function=f)
sage: M.is_valid()
True
sage: M.is_isomorphic(matroids.Uniform(3, 6))
True
>>> from sage.all import *
>>> from sage.matroids.advanced import *
>>> def f(X):
...     return min(len(X), Integer(3))
>>> M = RankMatroid(groundset=range(Integer(6)), rank_function=f)
>>> M.is_valid()
True
>>> M.is_isomorphic(matroids.Uniform(Integer(3), Integer(6)))
True
groundset()[source]#

Return the groundset of self.

EXAMPLES:

sage: from sage.matroids.advanced import *
sage: M = RankMatroid(range(6),
....:                 rank_function=matroids.Uniform(3, 6).rank)
sage: sorted(M.groundset())
[0, 1, 2, 3, 4, 5]
>>> from sage.all import *
>>> from sage.matroids.advanced import *
>>> M = RankMatroid(range(Integer(6)),
...                 rank_function=matroids.Uniform(Integer(3), Integer(6)).rank)
>>> sorted(M.groundset())
[0, 1, 2, 3, 4, 5]