Skip to content
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

simplify some all(all(...)) in combinat and geometry #35631

Merged
merged 1 commit into from
May 28, 2023
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
2 changes: 1 addition & 1 deletion src/sage/combinat/combinat_cython.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ def set_partition_composition(tuple sp1, tuple sp2):
diagram.append(tuple(block))

# Everything else should be completely contained in the top block
assert all(all(val > 0 for val in top) for top in remaining_top)
assert all(val > 0 for top in remaining_top for val in top)
diagram.extend(remaining_top)

return (tuple(diagram), num_loops)
Expand Down
2 changes: 1 addition & 1 deletion src/sage/combinat/crystals/tensor_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,7 @@ def __classcall_private__(cls, cartan_type, shapes = None, shape = None):
n1 = n + 1
else:
n1 = n
if not all(all(i == 0 for i in shape[n1:]) for shape in shapes):
if not all(i == 0 for shape in shapes for i in shape[n1:]):
raise ValueError("shapes should all have length at most equal to the rank or the rank + 1 in type A")
spin_shapes = tuple((tuple(shape) + (0,)*(n1-len(shape)))[:n1] for shape in shapes)
try:
Expand Down
4 changes: 2 additions & 2 deletions src/sage/combinat/designs/resolvable_bibd.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,13 +592,13 @@ def PBD_4_7(v,check=True, existence=False):
parall = []
plus_one = None
for S in AF:
if all(all(x not in SS for x in S) for SS in parall):
if all(x not in SS for SS in parall for x in S):
parall.append(S)
elif plus_one is None:
plus_one = S
if len(parall) == 4 and plus_one is not None:
break
X = set(sum(parall,plus_one))
X = set(sum(parall, plus_one))

S_4_5_7 = [X.intersection(S) for S in AF]
S_4_5_7 = [S for S in S_4_5_7 if len(S)>1]
Expand Down
10 changes: 5 additions & 5 deletions src/sage/combinat/diagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,20 +475,20 @@ def check(self):
sage: D = Diagram([(0,0), (0,-3), (2,2), (2,4)])
Traceback (most recent call last):
...
ValueError: Diagrams must be indexed by non-negative integers
ValueError: diagrams must be indexed by non-negative integers

The next example fails because one cell is indexed by rational
numbers::

sage: D = Diagram([(0,0), (0,3), (2/3,2), (2,4)])
Traceback (most recent call last):
...
ValueError: Diagrams must be indexed by non-negative integers
ValueError: diagrams must be indexed by non-negative integers
"""
from sage.sets.non_negative_integers import NonNegativeIntegers
NN = NonNegativeIntegers()
if not all(all(list(i in NN for i in c)) for c in self._cells):
raise ValueError("Diagrams must be indexed by non-negative integers")
if not all(i in NN for c in self._cells for i in c):
raise ValueError("diagrams must be indexed by non-negative integers")

def specht_module(self, base_ring=None):
r"""
Expand Down Expand Up @@ -884,7 +884,7 @@ def check(self):
sage: NorthwestDiagram([(0,1/2)])
Traceback (most recent call last):
...
ValueError: Diagrams must be indexed by non-negative integers
ValueError: diagrams must be indexed by non-negative integers
"""
from itertools import combinations
Diagram.check(self)
Expand Down
56 changes: 28 additions & 28 deletions src/sage/combinat/gelfand_tsetlin_patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@


class GelfandTsetlinPattern(ClonableArray,
metaclass=InheritComparisonClasscallMetaclass):
metaclass=InheritComparisonClasscallMetaclass):
r"""
A Gelfand-Tsetlin (sometimes written as Gelfand-Zetlin or Gelfand-Cetlin)
pattern. They were originally defined in [GC50]_.
Expand Down Expand Up @@ -197,7 +197,7 @@ def _repr_diagram(self) -> str:
for i, row in enumerate(self):
if i != 0:
ret += '\n'
ret += ' '*i
ret += ' ' * i
ret += ' '.join('%3s' % val for val in row)
return ret

Expand Down Expand Up @@ -234,13 +234,13 @@ def _latex_(self) -> str:
n = len(self)
if n == 0:
return "\\emptyset"
ret = "\\begin{array}{" + 'c'*(n*2-1) + "}\n"
ret = "\\begin{array}{" + 'c' * (n * 2 - 1) + "}\n"
for i, row in enumerate(self):
if i > 0:
ret += " \\\\\n"
ret += "& "*i
ret += "& " * i
ret += " & & ".join(repr(val) for val in row)
ret += " &"*i
ret += " &" * i
return ret + "\n\\end{array}"

