Skip to content

Commit

Permalink
sagemathgh-38165: simplify some calls to join
Browse files Browse the repository at this point in the history
    
by avoiding to create the inner list

### 📝 Checklist

- [x] The title is concise and informative.
- [x] The description explains in detail what this PR is about.
    
URL: sagemath#38165
Reported by: Frédéric Chapoton
Reviewer(s): Matthias Köppe
  • Loading branch information
Release Manager committed Jun 16, 2024
2 parents 4e4369d + b1f5514 commit 7a9adfd
Show file tree
Hide file tree
Showing 13 changed files with 31 additions and 30 deletions.
15 changes: 8 additions & 7 deletions src/sage/combinat/nu_tamari_lattice.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,13 @@ def delta_swap(p, k, delta):
raise ValueError("the index is greater than the length of the path")
# if delta is None:
# delta = [len(_) for _ in str(p._nu).split(sep='1')[1:]]
if k == 0 or p[k-1] == 1:
if k == 0 or p[k - 1] == 1:
raise ValueError("there is no such covering move")
found = False
i = p[:k].count(1)
j = k
alt = 0
while not found and j <= p.length()-1:
while not found and j <= p.length() - 1:
if p[j]:
alt += delta[i]
i += 1
Expand All @@ -188,9 +188,10 @@ def delta_swap(p, k, delta):
if alt == 0:
found = True
j += 1
q = p[:k-1] + p[k:j] + [p[k-1]] + p[j:]
q = p[:k - 1] + p[k:j] + [p[k - 1]] + p[j:]
return NuDyckWord(q, p._nu)


def AltNuTamariLattice(nu, delta=None):
r"""
Return the `(\delta,\nu)`-Tamari lattice (or alt `\nu`-Tamari lattice).
Expand Down Expand Up @@ -253,12 +254,12 @@ def AltNuTamariLattice(nu, delta=None):
- [CC2023]_
"""
if not( (isinstance(nu, (list, tuple)) and all(x in [0, 1] for x in nu)) or
(isinstance(nu, str) and all(x in ['0', '1'] for x in nu)) ):
if not ((isinstance(nu, (list, tuple)) and all(x in [0, 1] for x in nu)) or
(isinstance(nu, str) and all(x in ['0', '1'] for x in nu))):
raise ValueError("nu must be a list or a string of 0s and 1s")
nu = [int(a) for a in nu]
# transforms nu in a sequence of 0s and 1s if it is a list
nu = ''.join([str(a) for a in nu])
nu = ''.join(str(a) for a in nu)
# produces delta if delta is None, and check that delta is valid otherwise
deltamax = [len(a) for a in nu.split(sep='1')[1:]]
if delta is None:
Expand All @@ -270,4 +271,4 @@ def covers(p):
return [delta_swap(p, k, delta=delta) for k in range(1, p.length())
if not p[k - 1] and p[k]]
return LatticePoset({p: covers(p) for p in NuDyckWords(nu)},
check=False)
check=False)
2 changes: 1 addition & 1 deletion src/sage/geometry/integral_points.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,7 @@ cdef class Inequality_int:
'integer: (2, 3, 7) x + -5 >= 0'
"""
s = 'integer: ('
s += ', '.join([str(self.A[i]) for i in range(self.dim)])
s += ', '.join(str(self.A[i]) for i in range(self.dim))
s += ') x + ' + str(self.b) + ' >= 0'
return s
Expand Down
4 changes: 2 additions & 2 deletions src/sage/geometry/toric_lattice.py
Original file line number Diff line number Diff line change
Expand Up @@ -1163,7 +1163,7 @@ def _repr_(self):
"""
s = 'Sublattice '
s += '<'
s += ', '.join(map(str,self.basis()))
s += ', '.join(map(str, self.basis()))
s += '>'
return s

