Skip to content

Commit 2880f9c

Browse files
author
Release Manager
committed
Trac #22349: Deprecate sorting of Graph vertices and edges by default
Why does `Graph.vertices()` need to ''sort'' the list of vertices? If the user wants a sorted list, they can always call `sorted()` anyway. The same for `Graph.edges()`. Sorting is broken badly now that #22029 is merged. URL: https://trac.sagemath.org/22349 Reported by: jdemeyer Ticket author(s): John Palmieri, David Coudert Reviewer(s): David Coudert, John Palmieri
2 parents cd1e2b1 + fe93716 commit 2880f9c

File tree

172 files changed

+1196
-1156
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

172 files changed

+1196
-1156
lines changed

src/doc/en/prep/Quickstarts/Graphs-and-Discrete.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ Edges can be labeled.
102102
::
103103

104104
sage: L=graphs.CycleGraph(5)
105-
sage: for edge in L.edges():
105+
sage: for edge in L.edges(sort=True):
106106
....: u = edge[0]
107107
....: v = edge[1]
108108
....: L.set_edge_label(u, v, u*v)

src/doc/en/thematic_tutorials/algebraic_combinatorics/walks.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ We begin by creating a graph with 4 vertices::
1515

1616
This graph has no edges yet::
1717

18-
sage: G.vertices()
18+
sage: G.vertices(sort=True)
1919
[0, 1, 2, 3]
20-
sage: G.edges()
20+
sage: G.edges(sort=True)
2121
[]
2222

2323
Before we can add edges, we need to tell Sage that our graph can

src/doc/en/thematic_tutorials/lie/affine_finite_crystals.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ up to a relabeling of the arrows::
356356
sage: G = K.digraph()
357357
sage: Gdual = Kdual.digraph()
358358
sage: f = { 1:1, 0:2, 2:0 }
359-
sage: for u,v,label in Gdual.edges():
359+
sage: for u,v,label in Gdual.edges(sort=False):
360360
....: Gdual.set_edge_label(u,v,f[label])
361361
sage: G.is_isomorphic(Gdual, edge_labels = True)
362362
True

src/doc/en/thematic_tutorials/linear_programming.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ Let us write the Sage code of this MILP::
331331
332332
::
333333

334-
sage: p.set_objective(p.sum(matching[e] for e in g.edges(labels=False)))
334+
sage: p.set_objective(p.sum(matching[e] for e in g.edges(sort=False, labels=False)))
335335

336336
.. link
337337
@@ -417,7 +417,7 @@ graph, in which all the edges have a capacity of 1::
417417
418418
::
419419

420-
sage: for e in g.edges(labels=False):
420+
sage: for e in g.edges(sort=False, labels=False):
421421
....: p.add_constraint(f[e] <= 1)
422422

423423
.. link

src/doc/en/thematic_tutorials/sandpile.rst

+8-8
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ Laplacian.
161161

162162
**Example.** (Continued.) ::
163163

164-
sage: S.vertices() # the ordering of the vertices
164+
sage: S.vertices(sort=True) # the ordering of the vertices
165165
[0, 1, 2, 3]
166166
sage: S.laplacian()
167167
[ 0 0 0 0]
@@ -883,9 +883,9 @@ first presented. This internal format is returned by ``dict()``::
883883
Code for checking whether a given vertex is a sink::
884884

885885
sage: S = Sandpile({0:[], 1:[0, 3, 4], 2:[0, 3, 5], 3: [2, 5], 4: [1, 3], 5: [2, 3]},0)
886-
sage: [S.distance(v,0) for v in S.vertices()] # 0 is a sink
886+
sage: [S.distance(v,0) for v in S.vertices(sort=True)] # 0 is a sink
887887
[0, 1, 1, 2, 2, 2]
888-
sage: [S.distance(v,1) for v in S.vertices()] # 1 is not a sink
888+
sage: [S.distance(v,1) for v in S.vertices(sort=True)] # 1 is not a sink
889889
[+Infinity, 0, +Infinity, +Infinity, 1, +Infinity]
890890

891891
Methods
@@ -4609,7 +4609,7 @@ EXAMPLES::
46094609
sage: D = SandpileDivisor(S, [0,0,1,1])
46104610
sage: D.support()
46114611
[2, 3]
4612-
sage: S.vertices()
4612+
sage: S.vertices(sort=True)
46134613
[0, 1, 2, 3]
46144614

46154615
---
@@ -4654,7 +4654,7 @@ EXAMPLES::
46544654
{'a': 0, 'b': 1, 'c': 2}
46554655
sage: D.values()
46564656
[0, 1, 2]
4657-
sage: S.vertices()
4657+
sage: S.vertices(sort=True)
46584658
['a', 'b', 'c']
46594659