@combinatorial_map(name='to semistandard tableau')
Expand Down Expand Up @@ -282,9 +282,9 @@ def to_tableau(self):
if j >= len(ret):
if val == 0:
break
ret.append([i+1]*val)
ret.append([i + 1] * val)
else:
ret[j].extend([i+1]*(val-len(ret[j])))
ret[j].extend([i + 1] * (val - len(ret[j])))
S = SemistandardTableaux(max_entry=len(self))
return S(ret)

Expand All @@ -306,7 +306,7 @@ def boxed_entries(self) -> tuple:
ret = []
for i in range(1, len(self)):
for j in range(len(self[i])):
if self[i][j] == self[i-1][j]:
if self[i][j] == self[i - 1][j]:
ret.append((i, j))
return tuple(ret)

Expand All @@ -328,7 +328,7 @@ def circled_entries(self) -> tuple:
ret = []
for i in range(1, len(self)):
for j in range(len(self[i])):
if self[i][j] == self[i-1][j+1]:
if self[i][j] == self[i - 1][j + 1]:
ret.append((i, j))
return tuple(ret)

Expand Down Expand Up @@ -457,7 +457,7 @@ def weight(self) -> tuple:
sage: G.weight()
(2, 2, 3)
"""
wt = [self.row_sums()[-1]] + [self.row_sums()[i-1]-self.row_sums()[i] for i in reversed(range(1, len(self[0])))]
wt = [self.row_sums()[-1]] + [self.row_sums()[i - 1] - self.row_sums()[i] for i in reversed(range(1, len(self[0])))]
return tuple(wt)

def Tokuyama_coefficient(self, name='t'):
Expand Down Expand Up @@ -502,7 +502,7 @@ def Tokuyama_coefficient(self, name='t'):
t = R.gen(0)
if not self.is_strict():
return R.zero()
return (t+1)**(self.number_of_special_entries()) * t**(self.number_of_boxes())
return (t + 1)**self.number_of_special_entries() * t**self.number_of_boxes()

@combinatorial_map(order=2, name='Bender-Knuth involution')
def bender_knuth_involution(self, i) -> GelfandTsetlinPattern:
Expand Down Expand Up @@ -703,15 +703,16 @@ def __contains__(self, gt):
if self._n is not None and len(gt) != self._n:
return False
# Check if it has the correct maximum value
if self._k is not None and any( val > self._k for row in gt for val in row ):
if self._k is not None and any(val > self._k for row in gt
for val in row):
return False
# Check if it is a GT pattern
if not all( gt[i-1][j] >= gt[i][j] >= gt[i-1][j+1]
for i in range(1, len(gt)) for j in range(len(gt[i])) ):
if not all(gt[i-1][j] >= gt[i][j] >= gt[i-1][j+1]
for i in range(1, len(gt)) for j in range(len(gt[i]))):
return False
# Check if it is strict if applicable
if self._strict and any( gt[i][j] == gt[i][j-1] for i in range(len(gt))
for j in range(1, len(gt[i])) ):
if self._strict and any(gt[i][j] == gt[i][j-1] for i in range(len(gt))
for j in range(1, len(gt[i]))):
return False
return True

Expand Down Expand Up @@ -965,7 +966,7 @@ def _top_row_iter(self, n):
continue
# If it would create an invalid entry, backstep
if (pos > 0 and (row[pos] >= row[pos-1]
or (self._strict and row[pos] == row[pos-1]-1)) ) \
or (self._strict and row[pos] == row[pos-1]-1))) \
or (self._k is not None and row[pos] >= self._k):
row[pos] = -1
pos -= 1
Expand Down Expand Up @@ -1052,8 +1053,7 @@ def _toggle_markov_chain(self, chain_state, row, col, direction):
sage: G._toggle_markov_chain(state, 0, 2, 0)
sage: state
[[4, 2, 0], [3, 2], [2]]

"""
"""
if direction == 1:
upbound = self._k
if row != 0:
Expand Down Expand Up @@ -1130,8 +1130,7 @@ def _cftp(self, start_row):
True
"""
from sage.misc.randstate import current_randstate
from sage.misc.randstate import seed
from sage.misc.randstate import random
from sage.misc.randstate import seed, random

count = self._n * self._k
seedlist = [(current_randstate().long_seed(), count)]
Expand All @@ -1148,7 +1147,8 @@ def _cftp(self, start_row):
direction = random() % 2
self._toggle_markov_chain(upper, row, col, direction)
self._toggle_markov_chain(lower, row, col, direction)
if all(all(x == y for x, y in zip(l1, l2)) for l1, l2 in zip(upper, lower)):
if all(x == y for l1, l2 in zip(upper, lower)
for x, y in zip(l1, l2)):
break
count = seedlist[0][1] * 2
seedlist.insert(0, (current_randstate().long_seed(), count))
Expand Down Expand Up @@ -1283,7 +1283,7 @@ def __iter__(self):
[[4, 2, 1], [4, 2], [4]]]
"""
# If we enforce strictness, check to see if a specified top row is strict
if self._strict and any(self._row[i] == self._row[i+1] for i in range(self._n-1)):
if self._strict and any(self._row[i] == self._row[i + 1] for i in range(self._n - 1)):
return
if self._n == 0:
yield self.element_class(self, [])
Expand All @@ -1292,8 +1292,8 @@ def __iter__(self):
yield self.element_class(self, [list(self._row)])
return
# Setup the first row
iters = [None]*self._n
ret = [None]*self._n
iters = [None] * self._n
ret = [None] * self._n
ret[0] = list(self._row)
min_pos = 1
iters[1] = self._row_iter(ret[0])
Expand All @@ -1307,7 +1307,7 @@ def __iter__(self):
yield self.element_class(self, ret[:])
pos -= 1
continue
iters[pos] = self._row_iter(ret[pos-1])
iters[pos] = self._row_iter(ret[pos - 1])
except StopIteration:
pos -= 1

Expand Down Expand Up @@ -1358,12 +1358,12 @@ def Tokuyama_formula(self, name='t'):
0
"""
n = self._n
variables = [name] + ["x%d" % i for i in range(1, n+1)]
variables = [name] + ["x%d" % i for i in range(1, n + 1)]
R = PolynomialRing(ZZ, names=variables)
t = R.gen(0)
x = R.gens()[1:]
GT = GelfandTsetlinPatterns(top_row=self._row, strict=True)
return sum((t+1)**(gt.number_of_special_entries()) * t**(gt.number_of_boxes()) * prod(x[i]**gt.weight()[i] for i in range(n)) for gt in GT)
return sum((t + 1)**gt.number_of_special_entries() * t**gt.number_of_boxes() * prod(x[i]**gt.weight()[i] for i in range(n)) for gt in GT)

def _cftp_upper(self) -> list:
"""
Expand Down
3 changes: 2 additions & 1 deletion src/sage/combinat/path_tableaux/frieze.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,8 @@ def is_integral(self):
"""
n = len(self)
cd = CylindricalDiagram(self).diagram
return all(all(k in ZZ for k in a[i+1:n+i-2]) for i, a in enumerate(cd))
return all(k in ZZ for i, a in enumerate(cd)
for k in a[i + 1:n + i - 2])

def triangulation(self):
r"""
Expand Down
4 changes: 2 additions & 2 deletions src/sage/combinat/path_tableaux/semistandard.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def is_skew(self):
"""
return bool(self[0])

def is_integral(self):
def is_integral(self) -> bool:
"""
Return ``True`` if all entries are non-negative integers.

Expand All @@ -259,7 +259,7 @@ def is_integral(self):
sage: path_tableaux.SemistandardPathTableau([[],[3],[3,-2]]).is_integral()
False
"""
return all(all(i in NN for i in a) for a in self)
return all(i in NN for a in self for i in a)

def local_rule(self, i):
r"""
Expand Down
9 changes: 5 additions & 4 deletions src/sage/combinat/plane_partition.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def check(self):
ValueError: entries not all integers

"""
if not all(all(a in ZZ for a in b) for b in self):
if not all(a in ZZ for b in self for a in b):
raise ValueError("entries not all integers")
for row in self:
if not all(c >= 0 for c in row):
Expand Down Expand Up @@ -1374,7 +1374,7 @@ def __contains__(self, pp):
if isinstance(pp, (list, tuple)):
if not pp:
return True
if not all(all(a in ZZ for a in b) for b in pp):
if not all(a in ZZ for b in pp for a in b):
return False
for row in pp:
if not all(c >= 0 for c in row):
Expand Down Expand Up @@ -1852,7 +1852,8 @@ def to_poset(self):
def comp(x, y):
return all(a <= b for a, b in zip(x, y))

