Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Oriented Matroids Package #38024

Open
wants to merge 52 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
57ac44c
Add Oriented Matroids Package
thecaligarmo May 18, 2024
59fe83d
Merge tag '10.4.beta7' into oriented_matroids
gmou3 May 28, 2024
887d562
Some formatting recommendations
gmou3 May 28, 2024
4c101bc
Merge remote-tracking branch 'sagemath/develop' into oriented_matroids
gmou3 Jun 1, 2024
b9cefa8
Merge branch 'develop' into oriented_matroids
fchapoton Jun 17, 2024
ffbe028
Update src/sage/matroids/all.py
fchapoton Jun 17, 2024
00cff53
Merge branch 'develop' into oriented_matroids
thecaligarmo Jul 2, 2024
5ffcd32
Remove catalog from oriented matroids (unused), update error messages
thecaligarmo Jul 2, 2024
da8ef8f
Fix doctest
thecaligarmo Jul 2, 2024
01ea791
Merge branch 'oriented_matroids' into oriented_matroids
thecaligarmo Jul 4, 2024
c13eaf9
Merge pull request #1 from gmou3/oriented_matroids
thecaligarmo Jul 4, 2024
1b1a269
Fix test error
thecaligarmo Jul 4, 2024
eb1cc24
Fix lint issue
thecaligarmo Jul 4, 2024
b03771d
Add `# long time`s and cosmetics
gmou3 Sep 6, 2024
567834b
Merge branch 'sagemath:develop' into oriented_matroids
gmou3 Sep 6, 2024
3a4c1fc
Delete catalog files
gmou3 Sep 7, 2024
eef7bf4
PEP edits
gmou3 Sep 7, 2024
ea931e4
Merge branch 'develop' into oriented_matroids
thecaligarmo Sep 7, 2024
a9640f5
Merge branch 'oriented_matroids' into oriented_matroids
thecaligarmo Sep 7, 2024
988a572
Merge pull request #2 from gmou3/oriented_matroids
thecaligarmo Sep 7, 2024
f0face7
Remove an uneeded test
thecaligarmo Sep 8, 2024
910f4d4
Use new FlatsMatroid for matroid coming from covectors
thecaligarmo Sep 8, 2024
cb8cdc8
Make deletion test faster
thecaligarmo Sep 8, 2024
4ee7649
Integrate `FlatsMatroid` and redelete catalog files
gmou3 Sep 8, 2024
4667610
Update src/sage/matroids/oriented_matroids/abstract_oriented_matroid.py
thecaligarmo Sep 12, 2024
f0cffe6
Remove automatic validity check
gmou3 Sep 13, 2024
8966145
Merge remote-tracking branch 'sagemath/develop' into orientedmatroids
gmou3 Sep 15, 2024
13b776c
Merge branch 'develop' into oriented_matroids
thecaligarmo Sep 22, 2024
e44065d
Merge branch 'oriented_matroids' into orientedmatroids
thecaligarmo Sep 22, 2024
6222677
Merge pull request #4 from gmou3/orientedmatroids
thecaligarmo Sep 22, 2024
484dbda
Update is_valid to allow returns
thecaligarmo Sep 22, 2024
2c4a6c7
Add gmou3's pull request
thecaligarmo Sep 22, 2024
373c191
Change with_error to certificate
thecaligarmo Sep 23, 2024
fcc1bcc
Edits suggested by Travis
thecaligarmo Oct 5, 2024
da6cf53
Fix doc
thecaligarmo Oct 5, 2024
69c0bbd
Update docs
thecaligarmo Oct 5, 2024
8b6ac18
Merge branch 'develop' into oriented_matroids
thecaligarmo Oct 5, 2024
8711574
Remove Abstract OM and replace OM constructor with object
thecaligarmo Oct 5, 2024
2b46653
Fix code style
thecaligarmo Oct 5, 2024
f5316f3
Apply suggestions from code review
thecaligarmo Nov 9, 2024
53ac251
Update src/sage/matroids/oriented_matroids/signed_subset_element.py
thecaligarmo Nov 9, 2024
d9a3d83
Update src/sage/matroids/oriented_matroids/signed_subset_element.py
thecaligarmo Nov 9, 2024
287f250
Update src/sage/matroids/oriented_matroids/signed_subset_element.py
thecaligarmo Nov 9, 2024
6461e1a
Update src/sage/matroids/oriented_matroids/signed_subset_element.py
thecaligarmo Nov 9, 2024
cb9c8e5
Apply suggestions from code review
thecaligarmo Nov 9, 2024
1f57f5c
Merge branch 'develop' into oriented_matroids
thecaligarmo Nov 9, 2024
605a320
Doc changes
thecaligarmo Nov 9, 2024
7fcd02b
Doctest fixes and a minor bug fix
thecaligarmo Nov 9, 2024
5a60b5f
Fix doctests and remove signed subset testsuite
thecaligarmo Nov 9, 2024
b1a6d47
Update certificates to be dicts
thecaligarmo Nov 9, 2024
46c149c
Add some tests
thecaligarmo Nov 9, 2024
220ac29
Add some new properties and remove dual
thecaligarmo Nov 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,8 @@
"Cython"
],
"editor.formatOnType": true,
"esbonio.sphinx.confDir": ""
"esbonio.sphinx.confDir": "",
"flake8.args": [
"--select=E111,E21,E221,E222,E225,E227,E228,E25,E271,E303,E305,E306,E401,E502,E701,E702,E703,E71,E72,W291,W293,W391,W605"
]
}
28 changes: 28 additions & 0 deletions src/doc/en/reference/matroids/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,32 @@ Internals
sage/matroids/set_system
sage/matroids/unpickling

