From 70e96f2b792044a1fa72c0df4ae1f9e4b8fd531b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Thu, 25 Sep 2025 17:51:09 +0200 Subject: [PATCH 1/7] convert some methods in designs and graphs to n_* --- src/sage/combinat/designs/bibd.py | 8 +- .../designs/gen_quadrangles_with_spread.pyx | 2 +- .../designs/group_divisible_designs.py | 4 +- .../combinat/designs/incidence_structures.py | 117 ++++++++++-------- src/sage/combinat/designs/resolvable_bibd.py | 4 +- .../designs/steiner_quadruple_systems.py | 14 +-- .../combinat/designs/subhypergraph_search.pyx | 16 +-- src/sage/combinat/designs/twographs.py | 9 +- src/sage/graphs/hypergraph_generators.py | 4 +- src/sage/matrix/matrix2.pyx | 4 +- 10 files changed, 98 insertions(+), 84 deletions(-) diff --git a/src/sage/combinat/designs/bibd.py b/src/sage/combinat/designs/bibd.py index 46ea2ba14fa..22de9915bea 100644 --- a/src/sage/combinat/designs/bibd.py +++ b/src/sage/combinat/designs/bibd.py @@ -334,7 +334,7 @@ def balanced_incomplete_block_design(v, k, lambd=1, existence=False, use_LJCR=Fa return False raise EmptySetError(f"there exists no ({v},{k},{lambd})-BIBD") B = B.incidence_structure() - if B.num_blocks() == expected_n_of_blocks: + if B.n_blocks() == expected_n_of_blocks: if existence: return True else: @@ -1467,7 +1467,7 @@ def __repr__(self): (13,3,1)-Balanced Incomplete Block Design """ bsizes = list(frozenset(self.block_sizes())) - return "Pairwise Balanced Design on {} points with sets of sizes in {}".format(self.num_points(), bsizes) + return "Pairwise Balanced Design on {} points with sets of sizes in {}".format(self.n_points(), bsizes) class BalancedIncompleteBlockDesign(PairwiseBalancedDesign): @@ -1526,10 +1526,10 @@ def __repr__(self): sage: b=designs.balanced_incomplete_block_design(9,3); b (9,3,1)-Balanced Incomplete Block Design """ - v = self.num_points() + v = self.n_points() k = len(self._blocks[0]) if self._blocks else 0 l = self._lambd - return "({},{},{})-Balanced Incomplete Block Design".format(v,k,l) + return f"({v},{k},{l})-Balanced Incomplete Block Design" def arc(self, s=2, solver=None, verbose=0, *, integrality_tolerance=1e-3): r""" diff --git a/src/sage/combinat/designs/gen_quadrangles_with_spread.pyx b/src/sage/combinat/designs/gen_quadrangles_with_spread.pyx index 43eeecf4c0c..6e2c084e7e5 100644 --- a/src/sage/combinat/designs/gen_quadrangles_with_spread.pyx +++ b/src/sage/combinat/designs/gen_quadrangles_with_spread.pyx @@ -217,7 +217,7 @@ def dual_GQ_ovoid(GQ, O): # GQ.ground_set()[i] becomes newBlocks[i] # GQ.blocks()[i] becomes i - newBlocks = [[] for _ in range(GQ.num_points())] + newBlocks = [[] for _ in range(GQ.n_points())] pointsToInt = {p: i for i, p in enumerate(GQ.ground_set())} for i, b in enumerate(GQ.blocks()): diff --git a/src/sage/combinat/designs/group_divisible_designs.py b/src/sage/combinat/designs/group_divisible_designs.py index 7b37b6101b9..a1fcebae512 100644 --- a/src/sage/combinat/designs/group_divisible_designs.py +++ b/src/sage/combinat/designs/group_divisible_designs.py @@ -292,7 +292,7 @@ def __init__(self, points, groups, blocks, G=None, K=None, lambd=1, if check or groups is None: is_gdd = is_group_divisible_design(self._groups, self._blocks, - self.num_points(), G, K, + self.n_points(), G, K, lambd, verbose=1) assert is_gdd if groups is None: @@ -355,6 +355,6 @@ def __repr__(self): if not gdd_type: gdd_type = "1^0" - v = self.num_points() + v = self.n_points() return "Group Divisible Design on {} points of type {}".format(v, gdd_type) diff --git a/src/sage/combinat/designs/incidence_structures.py b/src/sage/combinat/designs/incidence_structures.py index f73a2a3a468..1365b7f2df5 100644 --- a/src/sage/combinat/designs/incidence_structures.py +++ b/src/sage/combinat/designs/incidence_structures.py @@ -271,7 +271,7 @@ def __repr__(self): Incidence structure with 7 points and 7 blocks """ return 'Incidence structure with {} points and {} blocks'.format( - self.num_points(), self.num_blocks()) + self.n_points(), self.n_blocks()) __str__ = __repr__ @@ -308,11 +308,11 @@ def __eq__(self, other): if self._points == other._points: return self._blocks == other._blocks - if (self.num_points() != other.num_points() or - self.num_blocks() != other.num_blocks()): + if (self.n_points() != other.n_points() or + self.n_blocks() != other.n_blocks()): return False - p_to_i = self._point_to_index if self._point_to_index else list(range(self.num_points())) + p_to_i = self._point_to_index if self._point_to_index else list(range(self.n_points())) if any(p not in p_to_i for p in other.ground_set()): return False @@ -408,9 +408,9 @@ def canonical_label(self): if self._canonical_label is None: from sage.graphs.graph import Graph g = Graph() - n = self.num_points() + n = self.n_points() g.add_edges((i+n, x) for i, b in enumerate(self._blocks) for x in b) - canonical_label = g.canonical_label([list(range(n)), list(range(n, n+self.num_blocks()))], certificate=True)[1] + canonical_label = g.canonical_label([list(range(n)), list(range(n, n+self.n_blocks()))], certificate=True)[1] canonical_label = [canonical_label[x] for x in range(n)] self._canonical_label = canonical_label @@ -473,8 +473,8 @@ def is_isomorphic(self, other, certificate=False): sage: IS1._canonical_label is None or IS2._canonical_label is None False """ - if (self.num_points() != other.num_points() or - self.num_blocks() != other.num_blocks() or + if (self.n_points() != other.n_points() or + self.n_blocks() != other.n_blocks() or sorted(self.block_sizes()) != sorted(other.block_sizes())): return {} if certificate else False @@ -581,7 +581,7 @@ def copy(self): IS = IncidenceStructure(self._blocks, name=self._name, check=False) - IS.relabel(dict(zip(range(self.num_points()), self._points))) + IS.relabel(dict(zip(range(self.n_points()), self._points))) IS._canonical_label = None if self._canonical_label is None else self._canonical_label[:] return IS @@ -631,7 +631,7 @@ def induced_substructure(self, points): """ # Checking the input if self._point_to_index is None: - n = self.num_points() + n = self.n_points() for x in points: x = int(x) if x < 0 or x >= n: @@ -706,7 +706,7 @@ def trace(self, points, min_size=1, multiset=True): """ # Checking the input if self._point_to_index is None: - n = self.num_points() + n = self.n_points() int_points = frozenset(int(x) for x in points) for x in int_points: if x < 0 or x >= n: @@ -737,34 +737,52 @@ def ground_set(self): """ return self._points[:] - def num_points(self): + def n_points(self) -> int: r""" Return the size of the ground set. EXAMPLES:: - sage: designs.DesarguesianProjectivePlaneDesign(2).num_points() + sage: designs.DesarguesianProjectivePlaneDesign(2).n_points() 7 sage: B = IncidenceStructure(4, [[0,1],[0,2],[0,3],[1,2], [1,2,3]]) - sage: B.num_points() + sage: B.n_points() 4 + + TESTS: + + The old method name is kept as an alias:: + + sage: designs.DesarguesianProjectivePlaneDesign(2).npoints() + 7 """ return len(self._points) - def num_blocks(self): + num_points = n_points + + def n_blocks(self) -> int: r""" Return the number of blocks. EXAMPLES:: - sage: designs.DesarguesianProjectivePlaneDesign(2).num_blocks() + sage: designs.DesarguesianProjectivePlaneDesign(2).n_blocks() 7 sage: B = IncidenceStructure(4, [[0,1],[0,2],[0,3],[1,2], [1,2,3]]) - sage: B.num_blocks() + sage: B.n_blocks() 5 + + TESTS: + + The old method name is kept as an alias:: + + sage: designs.DesarguesianProjectivePlaneDesign(2).npoints() + 7 """ return len(self._blocks) + num_blocks = n_blocks + def blocks(self): """ Return the list of blocks. @@ -881,14 +899,14 @@ def degrees(self, size=None): True """ if size is None: - d = [0]*self.num_points() + d = [0]*self.n_points() for b in self._blocks: for x in b: d[x] += 1 return {p: d[i] for i, p in enumerate(self._points)} else: from itertools import combinations - d = {t: 0 for t in combinations(range(self.num_points()), size)} + d = {t: 0 for t in combinations(range(self.n_points()), size)} for b in self._blocks: for s in combinations(b, size): d[s] += 1 @@ -947,9 +965,9 @@ def is_regular(self, r=None) -> bool | int: ... ValueError: This incidence structure has no points. """ - if self.num_points() == 0: + if self.n_points() == 0: raise ValueError("This incidence structure has no points.") - count = [0] * self.num_points() + count = [0] * self.n_points() for b in self._blocks: for x in b: count[x] += 1 @@ -998,7 +1016,7 @@ def is_uniform(self, k=None) -> bool | int: ... ValueError: This incidence structure has no blocks. """ - if self.num_blocks() == 0: + if self.n_blocks() == 0: raise ValueError("This incidence structure has no blocks.") sizes = set(self.block_sizes()) if len(sizes) != 1: @@ -1019,7 +1037,7 @@ def is_connected(self) -> bool: False """ from sage.sets.disjoint_set import DisjointSet - D = DisjointSet(self.num_points()) + D = DisjointSet(self.n_points()) for B in self._blocks: x = B[0] for i in range(1, len(B)): @@ -1059,7 +1077,7 @@ def _gap_(self): sage: BD._gap_() 'BlockDesign(7,[[1, 2, 3], [1, 4, 5], [1, 6, 7], [2, 4, 6], [2, 5, 7], [3, 4, 7], [3, 5, 6]])' """ - v = self.num_points() + v = self.n_points() gB = [[x + 1 for x in b] for b in self._blocks] return "BlockDesign({},{})".format(v, gB) @@ -1075,7 +1093,7 @@ def _libgap_(self): isBlockDesign := true, v := 4 ) """ libgap.load_package("design") - v = self.num_points() + v = self.n_points() gB = [[x + 1 for x in b] for b in self._blocks] return libgap.BlockDesign(v, gB) @@ -1144,7 +1162,7 @@ def incidence_matrix(self): """ from sage.matrix.constructor import matrix from sage.rings.integer_ring import ZZ - A = matrix(ZZ, self.num_points(), self.num_blocks(), sparse=True) + A = matrix(ZZ, self.n_points(), self.n_blocks(), sparse=True) for j, b in enumerate(self._blocks): for i in b: A[i, j] = 1 @@ -1300,23 +1318,23 @@ def complement(self, uniform=False): raise ValueError("The incidence structure is not uniform.") blocks = [] - num_blocks = self.num_blocks() + n_blocks = self.n_blocks() i = 0 from itertools import combinations - for B in combinations(range(self.num_points()), k): + for B in combinations(range(self.n_points()), k): B = list(B) - while i < num_blocks and self._blocks[i] < B: + while i < n_blocks and self._blocks[i] < B: i += 1 - if i < num_blocks and self._blocks[i] == B: + if i < n_blocks and self._blocks[i] == B: i += 1 continue blocks.append(B) I = IncidenceStructure(blocks, copy=False) else: - X = set(range(self.num_points())) + X = set(range(self.n_points())) I = IncidenceStructure([X.difference(B) for B in self._blocks]) - I.relabel({i: self._points[i] for i in range(self.num_points())}) + I.relabel({i: self._points[i] for i in range(self.n_points())}) return I def relabel(self, perm=None, inplace=True): @@ -1387,7 +1405,7 @@ def relabel(self, perm=None, inplace=True): return G if perm is None: - self._points = list(range(self.num_points())) + self._points = list(range(self.n_points())) self._point_to_index = None return @@ -1408,7 +1426,7 @@ def relabel(self, perm=None, inplace=True): raise ValueError("two points are getting relabelled with the same name") self._points = [perm[x] for x in self._points] - if self._points == list(range(self.num_points())): + if self._points == list(range(self.n_points())): self._point_to_index = None else: self._point_to_index = {v: i for i, v in enumerate(self._points)} @@ -1470,7 +1488,7 @@ def packing(self, solver=None, verbose=0, *, integrality_tolerance=1e-3): p.add_constraint(p.sum([b[i] for i in L]) <= 1) # Maximum number of blocks - p.set_objective(p.sum([b[i] for i in range(self.num_blocks())])) + p.set_objective(p.sum([b[i] for i in range(self.n_blocks())])) p.solve(log=verbose) @@ -1615,7 +1633,7 @@ def is_t_design(self, t=None, v=None, k=None, l=None, return_parameters=False): # Missing parameters ? if v is None: - v = self.num_points() + v = self.n_points() if k is None: k = len(self._blocks[0]) if self._blocks else 0 @@ -1623,11 +1641,11 @@ def is_t_design(self, t=None, v=None, k=None, l=None, return_parameters=False): if l is not None and t is None: raise ValueError("t must be set when l=None") - b = self.num_blocks() + b = self.n_blocks() # Trivial wrong answers if (any(len(block) != k for block in self._blocks) or # non k-uniform - v != self.num_points()): + v != self.n_points()): return (False, (0, 0, 0, 0)) if return_parameters else False # Trivial case t>k @@ -1873,10 +1891,10 @@ def automorphism_group(self): from sage.graphs.graph import Graph from sage.groups.perm_gps.permgroup import PermutationGroup g = Graph() - n = self.num_points() + n = self.n_points() g.add_edges((i + n, x) for i, b in enumerate(self._blocks) for x in b) ag = g.automorphism_group(partition=[list(range(n)), - list(range(n, n + self.num_blocks()))]) + list(range(n, n + self.n_blocks()))]) if self._point_to_index: gens = [[tuple([self._points[i] for i in cycle if (not cycle or cycle[0] < n)]) @@ -1985,7 +2003,7 @@ def is_resolvable(self, certificate=False, solver=None, verbose=0, check=True, n_classes = degrees.pop() p = MixedIntegerLinearProgram(solver=solver) b = p.new_variable(binary=True) - domain = list(range(self.num_points())) + domain = list(range(self.n_points())) # Lists of blocks containing i for every i dual = [[] for _ in domain] @@ -2015,7 +2033,7 @@ def is_resolvable(self, certificate=False, solver=None, verbose=0, check=True, if check and self._classes is not False: assert sorted(id(c) for cls in self._classes for c in cls) == sorted(id(b) for b in self._blocks), "some set does not appear exactly once" - domain = list(range(self.num_points())) + domain = list(range(self.n_points())) for i, c in enumerate(self._classes): assert sorted(sum(c, [])) == domain, "class {} is not a partition".format(i) @@ -2034,7 +2052,7 @@ def is_resolvable(self, certificate=False, solver=None, verbose=0, check=True, return True def coloring(self, k=None, solver=None, verbose=0, - *, integrality_tolerance=1e-3): + *, integrality_tolerance=1e-3) -> list: r""" Compute a (weak) `k`-coloring of the hypergraph. @@ -2087,14 +2105,14 @@ def coloring(self, k=None, solver=None, verbose=0, 3 """ if k is None: - for k in range(self.num_points() + 1): + for k in range(self.n_points() + 1): try: return self.coloring(k) except ValueError: pass if k == 0: - if self.num_points(): + if self.n_points(): raise ValueError("Only empty hypergraphs are 0-chromatic") return [] elif any(len(x) == 1 for x in self._blocks): @@ -2110,7 +2128,7 @@ def coloring(self, k=None, solver=None, verbose=0, p = MixedIntegerLinearProgram(solver=solver) b = p.new_variable(binary=True) - for x in range(self.num_points()): + for x in range(self.n_points()): p.add_constraint(p.sum(b[x, i] for i in range(k)) == 1) for s in self._blocks: @@ -2130,7 +2148,7 @@ def coloring(self, k=None, solver=None, verbose=0, return col - def edge_coloring(self) -> list: + def edge_coloring(self) -> list[list]: r""" Compute a proper edge-coloring. @@ -2154,12 +2172,12 @@ def edge_coloring(self) -> list: from sage.graphs.graph import Graph blocks = self.blocks() blocks_sets = [frozenset(b) for b in blocks] - g = Graph([list(range(self.num_blocks())), + g = Graph([list(range(self.n_blocks())), lambda x, y: len(blocks_sets[x] & blocks_sets[y])], loops=False) return [[blocks[i] for i in C] for C in g.coloring(algorithm='MILP')] - def _spring_layout(self): + def _spring_layout(self) -> dict: r""" Return a spring layout for the points. @@ -2345,7 +2363,6 @@ def is_spread(self, spread) -> bool: sage: E.is_spread([[1]]) True """ - points = set(self.ground_set()) allBlocks = set(map(frozenset, self.blocks())) for block in spread: diff --git a/src/sage/combinat/designs/resolvable_bibd.py b/src/sage/combinat/designs/resolvable_bibd.py index 8e4769c00f5..63d67ddb3ae 100644 --- a/src/sage/combinat/designs/resolvable_bibd.py +++ b/src/sage/combinat/designs/resolvable_bibd.py @@ -804,10 +804,10 @@ def PBD_4_7_from_Y(gdd, check=True): for G in gdd.groups(): gs = len(G) for B in group_PBD[gs]: - PBD.append([3*G[x//3]+(x % 3) if x < 3*gs else 3*gdd.num_points() + PBD.append([3*G[x//3]+(x % 3) if x < 3*gs else 3*gdd.n_points() for x in B]) - return PairwiseBalancedDesign(3*gdd.num_points()+1, + return PairwiseBalancedDesign(3*gdd.n_points()+1, blocks=PBD, K=[4, 7], check=check, diff --git a/src/sage/combinat/designs/steiner_quadruple_systems.py b/src/sage/combinat/designs/steiner_quadruple_systems.py index ad455da0309..bc866a63161 100644 --- a/src/sage/combinat/designs/steiner_quadruple_systems.py +++ b/src/sage/combinat/designs/steiner_quadruple_systems.py @@ -83,7 +83,7 @@ def two_n(B): ....: if not two_n(sqs).is_t_design(3,2*n,4,1): ....: print("Something is wrong !") """ - n = B.num_points() + n = B.n_points() Y = [] # Line 1 @@ -121,7 +121,7 @@ def three_n_minus_two(B): ....: if not three_n_minus_two(sqs).is_t_design(3,3*n-2,4,1): ....: print("Something is wrong !") """ - n = B.num_points() + n = B.n_points() A = n-1 Y = [] # relabel function @@ -178,7 +178,7 @@ def three_n_minus_eight(B): ....: if not three_n_minus_eight(sqs).is_t_design(3,3*n-8,4,1): ....: print("Something is wrong !") """ - n = B.num_points() + n = B.n_points() if (n % 12) != 2: raise ValueError("n must be equal to 2 mod 12") @@ -240,7 +240,7 @@ def three_n_minus_four(B): ....: if not three_n_minus_four(sqs).is_t_design(3,3*n-4,4,1): ....: print("Something is wrong !") """ - n = B.num_points() + n = B.n_points() if n % 12 != 10: raise ValueError("n must be equal to 10 mod 12") @@ -305,7 +305,7 @@ def four_n_minus_six(B): ....: if not four_n_minus_six(sqs).is_t_design(3,4*n-6,4,1): ....: print("Something is wrong !") """ - n = B.num_points() + n = B.n_points() f = n-2 r = lambda i,ii,x : (2*(i % 2)+(ii % 2))*(n-2)+(x) % (n-2) @@ -378,7 +378,7 @@ def twelve_n_minus_ten(B): ....: if not twelve_n_minus_ten(sqs).is_t_design(3,12*n-10,4,1): ....: print("Something is wrong !") """ - n = B.num_points() + n = B.n_points() B14 = steiner_quadruple_system(14) r = lambda i,x : i % (n-1)+(x % 12)*(n-1) @@ -474,7 +474,7 @@ def relabel_system(B): sage: relabel_system(SQS8) Incidence structure with 8 points and 14 blocks """ - n = B.num_points() + n = B.n_points() B0 = B._blocks[0] label = { diff --git a/src/sage/combinat/designs/subhypergraph_search.pyx b/src/sage/combinat/designs/subhypergraph_search.pyx index 64e9899e207..61ff291f6ae 100644 --- a/src/sage/combinat/designs/subhypergraph_search.pyx +++ b/src/sage/combinat/designs/subhypergraph_search.pyx @@ -360,16 +360,16 @@ cdef class SubHypergraphSearch: self.points1 = H1._points self.points2 = H2._points self.induced = induced - cdef int n1 = H1.num_points() - cdef int n2 = H2.num_points() + cdef int n1 = H1.n_points() + cdef int n2 = H2.n_points() - if n2>64: - raise RuntimeError("H2 has {}>64 points".format(n2)) + if n2 > 64: + raise RuntimeError(f"H2 has {n2}>64 points") - self.h1 = h_init(n1,H1._blocks) - self.h2 = h_init(n2,H2._blocks) - self.tmp1 = h_init(n1,H1._blocks) # No actual need to fill them, - self.tmp2 = h_init(n2,H2._blocks) # only allocate the memory + self.h1 = h_init(n1, H1._blocks) + self.h2 = h_init(n2, H2._blocks) + self.tmp1 = h_init(n1, H1._blocks) # No actual need to fill them, + self.tmp2 = h_init(n2, H2._blocks) # only allocate the memory self.step = sig_malloc((n2+1)*sizeof(int)) diff --git a/src/sage/combinat/designs/twographs.py b/src/sage/combinat/designs/twographs.py index 9af4e9d7bc8..a8b6a83f945 100644 --- a/src/sage/combinat/designs/twographs.py +++ b/src/sage/combinat/designs/twographs.py @@ -237,7 +237,7 @@ def is_twograph(T) -> bool: return False # A structure for a fast triple existence check - v_to_blocks = {v: set() for v in range(T.num_points())} + v_to_blocks = {v: set() for v in range(T.n_points())} for B in T._blocks: B = frozenset(B) for x in B: @@ -248,11 +248,8 @@ def has_triple(x_y_z) -> bool: return bool(v_to_blocks[x] & v_to_blocks[y] & v_to_blocks[z]) # Check that every quadruple contains an even number of triples - for quad in combinations(range(T.num_points()), 4): - if sum(map(has_triple, combinations(quad, 3))) % 2: - return False - - return True + return not any(sum(map(has_triple, combinations(quad, 3))) % 2 + for quad in combinations(range(T.n_points()), 4)) def twograph_descendant(G, v, name=None): diff --git a/src/sage/graphs/hypergraph_generators.py b/src/sage/graphs/hypergraph_generators.py index fded49dd247..010244d045f 100644 --- a/src/sage/graphs/hypergraph_generators.py +++ b/src/sage/graphs/hypergraph_generators.py @@ -304,9 +304,9 @@ def BinomialRandomUniform(self, n, k, p): EXAMPLES:: - sage: hypergraphs.BinomialRandomUniform(50, 3, 1).num_blocks() # needs numpy, long time + sage: hypergraphs.BinomialRandomUniform(50, 3, 1).n_blocks() # needs numpy, long time 19600 - sage: hypergraphs.BinomialRandomUniform(50, 3, 0).num_blocks() # needs numpy + sage: hypergraphs.BinomialRandomUniform(50, 3, 0).n_blocks() # needs numpy 0 TESTS:: diff --git a/src/sage/matrix/matrix2.pyx b/src/sage/matrix/matrix2.pyx index 99b0ffa33ac..489855807ac 100644 --- a/src/sage/matrix/matrix2.pyx +++ b/src/sage/matrix/matrix2.pyx @@ -21078,13 +21078,13 @@ def _matrix_power_symbolic(A, n): # Where each Jordan block starts, and number of blocks block_start = [0] + J.subdivisions()[0] - num_blocks = len(block_start) + n_blocks = len(block_start) # Prepare matrix M to store `J^n`, computed by Jordan block M = matrix(SR, J.ncols()) M.subdivide(J.subdivisions()) - for k in range(num_blocks): + for k in range(n_blocks): # Jordan block Jk, its dimension nk, the eigenvalue m Jk = J.subdivision(k, k) From 5ae07a9d68bec80621807d164006583ef1a796f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Thu, 25 Sep 2025 18:54:28 +0200 Subject: [PATCH 2/7] fixes --- src/sage/combinat/designs/incidence_structures.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sage/combinat/designs/incidence_structures.py b/src/sage/combinat/designs/incidence_structures.py index 1365b7f2df5..c76e6bf7aff 100644 --- a/src/sage/combinat/designs/incidence_structures.py +++ b/src/sage/combinat/designs/incidence_structures.py @@ -753,7 +753,7 @@ def n_points(self) -> int: The old method name is kept as an alias:: - sage: designs.DesarguesianProjectivePlaneDesign(2).npoints() + sage: designs.DesarguesianProjectivePlaneDesign(2).num_points() 7 """ return len(self._points) @@ -776,7 +776,7 @@ def n_blocks(self) -> int: The old method name is kept as an alias:: - sage: designs.DesarguesianProjectivePlaneDesign(2).npoints() + sage: designs.DesarguesianProjectivePlaneDesign(2).num_blocks() 7 """ return len(self._blocks) From e590e07ba28efc6d79f2795a5f0a984e6ad653f3 Mon Sep 17 00:00:00 2001 From: Martin Rubey Date: Mon, 29 Sep 2025 20:13:15 +0200 Subject: [PATCH 3/7] provide aliases n_vertices, n_edges, n_faces --- src/sage/graphs/generic_graph.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/sage/graphs/generic_graph.py b/src/sage/graphs/generic_graph.py index 3383c2bd44b..7434fda83ed 100644 --- a/src/sage/graphs/generic_graph.py +++ b/src/sage/graphs/generic_graph.py @@ -4803,8 +4803,8 @@ def order(self): """ Return the number of vertices. - Note that ``len(G)`` and :meth:`num_verts` also return the number of - vertices in `G`. + Note that ``len(G)`` and :meth:`n_vertices` also return the + number of vertices in `G`. EXAMPLES:: @@ -4817,6 +4817,7 @@ def order(self): sage: G = graphs.TetrahedralGraph() sage: len(G) 4 + """ return self._backend.num_verts() @@ -4824,22 +4825,27 @@ def order(self): num_verts = order + n_vertices = order + def size(self): """ Return the number of edges. - Note that :meth:`num_edges` also returns the number of edges in `G`. + Note that :meth:`n_edges` also returns the number of edges in `G`. EXAMPLES:: sage: G = graphs.PetersenGraph() sage: G.size() 15 + """ return self._backend.num_edges(self._directed) num_edges = size + n_edges = size + def eulerian_circuit(self, return_vertices=False, labels=True, path=False): r""" Return a list of edges forming an Eulerian circuit if one exists. @@ -6987,7 +6993,7 @@ def faces(self, embedding=None): faces.append(path) return faces - def num_faces(self, embedding=None): + def n_faces(self, embedding=None): """ Return the number of faces of an embedded graph. @@ -7074,6 +7080,8 @@ def num_faces(self, embedding=None): F += g.num_faces(emb) - 1 return F + num_faces = n_faces + def planar_dual(self, embedding=None): """ Return the planar dual of an embedded graph. From fd41cecd9ecc6083babf4df2447ba9770d21fe8a Mon Sep 17 00:00:00 2001 From: Martin Rubey Date: Mon, 29 Sep 2025 20:32:51 +0200 Subject: [PATCH 4/7] use n_ in docstrings --- src/doc/en/thematic_tutorials/sandpile.rst | 2 +- src/sage/categories/coxeter_groups.py | 8 +++---- src/sage/categories/semigroups.py | 6 ++--- src/sage/combinat/constellation.py | 4 ++-- src/sage/combinat/posets/hasse_diagram.py | 2 +- src/sage/graphs/digraph.py | 2 +- src/sage/graphs/digraph_generators.py | 12 +++++----- src/sage/graphs/generators/families.py | 22 ++++++++--------- src/sage/graphs/generators/smallgraphs.py | 2 +- src/sage/graphs/generators/trees.pyx | 4 ++-- src/sage/graphs/generic_graph.py | 24 +++++++++---------- src/sage/graphs/graph.py | 10 ++++---- src/sage/graphs/graph_generators_pyx.pyx | 2 +- .../perm_gps/partn_ref/refinement_graphs.pyx | 6 ++--- src/sage/matroids/graphic_matroid.pyx | 6 ++--- src/sage/sandpiles/sandpile.py | 2 +- 16 files changed, 57 insertions(+), 57 deletions(-) diff --git a/src/doc/en/thematic_tutorials/sandpile.rst b/src/doc/en/thematic_tutorials/sandpile.rst index 01ece68e834..694423194c3 100644 --- a/src/doc/en/thematic_tutorials/sandpile.rst +++ b/src/doc/en/thematic_tutorials/sandpile.rst @@ -4365,7 +4365,7 @@ EXAMPLES:: {0: 2, 1: 3, 2: 1, 3: 2} sage: n(mean([D.simulate_threshold().deg() for _ in range(10)])) # random 7.10000000000000 - sage: n(s.stationary_density()*s.num_verts()) + sage: n(s.stationary_density()*s.n_vertices()) 6.93750000000000 .. NOTE:: diff --git a/src/sage/categories/coxeter_groups.py b/src/sage/categories/coxeter_groups.py index 3390b02b6d5..b69adcb37b9 100644 --- a/src/sage/categories/coxeter_groups.py +++ b/src/sage/categories/coxeter_groups.py @@ -1885,11 +1885,11 @@ def reduced_word_graph(self): sage: W = WeylGroup(['A', 3], prefix='s') sage: w0 = W.long_element() sage: G = w0.reduced_word_graph() - sage: G.num_verts() + sage: G.n_vertices() 16 sage: len(w0.reduced_words()) 16 - sage: G.num_edges() + sage: G.n_edges() 18 sage: len([e for e in G.edges(sort=False) if e[2] == 2]) 10 @@ -1906,9 +1906,9 @@ def reduced_word_graph(self): sage: # needs sage.combinat sage.graphs sage.groups sage: w1 = W.one() sage: G = w1.reduced_word_graph() - sage: G.num_verts() + sage: G.n_vertices() 1 - sage: G.num_edges() + sage: G.n_edges() 0 .. SEEALSO:: diff --git a/src/sage/categories/semigroups.py b/src/sage/categories/semigroups.py index 679ed3075b5..0ade7cfeefd 100644 --- a/src/sage/categories/semigroups.py +++ b/src/sage/categories/semigroups.py @@ -208,7 +208,7 @@ def cayley_graph(self, side='right', simple=False, elements=None, ....: vertex_colors={(1,1,1): G.vertices(sort=True)}, ....: bgcolor=(0,0,0), color_by_label=True, ....: xres=700, yres=700, iterations=200) - sage: G.num_edges() + sage: G.n_edges() 120 sage: # needs sage.combinat sage.graphs sage.groups @@ -221,7 +221,7 @@ def cayley_graph(self, side='right', simple=False, elements=None, sage: # needs sage.graphs sage.groups sage: G = A5.cayley_graph(generators=[A5.gens()[0]]) - sage: G.num_edges() + sage: G.n_edges() 60 sage: g = PermutationGroup([(i + 1, j + 1) ....: for i in range(5) @@ -242,7 +242,7 @@ def cayley_graph(self, side='right', simple=False, elements=None, ....: for w in sum((list(Words(M.semigroup_generators(), k)) ....: for k in range(4)), [])] sage: G = M.cayley_graph(elements=elements) - sage: G.num_verts(), G.num_edges() + sage: G.n_vertices(), G.n_edges() (85, 84) sage: G.show3d(color_by_label=True, edge_size=0.001, vertex_size=0.01) # needs sage.plot diff --git a/src/sage/combinat/constellation.py b/src/sage/combinat/constellation.py index 249e29a274e..649c4b6dbc0 100644 --- a/src/sage/combinat/constellation.py +++ b/src/sage/combinat/constellation.py @@ -885,9 +885,9 @@ def braid_group_orbit(self): g1 (0)(1,4)(2)(3) g2 (0,1,3,2,4) sage: G = c.braid_group_orbit() - sage: G.num_verts() + sage: G.n_vertices() 4 - sage: G.num_edges() + sage: G.n_edges() 12 """ G = DiGraph(multiedges=True, loops=True) diff --git a/src/sage/combinat/posets/hasse_diagram.py b/src/sage/combinat/posets/hasse_diagram.py index e0e1911612c..623d6fee232 100644 --- a/src/sage/combinat/posets/hasse_diagram.py +++ b/src/sage/combinat/posets/hasse_diagram.py @@ -942,7 +942,7 @@ def cardinality(self): sage: H = L.hasse_diagram() sage: H.size() 80 - sage: H.size() == H.num_edges() + sage: H.size() == H.n_edges() True """ return self.order() diff --git a/src/sage/graphs/digraph.py b/src/sage/graphs/digraph.py index cf672df66fc..22970cbc6fd 100644 --- a/src/sage/graphs/digraph.py +++ b/src/sage/graphs/digraph.py @@ -1611,7 +1611,7 @@ def feedback_edge_set(self, constraint_generation=True, value_only=False, `vu` is in the returned feedback arc set:: sage: g = graphs.RandomGNP(5,.3) - sage: while not g.num_edges(): + sage: while not g.n_edges(): ....: g = graphs.RandomGNP(5,.3) sage: dg = DiGraph(g) sage: feedback = dg.feedback_edge_set() # needs sage.numerical.mip diff --git a/src/sage/graphs/digraph_generators.py b/src/sage/graphs/digraph_generators.py index 820131745fa..78e36e9d6c3 100644 --- a/src/sage/graphs/digraph_generators.py +++ b/src/sage/graphs/digraph_generators.py @@ -1536,9 +1536,9 @@ def RandomDirectedGN(self, n, kernel=None, seed=None, immutable=False): sage: # needs networkx sage: D = digraphs.RandomDirectedGN(25) - sage: D.num_verts() + sage: D.n_vertices() 25 - sage: D.num_edges() + sage: D.n_edges() 24 sage: D.is_connected() True @@ -1618,7 +1618,7 @@ def RandomDirectedGNP(self, n, p, loops=False, seed=None, immutable=False): EXAMPLES:: sage: D = digraphs.RandomDirectedGNP(10, .2) - sage: D.num_verts() + sage: D.n_vertices() 10 sage: D.parent() is DiGraph True @@ -1654,15 +1654,15 @@ def RandomDirectedGNM(self, n, m, loops=False, immutable=False): EXAMPLES:: sage: D = digraphs.RandomDirectedGNM(10, 5) - sage: D.num_verts() + sage: D.n_vertices() 10 - sage: D.num_edges() + sage: D.n_edges() 5 With loops:: sage: D = digraphs.RandomDirectedGNM(10, 100, loops = True) - sage: D.num_verts() + sage: D.n_vertices() 10 sage: D.loops() [(0, 0, None), (1, 1, None), (2, 2, None), (3, 3, None), diff --git a/src/sage/graphs/generators/families.py b/src/sage/graphs/generators/families.py index 7a6a6eecdfd..28db9a6c1ef 100644 --- a/src/sage/graphs/generators/families.py +++ b/src/sage/graphs/generators/families.py @@ -561,9 +561,9 @@ def BarbellGraph(n1, n2): sage: n1, n2 = randint(3, 10), randint(0, 10) sage: g = graphs.BarbellGraph(n1, n2) - sage: g.num_verts() == 2 * n1 + n2 + sage: g.n_vertices() == 2 * n1 + n2 True - sage: g.num_edges() == 2 * binomial(n1, 2) + n2 + 1 # needs sage.symbolic + sage: g.n_edges() == 2 * binomial(n1, 2) + n2 + 1 # needs sage.symbolic True sage: g.is_connected() True @@ -638,9 +638,9 @@ def LollipopGraph(n1, n2): sage: n1, n2 = randint(3, 10), randint(0, 10) sage: g = graphs.LollipopGraph(n1, n2) - sage: g.num_verts() == n1 + n2 + sage: g.n_vertices() == n1 + n2 True - sage: g.num_edges() == binomial(n1, 2) + n2 # needs sage.symbolic + sage: g.n_edges() == binomial(n1, 2) + n2 # needs sage.symbolic True sage: g.is_connected() True @@ -711,9 +711,9 @@ def TadpoleGraph(n1, n2): sage: n1, n2 = randint(3, 10), randint(0, 10) sage: g = graphs.TadpoleGraph(n1, n2) - sage: g.num_verts() == n1 + n2 + sage: g.n_vertices() == n1 + n2 True - sage: g.num_edges() == n1 + n2 + sage: g.n_edges() == n1 + n2 True sage: g.girth() == n1 True @@ -761,10 +761,10 @@ def AztecDiamondGraph(n): sage: graphs.AztecDiamondGraph(2) Aztec Diamond graph of order 2 - sage: [graphs.AztecDiamondGraph(i).num_verts() for i in range(8)] + sage: [graphs.AztecDiamondGraph(i).n_vertices() for i in range(8)] [0, 4, 12, 24, 40, 60, 84, 112] - sage: [graphs.AztecDiamondGraph(i).num_edges() for i in range(8)] + sage: [graphs.AztecDiamondGraph(i).n_edges() for i in range(8)] [0, 4, 16, 36, 64, 100, 144, 196] sage: G = graphs.AztecDiamondGraph(3) @@ -803,9 +803,9 @@ def DipoleGraph(n): sage: n = randint(0, 10) sage: g = graphs.DipoleGraph(n) - sage: g.num_verts() == 2 + sage: g.n_vertices() == 2 True - sage: g.num_edges() == n + sage: g.n_edges() == n True sage: g.is_connected() == (n > 0) True @@ -2660,7 +2660,7 @@ def HanoiTowerGraph(pegs, disks, labels=True, positions=True): A slightly larger instance. :: sage: H = graphs.HanoiTowerGraph(4, 6, labels=False, positions=False) - sage: H.num_verts() + sage: H.n_vertices() 4096 sage: H.distance(0, 4^6-1) 17 diff --git a/src/sage/graphs/generators/smallgraphs.py b/src/sage/graphs/generators/smallgraphs.py index 55e2d493bf9..5c596626125 100644 --- a/src/sage/graphs/generators/smallgraphs.py +++ b/src/sage/graphs/generators/smallgraphs.py @@ -3285,7 +3285,7 @@ def HoffmanSingletonGraph(): 5 sage: HS.diameter() 2 - sage: HS.num_verts() + sage: HS.n_vertices() 50 Note that you get a different layout each time you create the graph. :: diff --git a/src/sage/graphs/generators/trees.pyx b/src/sage/graphs/generators/trees.pyx index 84e0fdf2df2..6f5cf892942 100644 --- a/src/sage/graphs/generators/trees.pyx +++ b/src/sage/graphs/generators/trees.pyx @@ -306,7 +306,7 @@ def RandomLobster(n, p, q, seed=None): sage: G.delete_vertices(leaves) # path sage: s = G.degree_sequence() sage: if G: - ....: if G.num_verts() == 1: + ....: if G.n_vertices() == 1: ....: assert s == [0] ....: else: ....: assert s[-2:] == [1, 1] @@ -511,7 +511,7 @@ cdef class TreeIterator: ....: for t in TreeIterator(n): ....: if not t.is_tree(): ....: return False - ....: if t.num_verts() != n: + ....: if t.n_vertices() != n: ....: return False ....: if t.num_edges() != n - 1: ....: return False diff --git a/src/sage/graphs/generic_graph.py b/src/sage/graphs/generic_graph.py index 7434fda83ed..c939e3fc7ab 100644 --- a/src/sage/graphs/generic_graph.py +++ b/src/sage/graphs/generic_graph.py @@ -870,7 +870,7 @@ def _bit_vector(self): '101001100110000010000001001000010110000010110' sage: len([a for a in G._bit_vector() if a == '1']) 15 - sage: G.num_edges() + sage: G.n_edges() 15 TESTS: @@ -7021,35 +7021,35 @@ def n_faces(self, embedding=None): EXAMPLES:: sage: T = graphs.TetrahedralGraph() - sage: T.num_faces() + sage: T.n_faces() 4 The external face of a disconnected graph is counted only once:: - sage: (T + T).num_faces() + sage: (T + T).n_faces() 7 - sage: (T + T + T).num_faces() + sage: (T + T + T).n_faces() 10 Trees and forests have a single face:: sage: T = graphs.RandomTree(10) - sage: T.num_faces() + sage: T.n_faces() 1 - sage: (T + T).num_faces() + sage: (T + T).n_faces() 1 TESTS:: sage: G = graphs.CompleteBipartiteGraph(3, 3) - sage: G.num_faces() + sage: G.n_faces() Traceback (most recent call last): ... ValueError: no embedding is provided and the graph is not planar Issue :issue:`22003` is fixed:: - sage: Graph(1).num_faces() + sage: Graph(1).n_faces() 1 """ if not self: @@ -13297,10 +13297,10 @@ def set_edge_label(self, u, v, l): :: sage: G = Graph({0: {1: 1}}, sparse=True) - sage: G.num_edges() + sage: G.n_edges() 1 sage: G.set_edge_label(0, 1, 1) - sage: G.num_edges() + sage: G.n_edges() 1 """ if self.allows_multiple_edges(): @@ -20260,7 +20260,7 @@ def cartesian_product(self, other, immutable=None): ((1, 'ab'), (1, 'ba')), ((1, 'ab'), (1, 'bb')), ((1, 'ba'), (1, 'aa')), ((1, 'ba'), (1, 'ab')), ((1, 'bb'), (1, 'ba')), ((1, 'bb'), (1, 'bb'))] - sage: Q.strongly_connected_components_digraph().num_verts() # needs sage.combinat + sage: Q.strongly_connected_components_digraph().n_vertices() # needs sage.combinat 2 sage: V = Q.strongly_connected_component_containing_vertex((0, 'aa')) # needs sage.combinat sage: B.is_isomorphic(Q.subgraph(V)) # needs sage.combinat @@ -26383,7 +26383,7 @@ def symmetric_edge_polytope(self, backend=None): sage: n = randint(5, 12) sage: G = Graph() - sage: while not G.num_edges(): # needs networkx + sage: while not G.n_edges(): # needs networkx ....: G = graphs.RandomGNP(n, 0.2) sage: P = G.symmetric_edge_polytope() # needs networkx sage.geometry.polyhedron sage: P.ambient_dim() == n # needs networkx sage.geometry.polyhedron diff --git a/src/sage/graphs/graph.py b/src/sage/graphs/graph.py index 248fd65d12f..d44c9f6aa31 100644 --- a/src/sage/graphs/graph.py +++ b/src/sage/graphs/graph.py @@ -968,9 +968,9 @@ def __init__(self, data=None, pos=None, loops=None, format=None, Loops are not counted as multiedges (see :issue:`11693`) and edges are not counted twice :: - sage: Graph({1:[1]}).num_edges() + sage: Graph({1:[1]}).n_edges() 1 - sage: Graph({1:[2,2]}).num_edges() + sage: Graph({1:[2,2]}).n_edges() 2 An empty list or dictionary defines a simple graph @@ -5363,7 +5363,7 @@ def distance_graph(self, dist): sage: G = graphs.OddGraph(4) sage: d = G.diameter() - sage: n = G.num_verts() + sage: n = G.n_vertices() sage: H = G.distance_graph(list(range(d+1))) sage: H.is_isomorphic(graphs.CompleteGraph(n)) False @@ -5418,10 +5418,10 @@ def distance_graph(self, dist): Empty input, or unachievable distances silently yield empty graphs:: sage: G = graphs.CompleteGraph(5) - sage: G.distance_graph([]).num_edges() + sage: G.distance_graph([]).n_edges() 0 sage: G = graphs.CompleteGraph(5) - sage: G.distance_graph(23).num_edges() + sage: G.distance_graph(23).n_edges() 0 It is an error to provide a distance that is not an integer type:: diff --git a/src/sage/graphs/graph_generators_pyx.pyx b/src/sage/graphs/graph_generators_pyx.pyx index e66ef2234c9..0f874ba1a03 100644 --- a/src/sage/graphs/graph_generators_pyx.pyx +++ b/src/sage/graphs/graph_generators_pyx.pyx @@ -52,7 +52,7 @@ def RandomGNP(n, p, bint directed=False, bint loops=False, seed=None, sage: from sage.graphs.graph_generators_pyx import RandomGNP sage: D = RandomGNP(10, .2, directed=True, seed=0) - sage: D.num_verts() + sage: D.n_vertices() 10 sage: D.edges(sort=True, labels=False) [(0, 3), (0, 6), (1, 7), (1, 9), (4, 6), (4, 7), (5, 4), (5, 6), diff --git a/src/sage/groups/perm_gps/partn_ref/refinement_graphs.pyx b/src/sage/groups/perm_gps/partn_ref/refinement_graphs.pyx index 1258ea280ab..8de59911bfa 100644 --- a/src/sage/groups/perm_gps/partn_ref/refinement_graphs.pyx +++ b/src/sage/groups/perm_gps/partn_ref/refinement_graphs.pyx @@ -362,18 +362,18 @@ def search_tree(G_in, partition, lab=True, dig=False, dict_rep=False, certificat Certain border cases need to be tested as well:: sage: G = Graph('Fll^G') - sage: a,b,c = st(G, [range(G.num_verts())], order=True); b + sage: a,b,c = st(G, [range(G.n_vertices())], order=True); b Graph on 7 vertices sage: c 48 sage: G = Graph(21) - sage: st(G, [range(G.num_verts())], order=True)[2] == factorial(21) + sage: st(G, [range(G.n_vertices())], order=True)[2] == factorial(21) True sage: G = Graph('^????????????????????{??N??@w??FaGa?PCO@CP?AGa?_QO?Q@G?CcA??cc????Bo????{????F_') sage: perm = {3:15, 15:3} sage: H = G.relabel(perm, inplace=False) - sage: st(G, [range(G.num_verts())])[1] == st(H, [range(H.num_verts())])[1] + sage: st(G, [range(G.n_vertices())])[1] == st(H, [range(H.n_vertices())])[1] True sage: st(Graph(':Dkw'), [range(5)], lab=False, dig=True) diff --git a/src/sage/matroids/graphic_matroid.pyx b/src/sage/matroids/graphic_matroid.pyx index 29a1c09c3aa..6cb8505220f 100644 --- a/src/sage/matroids/graphic_matroid.pyx +++ b/src/sage/matroids/graphic_matroid.pyx @@ -66,7 +66,7 @@ modified:: sage: N1 = M1.contract((0,1)) sage: N1.graph().edges_incident(0, sort=True) [(0, 2, (0, 2)), (0, 2, (1, 2)), (0, 3, (1, 3))] - sage: M2 = Matroid(range(G.num_edges()), G) + sage: M2 = Matroid(range(G.n_edges()), G) sage: N2 = M2.contract(0) sage: N1.is_isomorphic(N2) True @@ -229,7 +229,7 @@ cdef class GraphicMatroid(Matroid): sage: sorted(M.groundset()) [(0, 1), (0, 2), (1, 2), (1, 3), (2, 3)] sage: G = graphs.CompleteGraph(3).disjoint_union(graphs.CompleteGraph(4)) - sage: M = Matroid(range(G.num_edges()), G); sorted(M.groundset()) + sage: M = Matroid(range(G.n_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')])) sage: sorted(M.groundset()) @@ -1178,7 +1178,7 @@ cdef class GraphicMatroid(Matroid): 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) - sage: M = Matroid(range(G.num_edges()), G) + sage: M = Matroid(range(G.n_edges()), G) sage: M.graph().edges(sort=True) [(0, 1, 0), (0, 2, 1), diff --git a/src/sage/sandpiles/sandpile.py b/src/sage/sandpiles/sandpile.py index 0e1a80f0321..aa8a1a7ce2b 100644 --- a/src/sage/sandpiles/sandpile.py +++ b/src/sage/sandpiles/sandpile.py @@ -4879,7 +4879,7 @@ def simulate_threshold(self, distrib=None): {0: 2, 1: 3, 2: 1, 3: 2} sage: n(mean([D.simulate_threshold().deg() for _ in range(10)])) # random 7.10000000000000 - sage: n(s.stationary_density()*s.num_verts()) + sage: n(s.stationary_density()*s.n_vertices()) 6.93750000000000 .. NOTE:: From 96d324f514c9eebf000809a162dd2859b3eb7a73 Mon Sep 17 00:00:00 2001 From: Martin Rubey Date: Tue, 30 Sep 2025 10:47:48 +0200 Subject: [PATCH 5/7] also add aliases in the backends --- src/sage/graphs/base/c_graph.pyx | 26 +++++++++++-------- src/sage/graphs/base/graph_backends.pyx | 18 ++++++++----- .../graphs/base/static_sparse_backend.pyx | 14 ++++++---- src/sage/graphs/digraph.py | 2 +- 4 files changed, 36 insertions(+), 24 deletions(-) diff --git a/src/sage/graphs/base/c_graph.pyx b/src/sage/graphs/base/c_graph.pyx index 9d9653cccd0..88a8ceaa3b7 100644 --- a/src/sage/graphs/base/c_graph.pyx +++ b/src/sage/graphs/base/c_graph.pyx @@ -1418,7 +1418,7 @@ cdef class CGraphBackend(GenericGraphBackend): else: self._loops = False - def num_edges(self, directed): + def n_edges(self, directed): """ Return the number of edges in ``self``. @@ -1434,13 +1434,13 @@ cdef class CGraphBackend(GenericGraphBackend): .. SEEALSO:: - - :meth:`num_verts` + - :meth:`n_vertices` -- return the order of this graph. EXAMPLES:: sage: G = Graph(graphs.PetersenGraph()) - sage: G._backend.num_edges(False) + sage: G._backend.n_edges(False) 15 TESTS: @@ -1485,23 +1485,23 @@ cdef class CGraphBackend(GenericGraphBackend): 2 sage: from sage.graphs.base.sparse_graph import SparseGraphBackend sage: S = SparseGraphBackend(7) - sage: S.num_edges(False) + sage: S.n_edges(False) 0 sage: S.loops(True) sage: S.add_edge(1, 1, None, directed=False) - sage: S.num_edges(False) + sage: S.n_edges(False) 1 sage: S.multiple_edges(True) sage: S.add_edge(1, 1, None, directed=False) - sage: S.num_edges(False) + sage: S.n_edges(False) 2 sage: from sage.graphs.base.dense_graph import DenseGraphBackend sage: D = DenseGraphBackend(7) - sage: D.num_edges(False) + sage: D.n_edges(False) 0 sage: D.loops(True) sage: D.add_edge(1, 1, None, directed=False) - sage: D.num_edges(False) + sage: D.n_edges(False) 1 """ if directed: @@ -1521,7 +1521,9 @@ cdef class CGraphBackend(GenericGraphBackend): i = (i - k) // 2 return i + k - def num_verts(self): + num_edges = n_edges + + def n_vertices(self): """ Return the number of vertices in ``self``. @@ -1529,17 +1531,19 @@ cdef class CGraphBackend(GenericGraphBackend): .. SEEALSO:: - - :meth:`num_edges` + - :meth:`n_edges` -- return the number of (directed) edges in this graph. EXAMPLES:: sage: G = Graph(graphs.PetersenGraph()) - sage: G._backend.num_verts() + sage: G._backend.n_vertices() 10 """ return self.cg().num_verts + num_verts = n_vertices + cdef bint _delete_edge_before_adding(self) noexcept: """ Return whether we should delete edges before adding any. diff --git a/src/sage/graphs/base/graph_backends.pyx b/src/sage/graphs/base/graph_backends.pyx index 518fe1b6700..9dda18df7fe 100644 --- a/src/sage/graphs/base/graph_backends.pyx +++ b/src/sage/graphs/base/graph_backends.pyx @@ -35,8 +35,8 @@ Any graph backend must redefine the following methods (for which :meth:`~GenericGraphBackend.loops` | Get/set whether or not ``self`` allows loops. :meth:`~GenericGraphBackend.multiple_edges` | Get/set whether or not ``self`` allows multiple edges. :meth:`~GenericGraphBackend.name` | Get/set name of ``self``. - :meth:`~GenericGraphBackend.num_edges` | The number of edges in ``self`` - :meth:`~GenericGraphBackend.num_verts` | The number of vertices in ``self`` + :meth:`~GenericGraphBackend.n_edges` | The number of edges in ``self`` + :meth:`~GenericGraphBackend.n_vertices` | The number of vertices in ``self`` :meth:`~GenericGraphBackend.relabel` | Relabel the vertices of ``self`` by a permutation. :meth:`~GenericGraphBackend.set_edge_label` | Label the edge `(u,v)` by `l`. @@ -583,7 +583,7 @@ cdef class GenericGraphBackend(SageObject): """ raise NotImplementedError() - def num_edges(self, directed): + def n_edges(self, directed): """ Return the number of edges in ``self``. @@ -594,31 +594,35 @@ cdef class GenericGraphBackend(SageObject): TESTS:: sage: G = sage.graphs.base.graph_backends.GenericGraphBackend() - sage: G.num_edges(True) + sage: G.n_edges(True) Traceback (most recent call last): ... NotImplementedError - sage: G.num_edges(False) + sage: G.n_edges(False) Traceback (most recent call last): ... NotImplementedError """ raise NotImplementedError() - def num_verts(self): + num_edges = n_edges + + def n_vertices(self): """ Return the number of vertices in ``self``. TESTS:: sage: G = sage.graphs.base.graph_backends.GenericGraphBackend() - sage: G.num_verts() + sage: G.n_vertices() Traceback (most recent call last): ... NotImplementedError """ raise NotImplementedError() + num_verts = n_vertices + def relabel(self, perm, directed): """ Relabel the vertices of ``self`` by a permutation. diff --git a/src/sage/graphs/base/static_sparse_backend.pyx b/src/sage/graphs/base/static_sparse_backend.pyx index 687f4dfe90a..4eb491d5547 100644 --- a/src/sage/graphs/base/static_sparse_backend.pyx +++ b/src/sage/graphs/base/static_sparse_backend.pyx @@ -980,7 +980,7 @@ cdef class StaticSparseBackend(CGraphBackend): yield x return - def num_verts(self): + def n_vertices(self): r""" Return the number of vertices. @@ -988,11 +988,13 @@ cdef class StaticSparseBackend(CGraphBackend): sage: from sage.graphs.base.static_sparse_backend import StaticSparseBackend sage: g = StaticSparseBackend(graphs.PetersenGraph()) - sage: g.num_verts() + sage: g.n_vertices() 10 """ return self._order + num_verts = n_vertices + def allows_loops(self, value=None): r""" Return whether the graph allows loops. @@ -1043,7 +1045,7 @@ cdef class StaticSparseBackend(CGraphBackend): else: raise ValueError("the graph is immutable and cannot be changed in any way") - def num_edges(self, directed): + def n_edges(self, directed): r""" Return the number of edges. @@ -1056,13 +1058,13 @@ cdef class StaticSparseBackend(CGraphBackend): sage: from sage.graphs.base.static_sparse_backend import StaticSparseBackend sage: g = StaticSparseBackend(graphs.PetersenGraph()) - sage: g.num_edges(False) + sage: g.n_edges(False) 15 Testing the exception:: sage: g = StaticSparseBackend(digraphs.Circuit(4)) - sage: g.num_edges(False) + sage: g.n_edges(False) Traceback (most recent call last): ... NotImplementedError: Sorry, I have no idea what is expected in this situation. I don't think that it is well-defined either, especially for multigraphs. @@ -1095,6 +1097,8 @@ cdef class StaticSparseBackend(CGraphBackend): # Returns the number of edges return int(cg.g.m) + num_edges = n_edges + def iterator_edges(self, vertices, bint labels): r""" Iterate over the graph's edges. diff --git a/src/sage/graphs/digraph.py b/src/sage/graphs/digraph.py index 22970cbc6fd..4c7899a6e2a 100644 --- a/src/sage/graphs/digraph.py +++ b/src/sage/graphs/digraph.py @@ -1494,7 +1494,7 @@ def degree_polynomial(self): .. SEEALSO:: - :meth:`num_verts` for the value at `(x, y) = (1, 1)` + :meth:`n_vertices` for the value at `(x, y) = (1, 1)` EXAMPLES:: From 57156caca6be770c0e37d329dfc421cbf8d5d316 Mon Sep 17 00:00:00 2001 From: Martin Rubey Date: Tue, 30 Sep 2025 10:48:57 +0200 Subject: [PATCH 6/7] replace some leftovers --- src/sage/graphs/bliss.pyx | 2 +- src/sage/graphs/generators/trees.pyx | 2 +- src/sage/graphs/graph_generators.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/sage/graphs/bliss.pyx b/src/sage/graphs/bliss.pyx index 708742bc137..7b9a6398335 100644 --- a/src/sage/graphs/bliss.pyx +++ b/src/sage/graphs/bliss.pyx @@ -476,7 +476,7 @@ cpdef canonical_form(G, partition=None, return_graph=False, ....: for labels in product([0,1], repeat=len(edges)): ....: g = Graph([(u,v,l) for ((u,v),l) in zip(edges, labels)]) ....: gcan = canonical_form(g, use_edge_labels=True) - ....: for p in permutations(range(g.num_verts())): + ....: for p in permutations(range(g.n_vertices())): ....: h = Graph([(p[u], p[v], lab) for u,v,lab in g.edges(sort=True)]) ....: hcan = canonical_form(h, use_edge_labels=True) ....: if gcan != hcan: print(edges, labels, p) diff --git a/src/sage/graphs/generators/trees.pyx b/src/sage/graphs/generators/trees.pyx index 6f5cf892942..455c67a4dda 100644 --- a/src/sage/graphs/generators/trees.pyx +++ b/src/sage/graphs/generators/trees.pyx @@ -513,7 +513,7 @@ cdef class TreeIterator: ....: return False ....: if t.n_vertices() != n: ....: return False - ....: if t.num_edges() != n - 1: + ....: if t.n_edges() != n - 1: ....: return False ....: for tree in trees: ....: if tree.is_isomorphic(t): diff --git a/src/sage/graphs/graph_generators.py b/src/sage/graphs/graph_generators.py index a5b3d874280..0152e545eb0 100644 --- a/src/sage/graphs/graph_generators.py +++ b/src/sage/graphs/graph_generators.py @@ -798,7 +798,7 @@ def __call__(self, vertices=None, property=None, augment='edges', size=None, :: sage: for g in graphs(): - ....: if g.num_verts() > 3: break + ....: if g.n_vertices() > 3: break ....: print(g) Graph on 0 vertices Graph on 1 vertex From 4b2ae4925d09fd5ad0477da131b545ae044868b1 Mon Sep 17 00:00:00 2001 From: Martin Rubey Date: Tue, 30 Sep 2025 16:49:41 +0200 Subject: [PATCH 7/7] replace num_edges, num_faces and num_verts with n_edges, n_faces and n_vertices respectively --- src/sage/categories/crystals.py | 2 +- src/sage/combinat/posets/hasse_diagram.py | 4 +- .../posets/linear_extension_iterator.pyx | 2 +- src/sage/combinat/posets/posets.py | 2 +- .../combinat/root_system/cartan_matrix.py | 2 +- .../combinat/root_system/coxeter_matrix.py | 2 +- .../combinat/root_system/dynkin_diagram.py | 2 +- src/sage/combinat/species/species.py | 2 +- .../symmetric_group_representations.py | 6 +-- src/sage/combinat/words/finite_word.py | 2 +- src/sage/combinat/yang_baxter_graph.py | 2 +- src/sage/databases/findstat.py | 4 +- .../hyperplane_arrangement/library.py | 8 +-- src/sage/graphs/base/boost_graph.pyx | 6 +-- src/sage/graphs/base/static_sparse_graph.pyx | 4 +- src/sage/graphs/bipartite_graph.py | 4 +- src/sage/graphs/chrompoly.pyx | 6 +-- src/sage/graphs/connectivity.pyx | 4 +- src/sage/graphs/digraph.py | 4 +- src/sage/graphs/generators/random.py | 4 +- src/sage/graphs/generic_graph.py | 34 ++++++------ src/sage/graphs/genus.pyx | 2 +- src/sage/graphs/graph.py | 22 ++++---- src/sage/graphs/graph_generators.py | 4 +- src/sage/graphs/graph_plot.py | 2 +- src/sage/graphs/hyperbolicity.pyx | 13 +++-- .../graphs/isoperimetric_inequalities.pyx | 8 +-- src/sage/graphs/matchpoly.pyx | 4 +- src/sage/graphs/spanning_tree.pyx | 6 +-- src/sage/graphs/strongly_regular_db.pyx | 2 +- src/sage/graphs/tutte_polynomial.py | 6 +-- .../perm_gps/partn_ref/refinement_graphs.pyx | 8 +-- src/sage/groups/raag.py | 14 ++--- src/sage/matroids/constructor.py | 4 +- src/sage/matroids/graphic_matroid.pyx | 4 +- src/sage/quivers/ar_quiver.py | 6 +-- src/sage/quivers/path_semigroup.py | 8 +-- src/sage/sandpiles/sandpile.py | 52 +++++++++---------- 38 files changed, 134 insertions(+), 137 deletions(-) diff --git a/src/sage/categories/crystals.py b/src/sage/categories/crystals.py index c32f99895a0..5976a0c70de 100644 --- a/src/sage/categories/crystals.py +++ b/src/sage/categories/crystals.py @@ -171,7 +171,7 @@ def is_isomorphism(self): index_set = self._cartan_type.index_set() G = self.domain().digraph(index_set=index_set) - if self.codomain().cardinality() != G.num_verts(): + if self.codomain().cardinality() != G.n_vertices(): return False H = self.codomain().digraph(index_set=index_set) return G.is_isomorphic(H, edge_labels=True) diff --git a/src/sage/combinat/posets/hasse_diagram.py b/src/sage/combinat/posets/hasse_diagram.py index 623d6fee232..4dc1085fe8a 100644 --- a/src/sage/combinat/posets/hasse_diagram.py +++ b/src/sage/combinat/posets/hasse_diagram.py @@ -541,7 +541,7 @@ def is_chain(self) -> bool: """ if self.cardinality() == 0: return True - return (self.num_edges() + 1 == self.num_verts() and # tree + return (self.n_edges() + 1 == self.n_vertices() and # tree all(d <= 1 for d in self.out_degree()) and all(d <= 1 for d in self.in_degree())) @@ -589,7 +589,7 @@ def dual(self): False """ H = self.reverse(immutable=False) - H.relabel(perm=list(range(H.num_verts() - 1, -1, -1)), inplace=True) + H.relabel(perm=list(range(H.n_vertices() - 1, -1, -1)), inplace=True) return HasseDiagram(H) def _precompute_intervals(self) -> None: diff --git a/src/sage/combinat/posets/linear_extension_iterator.pyx b/src/sage/combinat/posets/linear_extension_iterator.pyx index c12fec69cd0..2d7dd588322 100644 --- a/src/sage/combinat/posets/linear_extension_iterator.pyx +++ b/src/sage/combinat/posets/linear_extension_iterator.pyx @@ -37,7 +37,7 @@ def _linear_extension_prepare(D): # the preprocessing routine found in Figure 7 of # "Generating Linear Extensions Fast" by # Pruesse and Ruskey - while dag_copy.num_verts() != 0: + while dag_copy.n_vertices() != 0: # find all the minimal elements of dag_copy minimal_elements = dag_copy.sources() if not minimal_elements: diff --git a/src/sage/combinat/posets/posets.py b/src/sage/combinat/posets/posets.py index 74765433797..698b6ad8084 100644 --- a/src/sage/combinat/posets/posets.py +++ b/src/sage/combinat/posets/posets.py @@ -5370,7 +5370,7 @@ def factor(self) -> list: dg = self._hasse_diagram if not dg.is_connected() or not dg.order(): raise NotImplementedError('the poset is empty or not connected') - if Integer(dg.num_verts()).is_prime(): + if Integer(dg.n_vertices()).is_prime(): return [self] if sum(e for _, e in self.degree_polynomial().factor()) == 1: return [self] diff --git a/src/sage/combinat/root_system/cartan_matrix.py b/src/sage/combinat/root_system/cartan_matrix.py index c8e665fcaa2..0611f621d32 100644 --- a/src/sage/combinat/root_system/cartan_matrix.py +++ b/src/sage/combinat/root_system/cartan_matrix.py @@ -1173,7 +1173,7 @@ def find_cartan_type_from_matrix(CM): relabel = [] for S in CM.dynkin_diagram().connected_components_subgraphs(): S = DiGraph(S) # We need a simple digraph here - n = S.num_verts() + n = S.n_vertices() # Build the list to test based upon rank if n == 1: relabel.append({1: S.vertices()[0]}) diff --git a/src/sage/combinat/root_system/coxeter_matrix.py b/src/sage/combinat/root_system/coxeter_matrix.py index f66d8edead5..218e7dad64b 100644 --- a/src/sage/combinat/root_system/coxeter_matrix.py +++ b/src/sage/combinat/root_system/coxeter_matrix.py @@ -1114,7 +1114,7 @@ def recognize_coxeter_type_from_matrix(coxeter_matrix, index_set): types = [] for S in G.connected_components_subgraphs(): - r = S.num_verts() + r = S.n_vertices() # Handle the special cases first if r == 1: types.append(CoxeterType(['A', 1]).relabel({1: S.vertices(sort=True)[0]})) diff --git a/src/sage/combinat/root_system/dynkin_diagram.py b/src/sage/combinat/root_system/dynkin_diagram.py index 3d10becf5c9..89900a3d3c4 100644 --- a/src/sage/combinat/root_system/dynkin_diagram.py +++ b/src/sage/combinat/root_system/dynkin_diagram.py @@ -459,7 +459,7 @@ def rank(self): sage: DynkinDiagram("A2","B2","F4").rank() 8 """ - return self.num_verts() + return self.n_vertices() def dynkin_diagram(self): """ diff --git a/src/sage/combinat/species/species.py b/src/sage/combinat/species/species.py index 3e44ded7677..51f0c888854 100644 --- a/src/sage/combinat/species/species.py +++ b/src/sage/combinat/species/species.py @@ -801,7 +801,7 @@ def algebraic_equation_system(self): Qz = QQ['z'].fraction_field() # Generate the variable names and the corresponding polynomial rings - var_names = ["node%s" % i for i in range(d.num_verts())] + var_names = ["node%s" % i for i in range(d.n_vertices())] R = Qz[", ".join(var_names)] R_gens_dict = R.gens_dict() diff --git a/src/sage/combinat/symmetric_group_representations.py b/src/sage/combinat/symmetric_group_representations.py index cb807b16bec..89abf82c6c8 100644 --- a/src/sage/combinat/symmetric_group_representations.py +++ b/src/sage/combinat/symmetric_group_representations.py @@ -677,9 +677,9 @@ def representation_matrix_for_simple_transposition(self, i): digraph = copy(Y._digraph) digraph.delete_edges((u, v) for (u, v, (j, beta)) in digraph.edges(sort=True) if j != i) - M = matrix(self._ring, digraph.num_verts()) + M = matrix(self._ring, digraph.n_vertices()) for g in digraph.connected_components_subgraphs(): - if g.num_verts() == 1: + if g.n_vertices() == 1: v, = g.vertices(sort=True) w = self._word_dict[v] trivial = None @@ -726,7 +726,7 @@ def _representation_matrix_uncached(self, permutation): [-1/2 3/2] [ 1/2 1/2] """ - m = self._yang_baxter_graph._digraph.num_verts() + m = self._yang_baxter_graph._digraph.n_vertices() M = matrix(self._ring, m, m, 1) for i in Permutation(permutation).reduced_word(): M *= self.representation_matrix_for_simple_transposition(i) diff --git a/src/sage/combinat/words/finite_word.py b/src/sage/combinat/words/finite_word.py index cc4a65d6528..c153b32b9fe 100644 --- a/src/sage/combinat/words/finite_word.py +++ b/src/sage/combinat/words/finite_word.py @@ -1674,7 +1674,7 @@ def reduced_rauzy_graph(self, n): g = copy(self.rauzy_graph(n)) # Otherwise it changes the rauzy_graph function. l = [v for v in g if g.in_degree(v) == 1 == g.out_degree(v)] - if g.num_verts() != 0 and len(l) == g.num_verts(): + if len(l) == g.n_vertices() != 0: # In this case, the Rauzy graph is simply a cycle. g = DiGraph() g.allow_loops(True) diff --git a/src/sage/combinat/yang_baxter_graph.py b/src/sage/combinat/yang_baxter_graph.py index 3fb02420f27..afafad0237a 100644 --- a/src/sage/combinat/yang_baxter_graph.py +++ b/src/sage/combinat/yang_baxter_graph.py @@ -292,7 +292,7 @@ def __len__(self): sage: Y.__len__() 16 """ - return self._digraph.num_verts() + return self._digraph.n_vertices() def __copy__(self): r""" diff --git a/src/sage/databases/findstat.py b/src/sage/databases/findstat.py index 417bf49ebc5..a51e3dd3c0a 100644 --- a/src/sage/databases/findstat.py +++ b/src/sage/databases/findstat.py @@ -4555,9 +4555,9 @@ def name(self, style='singular'): _SupportedFindStatCollection(lambda x: (lambda E, V: Graph([list(range(V)), lambda i,j: (i,j) in E or (j,i) in E], immutable=True))(*literal_eval(x)), - lambda X: str((X.edges(labels=False, sort=True), X.num_verts())), + lambda X: str((X.edges(labels=False, sort=True), X.n_vertices())), lambda x: (g.copy(immutable=True) for g in graphs(x, copy=False)), - lambda x: x.num_verts(), + lambda x: x.n_vertices(), lambda x: isinstance(x, Graph)), "IntegerPartitions": _SupportedFindStatCollection(lambda x: Partition(literal_eval(x)), diff --git a/src/sage/geometry/hyperplane_arrangement/library.py b/src/sage/geometry/hyperplane_arrangement/library.py index 2019cf4d363..a1c62e28c96 100644 --- a/src/sage/geometry/hyperplane_arrangement/library.py +++ b/src/sage/geometry/hyperplane_arrangement/library.py @@ -152,7 +152,7 @@ def bigraphical(self, G, A=None, K=QQ, names=None): ....: 'generic').n_regions() == 65 for _ in range(5)) True """ - n = G.num_verts() + n = G.n_vertices() if A is None: # default to G-semiorder arrangement A = matrix(K, n, lambda i, j: 1) elif A == 'generic': @@ -355,7 +355,7 @@ def G_semiorder(self, G, K=QQ, names=None): sage: hyperplane_arrangements.G_semiorder(g) Arrangement of 12 hyperplanes of dimension 5 and rank 4 """ - n = G.num_verts() + n = G.n_vertices() H = make_parent(K, n, names) x = H.gens() hyperplanes = [] @@ -394,7 +394,7 @@ def G_Shi(self, G, K=QQ, names=None): sage: a = hyperplane_arrangements.G_Shi(graphs.WheelGraph(4)); a Arrangement of 12 hyperplanes of dimension 4 and rank 3 """ - n = G.num_verts() + n = G.n_vertices() H = make_parent(K, n, names) x = H.gens() hyperplanes = [] @@ -445,7 +445,7 @@ def graphical(self, G, K=QQ, names=None): sage: h.characteristic_polynomial() # long time x^5 - 6*x^4 + 14*x^3 - 15*x^2 + 6*x """ - n = G.num_verts() + n = G.n_vertices() H = make_parent(K, n, names) x = H.gens() hyperplanes = [] diff --git a/src/sage/graphs/base/boost_graph.pyx b/src/sage/graphs/base/boost_graph.pyx index 41a41a2eaac..2ee2e5de86a 100644 --- a/src/sage/graphs/base/boost_graph.pyx +++ b/src/sage/graphs/base/boost_graph.pyx @@ -80,7 +80,7 @@ cdef boost_graph_from_sage_graph(BoostGenGraph *g, g_sage, vertex_to_int, revers if g.num_verts(): raise AssertionError("the given Boost graph must be empty") - cdef int N = g_sage.num_verts() + cdef int N = g_sage.n_vertices() cdef int i for i in range(N): @@ -136,7 +136,7 @@ cdef boost_weighted_graph_from_sage_graph(BoostWeightedGraph *g, if g.num_verts(): raise AssertionError("the given Boost graph must be empty") - cdef int N = g_sage.num_verts() + cdef int N = g_sage.n_vertices() cdef int i for i in range(N): @@ -1548,7 +1548,7 @@ cpdef min_cycle_basis(g_sage, weight_function=None, by_weight=False): """ cdef Py_ssize_t u_int, v_int, i, j cdef object u, v - cdef Py_ssize_t n = g_sage.num_verts() + cdef Py_ssize_t n = g_sage.n_vertices() cdef list int_to_vertex = list(g_sage) cdef dict vertex_to_int = {u: u_int for u_int, u in enumerate(int_to_vertex)} cdef list edgelist diff --git a/src/sage/graphs/base/static_sparse_graph.pyx b/src/sage/graphs/base/static_sparse_graph.pyx index 53b0ccc7a25..6ce11fa4d8d 100644 --- a/src/sage/graphs/base/static_sparse_graph.pyx +++ b/src/sage/graphs/base/static_sparse_graph.pyx @@ -1250,8 +1250,8 @@ def spectral_radius(G, prec=1e-10): cdef double e_min, e_max - if G.num_verts() == 1: - e_min = e_max = G.num_edges() + if G.n_vertices() == 1: + e_min = e_max = G.n_edges() return (e_min, e_max) is_bipartite, colors = G.is_bipartite(certificate=True) diff --git a/src/sage/graphs/bipartite_graph.py b/src/sage/graphs/bipartite_graph.py index 1e7021e4a96..13aaa5f1a49 100644 --- a/src/sage/graphs/bipartite_graph.py +++ b/src/sage/graphs/bipartite_graph.py @@ -460,7 +460,7 @@ def __init__(self, data=None, partition=None, check=True, hash_labels=None, *arg # Some error checking. if left & right: raise ValueError("the parts are not disjoint") - if len(left) + len(right) != self.num_verts(): + if len(left) + len(right) != self.n_vertices(): raise ValueError("not all vertices appear in partition") if check: @@ -523,7 +523,7 @@ def edges(): # Some error checking. if left & right: raise ValueError("the parts are not disjoint") - if len(left) + len(right) != self.num_verts(): + if len(left) + len(right) != self.n_vertices(): raise ValueError("not all vertices appear in partition") if isinstance(data, (networkx_MultiGraph, networkx_Graph)): diff --git a/src/sage/graphs/chrompoly.pyx b/src/sage/graphs/chrompoly.pyx index 35327903e5f..9037beee8a0 100644 --- a/src/sage/graphs/chrompoly.pyx +++ b/src/sage/graphs/chrompoly.pyx @@ -162,7 +162,7 @@ def chromatic_polynomial(G, return_tree_basis=False, algorithm='C', cache=None): return R.prod(chromatic_polynomial(g, algorithm='C') for g in G.connected_components_subgraphs()) x = R.gen() if G.is_tree(): - return x * (x - 1) ** (G.num_verts() - 1) + return x * (x - 1) ** (G.n_vertices() - 1) cdef int nverts, nedges, i, j, u, v, top, bot, num_chords, next_v cdef int *queue @@ -175,8 +175,8 @@ def chromatic_polynomial(G, return_tree_basis=False, algorithm='C', cache=None): cdef mpz_t *coeffs G = G.relabel(inplace=False, immutable=False) G.remove_multiple_edges() - nverts = G.num_verts() - nedges = G.num_edges() + nverts = G.n_vertices() + nedges = G.n_edges() cdef MemoryAllocator mem = MemoryAllocator() queue = mem.allocarray(nverts, sizeof(int)) diff --git a/src/sage/graphs/connectivity.pyx b/src/sage/graphs/connectivity.pyx index b1f6db2b54f..504246b2adc 100644 --- a/src/sage/graphs/connectivity.pyx +++ b/src/sage/graphs/connectivity.pyx @@ -154,7 +154,7 @@ def is_connected(G, forbidden_vertices=None): for _ in G.depth_first_search(v, ignore_direction=True, forbidden_vertices=forbidden): n += 1 - return n == G.num_verts() + return n == G.n_vertices() def connected_components(G, sort=False, key=None, forbidden_vertices=None): @@ -1576,7 +1576,7 @@ def edge_connectivity(G, raise ValueError("the Boost implementation is currently not able to handle edge labels") # Otherwise, an error is created - if not g.num_edges() or not g.num_verts(): + if not g.n_edges() or not g.n_vertices(): if value_only: return 0 elif vertices: diff --git a/src/sage/graphs/digraph.py b/src/sage/graphs/digraph.py index 4c7899a6e2a..9015353ac5a 100644 --- a/src/sage/graphs/digraph.py +++ b/src/sage/graphs/digraph.py @@ -2389,7 +2389,7 @@ def eccentricity(self, v=None, by_weight=False, algorithm=None, weight_function=weight_function, check_weight=False) - if len(length) != self.num_verts(): + if len(length) != self.n_vertices(): ecc[u] = Infinity else: ecc[u] = max(length.values()) @@ -3478,7 +3478,7 @@ def _girth_bfs(self, odd=False, certificate=False): * :meth:`~sage.graphs.GenericGraph.odd_girth` -- return the odd girth of the graph """ - n = self.num_verts() + n = self.n_vertices() best = n + 1 seen = set() for w in self: diff --git a/src/sage/graphs/generators/random.py b/src/sage/graphs/generators/random.py index 897724e9794..93c4b4cb270 100644 --- a/src/sage/graphs/generators/random.py +++ b/src/sage/graphs/generators/random.py @@ -2170,8 +2170,8 @@ def RandomTriangulation(n, set_position=False, k=3, seed=None): graph.add_edges(edges) graph.set_embedding(embedding) graph.relabel({0: -2, 1: -1}) - assert graph.num_edges() == 3*n - 3 - k - assert graph.num_verts() == n + assert graph.n_edges() == 3*n - 3 - k + assert graph.n_vertices() == n if set_position: graph.layout(layout='planar', save_pos=True) return graph diff --git a/src/sage/graphs/generic_graph.py b/src/sage/graphs/generic_graph.py index c939e3fc7ab..7dd93a41cef 100644 --- a/src/sage/graphs/generic_graph.py +++ b/src/sage/graphs/generic_graph.py @@ -2026,7 +2026,7 @@ def igraph_graph(self, vertex_list=None, vertex_attrs={}, edge_attrs={}): igraph_feature().require() import igraph - return igraph.Graph(n=self.num_verts(), + return igraph.Graph(n=self.n_vertices(), edges=edges, directed=self.is_directed(), vertex_attrs=vertex_attrs, @@ -2713,7 +2713,7 @@ def reorder(u, v): if base_ring is None: base_ring = ZZ immutable = kwds.pop('immutable', False) - m = matrix(base_ring, self.num_verts(), self.num_edges(), sparse=sparse, **kwds) + m = matrix(base_ring, self.n_vertices(), self.n_edges(), sparse=sparse, **kwds) if oriented: for i, e in enumerate(edges): @@ -3030,9 +3030,9 @@ def func(u, v, label): from sage.matrix.constructor import matrix if base_ring is None: - M = matrix(self.num_verts(), D, sparse=sparse, **kwds) + M = matrix(self.n_vertices(), D, sparse=sparse, **kwds) else: - M = matrix(base_ring, self.num_verts(), D, sparse=sparse, **kwds) + M = matrix(base_ring, self.n_vertices(), D, sparse=sparse, **kwds) return M def kirchhoff_matrix(self, weighted=None, indegree=True, normalized=False, signless=False, **kwds): @@ -4819,7 +4819,7 @@ def order(self): 4 """ - return self._backend.num_verts() + return self._backend.n_vertices() __len__ = order @@ -4840,7 +4840,7 @@ def size(self): 15 """ - return self._backend.num_edges(self._directed) + return self._backend.n_edges(self._directed) num_edges = size @@ -7077,7 +7077,7 @@ def n_faces(self, embedding=None): F = 1 for g in self.connected_components_subgraphs(): emb = None if embedding is None else {v: embedding[v] for v in g} - F += g.num_faces(emb) - 1 + F += g.n_faces(emb) - 1 return F num_faces = n_faces @@ -15252,7 +15252,7 @@ def subgraph_decompositions(self, H, induced=False): multiedges using allow_multiple_edges(). """ # number of edges of H must divide the number of edges of self - if self.num_edges() % H.num_edges(): + if self.n_edges() % H.n_edges(): return from sage.combinat.matrices.dancing_links import dlx_solver @@ -16244,7 +16244,7 @@ def is_subgraph(self, other, induced=True, up_to_isomorphism=False): if isinstance(self, DiGraph) and not isinstance(other, DiGraph): raise ValueError('the input parameter must be a DiGraph') - if self.num_verts() > other.num_verts() or self.num_edges() > other.num_edges(): + if self.n_vertices() > other.n_vertices() or self.n_edges() > other.n_edges(): return False if up_to_isomorphism: @@ -17075,7 +17075,7 @@ def _girth_bfs(self, odd=False, certificate=False): * :meth:`~GenericGraph.girth` -- return the girth of the graph. * :meth:`~GenericGraph.odd_girth` -- return the odd girth of the graph. """ - n = self.num_verts() + n = self.n_vertices() best = n + 1 seen = set() for w in self: @@ -17509,7 +17509,7 @@ def centrality_closeness(self, vert=None, by_weight=False, algorithm=None, else: distv = distances[v] try: - closeness[v] = float(len(distv) - 1) * (len(distv) - 1) / (float(sum(distv.values())) * (self.num_verts() - 1)) + closeness[v] = float(len(distv) - 1) * (len(distv) - 1) / (float(sum(distv.values())) * (self.n_vertices() - 1)) except ZeroDivisionError: pass if onlyone: @@ -18513,7 +18513,7 @@ def shortest_path_lengths(self, u, by_weight=False, algorithm=None, elif algorithm == 'Dijkstra_NetworkX': import networkx # If this is not present, an error might be raised by NetworkX - if self.num_verts() == 1 and next(self.vertex_iterator()) == u: + if self.n_vertices() == 1 and next(self.vertex_iterator()) == u: return {u: [u]} if by_weight: if self.is_directed(): @@ -21706,7 +21706,7 @@ def layout_tree(self, tree_orientation='down', tree_root=None, # obstruction[y] is the smallest value of x to which a vertex at height # y can be assigned. All vertices at height y which have already been # assigned are on the left of (x-1,y). - obstruction = [0.0] * self.num_verts() + obstruction = [0.0] * self.n_vertices() if tree_orientation in ['down', 'left']: o = -1 @@ -22244,7 +22244,7 @@ def _rich_repr_(self, display_manager, **kwds): sage: dm.preferences.supplemental_plot = 'never' """ prefs = display_manager.preferences - is_small = (0 < self.num_verts() < 20) + is_small = (0 < self.n_vertices() < 20) can_plot = (prefs.supplemental_plot != 'never') plot_graph = can_plot and (prefs.supplemental_plot == 'always' or is_small) # Under certain circumstances we display the plot as graphics @@ -24967,7 +24967,7 @@ def automorphism_group(self, partition=None, verbosity=0, if orbits: G_from = {G_to[v]: v for v in G_to} from sage.groups.perm_gps.partn_ref.refinement_graphs import get_orbits - output.append([[G_from[v] for v in W] for W in get_orbits(a, self.num_verts())]) + output.append([[G_from[v] for v in W] for W in get_orbits(a, self.n_vertices())]) if len(output) == 1: return output[0] @@ -26339,7 +26339,7 @@ def edge_polytope(self, backend=None): """ from sage.matrix.special import identity_matrix from sage.geometry.polyhedron.parent import Polyhedra - dim = self.num_verts() + dim = self.n_vertices() e = identity_matrix(dim).rows() dic = {v: e[i] for i, v in enumerate(self)} vertices = ((dic[i] + dic[j]) for i, j in self.edge_iterator(sort_vertices=False, labels=False)) @@ -26470,7 +26470,7 @@ def symmetric_edge_polytope(self, backend=None): from itertools import chain from sage.matrix.special import identity_matrix from sage.geometry.polyhedron.parent import Polyhedra - dim = self.num_verts() + dim = self.n_vertices() e = identity_matrix(dim).rows() dic = {v: e[i] for i, v in enumerate(self)} vertices = chain(((dic[i] - dic[j]) for i, j in self.edge_iterator(sort_vertices=False, labels=False)), diff --git a/src/sage/graphs/genus.pyx b/src/sage/graphs/genus.pyx index 2f6b79bae83..e387228b603 100644 --- a/src/sage/graphs/genus.pyx +++ b/src/sage/graphs/genus.pyx @@ -608,7 +608,7 @@ def simple_connected_graph_genus(G, set_embedding=False, check=True, minimal=Tru cutoff = 1 else: style = 2 - cutoff = 1 + (G.num_edges() - G.num_verts()) / 2 # rounding here is ok + cutoff = 1 + (G.n_edges() - G.n_vertices()) / 2 # rounding here is ok g = GG.genus(style=style, cutoff=cutoff, record_embedding=set_embedding) if set_embedding: diff --git a/src/sage/graphs/graph.py b/src/sage/graphs/graph.py index d44c9f6aa31..2386980da60 100644 --- a/src/sage/graphs/graph.py +++ b/src/sage/graphs/graph.py @@ -2228,9 +2228,9 @@ def is_overfull(self): True """ # # A possible optimized version. But the gain in speed is very little. - # return bool(self._backend.num_verts() & 1) and ( # odd order n - # 2 * self._backend.num_edges(self._directed) > #2m > \Delta(G)*(n-1) - # max(self.degree()) * (self._backend.num_verts() - 1)) + # return bool(self._backend.n_vertices() & 1) and ( # odd order n + # 2 * self._backend.n_edges(self._directed) > #2m > \Delta(G)*(n-1) + # max(self.degree()) * (self._backend.n_vertices() - 1)) # unoptimized version return (self.order() % 2 == 1) and ( 2 * self.size() > max(self.degree()) * (self.order() - 1)) @@ -4943,7 +4943,7 @@ def eccentricity(self, v=None, by_weight=False, algorithm=None, weight_function=weight_function, check_weight=check_weight) - if len(length) != self.num_verts(): + if len(length) != self.n_vertices(): ecc[u] = Infinity else: ecc[u] = max(length.values()) @@ -9164,7 +9164,7 @@ def most_common_neighbors(self, nonedgesonly=True): [(0, 2), (1, 3)] """ self._scream_if_not_simple() - if self.num_verts() < 2: + if self.n_vertices() < 2: raise ValueError('this method is defined for graphs with at least 2 vertices') verts = list(self) M = self.common_neighbors_matrix(vertices=verts, nonedgesonly=nonedgesonly) @@ -9172,8 +9172,8 @@ def most_common_neighbors(self, nonedgesonly=True): coefficients = M.coefficients() if coefficients: maximum = max(coefficients) - for v in range(self.num_verts()): - for w in range(v + 1, self.num_verts()): + for v in range(self.n_vertices()): + for w in range(v + 1, self.n_vertices()): if M[v, w] == maximum: output.append((verts[v], verts[w])) return output @@ -9591,14 +9591,14 @@ def is_projective_planar(self, return_map=False): """ from sage.graphs.generators.families import p2_forbidden_minors - num_verts_G = self.num_verts() - num_edges_G = self.num_edges() + num_verts_G = self.n_vertices() + num_edges_G = self.n_edges() for forbidden_minor in p2_forbidden_minors(): # Can't be a minor if it has more vertices or edges than G - if (forbidden_minor.num_verts() > num_verts_G - or forbidden_minor.num_edges() > num_edges_G): + if (forbidden_minor.n_vertices() > num_verts_G + or forbidden_minor.n_edges() > num_edges_G): continue try: diff --git a/src/sage/graphs/graph_generators.py b/src/sage/graphs/graph_generators.py index 0152e545eb0..51a0b222343 100644 --- a/src/sage/graphs/graph_generators.py +++ b/src/sage/graphs/graph_generators.py @@ -846,11 +846,11 @@ def extra_property(x): return degree_sequence == sorted(x.degree()) else: def property(x): - D = sorted(x.degree() + [0] * (vertices - x.num_verts())) + D = sorted(x.degree() + [0] * (vertices - x.n_vertices())) return all(degree_sequence[i] >= d for i, d in enumerate(D)) def extra_property(x): - if x.num_verts() != vertices: + if x.n_vertices() != vertices: return False return degree_sequence == sorted(x.degree()) elif size is not None: diff --git a/src/sage/graphs/graph_plot.py b/src/sage/graphs/graph_plot.py index 1c340dbddf3..93ad73cd557 100644 --- a/src/sage/graphs/graph_plot.py +++ b/src/sage/graphs/graph_plot.py @@ -1697,7 +1697,7 @@ def layout_tree(self, root, orientation): stick = [root] parent = {u: root for u in children[root]} pos = {} - obstruction = [0.0] * T.num_verts() + obstruction = [0.0] * T.n_vertices() if orientation == 'down': o = -1 else: diff --git a/src/sage/graphs/hyperbolicity.pyx b/src/sage/graphs/hyperbolicity.pyx index c50055848b3..aff441d82e4 100644 --- a/src/sage/graphs/hyperbolicity.pyx +++ b/src/sage/graphs/hyperbolicity.pyx @@ -1308,13 +1308,12 @@ def hyperbolicity(G, # The hyperbolicity of some classes of graphs is known. If it is easy and # fast to test that a graph belongs to one of these classes, we do it. - if G.num_verts() <= 3: + if G.n_vertices() <= 3: # The hyperbolicity of a graph with 3 vertices is 0. # The certificate is the set of vertices. return 0, list(G), 0 - elif G.num_verts() == G.num_edges() + 1: - # G is a tree + elif G.is_tree(): # Any set of 4 vertices is a valid certificate return 0, list(G)[:4], 0 @@ -1326,7 +1325,7 @@ def hyperbolicity(G, cdef list certificate = [] cdef list certif - cdef int N = G.num_verts() + cdef int N = G.n_vertices() hyp = 0 hyp_UB = 0 @@ -1666,10 +1665,10 @@ def hyperbolicity_distribution(G, algorithm='sampling', sampling_size=10**6): # The hyperbolicity distribution of some classes of graphs is known. If it # is easy and fast to test that a graph belongs to one of these classes, we # do it. - if (G.num_verts() == G.num_edges() + 1) or G.is_clique(): - return {0: sampling_size if algorithm=='sampling' else binomial(G.num_verts(), 4)} + if G.is_tree() or G.is_clique(): + return {0: sampling_size if algorithm=='sampling' else binomial(G.n_vertices(), 4)} - cdef int N = G.num_verts() + cdef int N = G.n_vertices() cdef int i cdef unsigned short** distances cdef unsigned short* _distances_ diff --git a/src/sage/graphs/isoperimetric_inequalities.pyx b/src/sage/graphs/isoperimetric_inequalities.pyx index 0b6a3f792bc..b3ad32c7798 100644 --- a/src/sage/graphs/isoperimetric_inequalities.pyx +++ b/src/sage/graphs/isoperimetric_inequalities.pyx @@ -104,9 +104,9 @@ def cheeger_constant(g): if g.is_directed(): raise ValueError("Cheeger constant is only defined on non-oriented graph") g._scream_if_not_simple() - if g.num_verts() == 0: + if not g.n_vertices(): raise ValueError("Cheeger constant is not defined for the empty graph") - elif g.num_verts() == 1: + elif g.n_vertices() == 1: return Infinity elif not g.is_connected(): return QQ.zero() @@ -257,9 +257,9 @@ def edge_isoperimetric_number(g): if g.is_directed(): raise ValueError("edge isoperimetric number is only defined on non-oriented graph") g._scream_if_not_simple() - if g.num_verts() == 0: + if not g.n_vertices(): raise ValueError("edge-isoperimetric number not defined for the empty graph") - elif g.num_verts() == 1: + elif g.n_vertices() == 1: return Infinity elif not g.is_connected(): return QQ((0, 1)) diff --git a/src/sage/graphs/matchpoly.pyx b/src/sage/graphs/matchpoly.pyx index 3d910869e91..d4d1c1924e2 100644 --- a/src/sage/graphs/matchpoly.pyx +++ b/src/sage/graphs/matchpoly.pyx @@ -224,7 +224,7 @@ def matching_polynomial(G, complement=True, name=None): cdef int i, j, d cdef fmpz_poly_t pol - cdef int nverts = G.num_verts() + cdef int nverts = G.n_vertices() # Using Godsil's duality theorem when the graph is dense @@ -236,7 +236,7 @@ def matching_polynomial(G, complement=True, name=None): f += complete_poly(j) * f_comp[j] * (-1)**i return f - cdef int nedges = G.num_edges() + cdef int nedges = G.n_edges() # Relabelling the vertices of the graph as [0...n-1] so that they are sorted # in increasing order of degree diff --git a/src/sage/graphs/spanning_tree.pyx b/src/sage/graphs/spanning_tree.pyx index 501fe0cd6a0..cd297ed915a 100644 --- a/src/sage/graphs/spanning_tree.pyx +++ b/src/sage/graphs/spanning_tree.pyx @@ -336,8 +336,7 @@ def kruskal_iterator(G, by_weight=True, weight_function=None, check_weight=False if not G.is_connected(): return # G is now assumed to be a nonempty connected graph - if G.num_verts() == G.num_edges() + 1: - # G is a tree + if G.is_tree(): yield from G.edge_iterator() return @@ -827,8 +826,7 @@ def boruvka(G, by_weight=True, weight_function=None, check_weight=True, check=Fa if not G.is_connected(): return [] # G is now assumed to be a nonempty connected graph - if G.num_verts() == G.num_edges() + 1: - # G is a tree + if G.is_tree(): return G.edges(sort=False) by_weight, weight_function = G._get_weight_function(by_weight=by_weight, diff --git a/src/sage/graphs/strongly_regular_db.pyx b/src/sage/graphs/strongly_regular_db.pyx index b60a73b30e4..9ce3afdca6f 100644 --- a/src/sage/graphs/strongly_regular_db.pyx +++ b/src/sage/graphs/strongly_regular_db.pyx @@ -2500,7 +2500,7 @@ def strongly_regular_from_two_intersection_set(M): for qq in K if not qq == K.zero()]) g.relabel() e = QQ((1,k)) - qq = g.num_verts()**e + qq = g.n_vertices()**e g.name('two-intersection set in PG('+str(k)+','+str(qq)+')') return g diff --git a/src/sage/graphs/tutte_polynomial.py b/src/sage/graphs/tutte_polynomial.py index b44cc50a580..6a2d16de58d 100644 --- a/src/sage/graphs/tutte_polynomial.py +++ b/src/sage/graphs/tutte_polynomial.py @@ -584,7 +584,7 @@ def tutte_polynomial(G, edge_selector=None, cache=None): 52 """ R = ZZ['x, y'] - if G.num_edges() == 0: + if not G.n_edges(): return R.one() G = G.relabel(inplace=False, immutable=False) # making sure the vertices are integers @@ -615,7 +615,7 @@ def _tutte_polynomial_internal(G, x, y, edge_selector, cache=None): sage: P.tutte_polynomial() # indirect doctest x^4 + x^3 + x^2 + x + y """ - if not G.num_edges(): + if not G.n_edges(): return x.parent().one() def recursive_tp(graph=None): @@ -667,7 +667,7 @@ def yy(start, end): # instead of n (allowing for the last part of the recursion). # Additionally, the first operand of the final product should be # (x+y^{1...(d_n+d_{n-1}-1)}) instead of just (x+y^(d_n+d_{n-1}-1) - if uG.num_verts() == uG.num_edges(): # G is a multi-cycle + if uG.n_vertices() == uG.n_edges(): # G is a multi-cycle n = len(d) result = 0 for i in range(n - 2): diff --git a/src/sage/groups/perm_gps/partn_ref/refinement_graphs.pyx b/src/sage/groups/perm_gps/partn_ref/refinement_graphs.pyx index 8de59911bfa..9fb067784ba 100644 --- a/src/sage/groups/perm_gps/partn_ref/refinement_graphs.pyx +++ b/src/sage/groups/perm_gps/partn_ref/refinement_graphs.pyx @@ -84,8 +84,8 @@ def isomorphic(G1, G2, partn, ordering2, dig, use_indicator_function, sparse=Fal if G_in.has_loops(): loops = 1 if n == -1: - n = G_in.num_verts() - elif n != G_in.num_verts(): + n = G_in.n_vertices() + elif n != G_in.n_vertices(): return False if G_in.vertices(sort=True) != list(range(n)): G_in = copy(G_in) @@ -390,7 +390,7 @@ def search_tree(G_in, partition, lab=True, dig=False, dict_rep=False, certificat from copy import copy if isinstance(G_in, GenericGraph): loops = G_in.has_loops() - n = G_in.num_verts() + n = G_in.n_vertices() if G_in.vertices(sort=False) != list(range(n)): G_in = copy(G_in) to = G_in.relabel(return_map=True) @@ -1594,7 +1594,7 @@ def generate_dense_graphs_vert_addition(int n, base_G=None, return Integer(1) return Integer(2) - cdef int start_deg = 1 if base_G is None else base_G.num_verts() + cdef int start_deg = 1 if base_G is None else base_G.n_vertices() graph_iterator = allocate_dg_vert_gen(start_deg, n+1-start_deg) if graph_iterator is NULL: raise MemoryError diff --git a/src/sage/groups/raag.py b/src/sage/groups/raag.py index 4313f500319..c40ec8ddebc 100644 --- a/src/sage/groups/raag.py +++ b/src/sage/groups/raag.py @@ -162,7 +162,7 @@ def __classcall_private__(cls, G, names=None): G = Graph(G, immutable=True) else: G = G.copy(immutable=True) - if G.num_verts() == 0: + if not G.n_vertices(): raise ValueError("the graph must not be empty") if names is None: names = 'v' @@ -172,7 +172,7 @@ def __classcall_private__(cls, G, names=None): else: names = [names + str(v) for v in G.vertices(sort=False)] names = tuple(names) - if len(names) != G.num_verts(): + if len(names) != G.n_vertices(): raise ValueError("the number of generators must match the" " number of vertices of the defining graph") return super().__classcall__(cls, G, names) @@ -192,8 +192,8 @@ def __init__(self, G, names): F = FreeGroup(names=names) CG = Graph(G).complement() # Make sure it's mutable CG.relabel() # Standardize the labels - cm = [[-1] * CG.num_verts() for _ in range(CG.num_verts())] - for i in range(CG.num_verts()): + cm = [[-1] * CG.n_vertices() for _ in range(CG.n_vertices())] + for i in range(CG.n_vertices()): cm[i][i] = 1 for u, v in CG.edge_iterator(labels=False): cm[u][v] = 2 @@ -243,7 +243,7 @@ def gens(self) -> tuple: sage: G.gens() (vx, vy, vzeta) """ - return tuple(self.gen(i) for i in range(self._graph.num_verts())) + return tuple(self.gen(i) for i in range(self._graph.n_vertices())) def ngens(self): """ @@ -256,7 +256,7 @@ def ngens(self): sage: G.ngens() 5 """ - return self._graph.num_verts() + return self._graph.n_vertices() def graph(self): """ @@ -843,7 +843,7 @@ def ngens(self): sage: H.ngens() 4 """ - return self._group._graph.num_verts() + return self._group._graph.n_vertices() def degree_on_basis(self, I): """ diff --git a/src/sage/matroids/constructor.py b/src/sage/matroids/constructor.py index f1c0af7bea7..a12d929637c 100644 --- a/src/sage/matroids/constructor.py +++ b/src/sage/matroids/constructor.py @@ -908,7 +908,7 @@ def Matroid(groundset=None, data=None, **kwds): else: G = Graph(data) # Decide on the groundset - m = G.num_edges() + m = G.n_edges() if groundset is None: # 1. Attempt to use edge labels. sl = G.edge_labels() @@ -926,7 +926,7 @@ def Matroid(groundset=None, data=None, **kwds): # 1) we would need to fix the loops anyway # 2) Sage will sort the columns, making it impossible to keep labels! V = G.vertices(sort=True) - n = G.num_verts() + n = G.n_vertices() A = matrix(ZZ, n, m, 0) mm = 0 for i, j, k in G.edge_iterator(): diff --git a/src/sage/matroids/graphic_matroid.pyx b/src/sage/matroids/graphic_matroid.pyx index 6cb8505220f..8255e5c29de 100644 --- a/src/sage/matroids/graphic_matroid.pyx +++ b/src/sage/matroids/graphic_matroid.pyx @@ -186,8 +186,8 @@ cdef class GraphicMatroid(Matroid): # if the provided groundset is incomplete, it gets overwritten # invalidate ``None`` as label - if None in groundset_set or len(groundset_set) != G.num_edges(): - groundset = range(G.num_edges()) + if None in groundset_set or len(groundset_set) != G.n_edges(): + groundset = range(G.n_edges()) groundset_set = frozenset(groundset) self._groundset = groundset_set diff --git a/src/sage/quivers/ar_quiver.py b/src/sage/quivers/ar_quiver.py index 8e58c72a5d5..fd5d035f2ad 100644 --- a/src/sage/quivers/ar_quiver.py +++ b/src/sage/quivers/ar_quiver.py @@ -894,7 +894,7 @@ def detect_dynkin_quiver(quiver): return None G = Q.to_undirected() if G.is_path(): - dynkin_type.append(['A', Q.num_verts()]) + dynkin_type.append(['A', Q.n_vertices()]) continue degthree = G.vertices(degree=3) if len(degthree) != 1: @@ -905,9 +905,9 @@ def detect_dynkin_quiver(quiver): if len(path_lengths) != 3: return None if path_lengths[:2] == [1, 1]: - dynkin_type.append(['D', G.num_verts() + 1]) + dynkin_type.append(['D', G.n_vertices() + 1]) elif path_lengths[:2] == [1, 2] and path_lengths[2] in [2, 3, 4]: - dynkin_type.append(['E', G.num_verts() + 1]) + dynkin_type.append(['E', G.n_vertices() + 1]) else: return None if len(dynkin_type) == 1: diff --git a/src/sage/quivers/path_semigroup.py b/src/sage/quivers/path_semigroup.py index a417f3bb58e..06c5171c602 100644 --- a/src/sage/quivers/path_semigroup.py +++ b/src/sage/quivers/path_semigroup.py @@ -186,7 +186,7 @@ def __init__(self, Q): names = ['e_{0}'.format(v) for v in Q.vertex_iterator()] names += list(self._labels) self._quiver = Q - if Q.num_verts() == 1: + if Q.n_vertices() == 1: cat = cat.join([cat, Monoids()]) else: cat = cat.join([cat, Semigroups()]) @@ -205,7 +205,7 @@ def _repr_(self): sage: Q.path_semigroup() Monoid formed by the directed paths of Looped multi-digraph on 1 vertex """ - if self._quiver.num_verts() != 1: + if self._quiver.n_vertices() != 1: return "Partial semigroup formed by the directed paths of {}".format(self._quiver) return "Monoid formed by the directed paths of {}".format(self._quiver) @@ -261,7 +261,7 @@ def _coerce_map_from_(self, other): # internally, directly using the backend to make things faster. sQ = self._quiver._backend oQ = other.quiver()._backend - if sQ.num_verts() < oQ.num_verts(): + if sQ.n_vertices() < oQ.n_vertices(): return False if any(not sQ.has_vertex(v) for v in oQ.iterator_verts(None)): return False @@ -437,7 +437,7 @@ def ngens(self): 7 """ Q = self._quiver - return Q.num_verts() + Q.num_edges() + return Q.n_vertices() + Q.n_edges() @cached_method def gen(self, i): diff --git a/src/sage/sandpiles/sandpile.py b/src/sage/sandpiles/sandpile.py index aa8a1a7ce2b..37182a3a46e 100644 --- a/src/sage/sandpiles/sandpile.py +++ b/src/sage/sandpiles/sandpile.py @@ -642,7 +642,7 @@ def __init__(self, g, sink=None): del self._nonsink_vertices[self._sink_ind] # compute Laplacians: self._laplacian = self.laplacian_matrix(indegree=False) - temp = list(range(self.num_verts())) + temp = list(range(self.n_vertices())) del temp[self._sink_ind] self._reduced_laplacian = self._laplacian[temp, temp] @@ -780,7 +780,7 @@ def _repr_(self) -> str: sage: repr(Sandpile({0:[1,1], 1:[0]})) 'sandpile graph: 2 vertices, sink = 0' """ - return self._name + ': ' + str(self.num_verts()) + ' vertices, sink = ' + str(self.sink()) + return self._name + ': ' + str(self.n_vertices()) + ' vertices, sink = ' + str(self.sink()) def show(self, **kwds): r""" @@ -1228,7 +1228,7 @@ def all_k_config(self, k): sage: s.all_k_config(7) {1: 7, 2: 7, 3: 7} """ - return SandpileConfig(self, [k] * (self.num_verts() - 1)) + return SandpileConfig(self, [k] * (self.n_vertices() - 1)) def zero_config(self): r""" @@ -1312,11 +1312,11 @@ def _set_recurrents(self): True """ if self.name() == 'Complete sandpile graph': - n = self.num_verts() + n = self.n_vertices() self._recurrents = [SandpileConfig(self, [n - 1 - i for i in p]) for p in ParkingFunctions(n - 1)] elif self.name() == 'Cycle sandpile graph': - n = self.num_verts() + n = self.n_vertices() one = [1] * (n - 2) self._recurrents = [SandpileConfig(self, [1] * (n - 1))] + [SandpileConfig(self, one[:i] + [0] + one[i:]) for i in range(n - 1)] else: @@ -1502,7 +1502,7 @@ def genus(self): 1 """ if self.is_undirected(): - return self.laplacian().trace() / 2 - self.num_verts() + 1 + return self.laplacian().trace() / 2 - self.n_vertices() + 1 raise TypeError("the underlying graph must be undirected") def is_undirected(self): @@ -1647,7 +1647,7 @@ def _set_avalanche_polynomial(self): sage: '_avalanche_polynomial' in s.__dict__ # needs sage.combinat True """ - n = self.num_verts() - 1 + n = self.n_vertices() - 1 R = PolynomialRing(QQ, "x", n) A = R(0) V = [] @@ -1697,7 +1697,7 @@ def avalanche_polynomial(self, multivariable=True): return deepcopy(self._avalanche_polynomial) X = self._avalanche_polynomial.parent().gens() return self._avalanche_polynomial.subs({X[i]: X[0] - for i in range(1, self.num_verts() - 1)}) + for i in range(1, self.n_vertices() - 1)}) def nonspecial_divisors(self, verbose=True) -> list: r""" @@ -1768,7 +1768,7 @@ def canonical_divisor(self): """ if self.is_undirected(): return SandpileDivisor(self, [self.laplacian()[i][i] - 2 - for i in range(self.num_verts())]) + for i in range(self.n_vertices())]) raise TypeError("only for undirected graphs") def _set_invariant_factors(self): @@ -2195,9 +2195,9 @@ def markov_chain(self, state, distrib=None): V = self.vertices(sort=True) n = len(V) if isinstance(st, list): - if len(st) == self.num_verts() - 1: + if len(st) == self.n_vertices() - 1: st = SandpileConfig(self, st) - elif len(st) == self.num_verts(): + elif len(st) == self.n_vertices(): st = SandpileDivisor(self, st) else: raise SyntaxError(state) @@ -2239,7 +2239,7 @@ def _set_stationary_density(self): True """ if self.name() == 'Complete sandpile graph': - n = Integer(self.num_verts()) + n = Integer(self.n_vertices()) self._stationary_density = (n + QQ.one() / n + sum(falling_factorial(n, i) / n**i for i in range(1, n + 1)) - 3) / 2 elif self.is_undirected() and '_h_vector' not in self.__dict__: t = Graph(self).tutte_polynomial().subs(x=1) @@ -2248,13 +2248,13 @@ def _set_stationary_density(self): t = myR(t) dt = derivative(t, y).subs(y=1) t = t.subs(y=1) - self._stationary_density = (self.num_edges()/2 + dt/t)/self.num_verts() + self._stationary_density = (self.n_edges()/2 + dt/t)/self.n_vertices() else: sink_deg = self.out_degree(self.sink()) h = vector(ZZ, self.h_vector()) m = self.max_stable().deg() d = vector(ZZ, range(m, m-len(h), -1)) - self._stationary_density = (h*d/self.group_order() + sink_deg)/self.num_verts() + self._stationary_density = (h*d/self.group_order() + sink_deg)/self.n_vertices() def stationary_density(self): r""" @@ -2303,7 +2303,7 @@ def all_k_div(self, k): sage: S.all_k_div(7) {0: 7, 1: 7, 2: 7, 3: 7, 4: 7} """ - return SandpileDivisor(self, [k]*self.num_verts()) + return SandpileDivisor(self, [k]*self.n_vertices()) def zero_div(self): r""" @@ -2723,7 +2723,7 @@ def _set_points(self): True """ L = self._reduced_laplacian.transpose().dense_matrix() - n = self.num_verts() - 1 + n = self.n_vertices() - 1 D, U, V = L.smith_form() self._points = [] one = [1] * n @@ -2892,7 +2892,7 @@ def __init__(self, S, c): sage: ~(3*c) # stabilization {1: 2, 2: 2, 3: 0} """ - if len(c) == S.num_verts()-1: + if len(c) == S.n_vertices()-1: if isinstance(c, (dict, SandpileConfig)): dict.__init__(self, c) elif isinstance(c, list): @@ -3675,7 +3675,7 @@ def add_random(self, distrib=None): 1 and that its length is equal to the number of sink vertices or the number of nonsink vertices. """ c = deepcopy(self) - n = self._sandpile.num_verts() + n = self._sandpile.n_vertices() if distrib is None: # default = uniform distribution on nonsink vertices distrib = [QQ.one() / (n - 1)] * (n - 1) if len(distrib) == n - 1: # prob. dist. on nonsink vertices @@ -4135,7 +4135,7 @@ def __init__(self, S, D): sage: D.support() [1, 3, 4, 5] """ - if len(D) == S.num_verts(): + if len(D) == S.n_vertices(): if type(D) in [dict, SandpileDivisor, SandpileConfig]: dict.__init__(self, dict(D)) elif isinstance(D, list): @@ -4892,7 +4892,7 @@ def simulate_threshold(self, distrib=None): E = deepcopy(self) S = E.sandpile() V = S.vertices(sort=True) - n = S.num_verts() + n = S.n_vertices() if distrib is None: # default = uniform distribution distrib = [QQ.one() / n] * n X = GeneralDiscreteDistribution(distrib) @@ -4921,7 +4921,7 @@ def _set_linear_system(self): This method requires 4ti2. """ L = self._sandpile._laplacian.transpose() - n = self._sandpile.num_verts() + n = self._sandpile.n_vertices() # temporary file names lin_sys = tmp_filename() @@ -5210,7 +5210,7 @@ def _set_rank(self, set_witness=False): # If undirected and D has high degree, use Riemann-Roch. if S.is_undirected() and not set_witness: # We've been careful about loops - g = sum(S.laplacian().diagonal()) / 2 - S.num_verts() + 1 + g = sum(S.laplacian().diagonal()) / 2 - S.n_vertices() + 1 if self.deg() > 2 * g - 2: self._rank = self.deg() - g return # return early @@ -5218,7 +5218,7 @@ def _set_rank(self, set_witness=False): # the Cori-Le Borgne algorithm if S.name() == 'Complete sandpile graph' and not set_witness: # Cori-LeBorgne algorithm - n = S.num_verts() + n = S.n_vertices() rk = -1 E = self.q_reduced() k = E[S.sink()] @@ -5241,7 +5241,7 @@ def _set_rank(self, set_witness=False): else: rk = -1 while True: - for e in integer_vectors_nk_fast_iter(rk + 1, S.num_verts()): + for e in integer_vectors_nk_fast_iter(rk + 1, S.n_vertices()): E = SandpileDivisor(S, e) if not (self - E).effective_div(): self._rank = rk @@ -5328,7 +5328,7 @@ def _set_r_of_D(self, verbose=False): sage: D._set_r_of_D() # optional - 4ti2 """ eff = self.effective_div() - n = self._sandpile.num_verts() + n = self._sandpile.n_vertices() r = -1 if not eff: self._r_of_D = (r, self) @@ -5682,7 +5682,7 @@ def add_random(self, distrib=None): S = self.sandpile() V = S.vertices(sort=True) if distrib is None: # default = uniform distribution - n = S.num_verts() + n = S.n_vertices() distrib = [QQ.one() / n] * n X = GeneralDiscreteDistribution(distrib) i = X.get_random_element()