pl = [(x, y, z) for x in range(a) for y in range(x+1) for z in range(c)]
pl = [(x, y, z) for x in range(a) for y in range(x + 1)
for z in range(c)]
from sage.combinat.posets.posets import Poset
return Poset((pl, comp))

Expand Down Expand Up @@ -2048,7 +2049,7 @@ def comp2(x, y):
return comp(x, y) or comp(x, (y[2], y[0], y[1])) or comp(x, (y[1], y[2], y[0]))

pl = [(x, y, z) for x in range(a) for y in range(b) for z in range(x, c)
if y <= z and (x != z or y == x)]
if y <= z and (x != z or y == x)]
from sage.combinat.posets.posets import Poset
return Poset((pl, comp2))

Expand Down
15 changes: 14 additions & 1 deletion src/sage/combinat/ribbon_shaped_tableau.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,27 @@ def __classcall_private__(cls, rows):

sage: RibbonShapedTableau([[2,3],[1,4,5]])
[[None, None, 2, 3], [1, 4, 5]]

TESTS::

sage: RibbonShapedTableau([4,5])
Traceback (most recent call last):
...
TypeError: rows must be lists of positive integers

sage: RibbonShapedTableau([[2,3],[-4,5]])
Traceback (most recent call last):
...
TypeError: r must be a list of positive integers
"""
try:
r = [tuple(r) for r in rows]
except TypeError:
raise TypeError("rows must be lists of positive integers")
if not r:
return StandardRibbonShapedTableaux()(r)
if all(all(j is None or (isinstance(j, (int, Integer)) and j>0) for j in i) for i in r):
if all(j is None or (isinstance(j, (int, Integer)) and j > 0)
for i in r for j in i):
return StandardRibbonShapedTableaux()(r)
raise TypeError("r must be a list of positive integers")

Expand Down
9 changes: 4 additions & 5 deletions src/sage/combinat/symmetric_group_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -1339,14 +1339,13 @@ def rsw_shuffling_element(self, k):
sage: def test_rsw_comm(n):
....: QSn = SymmetricGroupAlgebra(QQ, n)
....: rsws = [QSn.rsw_shuffling_element(k) for k in range(2, n)]
....: return all( all( rsws[i] * rsws[j] == rsws[j] * rsws[i]
....: for j in range(i) )
....: for i in range(len(rsws)) )
....: return all(ri * rsws[j] == rsws[j] * ri
....: for i, ri in enumerate(rsws) for j in range(i))
sage: test_rsw_comm(3)
True
sage: test_rsw_comm(4)
sage: test_rsw_comm(4) # long time
True
sage: test_rsw_comm(5) # long time
sage: test_rsw_comm(5) # not tested
True

.. NOTE::
Expand Down
4 changes: 2 additions & 2 deletions src/sage/geometry/fan_morphism.py
Original file line number Diff line number Diff line change
Expand Up @@ -1393,8 +1393,8 @@ def is_injective(self):
return prod(self.factor()[1:]).is_injective()
# Now we know that underlying lattice morphism is bijective.
Sigma = self.domain_fan()
return all(all(self.image_cone(sigma).dim() == d for sigma in Sigma(d))
for d in range(1, Sigma.dim() + 1))
return all(self.image_cone(sigma).dim() == d
for d in range(1, Sigma.dim() + 1) for sigma in Sigma(d))

@cached_method
def is_surjective(self):
Expand Down
6 changes: 3 additions & 3 deletions src/sage/geometry/polyhedron/base_ZZ.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,14 +511,14 @@ def polar(self):
if not self.has_IP_property():
raise ValueError('The polytope must have the IP property.')

vertices = tuple( ieq.A()/ieq.b() for
ieq in self.inequality_generator() )
vertices = tuple(ieq.A() / ieq.b() for
ieq in self.inequality_generator())

ieqs = ((1,) + tuple(v[:]) for v in self.vertices())

pref_rep = 'Hrep' if self.n_vertices() <= self.n_inequalities() else 'Vrep'

if all( all(v_i in ZZ for v_i in v) for v in vertices):
if all(v_i in ZZ for v in vertices for v_i in v):
parent = self.parent()
vertices = (v.change_ring(ZZ) for v in vertices)
else:
Expand Down
Loading