From 268dadd157251fdf78924324bbf6d7dabefb76f2 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Sun, 4 Nov 2018 00:42:23 -0400 Subject: [PATCH] cone/permutation_invariant.py: use generator expressions where applicable. --- mjo/cone/permutation_invariant.py | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/mjo/cone/permutation_invariant.py b/mjo/cone/permutation_invariant.py index 7aad31e..d87ace2 100644 --- a/mjo/cone/permutation_invariant.py +++ b/mjo/cone/permutation_invariant.py @@ -33,17 +33,12 @@ def random_permutation_invariant_cone(lattice=None, V = K.lattice().vector_space() # The set of all permutatin matrices on ``V``. - Sn = [ p.matrix() for p in SymmetricGroup(V.dimension()) ] + Sn = ( p.matrix() for p in SymmetricGroup(V.dimension()) ) # Set of permuted generators - pgens = [] + pgens = ( permutation*V(g) for permutation in Sn for g in K ) - for g in K.rays(): - for permutation in Sn: - pgens.append(permutation * V(g)) - - L = ToricLattice(V.dimension()) - return Cone(pgens, lattice=L) + return Cone(pgens, K.lattice()) def is_permutation_invariant(K): @@ -60,9 +55,9 @@ def is_permutation_invariant(K): EXAMPLES:: - sage: all([ is_permutation_invariant(rearrangement_cone(p,n)) + sage: all( is_permutation_invariant(rearrangement_cone(p,n)) ....: for n in range(3, 6) - ....: for p in range(1, n) ]) + ....: for p in range(1, n) ) True """ @@ -71,13 +66,8 @@ def is_permutation_invariant(K): V = K.lattice().vector_space() # The set of all permutation matrices on ``V``. - Sn = [ p.matrix() for p in SymmetricGroup(V.dimension()) ] - - for permutation in Sn: - L = ToricLattice(V.dimension()) - permuted_gens = [ permutation * V(g) for g in K.rays() ] - for g in permuted_gens: - if not K.contains(g): - return False + Sn = ( p.matrix() for p in SymmetricGroup(V.dimension()) ) - return True + return all(K.contains(permutation*V(g)) + for g in K + for permutation in Sn) -- 2.43.2