Oriented Matroids
=================

.. toctree::
:maxdepth: 1

sage/matroids/oriented_matroids/oriented_matroid

Representations
---------------

.. toctree::
:maxdepth: 1

sage/matroids/oriented_matroids/circuit_oriented_matroid
sage/matroids/oriented_matroids/covector_oriented_matroid
sage/matroids/oriented_matroids/real_hyperplane_arrangement_oriented_matroid
sage/matroids/oriented_matroids/vector_oriented_matroid

Elements
--------

.. toctree::
:maxdepth: 1

sage/matroids/oriented_matroids/signed_subset_element

.. include:: ../footer.txt

4 changes: 4 additions & 0 deletions src/doc/en/reference/references/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -963,6 +963,10 @@ REFERENCES:
Anal. Appl. 15 (1994) 804-823.
:doi:`10.1137/S0895479892230031`

.. [BLSWZ1999] Anders Björner, Michel Las Vergnas, Bernd Sturmfels, Neil White
and Günter Ziegler, *Oriented Matroids*; Cambridge University
press, (1999).

.. [BHMPW20a] Tom Braden, June Huh, Jacob P. Matherne, Nicholas Proudfoot,
and Botong Wang, *A semi-small decomposition of the Chow
ring of a matroid*, :arxiv:`2002.03341` (2020).
Expand Down
4 changes: 4 additions & 0 deletions src/sage/matroids/all.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,9 @@
from sage.misc.lazy_import import lazy_import
lazy_import('sage.matroids.constructor', 'Matroid')
lazy_import('sage.matroids', 'matroids_catalog', 'matroids')

# Add Oriented Matroids
from sage.matroids.oriented_matroids.all import *

del lazy_import
del install_doc
8 changes: 8 additions & 0 deletions src/sage/matroids/oriented_matroids/all.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"""
Oriented Matroids
"""
from sage.misc.namespace_package import install_doc
install_doc(__package__, __doc__)

from sage.misc.lazy_import import lazy_import
lazy_import('sage.matroids.oriented_matroids.oriented_matroid', 'OrientedMatroid')
263 changes: 263 additions & 0 deletions src/sage/matroids/oriented_matroids/circuit_oriented_matroid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,263 @@
r"""
Oriented matroid with circuit axioms

This implements an oriented matroid using the circuit axioms.

AUTHORS:

- Aram Dermenjian (2019-07-12): Initial version
"""

# ****************************************************************************
# Copyright (C) 2019 Aram Dermenjian <aram.dermenjian.math at gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
# https://www.gnu.org/licenses/
# ****************************************************************************

from sage.matroids.oriented_matroids.oriented_matroid import OrientedMatroid


