Matroid computation in SageMath: visualizations

This post is another installment in my series on matroid computation in SageMath [1], with older posts herehere, here, and here. As always, clicking the “Evaluate” buttons below will execute the code and return the answer (or, in today’s post, draw the picture). The various computations are linked, so execute them in the right order.

Last summer, Jayant Apte was selected to participate in the Google Summer of Code program. During the summer he extended SageMath’s matroid capabilities in two major ways.

  • Drawing geometric representations of rank-3 matroids
  • A more efficient minor test for binary matroids

The first of these has been part of Sage for a while; the second is awaiting review but should be included fairly soon.

Let’s get started with everyone’s favorite matroid.

That was easy! We can deal with parallel elements too:

Loops are no problem either:

Note that we resort to a slightly different method of display for large parallel classes. The point in the geometric representation will receive a label that is not an element of the matroid, and below the diagram it will state that this label actually represents a parallel class of elements.

The examples above were chosen because the default positioning algorithm gives a decent picture. Unfortunately, that is not always the case:

In these instances, the options of the show() method come in handy. To get a full list, type in your own session of SageMath, and hit the key. This will bring up the help page of the method (assuming you defined $M$ to be a matroid in an earlier command). We will go through these options one by one.

This is not bad, but we don’t need a curved line to draw this diagram. The solution is to specify a different basis, whose elements will be placed at the corners of a triangle:

Trying different bases is not going to help the Pappus matroid too much. In that case, after inspecting, for instance, M.circuit_closures(), we can come up with custom coordinates for the points. To tell Sage that we’re doing this, we add the option pos_method=1.

A second example, just because:

Our final option today deals with betweenness. In projective geometry this is a meaningless concept, of course, but in a concrete diagram it can matter whether we draw a line from $a$ through $b$ to $c$ or from $b$ through $a$ to $c$. In SageMath, we can specify this through the line_orders option. An example should make this clear.

We specify the order on the line $\{d,e,f\}$:

A slightly less contrived example is provided by $\textrm{AG}(2,3)$.

I prefer a rotational symmetry to the curved lines:

It’s not perfect (I’d like the curved lines to protrude out of the square), but it’s in the ballpark.

Note: after you have drawn a matroid, the options for drawing so are saved. So next time,

will produce the same graphic.

There are many ways in which the drawing routines can be improved. Options like color, aspect ratio, letting the user decide how to handle parallel elements, and functionality like saving plot information when you save a matroid, adding “nice” plots to the built-in library of matroids, special plots for Dowling geometries, plots for rank-4 matroids, and the list goes on. Interested? There’s another Google Summer of Code coming up soon!

[1] SageMath is now the official name of the Sage Mathematical Software System.

Non-unimodality of 2-polymatroids

Guest post by Thomas Savitsky

A $k$-polymatroid is a generalization of a matroid in which the rank of an element is allowed to exceed one, but cannot exceed $k$.

Definition 1.
Let $S$ be a finite set. Suppose $\rho : 2^S \to \mathbb{N}$ satisfies the following four conditions:

  • if $X, Y \subseteq S$, then $\rho(X \cap Y) + \rho(X \cup Y) \le \rho(X) + \rho(Y)$
  • if $X \subseteq Y \subseteq S$, then $\rho(X) \le \rho(Y)$ (monotone);
  • $\rho(\varnothing) = 0$ (normalized); and
  • $\rho(\{x\}) \le k$ for all $x \in S$.

Then $(\rho, S)$ is a $k$-polymatroid with rank function $\rho$ and ground set $S$.

So a matroid is a $1$-polymatroid. Here are a few examples of $2$-polymatroids.

  • If $(r_1, S)$, and $(r_2, S)$ are matroids, then $(r_1+r_2, S)$ is a $2$-polymatroid.
  • If $G = (V, E)$ is a graph, one may define a $2$-polymatroid $(\rho, E)$, where
    $\rho(X)$ equals the number of vertices incident to $X$.
  • Given an $m \times 2n$ matrix with entries in a field, one may define a representable $2$-polymatroid on $n$ elements by pairing up the columns in a obvious manner.

We became interested in $k$-polymatroids and thought it would be practical to have a catalog of the small ones at our disposal. We successfully adapted the canonical deletion
approach used by Mayhew and Royle (see [MR08]) to catalog matroids on nine elements to $2$-polymatroids. This first required developing a theory of single-element extensions of $k$-polymatroids. We then wrote code in the C programming language and interfaced with Brendan McKay’s nauty program and the igraph graph library. After a few days of execution time on a desktop computer, our program produced a catalog of all $2$-polymatroids, up to isomorphism, on at most seven elements.