46604660

@@ -4715,9 +4715,9 @@ EXAMPLES::
47154715

47164716
sage: s = sandpiles.Cycle(4)
47174717
sage: D = SandpileDivisor(s,[2,0,0,0])
4718-
sage: [D.weierstrass_gap_seq(v,False) for v in s.vertices()]
4718+
sage: [D.weierstrass_gap_seq(v,False) for v in s.vertices(sort=True)]
47194719
[(1, 3), (1, 2), (1, 3), (1, 2)]
4720-
sage: [D.weierstrass_gap_seq(v) for v in s.vertices()]
4720+
sage: [D.weierstrass_gap_seq(v) for v in s.vertices(sort=True)]
47214721
[((1, 3), 1), ((1, 2), 0), ((1, 3), 1), ((1, 2), 0)]
47224722
sage: D.weierstrass_gap_seq() # gap sequence at sink vertex, 0
47234723
((1, 3), 1)
@@ -4786,7 +4786,7 @@ EXAMPLES::
47864786

47874787
sage: s = sandpiles.House()
47884788
sage: K = s.canonical_divisor()
4789-
sage: [K.weierstrass_rank_seq(v) for v in s.vertices()]
4789+
sage: [K.weierstrass_rank_seq(v) for v in s.vertices(sort=True)]
47904790
[(1, 0, -1), (1, 0, -1), (1, 0, -1), (1, 0, -1), (1, 0, 0, -1)]
47914791

47924792
---

src/sage/categories/category.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2639,7 +2639,7 @@ def category_graph(categories = None):
26392639
EXAMPLES::
26402640
26412641
sage: G = sage.categories.category.category_graph(categories = [Groups()])
2642-
sage: G.vertices()
2642+
sage: G.vertices(sort=True)
26432643
['groups', 'inverse unital magmas', 'magmas', 'monoids', 'objects',
26442644
'semigroups', 'sets', 'sets with partial maps', 'unital magmas']
26452645
sage: G.plot()

src/sage/categories/coxeter_groups.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ def coxeter_diagram(self):
171171
sage: W = CoxeterGroup(['H',3], implementation="reflection")
172172
sage: G = W.coxeter_diagram(); G
173173
Graph on 3 vertices
174-
sage: G.edges()
174+
sage: G.edges(sort=True)
175175
[(1, 2, 3), (2, 3, 5)]
176176
sage: CoxeterGroup(G) is W
177177
True
@@ -1079,7 +1079,7 @@ def bruhat_graph(self, x=None, y=None, edge_labels=False):
10791079
Check that the graph has the correct number of edges
10801080
(see :trac:`17744`)::
10811081
1082-
sage: len(G.edges())
1082+
sage: len(G.edges(sort=False))
10831083
16
10841084
"""
10851085
if x is None or x == 1:
@@ -1682,9 +1682,9 @@ def reduced_word_graph(self):
16821682
16
16831683
sage: G.num_edges()
16841684
18
1685-
sage: len([e for e in G.edges() if e[2] == 2])
1685+
sage: len([e for e in G.edges(sort=False) if e[2] == 2])
16861686
10
1687-
sage: len([e for e in G.edges() if e[2] == 3])
1687+
sage: len([e for e in G.edges(sort=False) if e[2] == 3])
16881688
8
16891689
16901690
TESTS::

src/sage/categories/crystals.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,7 @@ def digraph(self, subset=None, index_set=None):
847847
sage: S = T.subcrystal(max_depth=3)
848848
sage: G = T.digraph(subset=S); G
849849
Digraph on 5 vertices
850-
sage: sorted(G.vertices(), key=str)
850+
sage: G.vertices(sort=True, key=str)
851851
[(-Lambda[0] + 2*Lambda[1] - delta,),
852852
(1/2*Lambda[0] + Lambda[1] - Lambda[2] - 1/2*delta, -1/2*Lambda[0] + Lambda[1] - 1/2*delta),
853853
(1/2*Lambda[0] - Lambda[1] + Lambda[2] - 1/2*delta, -1/2*Lambda[0] + Lambda[1] - 1/2*delta),
@@ -870,7 +870,7 @@ def digraph(self, subset=None, index_set=None):
870870
871871
sage: C = crystals.KirillovReshetikhin(['D',4,1], 2, 1)
872872
sage: G = C.digraph(index_set=[1,3])
873-
sage: len(G.edges())
873+
sage: len(G.edges(sort=False))
874874
20
875875
sage: view(G) # optional - dot2tex graphviz, not tested (opens external window)
876876

src/sage/categories/examples/crystals.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ def e(self, i):
211211
[[1, 1, 0], [2, 1, 1], [3, 1, 2], [5, 1, 3], [4, 2, 0], [5, 2, 4]]
212212
"""
213213
assert i in self.index_set()
214-
for edge in self.parent().G.edges():
214+
for edge in self.parent().G.edges(sort=False):
215215
if edge[1] == int(str(self)) and edge[2] == i:
216216
return self.parent()(edge[0])
217217
return None

src/sage/categories/examples/finite_coxeter_groups.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class DihedralGroup(UniqueRepresentation, Parent):
7070
sage: TestSuite(G).run()
7171
7272
sage: c = FiniteCoxeterGroups().example(3).cayley_graph()
73-
sage: sorted(c.edges())
73+
sage: c.edges(sort=True)
7474
[((), (1,), 1),
7575
((), (2,), 2),
7676
((1,), (), 1),

src/sage/categories/finite_coxeter_groups.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ def weak_poset(self, side="right", facade=False):
431431
sage: W = WeylGroup(["A",2])
432432
sage: P = W.weak_poset(side = "twosided")
433433
sage: P.show()
434-
sage: len(P.hasse_diagram().edges())
434+
sage: len(P.hasse_diagram().edges(sort=False))
435435
8
436436
437437
This is the transitive closure of the union of left and
@@ -863,23 +863,23 @@ def coxeter_knuth_graph(self):
863863
sage: W = WeylGroup(['A',4], prefix='s')
864864
sage: w = W.from_reduced_word([1,2,1,3,2])
865865
sage: D = w.coxeter_knuth_graph()
866-
sage: D.vertices()
866+
sage: D.vertices(sort=True)
867867
[(1, 2, 1, 3, 2),
868868
(1, 2, 3, 1, 2),
869869
(2, 1, 2, 3, 2),
870870
(2, 1, 3, 2, 3),
871871
(2, 3, 1, 2, 3)]
872-
sage: D.edges()
872+
sage: D.edges(sort=True)
873873
[((1, 2, 1, 3, 2), (1, 2, 3, 1, 2), None),
874874
((1, 2, 1, 3, 2), (2, 1, 2, 3, 2), None),
875875
((2, 1, 2, 3, 2), (2, 1, 3, 2, 3), None),
876876
((2, 1, 3, 2, 3), (2, 3, 1, 2, 3), None)]
877877
878878
sage: w = W.from_reduced_word([1,3])
879879
sage: D = w.coxeter_knuth_graph()
880-
sage: D.vertices()
880+
sage: D.vertices(sort=True)
881881
[(1, 3), (3, 1)]
882-
sage: D.edges()
882+
sage: D.edges(sort=False)
883883
[]
884884
885885
TESTS::

src/sage/categories/regular_crystals.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,10 @@ def demazure_subcrystal(self, element, reduced_word, only_support=True):
249249
sage: K = crystals.KirillovReshetikhin(['A',1,1], 1, 2)
250250
sage: mg = K.module_generator()
251251
sage: S = K.demazure_subcrystal(mg, [1])
252-
sage: S.digraph().edges()
252+
sage: S.digraph().edges(sort=True)
253253
[([[1, 1]], [[1, 2]], 1), ([[1, 2]], [[2, 2]], 1)]
254254
sage: S = K.demazure_subcrystal(mg, [1], only_support=False)
255-
sage: S.digraph().edges()
255+
sage: S.digraph().edges(sort=True)
256256
[([[1, 1]], [[1, 2]], 1),
257257
([[1, 2]], [[1, 1]], 0),
258258
([[1, 2]], [[2, 2]], 1),
@@ -382,12 +382,12 @@ def dual_equivalence_graph(self, X=None, index_set=None, directed=True):
382382
383383
sage: T = crystals.Tableaux(['A',3], shape=[2,2])
384384
sage: G = T.dual_equivalence_graph()
385-
sage: sorted(G.edges())
385+
sage: G.edges(sort=True)
386386
[([[1, 3], [2, 4]], [[1, 2], [3, 4]], 2),
387387
([[1, 2], [3, 4]], [[1, 3], [2, 4]], 3)]
388388
sage: T = crystals.Tableaux(['A',4], shape=[3,2])
389389
sage: G = T.dual_equivalence_graph()
390-
sage: sorted(G.edges())
390+
sage: G.edges(sort=True)
391391
[([[1, 3, 5], [2, 4]], [[1, 3, 4], [2, 5]], 4),
392392
([[1, 3, 5], [2, 4]], [[1, 2, 5], [3, 4]], 2),
393393
([[1, 3, 4], [2, 5]], [[1, 2, 4], [3, 5]], 2),
@@ -397,20 +397,20 @@ def dual_equivalence_graph(self, X=None, index_set=None, directed=True):
397397
398398
sage: T = crystals.Tableaux(['A',4], shape=[3,1])
399399
sage: G = T.dual_equivalence_graph(index_set=[1,2,3])
400-
sage: G.vertices()
400+
sage: G.vertices(sort=True)
401401
[[[1, 3, 4], [2]], [[1, 2, 4], [3]], [[1, 2, 3], [4]]]
402-
sage: G.edges()
402+
sage: G.edges(sort=True)
403403
[([[1, 3, 4], [2]], [[1, 2, 4], [3]], 2),
404404
([[1, 2, 4], [3]], [[1, 2, 3], [4]], 3)]
405405
406406
TESTS::
407407
408408
sage: T = crystals.Tableaux(['A',4], shape=[3,1])
409409
sage: G = T.dual_equivalence_graph(index_set=[2,3])
410-
sage: sorted(G.edges())
410+
sage: G.edges(sort=True)
411411
[([[1, 2, 4], [3]], [[1, 2, 3], [4]], 3),
412412
([[2, 4, 5], [3]], [[2, 3, 5], [4]], 3)]
413-
sage: sorted(G.vertices())
413+
sage: G.vertices(sort=True)
414414
[[[1, 3, 4], [2]],
415415
[[1, 2, 4], [3]],
416416
[[2, 4, 5], [3]],
@@ -831,12 +831,12 @@ def dual_equivalence_class(self, index_set=None):
831831
832832
sage: T = crystals.Tableaux(['A',3], shape=[2,2])
833833
sage: G = T(2,1,4,3).dual_equivalence_class()
834-
sage: sorted(G.edges())
834+
sage: G.edges(sort=True)
835835
[([[1, 3], [2, 4]], [[1, 2], [3, 4]], 2),
836836
([[1, 3], [2, 4]], [[1, 2], [3, 4]], 3)]
837837
sage: T = crystals.Tableaux(['A',4], shape=[3,2])
838838
sage: G = T(2,1,4,3,5).dual_equivalence_class()
839-
sage: sorted(G.edges())
839+
sage: G.edges(sort=True)
840840
[([[1, 3, 5], [2, 4]], [[1, 3, 4], [2, 5]], 4),
841841
([[1, 3, 5], [2, 4]], [[1, 2, 5], [3, 4]], 2),
842842
([[1, 3, 5], [2, 4]], [[1, 2, 5], [3, 4]], 3),

src/sage/categories/semigroups.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ def cayley_graph(self, side="right", simple=False, elements = None, generators =
203203
Alternating group of order 5!/2 as a permutation group
204204
sage: G = A5.cayley_graph()
205205
sage: G.show3d(color_by_label=True, edge_size=0.01, edge_size2=0.02, vertex_size=0.03)
206-
sage: G.show3d(vertex_size=0.03, edge_size=0.01, edge_size2=0.02, vertex_colors={(1,1,1):G.vertices()}, bgcolor=(0,0,0), color_by_label=True, xres=700, yres=700, iterations=200) # long time (less than a minute)
206+
sage: G.show3d(vertex_size=0.03, edge_size=0.01, edge_size2=0.02, vertex_colors={(1,1,1):G.vertices(sort=True)}, bgcolor=(0,0,0), color_by_label=True, xres=700, yres=700, iterations=200) # long time (less than a minute)
207207
sage: G.num_edges()
208208
120
209209
@@ -239,40 +239,40 @@ def cayley_graph(self, side="right", simple=False, elements = None, generators =
239239
240240
sage: S = FiniteSemigroups().example(alphabet=('a','b'))
241241
sage: g = S.cayley_graph(simple=True)
242-
sage: g.vertices()
242+
sage: g.vertices(sort=True)
243243
['a', 'ab', 'b', 'ba']
244-
sage: g.edges()
244+
sage: g.edges(sort=True)
245245
[('a', 'ab', None), ('b', 'ba', None)]
246246
247247
::
248248
249249
sage: g = S.cayley_graph(side="left", simple=True)
250-
sage: g.vertices()
250+
sage: g.vertices(sort=True)
251251
['a', 'ab', 'b', 'ba']
252-
sage: g.edges()
252+
sage: g.edges(sort=True)
253253
[('a', 'ba', None), ('ab', 'ba', None), ('b', 'ab', None),
254254
('ba', 'ab', None)]
255255
256256
::
257257
258258
sage: g = S.cayley_graph(side="twosided", simple=True)
259-
sage: g.vertices()
259+
sage: g.vertices(sort=True)
260260
['a', 'ab', 'b', 'ba']
261-
sage: g.edges()
261+
sage: g.edges(sort=True)
262262
[('a', 'ab', None), ('a', 'ba', None), ('ab', 'ba', None),
263263
('b', 'ab', None), ('b', 'ba', None), ('ba', 'ab', None)]
264264
265265
::
266266
267267
sage: g = S.cayley_graph(side="twosided")
268-
sage: g.vertices()
268+
sage: g.vertices(sort=True)
269269
['a', 'ab', 'b', 'ba']
270-
sage: g.edges()
270+
sage: g.edges(sort=True)
271271
[('a', 'a', (0, 'left')), ('a', 'a', (0, 'right')), ('a', 'ab', (1, 'right')), ('a', 'ba', (1, 'left')), ('ab', 'ab', (0, 'left')), ('ab', 'ab', (0, 'right')), ('ab', 'ab', (1, 'right')), ('ab', 'ba', (1, 'left')), ('b', 'ab', (0, 'left')), ('b', 'b', (1, 'left')), ('b', 'b', (1, 'right')), ('b', 'ba', (0, 'right')), ('ba', 'ab', (0, 'left')), ('ba', 'ba', (0, 'right')), ('ba', 'ba', (1, 'left')), ('ba', 'ba', (1, 'right'))]
272272
273273
::
274274
275-
sage: s1 = SymmetricGroup(1); s = s1.cayley_graph(); s.vertices()
275+
sage: s1 = SymmetricGroup(1); s = s1.cayley_graph(); s.vertices(sort=False)
276276
[()]
277277
278278
TESTS::

src/sage/categories/simplicial_sets.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ def fundamental_group(self, simplify=True):
337337
if not skel.is_connected():
338338
graph = graph.subgraph(skel.base_point())
339339

340-
edges = [e[2] for e in graph.edges()]
340+
edges = [e[2] for e in graph.edges(sort=True)]
341341
spanning_tree = [e[2] for e in graph.min_spanning_tree()]
342342
gens = [e for e in edges if e not in spanning_tree]
343343

src/sage/categories/supercrystals.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def digraph(self, index_set=None):
7878
sage: Q = crystals.Letters(['Q',3])
7979
sage: G = Q.digraph(); G
8080
Multi-digraph on 3 vertices
81-
sage: G.edges()
81+
sage: G.edges(sort=True)
8282
[(1, 2, -1), (1, 2, 1), (2, 3, -2), (2, 3, 2)]
8383
8484
The edges of the crystal graph are by default colored using

src/sage/categories/weyl_groups.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,9 @@ def quantum_bruhat_graph(self, index_set=()):
248248
sage: g = W.quantum_bruhat_graph((1,3))
249249
sage: g
250250
Parabolic Quantum Bruhat Graph of Weyl Group of type ['A', 3] (as a matrix group acting on the ambient space) for nodes (1, 3): Digraph on 6 vertices
251-
sage: g.vertices()
251+
sage: g.vertices(sort=True)
252252
[s2*s3*s1*s2, s3*s1*s2, s1*s2, s3*s2, s2, 1]
253-
sage: g.edges()
253+
sage: g.edges(sort=True)
254254
[(s2*s3*s1*s2, s2, alpha[2]),
255255
(s3*s1*s2, s2*s3*s1*s2, alpha[1] + alpha[2] + alpha[3]),
256256
(s3*s1*s2, 1, alpha[2]),

src/sage/coding/linear_code.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2067,9 +2067,9 @@ def cosetGraph(self):
20672067
sage: M = matrix.identity(GF(3), 7)
20682068
sage: C = LinearCode(M)
20692069
sage: G = C.cosetGraph()
2070-
sage: G.vertices()
2070+
sage: G.vertices(sort=False)
20712071
[0]
2072-
sage: G.edges()
2072+
sage: G.edges(sort=False)
20732073
[]
20742074
"""
20752075
from sage.matrix.constructor import matrix

src/sage/coding/source_coding/huffman.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ def _generate_edges(self, tree, parent="", bit=""):
544544
sage: from sage.coding.source_coding.huffman import Huffman
545545
sage: H = Huffman("Sage")
546546
sage: T = H.tree()
547-
sage: T.edges(labels=None) # indirect doctest
547+
sage: T.edges(sort=True, labels=None) # indirect doctest
548548
[('0', 'S: 00'), ('0', 'a: 01'), ('1', 'e: 10'), ('1', 'g: 11'), ('root', '0'), ('root', '1')]
549549
"""
550550
if parent == "":

0 commit comments

Comments
 (0)