Skip to content

Commit

Permalink
sagemathgh-38013: DualMatroid: Add is_valid and relabel methods
Browse files Browse the repository at this point in the history
    
Implement class-specific `is_valid` and `relabel` methods.
Previously, such functionality was achieved through the generic and very
slow rank-based algorithms.

The PR also does a touch-up of the docstrings of `dual_matroid.py`.
    
URL: sagemath#38013
Reported by: gmou3
Reviewer(s): gmou3, Travis Scrimshaw
  • Loading branch information
Release Manager committed May 18, 2024
2 parents 29b0f98 + 54777b5 commit 55d4cb3
Show file tree
Hide file tree
Showing 12 changed files with 184 additions and 148 deletions.
6 changes: 3 additions & 3 deletions src/sage/matroids/basis_exchange_matroid.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,13 @@ cdef class BasisExchangeMatroid(Matroid):

cdef _relabel(self, mapping):
"""
Relabel each element ``e`` as ``mapping[e]``, where ``mapping`` is a
Relabel each element `e` as ``mapping[e]``, where ``mapping`` is a
given injective map.
INPUT:
- ``mapping`` -- a python object such that ``mapping[e]`` is the new
label of ``e``
- ``mapping`` -- a Python object such that ``mapping[e]`` is the new
label of `e`
OUTPUT: ``None``
Expand Down
8 changes: 4 additions & 4 deletions src/sage/matroids/basis_matroid.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -525,16 +525,16 @@ cdef class BasisMatroid(BasisExchangeMatroid):
r"""
Return an isomorphic matroid with relabeled groundset.
The output is obtained by relabeling each element ``e`` by
The output is obtained by relabeling each element `e` by
``mapping[e]``, where ``mapping`` is a given injective map. If
``mapping[e]`` is not defined, then the identity map is assumed.
INPUT:
- ``mapping`` -- a python object such that ``mapping[e]`` is the new
label of ``e``
- ``mapping`` -- a Python object such that ``mapping[e]`` is the new
label of `e`
OUTPUT: a matroid
OUTPUT: matroid
EXAMPLES::
Expand Down
8 changes: 4 additions & 4 deletions src/sage/matroids/circuit_closures_matroid.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -527,16 +527,16 @@ cdef class CircuitClosuresMatroid(Matroid):
r"""
Return an isomorphic matroid with relabeled groundset.
The output is obtained by relabeling each element ``e`` by
The output is obtained by relabeling each element `e` by
``mapping[e]``, where ``mapping`` is a given injective map. If
``mapping[e]`` is not defined, then the identity map is assumed.
INPUT:
- ``mapping`` -- a python object such that ``mapping[e]`` is the new
label of ``e``
- ``mapping`` -- a Python object such that ``mapping[e]`` is the new
label of `e`
OUTPUT: a matroid
OUTPUT: matroid
EXAMPLES::
Expand Down
6 changes: 3 additions & 3 deletions src/sage/matroids/circuits_matroid.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -406,14 +406,14 @@ cdef class CircuitsMatroid(Matroid):
r"""
Return an isomorphic matroid with relabeled groundset.
The output is obtained by relabeling each element ``e`` by
The output is obtained by relabeling each element `e` by
``mapping[e]``, where ``mapping`` is a given injective map. If
``mapping[e]`` is not defined, then the identity map is assumed.
INPUT:
- ``mapping`` -- a python object such that ``mapping[e]`` is the new
label of ``e``
- ``mapping`` -- a Python object such that ``mapping[e]`` is the new
label of `e`
OUTPUT: matroid
Expand Down
13 changes: 6 additions & 7 deletions src/sage/matroids/database_matroids.py
Original file line number Diff line number Diff line change
Expand Up @@ -1489,7 +1489,7 @@ def K5dual(groundset='abcdefghij'):
EXAMPLES::
sage: M = matroids.catalog.K5dual(); M
M*(K5): Matroid of rank 6 on 10 elements with 15 circuits
M*(K5): Dual of 'Graphic matroid of rank 4 on 10 elements'
sage: M.is_3connected()
True
sage: G1 = M.automorphism_group()
Expand All @@ -1502,7 +1502,6 @@ def K5dual(groundset='abcdefghij'):
[Oxl2011]_, p. 656.
"""
M = CompleteGraphic(5).dual()
M = Matroid(circuits=list(M.circuits()))
M = _rename_and_relabel(M, "M*(K5)", groundset)
return M

Expand Down Expand Up @@ -2067,7 +2066,7 @@ def Z(r, t=True, groundset=None):
- ``t`` -- boolean (default: ``True``); whether the spike is tipped
- ``groundset`` -- a string (optional); the groundset of the matroid
OUTPUT: a matroid; the unique rank-`r` binary spike (tipped or tipless)
OUTPUT: matroid; the unique rank-`r` binary spike (tipped or tipless)
EXAMPLES::
Expand Down Expand Up @@ -2173,7 +2172,7 @@ def Spike(r, t=True, C3=[], groundset=None):
The default (i.e. the empty list) results in a free `r`-spike
- ``groundset`` -- a string (optional); the groundset of the matroid
OUTPUT: a matroid; a rank-`r` spike (tipped or tipless)
OUTPUT: matroid; a rank-`r` spike (tipped or tipless)
EXAMPLES::
Expand Down Expand Up @@ -2291,7 +2290,7 @@ def Theta(n, groundset=None):
- ``n`` -- an integer (`n \ge 2`); the rank of the matroid
- ``groundset`` -- a string (optional); the groundset of the matroid
OUTPUT: a matroid (`\Theta_n`)
OUTPUT: matroid (`\Theta_n`)
EXAMPLES::
Expand Down Expand Up @@ -2364,7 +2363,7 @@ def Psi(r, groundset=None):
- ``r`` -- an integer (`r \ge 3`); the rank of the matroid
- ``groundset`` -- a string (optional); the groundset of the matroid
OUTPUT: a matroid (`\Psi_r`)
OUTPUT: matroid (`\Psi_r`)
EXAMPLES::
Expand Down Expand Up @@ -5234,7 +5233,7 @@ def _rename_and_relabel(M, name=None, groundset=None):
- ``name`` -- a string (optional)
- ``groundset`` -- a string (optional)
OUTPUT: a matroid
OUTPUT: matroid
"""
if groundset is not None:
if len(groundset) != len(M.groundset()):
Expand Down
Loading

0 comments on commit 55d4cb3

Please sign in to comment.