class CircuitOrientedMatroid(OrientedMatroid):
r"""
An oriented matroid implemented using circuit axioms.

This implements an oriented matroid using the circuit axioms. For this
let `\mathcal{C}` be a set of signed subsets and `E` a groundset. Then
a pair `M = (E, \mathcal{C})` is an oriented matroid using the circuit
axioms if (see Definition 3.2.1 in [BLSWZ1999]_):

- `\emptyset \notin \mathcal{C}`
- `\mathcal{C} = -\mathcal{C}`
- For all `X, Y \in \mathcal{C}`, if the support of `X` is contained
in the support of `Y` then `X = Y` or `X = -Y`
- For all `X, Y \in \mathcal{C}`, `X \neq -Y`, and
`e \in X^+ \cap Y^-` there exists a `Z \in \mathcal{C}` such that
`Z^+ \subseteq (X^+ \cup Y^+) \backslash \left\{e\right\}` and
`Z^- \subseteq (X^- \cup Y^-) \backslash \left\{e\right\}`.

INPUT:

- ``data`` -- a tuple containing :class:`SignedSubsetElement` elements or
data that can be used to construct :class:`SignedSubsetElement` elements
- ``groundset`` -- (default: ``None``) the groundset for the data; if not
provided, we grab the data from the signed subsets

EXAMPLES::

sage: from sage.matroids.oriented_matroids.oriented_matroid import OrientedMatroid
sage: M = OrientedMatroid([[1], [-1]], key='circuit'); M
Circuit oriented matroid of rank 0
sage: M.groundset()
(0,)

sage: C = [((1,4),(2,3)), ((2,3),(1,4))]
sage: M = OrientedMatroid(C, key='circuit'); M
Circuit oriented matroid of rank 3
sage: M.groundset()
(1, 2, 3, 4)
sage: M.an_element() in M.elements()
True
sage: M.elements() == M.circuits()
True

sage: C5 = [((1,),(3,),(2,)), ((1,2),(3,),(4,)),
....: ((3,),(1,),(2,)), ((3,),(1,2),(4,))]
sage: OrientedMatroid(C5, key='circuit')
Traceback (most recent call last):
...
ValueError: groundsets must be the same

.. SEEALSO::

- :class:`~sage.oriented_matroids.oriented_matroid.OrientedMatroid`
- :class:`~sage.oriented_matroids.oriented_matroids_category.OrientedMatroids`
"""
def __init__(self, data, groundset=None, category=None):
"""
Return a ``CircuitOrientedMatroid`` object.

EXAMPLES::

sage: from sage.matroids.oriented_matroids.oriented_matroid import OrientedMatroid
sage: M = OrientedMatroid([[1], [-1]], key='circuit'); M
Circuit oriented matroid of rank 0
sage: TestSuite(M).run()
"""
OrientedMatroid.__init__(self, category=category)

# Set up our circuits
circuits = []
if data:
for d in data:
# Convert to the appropriate element class
circuits.append(self.element_class(self, data=d, groundset=groundset))

# If our groundset is none, make sure the groundsets are the same for
# all elements
if groundset is None and len(circuits) > 0:
if len(data[0]) < 3:
groundset = []
for X in circuits:
groundset = list(set(groundset + X.groundset()))
else:
groundset = circuits[0].groundset()
for X in circuits:
if X.groundset() != groundset:
raise ValueError("groundsets must be the same")

self._circuits = circuits
self._elements = circuits

if groundset is None:
self._groundset = None

Check warning on line 116 in src/sage/matroids/oriented_matroids/circuit_oriented_matroid.py

View check run for this annotation

Codecov / codecov/patch

src/sage/matroids/oriented_matroids/circuit_oriented_matroid.py#L116

Added line #L116 was not covered by tests
else:
self._groundset = tuple(groundset)

def is_valid(self, certificate=False) -> bool | tuple[bool, dict]:
"""
Return whether our circuits satisfy the circuit axioms.

EXAMPLES::

sage: from sage.matroids.oriented_matroids.oriented_matroid import OrientedMatroid
sage: C = [((1,4),(2,3)), ((2,3),(1,4))]
sage: M = OrientedMatroid(C, key='circuit')
sage: M.is_valid(certificate=True)
(True, {})
sage: M.is_valid()
True

sage: C2 = [((1,4),(2,3)), ((1,3),(2,4)), ((2,3),(1,4))]
sage: M2 = OrientedMatroid(C2, key='circuit')
sage: M2.is_valid(certificate=True)
(False,
{'elt': (+: 1,4
-: 2,3
0: ,
+: 1,3
-: 2,4
0: ),
'msg': 'only same/opposites can have same support'})
sage: M2.is_valid()
False

sage: C3 = [((),()), ((1,4),(2,3)), ((2,3),(1,4))]
sage: M3 = OrientedMatroid(C3, key='circuit', groundset=[1,2,3,4])
sage: M3.is_valid(certificate=True)
(False,
{'elt': +:
-:
0: 1,2,3,4,
'msg': 'empty set not allowed'})

sage: C4= [((1,),()), ((1,4),(2,3)), ((2,3),(1,4))]
sage: M4 = OrientedMatroid(C4, key='circuit', groundset=[1,2,3,4])
sage: M4.is_valid(certificate=True)
(False,
{'elt': +: 1
-:
0: 2,3,4,
'msg': 'every element needs an opposite'})
"""
circuits = self.circuits()