By consulting our catalog, we produced Table 1, which lists the number of unlabeled $2$-polymatroids on the ground set $\{1, \ldots, n\}$ by rank.

Table 1: The number of unlabeled $2$-polymatroids.
rank $\backslash$ $n$ 0 1 2 3 4 5 6 7
0 1 1 1 1 1 1 1 1
1 1 2 3 4 5 6 7
2 1 4 10 21 39 68 112
3 2 12 49 172 573 1890
4 1 10 78 584 5236 72205
5 3 49 778 18033 971573
6 1 21 584 46661 149636721
7 4 172 18033 19498369
8 1 39 5236 149636721
9 5 573 971573
10 1 68 72205
11 6 1890
12 1 112
13 7
14 1
total 1 3 10 40 228 2380 94495 320863387


Surprisingly, the number of $2$-polymatroids on seven elements is not unimodal in rank. In contrast, matroids are conjectured to be unimodal in rank, and the catalog of matroids with nine elements supports this. By the way, the symmetry in the columns in Table 1 is accounted for by a notion of duality for $2$-polymatroids.

Note that one can obtain the analogue of Table 1 for labeled $2$-polymatroids by computing the automorphism group of each $2$-polymatroid and then using the Orbit-Stabilizer relation. This allowed us to confirm the results of our enumeration through another means. By interpreting a $2$-polymatroid as a solution to a certain integer programming program, the number of labeled $2$-polymatroids can theoretically be computed by integer programming software. Fortunately, the software package SCIP was up to the task when $n \le 7$.

See [Sa14] for more details on all of the above.

Now recall that a matroid $M$ is paving if it contains no circuit of size less than $r(M)$. If both $M$ and $M^{*}$ are paving, then $M$ is sparse-paving. If $M$ is sparse-paving, then one can show that that every set of size less than $r(M)$ is independent and that the dependent $r(M)$-subsets are circuit-hyperplanes; furthermore, the symmetric difference of any two circuit-hyperplanes must be at least $4$. In fact, sparse-paving matroids are characterized by these properties.

It is conjectured that almost all matroids are sparse-paving.

The ideas in the remainder of this post were communicated to me by
Rudi Pendavingh.

We first mention the following background item. Let $S = \{e_1, e_2, \dots, e_n\} \cup \{f_1, f_2, \dots, f_n\}$ be a set of size $2n$. Suppose $(r, S)$ is a matroid. We will pair up the elements of $S$ to define a $2$-polymatroid as follows. Define $S’ = \big\{\{e_1, f_1\}, \{e_2, f_2\}, \dots, \{e_n, f_n\}\big\}$, and define $\rho : S’ \to \mathbb{N}$ by
$$\rho\big(\big\{\{e_{i_1}, f_{i_1}\}, \{e_{i_2}, f_{i_2}\}, \dots, \{e_{i_m}, f_{i_m}\}\big\}\big) = r(\{e_{i_1}, f_{i_1}, e_{i_2}, f_{i_2},\dots, e_{i_m}, f_{i_m}\}).$$
Then $(\rho, S’)$ is a $2$-polymatroid on $n$ elements with $\rho(S’) = r(S)$. Furthermore, every $2$-polymatroid on $n$ elements may be obtained in this manner from a matroid on $2n$ elements. See Section 44.6b of Schrijver’s Combinatorial Optimization or Theorem 11.1.9 of Oxley’s Matroid Theory for details.

Now assume that $r$ is a sparse-paving matroid. If $r(S)$ is odd, then $\rho$ does not detect any of the circuit-hyperplanes of $r$; namely,
\rho(X) =
2|X| & \text{if} \ 2|X| < r(S),\\ r(S) & \text{if} \ 2|X| > r(S).\\
To illustrate, all the rank-$7$ sparse-paving matroids on 14 elements map, in this manner, to a single rank-$7$ $2$-polymatroid on seven elements. However, if $r(S)$ is even, then the circuit-hyperplanes of $r$ are picked up by $\rho$. Perhaps this observation, combined with the conjecture that almost all matroids are sparse-paving, makes the non-unimodality of $2$-polymatroids appear more reasonable.


[MR08] Dillon Mayhew and Gordon F. Royle.
Matroids with nine elements.
J. Combin. Theory Ser. B, 98(2):415–431, 2008.

[Sa14] Thomas J. Savitsky.
Enumeration of 2-polymatroids on up to seven elements.
SIAM J. Discrete Math., 28(4):1641–1650, 2014.