Skip to content

simplify some nested for loops #40439

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/sage/algebras/quatalg/quaternion_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -955,9 +955,10 @@ def maximal_order(self, take_shortcuts=True, order_basis=None):
Order of Quaternion Algebra (-22, 210) with base ring Rational Field
with basis (1, i, 1/2*i + 1/2*j, 1/2 + 17/22*i + 1/44*k)

sage: for d in ( m for m in range(1, 750) if is_squarefree(m) ): # long time (3s)
....: A = QuaternionAlgebra(d)
....: assert A.maximal_order(take_shortcuts=False).is_maximal()
sage: Q = QuaternionAlgebra
sage: all(Q(d).maximal_order(take_shortcuts=False).is_maximal()
....: for d in range(1, 350) if is_squarefree(d))
True

Specifying an order basis gives an extension of orders::

Expand Down
6 changes: 4 additions & 2 deletions src/sage/categories/finite_semigroups.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def j_classes(self):
return self.cayley_graph(side='twosided', simple=True).strongly_connected_components()

@cached_method
def j_classes_of_idempotents(self):
def j_classes_of_idempotents(self) -> list[list]:
r"""
Return all the idempotents of self, grouped by J-class.

Expand All @@ -108,7 +108,9 @@ def j_classes_of_idempotents(self):
[['a'], ['ab', 'ba'], ['abc', 'acb', 'bac', 'bca', 'cab', 'cba'],
['ac', 'ca'], ['b'], ['bc', 'cb'], ['c']]
"""
return [l for l in ([x for x in cl if attrcall('is_idempotent')(x)] for cl in self.j_classes()) if len(l) > 0]
it = ([x for x in cl if attrcall('is_idempotent')(x)]
for cl in self.j_classes())
return [ell for ell in it if ell]

@cached_method
def j_transversal_of_idempotents(self):
Expand Down
10 changes: 5 additions & 5 deletions src/sage/combinat/partition.py
Original file line number Diff line number Diff line change
Expand Up @@ -2043,7 +2043,7 @@ def cell_poset(self, orientation='SE'):
covers[(i, j)] = [(i, j - 1)]
return Poset(covers)

def frobenius_coordinates(self):
def frobenius_coordinates(self) -> tuple[list, list]:
"""
Return a pair of sequences of Frobenius coordinates aka beta numbers
of the partition.
Expand All @@ -2065,11 +2065,11 @@ def frobenius_coordinates(self):
mu = self
muconj = mu.conjugate() # Naive implementation
if len(mu) <= len(muconj):
a = [x for x in (val-i-1 for i, val in enumerate(mu)) if x >= 0]
b = [x for x in (muconj[i]-i-1 for i in range(len(a))) if x >= 0]
a = [x for i, val in enumerate(mu) if (x := val - i - 1) >= 0]
b = [x for i in range(len(a)) if (x := muconj[i] - i - 1) >= 0]
else:
b = [x for x in (val-i-1 for i, val in enumerate(muconj)) if x >= 0]
a = [x for x in (mu[i]-i-1 for i in range(len(b))) if x >= 0]
b = [x for i, val in enumerate(muconj) if (x := val - i - 1) >= 0]
a = [x for i in range(len(b)) if (x := mu[i] - i - 1) >= 0]
return (a, b)

def frobenius_rank(self):
Expand Down
5 changes: 3 additions & 2 deletions src/sage/graphs/generators/smallgraphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5473,8 +5473,9 @@ def JankoKharaghaniTonchevGraph():
301, 304, 308, 309, 310, 312, 313, 314, 316, 317, 318)
Gamma = Graph(multiedges=False, name='Janko-Kharaghani-Tonchev')
for i, b in ((1, B1), (163, B163)):
for j in (x[0] for x in st.OrbitsDomain(b)):
Gamma.add_edges(map(tuple, G.Orbit(libgap.Set([i, j]), libgap.OnSets)))
for x in st.OrbitsDomain(b):
Gamma.add_edges(map(tuple, G.Orbit(libgap.Set([i, x[0]]),
libgap.OnSets)))
Gamma.relabel(range(Gamma.order()))
return Gamma

Expand Down
4 changes: 2 additions & 2 deletions src/sage/graphs/orientations.py
Original file line number Diff line number Diff line change
Expand Up @@ -1361,7 +1361,7 @@ def bounded_outdegree_orientation(G, bound, solver=None, verbose=False,
d.add_edges(('s', vertices_id[v], b[v]) for v in vertices)

d.add_edges(((vertices_id[u], vertices_id[v]), 't', 1)
for u, v in G.edges(sort=False, labels=None))
for u, v in G.edges(sort=False, labels=None))

# each v is linked to its incident edges

Expand All @@ -1381,7 +1381,7 @@ def bounded_outdegree_orientation(G, bound, solver=None, verbose=False,
# The flow graph may not contain all the vertices, if they are
# not part of the flow...
edges = ((vertices[u], vertices[vv if vv != u else uu])
for u in (x for x in range(n) if x in flow)
for u in range(n) if u in flow
for uu, vv in flow.neighbors_out(u))

return _initialize_digraph(G, edges)
Expand Down
Loading