Expand All @@ -1186,7 +1186,7 @@ def _latex_(self):
\\left(0,\\,4,\\,8\\right)_{L}\\right\\rangle'
"""
s = '\\left\\langle'
s += ', '.join([ b._latex_() for b in self.basis() ])
s += ', '.join(b._latex_() for b in self.basis())
s += '\\right\\rangle'
return s

Expand Down
4 changes: 2 additions & 2 deletions src/sage/graphs/graph_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ def from_sparse6(G, g6_string):
k = int((ZZ(n) - 1).nbits())
ords = [ord(i) for i in s]
if any(o > 126 or o < 63 for o in ords):
raise RuntimeError("the string seems corrupt: valid characters are \n" + ''.join([chr(i) for i in range(63, 127)]))
bits = ''.join([int_to_binary_string(o-63).zfill(6) for o in ords])
raise RuntimeError("the string seems corrupt: valid characters are \n" + ''.join(chr(i) for i in range(63, 127)))
bits = ''.join(int_to_binary_string(o-63).zfill(6) for o in ords)
if not k:
b = [int(x) for x in bits]
x = [0] * len(b)
Expand Down
4 changes: 2 additions & 2 deletions src/sage/groups/finitely_presented.py
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ def __init__(self, free_group, relations, category=None):
ParentLibGAP.__init__(self, parent_gap)
Group.__init__(self, category=category)

def _repr_(self):
def _repr_(self) -> str:
"""
Return a string representation.
Expand All @@ -813,7 +813,7 @@ def _repr_(self):
'Finitely presented group < a, b | a, b^3 >'
"""
gens = ', '.join(self.variable_names())
rels = ', '.join([str(r) for r in self.relations()])
rels = ', '.join(str(r) for r in self.relations())
return 'Finitely presented group ' + '< ' + gens + ' | ' + rels + ' >'

def _latex_(self):
Expand Down
4 changes: 2 additions & 2 deletions src/sage/lfunctions/dokchitser.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,12 +467,12 @@ def repl(m):
raise TypeError("v (=%s) must be a list, tuple, or string" % v)
else:
CC = self.__CC
v = ','.join([CC(a)._pari_init_() for a in v])
v = ','.join(CC(a)._pari_init_() for a in v)
self._gp_eval('Avec = [%s]' % v)
if w is None:
self._gp_call_inst('initLdata', '"Avec[k]"', cutoff)
else:
w = ','.join([CC(a)._pari_init_() for a in w])
w = ','.join(CC(a)._pari_init_() for a in w)
self._gp_eval('Bvec = [%s]' % w)
self._gp_call_inst('initLdata', '"Avec[k]"', cutoff,
'"Bvec[k]"')
Expand Down
2 changes: 1 addition & 1 deletion src/sage/libs/eclib/mwrank.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def initprimes(filename, verb=False):
sage: import tempfile
sage: with tempfile.NamedTemporaryFile(mode='w+t') as f:
....: data = ' '.join([str(p) for p in prime_range(10^7,10^7+20)])
....: data = ' '.join(str(p) for p in prime_range(10^7, 10^7 + 20))
....: _ = f.write(data)
....: f.flush()
....: mwrank_initprimes(f.name, verb=True)
Expand Down
4 changes: 2 additions & 2 deletions src/sage/matrix/matrix1.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,9 @@ cdef class Matrix(Matrix0):
sage: a._mathematica_init_() # needs sage.symbolic
'{{Pi, Sin[x]}, {Cos[x], Exp[-1]}}'
"""
return '{' + ', '.join([v._mathematica_init_() for v in self.rows()]) + '}'
return '{' + ', '.join(v._mathematica_init_() for v in self.rows()) + '}'

def _magma_init_(self, magma):
def _magma_init_(self, magma) -> str:
r"""
Return a string that evaluates in the given Magma session to this
matrix.
Expand Down
2 changes: 1 addition & 1 deletion src/sage/misc/cython.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ def cython_lambda(vars, expr, verbose=0, **kwds):
if isinstance(vars, str):
v = vars
else:
v = ', '.join(['%s %s' % (typ, var) for typ, var in vars])
v = ', '.join('%s %s' % (typ, var) for typ, var in vars)

s = """
cdef class _s:
Expand Down
12 changes: 6 additions & 6 deletions src/sage/misc/sage_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -2185,7 +2185,7 @@ def __repr__(self):
"""
kind = "list" if self._sie_is_list else "tuple"
return "{%s: (%s)}" % \
(kind, ', '.join([repr(v) for v in self._sie_values]))
(kind, ', '.join(repr(v) for v in self._sie_values))

def _sie_referenced(self):
r"""
Expand Down Expand Up @@ -2290,8 +2290,8 @@ def __repr__(self):
{dict: {{atomic:'keaton'}:{atomic:'general'}, {atomic:'chan'}:{atomic:'master'}}}
"""
return "{dict: {%s}}" % \
', '.join([repr(key) + ':' + repr(val)
for key, val in self._sie_entries])
', '.join(repr(key) + ':' + repr(val)
for key, val in self._sie_entries)

def _sie_referenced(self):
r"""
Expand Down Expand Up @@ -2454,7 +2454,7 @@ def _sie_format(self, sif):
op = self._sie_op
fop = op
if op == '**':
lhs = sif.format(self._sie_operands[0], _prec_exponent+1)
lhs = sif.format(self._sie_operands[0], _prec_exponent + 1)
rhs = sif.format(self._sie_operands[1], _prec_exponent)
if self._sie_builder.preparse():
return '%s^%s' % (lhs, rhs), _prec_exponent
Expand All @@ -2475,7 +2475,7 @@ def _sie_format(self, sif):
raise ValueError('Unhandled op {} in SIE_binary'.format(op))

lhs = sif.format(self._sie_operands[0], prec)
rhs = sif.format(self._sie_operands[1], prec+1)
rhs = sif.format(self._sie_operands[1], prec + 1)
return '%s%s%s' % (lhs, fop, rhs), prec


Expand Down Expand Up @@ -2857,7 +2857,7 @@ def _sie_add_command(self, sif):
if len(self._sie_gens) == 1:
sif._commands += '%s = %s.gen()\n' % (self._sie_gens[0]._sie_get_varname(sif), self._sie_get_varname(sif))
else:
sif._commands += '%s = %s.gens()\n' % (','.join([g._sie_get_varname(sif) for g in self._sie_gens]), self._sie_get_varname(sif))
sif._commands += '%s = %s.gens()\n' % (','.join(g._sie_get_varname(sif) for g in self._sie_gens), self._sie_get_varname(sif))
self._sie_generated = True

def _sie_format(self, sif):
Expand Down
2 changes: 1 addition & 1 deletion src/sage/modules/fp_graded/steenrod/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def export_module_definition(self, powers_of_two_only=True):

# Print the degrees of the additive generators.
ret = '%d %s' % (len(additive_generator_degrees),
' '.join(['%d' % x for x in additive_generator_degrees]))
' '.join('%d' % x for x in additive_generator_degrees))

# A private function which transforms a vector in a given dimension
# to a vector of global indices for the basis elements corresponding
Expand Down
4 changes: 2 additions & 2 deletions src/sage/rings/number_field/totallyreal_rel.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ def __init__(self, F, m, B, a=None):
Z_Fbasis = self.Z_F.basis()

# Initialize variables.
if a == []:
if not a:
# No starting input, all polynomials will be found; initialize to zero.
self.a = [0]*m + [1]
self.amaxvals = [[]]*m
Expand All @@ -301,7 +301,7 @@ def __init__(self, F, m, B, a=None):
import numpy
for i in range(len(anm1s)):
Q = [[v(m*x) for v in self.Foo] + [0] for x in Z_Fbasis] + [[v(anm1s[i]) for v in self.Foo] + [10**6]]
pari_string = '['+';'.join([','.join(["%s" % ii for ii in row]) for row in zip(*Q)])+']'
pari_string = '[' + ';'.join(','.join("%s" % ii for ii in row) for row in zip(*Q)) + ']'
adj = pari(pari_string).qflll()[self.d]
anm1s[i] += sum([m*Z_Fbasis[ii]*int(adj[ii])//int(adj[self.d]) for ii in range(self.d)])

Expand Down
2 changes: 1 addition & 1 deletion src/sage/rings/valuation/value_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ def _repr_(self):
"""
if self.is_trivial():
return "Trivial Additive Abelian Semigroup"
return "Additive Abelian Semigroup generated by %s" % (', '.join([repr(g) for g in self._generators]),)
return "Additive Abelian Semigroup generated by %s" % (', '.join(repr(g) for g in self._generators),)

def __add__(self, other):
r"""
Expand Down

0 comments on commit 7a9adfd

Please sign in to comment.