for X in circuits:
# Axiom 1: Make sure empty is not present
if X.is_zero():
if certificate:
error_info = {
'msg': "empty set not allowed",
'elt': X
}
return (False, error_info)
return False

Check warning on line 177 in src/sage/matroids/oriented_matroids/circuit_oriented_matroid.py

View check run for this annotation

Codecov / codecov/patch

src/sage/matroids/oriented_matroids/circuit_oriented_matroid.py#L177

Added line #L177 was not covered by tests
# Axiom 2: (symmetry) Make sure negative exists
if -X not in circuits:
if certificate:
error_info = {
'msg': "every element needs an opposite",
'elt': X
}
return (False, error_info)
return False

Check warning on line 186 in src/sage/matroids/oriented_matroids/circuit_oriented_matroid.py

View check run for this annotation

Codecov / codecov/patch

src/sage/matroids/oriented_matroids/circuit_oriented_matroid.py#L186

Added line #L186 was not covered by tests
for Y in circuits:
# Axiom 3: (incomparability) supports must not be contained
if X.support().issubset(Y.support()):
if X != Y and X != -Y:
if certificate:
error_info = {
'msg': "only same/opposites can have same support",
'elt': (X, Y)
}
return (
False,
error_info
)
return False
# Axiom 4: Weak elimination
if X != -Y:
E = X.positives().intersection(Y.negatives())
for e in E:
p = X.positives().union(Y.positives())
p.discard(e)
n = X.negatives().union(Y.negatives())
n.discard(e)
found = False
for Z in circuits:
if found:
break
if Z.positives().issubset(p) and Z.negatives().issubset(n):
found = True
if not found:
if certificate:
error_info = {

Check warning on line 217 in src/sage/matroids/oriented_matroids/circuit_oriented_matroid.py

View check run for this annotation

Codecov / codecov/patch

src/sage/matroids/oriented_matroids/circuit_oriented_matroid.py#L205-L217

Added lines #L205 - L217 were not covered by tests
'msg': "weak elimination failed",
'elt': (X, Y)
}
return (False, error_info)
return False

Check warning on line 222 in src/sage/matroids/oriented_matroids/circuit_oriented_matroid.py

View check run for this annotation

Codecov / codecov/patch

src/sage/matroids/oriented_matroids/circuit_oriented_matroid.py#L221-L222

Added lines #L221 - L222 were not covered by tests
if certificate:
return (True, {})
return True

def _repr_(self) -> str:
"""
Return a string representation of ``self``.

EXAMPLES::

sage: from sage.matroids.oriented_matroids.oriented_matroid import OrientedMatroid
sage: C = [((1,),(2,)), ((2,),(1,)), ((3,),(4,)), ((4,),(3,))]
sage: OrientedMatroid(C, key='circuit', groundset=[1,2,3,4])
Circuit oriented matroid of rank 2
"""
try:
rep = f"Circuit oriented matroid of rank {self.rank()}"
except ValueError:
rep = "Circuit oriented matroid"

Check warning on line 241 in src/sage/matroids/oriented_matroids/circuit_oriented_matroid.py

View check run for this annotation

Codecov / codecov/patch

src/sage/matroids/oriented_matroids/circuit_oriented_matroid.py#L240-L241

Added lines #L240 - L241 were not covered by tests
return rep

def matroid(self):
r"""
Return the underlying matroid.

Given an oriented matroid defined using circuits, the *underlying
matroid* is the (circuit) matroid whose groundset is the groundset of
the oriented matroid and the circuits are the set of supports of all
the signed subsets.

EXAMPLES::

sage: from sage.matroids.oriented_matroids.oriented_matroid import OrientedMatroid
sage: C = [((1,),(2,)), ((2,),(1,)), ((3,),(4,)), ((4,),(3,))]
sage: M = OrientedMatroid(C, key='circuit', groundset=[1,2,3,4])
sage: M.matroid()
Matroid of rank 2 on 4 elements with 2 circuits
"""
from sage.matroids.constructor import Matroid
circs = list(set([frozenset(X.support()) for X in self.elements()]))
return Matroid(groundset=self.groundset(), circuits=circs)
Loading
Loading