diff --git a/src/sage/matroids/advanced.py b/src/sage/matroids/advanced.py index cd8453c7b94..bb246d2705c 100644 --- a/src/sage/matroids/advanced.py +++ b/src/sage/matroids/advanced.py @@ -14,6 +14,7 @@ - :class:`MinorMatroid ` - :class:`DualMatroid ` - :class:`RankMatroid ` + - :class:`RankMatroid ` - :class:`CircuitClosuresMatroid ` - :class:`BasisMatroid ` - :class:`FlatsMatroid ` @@ -49,6 +50,7 @@ - Stefan van Zwam (2013-04-01): initial version """ + import sage.matroids.matroid import sage.matroids.basis_exchange_matroid from .minor_matroid import MinorMatroid @@ -63,6 +65,4 @@ from . import lean_matrix from .extension import LinearSubclasses, MatroidExtensions from .union_matroid import MatroidUnion, MatroidSum, PartitionMatroid - -from sage.misc.lazy_import import lazy_import -from sage.matroids.graphic_matroid import GraphicMatroid +from .graphic_matroid import GraphicMatroid diff --git a/src/sage/matroids/catalog.py b/src/sage/matroids/catalog.py index 605dd30a3a3..9e702aba61c 100644 --- a/src/sage/matroids/catalog.py +++ b/src/sage/matroids/catalog.py @@ -6,6 +6,7 @@ :mod:`matroids.catalog ` (type this and hit :kbd:`Tab` for a list). """ + from sage.matroids.database_matroids import ( U24, U25, U35, K4, Whirl3, Q6, P6, U36, R6, Fano, FanoDual, NonFano, NonFanoDual, O7, P7, @@ -16,6 +17,7 @@ R12, ExtendedTernaryGolayCode, T12, PG23, ) + from sage.matroids.database_matroids import ( RelaxedNonFano, TippedFree3spike, AG23minusDY, TQ8, P8p, KP8, Sp8, Sp8pp, LP8, WQ8, @@ -30,6 +32,7 @@ FA15, N4, ) + from sage.matroids.database_matroids import ( NonVamos, NotP8, AG23minus, P9, R9A, R9B, Block_9_4, TicTacToe, diff --git a/src/sage/matroids/circuit_closures_matroid.pyx b/src/sage/matroids/circuit_closures_matroid.pyx index 08954cf3cb2..6976c6bf1a2 100644 --- a/src/sage/matroids/circuit_closures_matroid.pyx +++ b/src/sage/matroids/circuit_closures_matroid.pyx @@ -65,7 +65,6 @@ from .matroid cimport Matroid from .set_system cimport SetSystem from .utilities import setprint_s, cmp_elements_key - cdef class CircuitClosuresMatroid(Matroid): r""" A general matroid `M` is characterized by its rank `r(M)` and the set of diff --git a/src/sage/matroids/constructor.py b/src/sage/matroids/constructor.py index 8c483650df4..fc874b5fd13 100644 --- a/src/sage/matroids/constructor.py +++ b/src/sage/matroids/constructor.py @@ -105,7 +105,6 @@ # https://www.gnu.org/licenses/ # **************************************************************************** - from itertools import combinations from sage.matrix.constructor import Matrix from sage.structure.element import is_Matrix @@ -131,7 +130,6 @@ from .graphic_matroid import GraphicMatroid import sage.matroids.utilities - def Matroid(groundset=None, data=None, **kwds): r""" Construct a matroid. diff --git a/src/sage/matroids/database_collections.py b/src/sage/matroids/database_collections.py index ab650690e2c..60610bf3f22 100644 --- a/src/sage/matroids/database_collections.py +++ b/src/sage/matroids/database_collections.py @@ -159,14 +159,14 @@ def AllMatroids(n, r=None, type="all"): ....: for M in matroids.AllMatroids(n+7, r+3, "unorientable"): ....: assert M.is_valid() """ - from sage.matroids.constructor import Matroid + from .basis_matroid import BasisMatroid from sage.features.databases import DatabaseMatroids DatabaseMatroids().require() import matroid_database if type != "all" and type != "unorientable": try: - getattr(Matroid(bases=[[1, 2], [1, 3]]), "is_" + type) + getattr(BasisMatroid(groundset=[0], bases=[[0]]), "is_" + type) except AttributeError: raise AttributeError( "The type \"%s\" is not available. " % type + @@ -184,7 +184,7 @@ def AllMatroids(n, r=None, type="all"): for r in rng: if (r == 0 or r == n) and type != "unorientable": - M = Matroid(groundset=range(n), bases=[range(r)]) + M = BasisMatroid(groundset=range(n), bases=[range(r)]) M.rename(type + "_n" + str(n).zfill(2) + "_r" + str(r).zfill(2) + "_#" + "0" + ": " + repr(M)) if type == "all": yield M @@ -207,7 +207,7 @@ def AllMatroids(n, r=None, type="all"): cnt = 0 for B in matroids_bases(n, rp): - M = Matroid(groundset=range(n), bases=B) + M = BasisMatroid(groundset=range(n), bases=B) if type != "unorientable" and n - r < r: M = M.dual() diff --git a/src/sage/matroids/dual_matroid.py b/src/sage/matroids/dual_matroid.py index 82bd1f9dae0..851a97024e9 100644 --- a/src/sage/matroids/dual_matroid.py +++ b/src/sage/matroids/dual_matroid.py @@ -112,9 +112,7 @@ def groundset(self): The groundset is the set of elements that comprise the matroid. - OUTPUT: - - A set. + OUTPUT: set EXAMPLES:: @@ -133,11 +131,9 @@ def _rank(self, X): INPUT: - - ``X`` -- an object with Python's ``frozenset`` interface. + - ``X`` -- an object with Python's ``frozenset`` interface - OUTPUT: - - The rank of ``X`` in the matroid. + OUTPUT: integer EXAMPLES:: @@ -153,12 +149,10 @@ def _corank(self, X): INPUT: - - ``X`` -- An object with Python's ``frozenset`` interface - containing a subset of ``self.groundset()``. - - OUTPUT: + - ``X`` -- an object with Python's ``frozenset`` interface + containing a subset of ``self.groundset()`` - The corank of ``X``. + OUTPUT: integer EXAMPLES:: @@ -177,9 +171,7 @@ def _max_independent(self, X): - ``X`` -- an object with Python's ``frozenset`` interface containing a subset of ``self.groundset()`` - OUTPUT: - - A maximal independent subset of ``X``. + OUTPUT: a maximal independent subset of ``X`` EXAMPLES:: @@ -204,10 +196,8 @@ def _circuit(self, X): - ``X`` -- an object with Python's ``frozenset`` interface containing a subset of ``self.groundset()`` - OUTPUT: - - A circuit contained in ``X``, if it exists. Otherwise an error is - raised. + OUTPUT: a circuit contained in ``X``, if it exists; otherwise, an error is + raised EXAMPLES:: @@ -232,9 +222,7 @@ def _closure(self, X): - ``X`` -- an object with Python's ``frozenset`` interface containing a subset of ``self.groundset()`` - OUTPUT: - - The smallest closed set containing ``X``. + OUTPUT: the smallest closed set containing ``X`` EXAMPLES:: @@ -253,9 +241,7 @@ def _max_coindependent(self, X): - ``X`` -- an object with Python's ``frozenset`` interface containing a subset of ``self.groundset()`` - OUTPUT: - - A maximal coindependent subset of ``X``. + OUTPUT: a maximal coindependent subset of ``X`` EXAMPLES:: @@ -280,9 +266,7 @@ def _coclosure(self, X): - ``X`` -- an object with Python's ``frozenset`` interface containing a subset of ``self.groundset()`` - OUTPUT: - - The smallest coclosed set containing ``X``. + OUTPUT: the smallest coclosed set containing ``X`` EXAMPLES:: @@ -301,10 +285,8 @@ def _cocircuit(self, X): - ``X`` -- an object with Python's ``frozenset`` interface containing a subset of ``self.groundset()`` - OUTPUT: - - A cocircuit contained in ``X``, if it exists. Otherwise an error is - raised. + OUTPUT: a cocircuit contained in ``X``, if it exists; otherwise, an error is + raised EXAMPLES:: @@ -324,14 +306,12 @@ def _minor(self, contractions=None, deletions=None): INPUT: - - ``contractions`` -- An object with Python's ``frozenset`` interface - containing a subset of ``self.groundset()``. - - ``deletions`` -- An object with Python's ``frozenset`` interface - containing a subset of ``self.groundset()``. - - OUTPUT: + - ``contractions`` -- an object with Python's ``frozenset`` interface + containing a subset of ``self.groundset()`` + - ``deletions`` -- an object with Python's ``frozenset`` interface + containing a subset of ``self.groundset()`` - A ``DualMatroid`` instance representing + OUTPUT: a class:`DualMatroid` representing `(``self._matroid`` / ``deletions`` \ ``contractions``)^*` .. NOTE:: @@ -339,8 +319,8 @@ def _minor(self, contractions=None, deletions=None): This method does NOT do any checks. Besides the assumptions above, we assume the following: - - ``contractions`` is independent - - ``deletions`` is coindependent + - ``contractions`` is independent; + - ``deletions`` is coindependent; - ``contractions`` and ``deletions`` are disjoint. EXAMPLES:: @@ -367,8 +347,7 @@ def dual(self): Let `M` be a matroid with groundset `E`. If `B` is the set of bases of `M`, then the set `\{E - b : b \in B\}` is the set of bases of another matroid, the *dual* of `M`. Note that the dual of the dual of - `M` equals `M`, so if this is the - :class:`DualMatroid` instance + `M` equals `M`, so if this is the :class:`DualMatroid` instance wrapping `M` then the returned matroid is `M`. OUTPUT: the dual matroid @@ -521,17 +500,18 @@ def __reduce__(self): version = 0 return sage.matroids.unpickling.unpickle_dual_matroid, (version, data) - def relabel(self, f): + def relabel(self, mapping): r""" Return an isomorphic matroid with relabeled groundset. - The output is obtained by relabeling each element ``e`` by ``f[e]``, - where ``f`` is a given injective map. If ``e not in f`` then the - identity map is assumed. + The output is obtained by relabeling each element ``e`` by + ``mapping[e]``, where ``mapping`` is a given injective map. If + ``e not in mapping`` then the identity map is assumed. INPUT: - - ``f`` -- a python object such that `f[e]` is the new label of `e` + - ``mapping`` -- a python object such that `mapping[e]` is the new + label of `e` OUTPUT: matroid @@ -554,5 +534,5 @@ def relabel(self, f): sage: for S in powerset(M.groundset()): ....: assert M.rank(S) == N.rank([f[x] for x in S]) """ - M = self._matroid.relabel(f).dual() + M = self._matroid.relabel(mapping).dual() return M diff --git a/src/sage/matroids/extension.pyx b/src/sage/matroids/extension.pyx index b45a82eda6c..d4ede4e3101 100644 --- a/src/sage/matroids/extension.pyx +++ b/src/sage/matroids/extension.pyx @@ -15,10 +15,8 @@ See also :mod:`sage.matroids.advanced`. AUTHORS: - Rudi Pendavingh, Stefan van Zwam (2013-04-01): initial version - -Methods -======= """ + # **************************************************************************** # Copyright (C) 2013 Rudi Pendavingh # Copyright (C) 2013 Stefan van Zwam @@ -33,7 +31,6 @@ Methods from sage.data_structures.bitset_base cimport * from sage.matroids.basis_matroid cimport BasisMatroid - cdef class CutNode: """ An internal class used for creating linear subclasses of a matroids in a @@ -246,7 +243,6 @@ cdef class LinearSubclassesIter: if res is not None: return res - cdef class LinearSubclasses: r""" An iterable set of linear subclasses of a matroid. @@ -410,7 +406,6 @@ cdef class LinearSubclasses: cdef long p return [self._hyperplanes[p] for p in node.planes()] - cdef class MatroidExtensions(LinearSubclasses): r""" An iterable set of single-element extensions of a given matroid. diff --git a/src/sage/matroids/flats_matroid.pyx b/src/sage/matroids/flats_matroid.pyx index 08442dbd370..bca91ac6ae0 100644 --- a/src/sage/matroids/flats_matroid.pyx +++ b/src/sage/matroids/flats_matroid.pyx @@ -19,6 +19,7 @@ AUTHORS: - Giorgos Mousa (2024-01-01): initial version """ + # **************************************************************************** # Copyright (C) 2024 Giorgos Mousa # @@ -28,11 +29,11 @@ AUTHORS: # (at your option) any later version. # https://www.gnu.org/licenses/ # **************************************************************************** + from cpython.object cimport Py_EQ, Py_NE from sage.structure.richcmp cimport rich_to_bool, richcmp from .matroid cimport Matroid from .set_system cimport SetSystem -from .utilities import setprint_s cdef class FlatsMatroid(Matroid): r""" diff --git a/src/sage/matroids/graphic_matroid.pyx b/src/sage/matroids/graphic_matroid.pyx index 03f13a54087..42cf89587a3 100644 --- a/src/sage/matroids/graphic_matroid.pyx +++ b/src/sage/matroids/graphic_matroid.pyx @@ -23,9 +23,9 @@ See also :mod:`sage.matroids.advanced`. Graphic matroids do not have a representation matrix or any of the functionality of regular matroids. It is possible to get an instance of the -:class:`~sage.matroids.linear_matroid.RegularMatroid` class -by using the ``regular`` keyword when constructing the matroid. -It is also possible to cast a GraphicMatroid as a RegularMatroid with the +:class:`~sage.matroids.linear_matroid.RegularMatroid` class by using the +``regular`` keyword when constructing the matroid. It is also possible to cast +a class:`GraphicMatroid` as a class:`RegularMatroid` with the :meth:`~sage.matroids.graphic_matroids.GraphicMatroid.regular_matroid` method:: @@ -75,10 +75,8 @@ modified:: AUTHORS: - Zachary Gershkoff (2017-07-07): initial version - -Methods -======= """ + # **************************************************************************** # Copyright (C) 2017 Zachary Gershkoff # @@ -88,33 +86,29 @@ Methods # the License, or (at your option) any later version. # https://www.gnu.org/licenses/ # **************************************************************************** -from .matroid cimport Matroid +from .matroid cimport Matroid from copy import copy, deepcopy from .utilities import newlabel, split_vertex, sanitize_contractions_deletions from itertools import combinations from sage.rings.integer import Integer from sage.sets.disjoint_set cimport DisjointSet_of_hashables - cdef class GraphicMatroid(Matroid): r""" The graphic matroid class. INPUT: - - ``G`` -- a Graph - - ``groundset`` -- (optional) a list in 1-1 correspondence with - ``G.edge_iterator()`` + - ``G`` -- class:`Graph` + - ``groundset`` -- list (optional); in 1-1 correspondence with ``G.edge_iterator()`` - OUTPUT: a ``GraphicMatroid`` instance where the groundset elements are the - edges of ``G`` + OUTPUT: class:`GraphicMatroid` where the groundset elements are the edges of `G` .. NOTE:: - If a disconnected graph is given as input, the instance of - ``GraphicMatroid`` will connect the graph components and store - this as its graph. + If a disconnected graph is given as input, the instance of class:`GraphicMatroid` + will connect the graph components and store this as its graph. EXAMPLES:: @@ -166,8 +160,7 @@ cdef class GraphicMatroid(Matroid): sage: from sage.matroids.advanced import * sage: G1 = graphs.CycleGraph(3); G2 = graphs.DiamondGraph() sage: G = G1.disjoint_union(G2) - sage: M = GraphicMatroid(G) - sage: M + sage: M = GraphicMatroid(G); M Graphic matroid of rank 5 on 8 elements sage: M.graph() Looped multi-graph on 6 vertices @@ -237,8 +230,7 @@ cdef class GraphicMatroid(Matroid): sage: M = Matroid(graphs.DiamondGraph()) sage: sorted(M.groundset()) [(0, 1), (0, 2), (1, 2), (1, 3), (2, 3)] - sage: G = graphs.CompleteGraph(3) - sage: G = G.disjoint_union(graphs.CompleteGraph(4)) + sage: G = graphs.CompleteGraph(3).disjoint_union(graphs.CompleteGraph(4)) sage: M = Matroid(range(G.num_edges()), G); sorted(M.groundset()) [0, 1, 2, 3, 4, 5, 6, 7, 8] sage: M = Matroid(Graph([(0, 1, 'a'), (0, 2, 'b'), (0, 3, 'c')])) @@ -251,8 +243,8 @@ cdef class GraphicMatroid(Matroid): """ Return the rank of a set ``X``. - This method does no checking on ``X``, and - ``X`` may be assumed to have the same interface as ``frozenset``. + This method does no checking on ``X``, and ``X`` may be assumed to have + the same interface as ``frozenset``. INPUT: @@ -263,10 +255,8 @@ cdef class GraphicMatroid(Matroid): EXAMPLES:: sage: from sage.matroids.advanced import * - sage: edgelist = [(0,0,0), (0,1,1), (0,2,2), (0,3,3), (1,2,4), - ....: (1,3,5)] - sage: M = GraphicMatroid(Graph(edgelist, loops=True, - ....: multiedges=True)) + sage: edgelist = [(0,0,0), (0,1,1), (0,2,2), (0,3,3), (1,2,4), (1,3,5)] + sage: M = GraphicMatroid(Graph(edgelist, loops=True, multiedges=True)) sage: M.rank([0]) 0 sage: M.rank([1,2]) @@ -276,8 +266,7 @@ cdef class GraphicMatroid(Matroid): sage: M.rank(M.groundset()) 3 sage: edgelist = [(0,0,0), (1,2,1), (1,2,2), (2,3,3)] - sage: M = GraphicMatroid(Graph(edgelist, loops=True, - ....: multiedges=True)) + sage: M = GraphicMatroid(Graph(edgelist, loops=True, multiedges=True)) sage: M.rank(M.groundset()) 2 sage: M.rank([0,3]) @@ -293,7 +282,7 @@ cdef class GraphicMatroid(Matroid): DS_vertices.union(u, v) return (len(vertices) - DS_vertices.number_of_subsets()) - # Representation: + # representation: def _repr_(self): """ @@ -301,20 +290,17 @@ cdef class GraphicMatroid(Matroid): EXAMPLES:: - sage: M = Matroid(graphs.CompleteGraph(5)) - sage: M + sage: M = Matroid(graphs.CompleteGraph(5)); M Graphic matroid of rank 4 on 10 elements - sage: G = Graph([(0, 0), (0, 1), (0, 2), (1, 1), (2, 2)], - ....: loops=True) - sage: M = Matroid(G) - sage: M + sage: G = Graph([(0, 0), (0, 1), (0, 2), (1, 1), (2, 2)], loops=True) + sage: M = Matroid(G); M Graphic matroid of rank 2 on 5 elements """ r = self._rank(self._groundset) n = len(self._groundset) return f'Graphic matroid of rank {r} on {n} elements' - # Comparison: + # comparison: cpdef _vertex_stars(self): """ @@ -472,7 +458,7 @@ cdef class GraphicMatroid(Matroid): version = 0 return unpickle_graphic_matroid, (version, data) - # Overrides: + # overrides cpdef _minor(self, contractions, deletions): """ @@ -480,15 +466,13 @@ cdef class GraphicMatroid(Matroid): INPUT: - - ``contractions`` -- frozenset; subset of ``self.groundset()`` to be - contracted - - ``deletions`` -- frozenset; subset of ``self.groundset()`` to be - deleted + - ``contractions`` -- frozenset; subset of ``self.groundset()`` to be contracted + - ``deletions`` -- frozenset; subset of ``self.groundset()`` to be deleted Assumptions: contractions are independent, deletions are coindependent, contractions and deletions are disjoint. - OUTPUT: an instance of ``GraphicMatroid`` + OUTPUT: class:`GraphicMatroid` EXAMPLES:: @@ -509,16 +493,15 @@ cdef class GraphicMatroid(Matroid): # deletions first so contractions don't mess up the vertices g.delete_edges(del_edges) g.contract_edges(cont_edges) - return GraphicMatroid(g) cpdef _has_minor(self, N, bint certificate=False): """ - Check if the matroid has a minor isomorphic to M(H). + Check if the matroid has a minor isomorphic to `M(H)`. INPUT: - - ``N`` - a matroid + - ``N`` - matroid - ``certificate`` - (default: ``False``) if ``True``, returns the certificate isomorphism from the minor of ``self`` to ``N`` @@ -719,8 +702,7 @@ cdef class GraphicMatroid(Matroid): Make sure the closure gets loops:: sage: edgelist = [(0, 0), (0, 1), (0, 2), (0, 3), (1, 2), (1, 2)] - sage: M = Matroid(range(6), Graph(edgelist, loops=True, - ....: multiedges=True)) + sage: M = Matroid(range(6), Graph(edgelist, loops=True, multiedges=True)) sage: M.graph().edges(sort=True) [(0, 0, 0), (0, 1, 1), (0, 2, 2), (0, 3, 3), (1, 2, 4), (1, 2, 5)] sage: sorted(M._closure([4])) @@ -830,10 +812,8 @@ cdef class GraphicMatroid(Matroid): - ``X`` -- an iterable container of groundset elements - OUTPUT: - - ``frozenset`` instance containing a subset of ``X``. - A :class:`ValueError` is raised if the set contains no circuit. + OUTPUT: ``frozenset`` instance containing a subset of ``X``; + a :class:`ValueError` is raised if the set contains no circuit EXAMPLES:: @@ -1035,8 +1015,7 @@ cdef class GraphicMatroid(Matroid): sage: M._is_isomorphic(O) False """ - # Check for 3-connectivity so we don't have to worry about Whitney - # twists + # Check for 3-connectivity so we don't have to worry about Whitney twists if isinstance(other, GraphicMatroid) and other.is_3connected(): G = self.graph() H = other.graph() @@ -1069,9 +1048,7 @@ cdef class GraphicMatroid(Matroid): # Now invert iso0 to get iso1, an isomorphism from self to M. iso1 = {iso0[e]: e for e in iso0} # iso2: isomorphism from M and other. - isomorphic, iso2 = M._is_isomorphic( - other, certificate=certificate - ) + isomorphic, iso2 = M._is_isomorphic(other, certificate=certificate) if not isomorphic: return (False, None) # Compose iso1 and iso2, to go from self to other. @@ -1089,7 +1066,7 @@ cdef class GraphicMatroid(Matroid): - ``other`` -- matroid - OUTPUT: a dictionary, or ``None`` + OUTPUT: dictionary or ``None`` EXAMPLES:: @@ -1162,7 +1139,7 @@ cdef class GraphicMatroid(Matroid): """ return True - # Graphic methods: + # graphic methods cpdef graph(self): """ @@ -1170,7 +1147,7 @@ cdef class GraphicMatroid(Matroid): The graph will always have loops and multiedges enabled. - OUTPUT: a graph + OUTPUT: graph EXAMPLES:: @@ -1194,13 +1171,12 @@ cdef class GraphicMatroid(Matroid): input graph as keys, and the corresponding vertex label after any merging as values. - OUTPUT: a dictionary + OUTPUT: dictionary EXAMPLES:: sage: G = Graph([(0, 1), (0, 2), (1, 2), (3, 4), (3, 5), (4, 5), - ....: (6, 7), (6, 8), (7, 8), (8, 8), (7, 8)], multiedges=True, - ....: loops=True) + ....: (6, 7), (6, 8), (7, 8), (8, 8), (7, 8)], multiedges=True, loops=True) sage: M = Matroid(range(G.num_edges()), G) sage: M.graph().edges(sort=True) [(0, 1, 0), @@ -1225,16 +1201,16 @@ cdef class GraphicMatroid(Matroid): INPUT: - - ``X`` -- a subset of the groundset + - ``X`` -- subset of the groundset - OUTPUT: a list of graph edges + OUTPUT: list of graph edges EXAMPLES:: sage: M = Matroid(range(5), graphs.DiamondGraph()) - sage: M.groundset_to_edges([2,3,4]) + sage: M.groundset_to_edges([2, 3, 4]) [(1, 2, 2), (1, 3, 3), (2, 3, 4)] - sage: M.groundset_to_edges([2,3,4,5]) + sage: M.groundset_to_edges([2, 3, 4, 5]) Traceback (most recent call last): ... ValueError: input must be a subset of the groundset @@ -1250,14 +1226,14 @@ cdef class GraphicMatroid(Matroid): INPUT: - - ``X`` -- a subset of the groundset + - ``X`` -- subset of the groundset - OUTPUT: a list of graph edges + OUTPUT: list of graph edges EXAMPLES:: sage: M = Matroid(range(5), graphs.DiamondGraph()) - sage: M._groundset_to_edges([2,3,4]) + sage: M._groundset_to_edges([2, 3, 4]) [(1, 2, 2), (1, 3, 3), (2, 3, 4)] """ return [(self._groundset_edge_map[x][0], self._groundset_edge_map[x][1], x) for x in X] @@ -1268,9 +1244,9 @@ cdef class GraphicMatroid(Matroid): INPUT: - - ``X`` -- a subset of the groundset + - ``X`` -- subset of the groundset - OUTPUT: a graph + OUTPUT: graph EXAMPLES:: @@ -1293,18 +1269,17 @@ cdef class GraphicMatroid(Matroid): INPUT: - - ``X`` -- a subset of the groundset + - ``X`` -- subset of the groundset - OUTPUT: a graph + OUTPUT: graph EXAMPLES:: sage: M = Matroid(range(5), graphs.DiamondGraph()) - sage: M._subgraph_from_set([0,1,2]) + sage: M._subgraph_from_set([0, 1, 2]) Looped multi-graph on 3 vertices """ from sage.graphs.graph import Graph - edge_list = self._groundset_to_edges(X) return Graph(edge_list, loops=True, multiedges=True) @@ -1317,15 +1292,15 @@ cdef class GraphicMatroid(Matroid): INPUT: - - ``u`` -- a vertex in the matroid's graph + - ``u`` -- vertex in the matroid's graph - ``v`` -- (optional) another vertex - ``element`` -- (optional) the label of the new element OUTPUT: - A GraphicMatroid with the specified element added. Note that if ``v`` - is not specifies or if ``v`` is ``u``, then the new element will be a - loop. If the new element's label is not specified, it will be + A class:`GraphicMatroid` with the specified element added. Note that if + ``v`` is not specified or if ``v`` is ``u``, then the new element will + be a loop. If the new element's label is not specified, it will be generated automatically. EXAMPLES:: @@ -1334,18 +1309,16 @@ cdef class GraphicMatroid(Matroid): sage: M1 = M.graphic_extension(0,1,'a'); M1 Graphic matroid of rank 3 on 7 elements sage: list(M1.graph().edge_iterator()) - [(0, 1, 'a'), (0, 1, 0), (0, 2, 1), (0, 3, 2), (1, 2, 3), - (1, 3, 4), (2, 3, 5)] + [(0, 1, 'a'), (0, 1, 0), (0, 2, 1), (0, 3, 2), (1, 2, 3), (1, 3, 4), (2, 3, 5)] sage: M2 = M1.graphic_extension(3); M2 Graphic matroid of rank 3 on 8 elements :: sage: M = Matroid(range(10), graphs.PetersenGraph()) - sage: EX_G = M.graphic_extension(0, 'b', 'c').graph() - sage: sorted(EX_G.vertex_iterator(), key=str) + sage: sorted(M.graphic_extension(0, 'b', 'c').graph().vertex_iterator(), key=str) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'b'] - sage: EX_G = M.graphic_extension('a', 'b', 'c').graph() + sage: M.graphic_extension('a', 'b', 'c').graph().vertices(sort=False) Traceback (most recent call last): ... ValueError: u must be an existing vertex @@ -1397,8 +1370,8 @@ cdef class GraphicMatroid(Matroid): OUTPUT: - An iterable containing instances of ``GraphicMatroid``. If ``vertices`` - is not specified, every vertex is used. + An iterable containing instances of class:`GraphicMatroid`. If + ``vertices`` is not specified, every vertex is used. .. NOTE:: @@ -1411,20 +1384,13 @@ cdef class GraphicMatroid(Matroid): sage: I = M.graphic_extensions('a') sage: for N in I: ....: list(N.graph().edge_iterator()) - [(0, 0, 'a'), (0, 1, 0), (0, 2, 1), (1, 2, 2), (1, 3, 3), - (2, 3, 4)] - [(0, 1, 'a'), (0, 1, 0), (0, 2, 1), (1, 2, 2), (1, 3, 3), - (2, 3, 4)] - [(0, 1, 0), (0, 2, 'a'), (0, 2, 1), (1, 2, 2), (1, 3, 3), - (2, 3, 4)] - [(0, 1, 0), (0, 2, 1), (0, 3, 'a'), (1, 2, 2), (1, 3, 3), - (2, 3, 4)] - [(0, 1, 0), (0, 2, 1), (1, 2, 'a'), (1, 2, 2), (1, 3, 3), - (2, 3, 4)] - [(0, 1, 0), (0, 2, 1), (1, 2, 2), (1, 3, 'a'), (1, 3, 3), - (2, 3, 4)] - [(0, 1, 0), (0, 2, 1), (1, 2, 2), (1, 3, 3), (2, 3, 'a'), - (2, 3, 4)] + [(0, 0, 'a'), (0, 1, 0), (0, 2, 1), (1, 2, 2), (1, 3, 3), (2, 3, 4)] + [(0, 1, 'a'), (0, 1, 0), (0, 2, 1), (1, 2, 2), (1, 3, 3), (2, 3, 4)] + [(0, 1, 0), (0, 2, 'a'), (0, 2, 1), (1, 2, 2), (1, 3, 3), (2, 3, 4)] + [(0, 1, 0), (0, 2, 1), (0, 3, 'a'), (1, 2, 2), (1, 3, 3), (2, 3, 4)] + [(0, 1, 0), (0, 2, 1), (1, 2, 'a'), (1, 2, 2), (1, 3, 3), (2, 3, 4)] + [(0, 1, 0), (0, 2, 1), (1, 2, 2), (1, 3, 'a'), (1, 3, 3), (2, 3, 4)] + [(0, 1, 0), (0, 2, 1), (1, 2, 2), (1, 3, 3), (2, 3, 'a'), (2, 3, 4)] :: @@ -1479,8 +1445,8 @@ cdef class GraphicMatroid(Matroid): OUTPUT: - An instance of GraphicMatroid coextended by the new element. If ``X`` - is not specified, the new element will be a coloop. + An instance of class:`GraphicMatroid` coextended by the new element. + If ``X`` is not specified, the new element will be a coloop. .. NOTE:: @@ -1549,12 +1515,10 @@ cdef class GraphicMatroid(Matroid): sage: M = Matroid(range(5), graphs.DiamondGraph()) sage: N = M.graphic_coextension(u=3, v=5, element='a') sage: N.graph().edges(sort=True) - [(0, 1, 0), (0, 2, 1), (1, 2, 2), (1, 3, 3), (2, 3, 4), - (3, 5, 'a')] + [(0, 1, 0), (0, 2, 1), (1, 2, 2), (1, 3, 3), (2, 3, 4), (3, 5, 'a')] sage: N = M.graphic_coextension(u=3, element='a') sage: N.graph().edges(sort=True) - [(0, 1, 0), (0, 2, 1), (1, 2, 2), (1, 3, 3), (2, 3, 4), - (3, 4, 'a')] + [(0, 1, 0), (0, 2, 1), (1, 2, 2), (1, 3, 3), (2, 3, 4), (3, 4, 'a')] sage: N = M.graphic_coextension(u=3, v=3, element='a') Traceback (most recent call last): ... @@ -1592,8 +1556,7 @@ cdef class GraphicMatroid(Matroid): return GraphicMatroid(G) - def graphic_coextensions(self, vertices=None, v=None, element=None, - cosimple=False): + def graphic_coextensions(self, vertices=None, v=None, element=None, cosimple=False): """ Return an iterator of graphic coextensions. @@ -1616,13 +1579,12 @@ cdef class GraphicMatroid(Matroid): OUTPUT: - An iterable containing instances of ``GraphicMatroid``. If ``vertices`` - is not specified, the method iterates over all vertices. + An iterable containing instances of class:`GraphicMatroid`. If + ``vertices`` is not specified, the method iterates over all vertices. EXAMPLES:: - sage: G = Graph([(0, 1), (0, 2), (0, 3), (0, 4), (1, 2), (1, 4), - ....: (2, 3), (3, 4)]) + sage: G = Graph([(0, 1), (0, 2), (0, 3), (0, 4), (1, 2), (1, 4), (2, 3), (3, 4)]) sage: M = Matroid(range(8), G) sage: I = M.graphic_coextensions(vertices=[0], element='a') sage: sorted([N.graph().edges_incident(0, sort=True) for N in I], key=str) @@ -1669,21 +1631,20 @@ cdef class GraphicMatroid(Matroid): sage: M = Matroid(graphs.WheelGraph(9)) sage: I = M.graphic_coextensions() - sage: len(list(I)) + sage: sum(1 for N in I) 136 sage: I = M.graphic_coextensions(cosimple=True) - sage: len(list(I)) + sage: sum(1 for N in I) 119 - sage: len(list( - ....: Matroid(graphs.WheelGraph(8)).graphic_coextensions())) + sage: sum(1 for N in Matroid(graphs.WheelGraph(8)).graphic_coextensions()) 71 This graph has max degree 3, so the only series extensions should be non-cosimple, ie. a coloop and one for every coseries class. 12 total:: - sage: edgedict = {0: [1,2,3], 1: [2,4], 2: [3], 3: [6], 4: [5,7], - ....: 5: [6,7], 6: [7]} + sage: edgedict = {0: [1, 2, 3], 1: [2, 4], 2: [3], 3: [6], + ....: 4: [5, 7], 5: [6, 7], 6: [7]} sage: M = Matroid(range(12), Graph(edgedict)) sage: sorted(M.coclosure([4])) [4, 6] @@ -1760,24 +1721,20 @@ cdef class GraphicMatroid(Matroid): - ``X`` -- the set of elements to be twisted with respect to the rest of the matroid - OUTPUT: - - An instance of ``GraphicMatroid`` isomorphic to this matroid but with - a graph that is not necessarily isomorphic. + OUTPUT: class:`GraphicMatroid` isomorphic to this matroid but + with a graph that is not necessarily isomorphic EXAMPLES:: - sage: edgelist = [(0,1,0), (1,2,1), (1,2,2), (2,3,3), (2,3,4), - ....: (2,3,5), (3,0,6)] + sage: edgelist = [(0, 1, 0), (1, 2, 1), (1, 2, 2), (2, 3, 3), + ....: (2, 3, 4), (2, 3, 5), (3, 0, 6)] sage: M = Matroid(Graph(edgelist, multiedges=True)) - sage: M1 = M.twist([0,1,2]); M1.graph().edges(sort=True) - [(0, 1, 1), (0, 1, 2), (0, 3, 6), (1, 2, 0), (2, 3, 3), (2, 3, 4), - (2, 3, 5)] - sage: M2 = M.twist([0,1,3]) + sage: M1 = M.twist([0, 1, 2]); M1.graph().edges(sort=True) + [(0, 1, 1), (0, 1, 2), (0, 3, 6), (1, 2, 0), (2, 3, 3), (2, 3, 4), (2, 3, 5)] + sage: M2 = M.twist([0, 1, 3]) Traceback (most recent call last): ... - ValueError: the input must display a 2-separation that is not a - 1-separation + ValueError: the input must display a 2-separation that is not a 1-separation TESTS:: @@ -1870,14 +1827,12 @@ cdef class GraphicMatroid(Matroid): INPUT: - - ``X`` -- a subset of the groundset - - ``u`` -- a vertex spanned by the edges of the elements in ``X`` - - ``v`` -- a vertex spanned by the edges of the elements not in ``X`` - - OUTPUT: + - ``X`` -- subset of the groundset + - ``u`` -- vertex spanned by the edges of the elements in ``X`` + - ``v`` -- vertex spanned by the edges of the elements not in ``X`` - An instance of ``GraphicMatroid`` isomorphic to this matroid but with - a graph that is not necessarily isomorphic. + OUTPUT: class:`GraphicMatroid` isomorphic to this matroid but + with a graph that is not necessarily isomorphic EXAMPLES:: @@ -1995,7 +1950,8 @@ cdef class GraphicMatroid(Matroid): cpdef regular_matroid(self): """ - Return an instance of RegularMatroid isomorphic to this GraphicMatroid. + Return an instance of class:`RegularMatroid` isomorphic to this + class:`GraphicMatroid`. EXAMPLES:: @@ -2012,8 +1968,7 @@ cdef class GraphicMatroid(Matroid): Check that :issue:`28482` is fixed:: - sage: G = Graph([[3, 4], [4, 1], [1, 2], [2, 3], [3, 5], [5, 6], - ....: [6, 3]]) + sage: G = Graph([[3, 4], [4, 1], [1, 2], [2, 3], [3, 5], [5, 6], [6, 3]]) sage: M = Matroid(G) sage: R = M.regular_matroid() sage: set(M.circuits()) == set(R.circuits()) diff --git a/src/sage/matroids/linear_matroid.pyx b/src/sage/matroids/linear_matroid.pyx index 3e1be5bc3e9..4b6f10b1bba 100644 --- a/src/sage/matroids/linear_matroid.pyx +++ b/src/sage/matroids/linear_matroid.pyx @@ -1272,10 +1272,10 @@ cdef class LinearMatroid(BasisExchangeMatroid): INPUT: - - ``contractions`` -- An object with Python's ``frozenset`` interface - containing a subset of ``self.groundset()``. - - ``deletions`` -- An object with Python's ``frozenset`` interface - containing a subset of ``self.groundset()``. + - ``contractions`` -- an object with Python's ``frozenset`` interface + containing a subset of ``self.groundset()`` + - ``deletions`` -- an object with Python's ``frozenset`` interface + containing a subset of ``self.groundset()`` .. NOTE:: @@ -3721,10 +3721,10 @@ cdef class BinaryMatroid(LinearMatroid): INPUT: - - ``contractions`` -- An object with Python's ``frozenset`` interface - containing a subset of ``self.groundset()``. - - ``deletions`` -- An object with Python's ``frozenset`` interface - containing a subset of ``self.groundset()``. + - ``contractions`` -- an object with Python's ``frozenset`` interface + containing a subset of ``self.groundset()`` + - ``deletions`` -- an object with Python's ``frozenset`` interface + containing a subset of ``self.groundset()`` .. NOTE:: @@ -4667,10 +4667,10 @@ cdef class TernaryMatroid(LinearMatroid): INPUT: - - ``contractions`` -- An object with Python's ``frozenset`` interface - containing a subset of ``self.groundset()``. - - ``deletions`` -- An object with Python's ``frozenset`` interface - containing a subset of ``self.groundset()``. + - ``contractions`` -- an object with Python's ``frozenset`` interface + containing a subset of ``self.groundset()`` + - ``deletions`` -- an object with Python's ``frozenset`` interface + containing a subset of ``self.groundset()`` .. NOTE:: @@ -5443,10 +5443,10 @@ cdef class QuaternaryMatroid(LinearMatroid): INPUT: - - ``contractions`` -- An object with Python's ``frozenset`` interface - containing a subset of ``self.groundset()``. - - ``deletions`` -- An object with Python's ``frozenset`` interface - containing a subset of ``self.groundset()``. + - ``contractions`` -- an object with Python's ``frozenset`` interface + containing a subset of ``self.groundset()`` + - ``deletions`` -- an object with Python's ``frozenset`` interface + containing a subset of ``self.groundset()`` .. NOTE:: diff --git a/src/sage/matroids/matroid.pyx b/src/sage/matroids/matroid.pyx index bb00c629573..e7d97353c1b 100644 --- a/src/sage/matroids/matroid.pyx +++ b/src/sage/matroids/matroid.pyx @@ -502,7 +502,7 @@ cdef class Matroid(SageObject): INPUT: - - ``X`` -- an object with Python's ``frozenset`` interface. + - ``X`` -- an object with Python's ``frozenset`` interface OUTPUT: an integer @@ -1135,10 +1135,10 @@ cdef class Matroid(SageObject): INPUT: - - ``contractions`` -- An object with Python's ``frozenset`` interface - containing a subset of ``self.groundset()``. - - ``deletions`` -- An object with Python's ``frozenset`` interface - containing a subset of ``self.groundset()``. + - ``contractions`` -- an object with Python's ``frozenset`` interface + containing a subset of ``self.groundset()`` + - ``deletions`` -- an object with Python's ``frozenset`` interface + containing a subset of ``self.groundset()`` .. NOTE:: @@ -3627,7 +3627,7 @@ cdef class Matroid(SageObject): - ``other`` -- matroid - OUTPUT: a dictionary, or ``None`` + OUTPUT: dictionary or ``None`` EXAMPLES:: @@ -3661,7 +3661,7 @@ cdef class Matroid(SageObject): - ``other`` -- matroid - OUTPUT: a dictionary, or ``None`` + OUTPUT: dictionary or ``None`` EXAMPLES:: @@ -3951,9 +3951,9 @@ cdef class Matroid(SageObject): .. WARNING:: - This method is linked to ``__richcmp__`` (in Cython) and - ``__cmp__`` or ``__eq__``/``__ne__`` (in Python). If you override - one, you should (and in Cython: MUST) override the other! + This method is linked to __richcmp__ (in Cython) and __cmp__ or + __eq__/__ne__ (in Python). If you override one, you should (and in + Cython: MUST) override the other! EXAMPLES:: diff --git a/src/sage/matroids/minor_matroid.py b/src/sage/matroids/minor_matroid.py index 4f0ee3cfe59..afdd88dd060 100644 --- a/src/sage/matroids/minor_matroid.py +++ b/src/sage/matroids/minor_matroid.py @@ -168,7 +168,7 @@ def _rank(self, X): INPUT: - - ``X`` -- an object with Python's ``frozenset`` interface. + - ``X`` -- an object with Python's ``frozenset`` interface OUTPUT: @@ -317,10 +317,10 @@ def _minor(self, contractions, deletions): INPUT: - - ``contractions`` -- An object with Python's ``frozenset`` interface - containing a subset of ``self.groundset()``. - - ``deletions`` -- An object with Python's ``frozenset`` interface - containing a subset of ``self.groundset()``. + - ``contractions`` -- an object with Python's ``frozenset`` interface + containing a subset of ``self.groundset()`` + - ``deletions`` -- an object with Python's ``frozenset`` interface + containing a subset of ``self.groundset()`` OUTPUT: diff --git a/src/sage/matroids/union_matroid.pyx b/src/sage/matroids/union_matroid.pyx index 19b3b45d143..f5cefda38a5 100644 --- a/src/sage/matroids/union_matroid.pyx +++ b/src/sage/matroids/union_matroid.pyx @@ -82,7 +82,7 @@ cdef class MatroidUnion(Matroid): INPUT: - - ``X`` -- an object with Python's ``frozenset`` interface. + - ``X`` -- an object with Python's ``frozenset`` interface OUTPUT: @@ -215,7 +215,7 @@ cdef class MatroidSum(Matroid): INPUT: - - ``X`` -- an object with Python's ``frozenset`` interface. + - ``X`` -- an object with Python's ``frozenset`` interface OUTPUT: @@ -314,7 +314,7 @@ cdef class PartitionMatroid(Matroid): INPUT: - - ``X`` -- an object with Python's ``frozenset`` interface. + - ``X`` -- an object with Python's ``frozenset`` interface OUTPUT: