Skip to content

Commit 58eabb4

Browse files
author
Release Manager
committed
gh-39797: Small changes in matroids fixes #20175 about a better picture for one specific matroid plus a bunch of other minor changes, adding typing annotations ### 📝 Checklist - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [x] I have updated the documentation and checked the documentation preview. URL: #39797 Reported by: Frédéric Chapoton Reviewer(s): Travis Scrimshaw
2 parents c9cf964 + 605af40 commit 58eabb4

File tree

2 files changed

+45
-31
lines changed

2 files changed

+45
-31
lines changed

src/sage/matroids/database_matroids.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2133,7 +2133,7 @@ def Z(r, t=True, groundset=None):
21332133
Id = Matrix(GF(2), identity_matrix(r))
21342134
J = Matrix(GF(2), ones_matrix(r))
21352135
tip = Matrix(GF(2), ones_matrix(r, 1))
2136-
A = Id.augment(J-Id).augment(tip)
2136+
A = Id.augment(J - Id).augment(tip)
21372137

21382138
M = Matroid(A)
21392139
X = [f'x{i}' for i in range(1, r + 1)]
@@ -2250,7 +2250,7 @@ def Spike(r, t=True, C3=[], groundset=None):
22502250
else:
22512251
for S in C3:
22522252
for xy in S:
2253-
if xy not in X+Y:
2253+
if xy not in X + Y:
22542254
raise ValueError(
22552255
"The sets in C3 must contain elements xi and yi only."
22562256
)
@@ -2422,13 +2422,13 @@ def genbin(n, bs=""):
24222422
for i in range(0, r):
24232423
for k in range(1, r - 2):
24242424
I0 = [f'a{i}', f'b{i}']
2425-
IK = [f'a{(i+k) % r}', f'b{(i+k) % r}']
2425+
IK = [f'a{(i + k) % r}', f'b{(i + k) % r}']
24262426
for AB in generate_binary_strings(k - 1):
24272427
C = []
24282428
C += I0 + IK
24292429
j = 1
24302430
for z in AB:
2431-
C += [f'{z}{(i+j) % r}']
2431+
C += [f'{z}{(i + j) % r}']
24322432
j += 1
24332433
NSC += [C]
24342434

@@ -5029,6 +5029,17 @@ def BetsyRoss(groundset=None):
50295029
'cjk', 'dfk', 'dgh', 'dij', 'efj', 'egk', 'ehi']
50305030
M = Matroid(rank=3, nonspanning_circuits=NSC)
50315031
M = _rename_and_relabel(M, "BetsyRoss", groundset)
5032+
pos = {'a': (0, 1.61000000000000),
5033+
'c': (0.946334256190882, -1.30251736094367),
5034+
'b': (1.53120099123520, 0.497517360943665),
5035+
'e': (-1.53120099123520, 0.497517360943665),
5036+
'd': (-0.946334256190882, -1.30251736094367),
5037+
'g': (0.590718333102580, -0.191936021350899),
5038+
'f': (0.365084007635076, 0.502495027562079),
5039+
'i': (-0.590718333102580, -0.191936021350899),
5040+
'h': (0, -0.621118012422360),
5041+
'k': (0, 0), 'j': (-0.365084007635076, 0.502495027562079)}
5042+
M._fix_positions(pos_dict=pos)
50325043
return M
50335044

50345045

@@ -5246,6 +5257,6 @@ def _rename_and_relabel(M, name=None, groundset=None):
52465257
M = M.relabel(dict(zip(M.groundset(), groundset)))
52475258

52485259
if name is not None:
5249-
M.rename(name+": " + repr(M))
5260+
M.rename(name + ": " + repr(M))
52505261

52515262
return M

src/sage/matroids/matroids_plot_helpers.py

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,17 @@
7474
import scipy
7575
import scipy.interpolate
7676
import numpy as np
77+
78+
from sage.matroids.advanced import newlabel
7779
from sage.misc.lazy_import import lazy_import
78-
lazy_import("sage.plot.all", ["Graphics", "line", "text", "polygon2d", "point", "points"])
79-
lazy_import("sage.plot.colors", "Color")
8080
from sage.sets.set import Set
81-
from sage.matroids.advanced import newlabel
81+
82+
lazy_import("sage.plot.all", ["Graphics", "line", "text",
83+
"polygon2d", "point", "points"])
84+
lazy_import("sage.plot.colors", "Color")
8285

8386

84-
def it(M, B1, nB1, lps):
87+
def it(M, B1, nB1, lps) -> tuple[dict, list, list, list]:
8588
r"""
8689
Return points on and off the triangle and lines to be drawn for a rank 3
8790
matroid.
@@ -178,7 +181,7 @@ def it(M, B1, nB1, lps):
178181
return pts, trilines, nontripts, curvedlines
179182

180183

181-
def trigrid(tripts):
184+
def trigrid(tripts) -> list[list]:
182185
"""
183186
Return a grid of 4 points inside given 3 points as a list.
184187
@@ -205,7 +208,7 @@ def trigrid(tripts):
205208
206209
.. NOTE::
207210
208-
This method does NOT do any checks.
211+
This method does NOT do any checks.
209212
"""
210213
pairs = [[0, 1], [1, 2], [0, 2]]
211214
cpt = [float(tripts[0][0] + tripts[1][0] + tripts[2][0]) / 3,
@@ -218,7 +221,7 @@ def trigrid(tripts):
218221
return grid
219222

220223

221-
def addnontripts(tripts_labels, nontripts_labels, ptsdict):
224+
def addnontripts(tripts_labels, nontripts_labels, ptsdict) -> dict:
222225
"""
223226
Return modified ``ptsdict`` with additional keys and values corresponding
224227
to ``nontripts``.
@@ -260,16 +263,16 @@ def addnontripts(tripts_labels, nontripts_labels, ptsdict):
260263
261264
.. NOTE::
262265
263-
This method does NOT do any checks.
266+
This method does NOT do any checks.
264267
"""
265268
tripts = [list(ptsdict[p]) for p in tripts_labels]
266269
pairs = [[0, 1], [1, 2], [0, 2]]
267270
q = [tripts]
268271
num = len(nontripts_labels)
269-
gridpts = [[float((tripts[0][0]+tripts[1][0]+tripts[2][0])/3),
270-
float(tripts[0][1]+tripts[1][1]+tripts[2][1])/3]]
272+
gridpts = [[float((tripts[0][0] + tripts[1][0] + tripts[2][0]) / 3),
273+
float(tripts[0][1] + tripts[1][1] + tripts[2][1]) / 3]]
271274
n = 0
272-
while n < num+1:
275+
while n < num + 1:
273276
g = trigrid(q[0])
274277
q.extend([[g[0], q[0][pairs[0][0]], q[0][pairs[0][1]]],
275278
[g[0], q[0][pairs[1][0]], q[0][pairs[1][1]]],
@@ -285,7 +288,7 @@ def addnontripts(tripts_labels, nontripts_labels, ptsdict):
285288
return ptsdict
286289

287290

288-
def createline(ptsdict, ll, lineorders2=None):
291+
def createline(ptsdict, ll, lineorders2=None) -> tuple[list, list, list, list]:
289292
"""
290293
Return ordered lists of coordinates of points to be traversed to draw a
291294
2D line.
@@ -334,7 +337,7 @@ def createline(ptsdict, ll, lineorders2=None):
334337
335338
.. NOTE::
336339
337-
This method does NOT do any checks.
340+
This method does NOT do any checks.
338341
"""
339342
x, lo = line_hasorder(ll, lineorders2)
340343
flip = False
@@ -367,7 +370,7 @@ def createline(ptsdict, ll, lineorders2=None):
367370
return sortedx, sortedy, x_i, y_i
368371

369372

370-
def slp(M1, pos_dict=None, B=None):
373+
def slp(M1, pos_dict=None, B=None) -> tuple:
371374
"""
372375
Return simple matroid, loops and parallel elements of given matroid.
373376
@@ -413,7 +416,7 @@ def slp(M1, pos_dict=None, B=None):
413416
414417
.. NOTE::
415418
416-
This method does NOT do any checks.
419+
This method does NOT do any checks.
417420
"""
418421
L = set(M1.loops())
419422
nP = L | set(M1.simplify().groundset())
@@ -445,7 +448,7 @@ def slp(M1, pos_dict=None, B=None):
445448
return [M1.delete(L | P), L, P]
446449

447450

448-
def addlp(M, M1, L, P, ptsdict, G=None, limits=None):
451+
def addlp(M, M1, L, P, ptsdict, G=None, limits=None) -> tuple:
449452
"""
450453
Return a graphics object containing loops (in inset) and parallel elements
451454
of matroid.
@@ -482,7 +485,7 @@ def addlp(M, M1, L, P, ptsdict, G=None, limits=None):
482485
483486
.. NOTE::
484487
485-
This method does NOT do any checks.
488+
This method does NOT do any checks.
486489
"""
487490
if G is None:
488491
G = Graphics()
@@ -551,7 +554,7 @@ def addlp(M, M1, L, P, ptsdict, G=None, limits=None):
551554
return G, limits
552555

553556

554-
def line_hasorder(l, lodrs=None):
557+
def line_hasorder(l, lodrs=None) -> tuple[bool, list]:
555558
"""
556559
Determine if an order is specified for a line.
557560
@@ -581,7 +584,7 @@ def line_hasorder(l, lodrs=None):
581584
582585
.. NOTE::
583586
584-
This method does NOT do any checks.
587+
This method does NOT do any checks.
585588
"""
586589
if lodrs is not None:
587590
set_l = Set(l)
@@ -592,7 +595,7 @@ def line_hasorder(l, lodrs=None):
592595
return False, []
593596

594597

595-
def lineorders_union(lineorders1, lineorders2):
598+
def lineorders_union(lineorders1, lineorders2) -> list:
596599
"""
597600
Return a list of ordered lists of ground set elements that corresponds to
598601
union of two sets of ordered lists of ground set elements in a sense.
@@ -633,7 +636,7 @@ def lineorders_union(lineorders1, lineorders2):
633636
return None
634637

635638

636-
def posdict_is_sane(M1, pos_dict):
639+
def posdict_is_sane(M1, pos_dict) -> bool:
637640
"""
638641
Return a boolean establishing sanity of ``posdict`` wrt matroid ``M``.
639642
@@ -665,8 +668,8 @@ def posdict_is_sane(M1, pos_dict):
665668
666669
.. NOTE::
667670
668-
This method does NOT do any checks. ``M1`` is assumed to be a
669-
matroid and ``posdict`` is assumed to be a dictionary.
671+
This method does NOT do any checks. ``M1`` is assumed to be a
672+
matroid and ``posdict`` is assumed to be a dictionary.
670673
"""
671674
L = set(M1.loops())
672675
nP = L | set(M1.simplify().groundset())
@@ -683,7 +686,7 @@ def posdict_is_sane(M1, pos_dict):
683686
for x in list(set(M1.groundset()) - (L | set(allP))))
684687

685688

686-
def tracklims(lims, x_i=[], y_i=[]):
689+
def tracklims(lims, x_i=[], y_i=[]) -> list:
687690
"""
688691
Return modified limits list.
689692
@@ -704,7 +707,7 @@ def tracklims(lims, x_i=[], y_i=[]):
704707
705708
.. NOTE::
706709
707-
This method does NOT do any checks.
710+
This method does NOT do any checks.
708711
"""
709712
if lims is not None and lims[0] is not None and lims[1] is not None and \
710713
lims[2] is not None and lims[3] is not None:
@@ -752,7 +755,7 @@ def geomrep(M1, B1=None, lineorders1=None, pd=None, sp=False):
752755
753756
.. NOTE::
754757
755-
This method does NOT do any checks.
758+
This method does NOT do any checks.
756759
"""
757760
G = Graphics()
758761
# create lists of loops and parallel elements and simplify given matroid

0 commit comments

Comments
 (0)