# 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
```

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 *
```

AUTHORS:

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

## Methods#

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

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
```
groundset()#

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]
```