Skip to content

Commit

Permalink
sagemathgh-37145: Add matroid attribute girth()
Browse files Browse the repository at this point in the history
    
<!-- ^^^^^
Please provide a concise, informative and self-explanatory title.
Don't put issue numbers in there, do this in the PR body below.
For example, instead of "Fixes sagemath#1234" use "Introduce new method to
calculate 1+1"
-->
<!-- Describe your changes here in detail -->
Added a function `girth()` to the main matroid class. This is a standard
notion which corresponds to the size of the smallest circuit of the
matroid. A similar notion exists for graphs.

<!-- Why is this change required? What problem does it solve? -->
<!-- If this PR resolves an open issue, please link to it here. For
example "Fixes sagemath#12345". -->
<!-- If your change requires a documentation PR, please link it
appropriately. -->

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->
<!-- If your change requires a documentation PR, please link it
appropriately -->
<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
<!-- Feel free to remove irrelevant items. -->

- [x] The title is concise, informative, and self-explanatory.
- [x] The description explains in detail what this PR is about.
- [x] I have created tests covering the changes.
- [x] I have updated the documentation accordingly.
    
URL: sagemath#37145
Reported by: gmou3
Reviewer(s): Travis Scrimshaw
  • Loading branch information
Release Manager committed Jan 29, 2024
2 parents 84bb337 + 58521e5 commit 0021b23
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/sage/matroids/matroid.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ cdef class Matroid(SageObject):
cpdef _is_3connected_BC_recursion(self, basis, fund_cocircuits) noexcept
cpdef is_paving(self) noexcept
cpdef is_sparse_paving(self) noexcept
cpdef girth(self) noexcept

# representability
cpdef _local_binary_matroid(self, basis=*) noexcept
Expand Down
29 changes: 29 additions & 0 deletions src/sage/matroids/matroid.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ additional functionality (e.g. linear extensions).
- :meth:`connectivity() <sage.matroids.matroid.Matroid.connectivity>`
- :meth:`is_paving() <sage.matroids.matroid.Matroid.is_paving>`
- :meth:`is_sparse_paving() <sage.matroids.matroid.Matroid.is_sparse_paving>`
- :meth:`girth() <sage.matroids.matroid.Matroid.girth>`
- Representation
- :meth:`binary_matroid() <sage.matroids.matroid.Matroid.binary_matroid>`
Expand Down Expand Up @@ -5976,6 +5977,34 @@ cdef class Matroid(SageObject):
return False
return True

cpdef girth(self) noexcept:
r"""
Return the girth of the matroid.
The girth is the size of the smallest circuit. In case the matroid has
no circuits the girth is `\infty`.
EXAMPLES::
sage: matroids.Uniform(5, 5).girth()
+Infinity
sage: matroids.catalog.K4().girth()
3
sage: matroids.catalog.Vamos().girth()
4
REFERENCES:
[Oxl2011]_, p. 327.
"""
for k in range(self.rank() + 2):
for X in combinations(self.groundset(), k):
X = frozenset(X)
if self._is_circuit(X):
return k
from sage.rings.infinity import infinity
return infinity

# representability

cpdef _local_binary_matroid(self, basis=None) noexcept:
Expand Down

0 comments on commit 0021b23

Please sign in to comment.