From: Michael Orlitzky Date: Sun, 4 Nov 2018 05:24:08 +0000 (-0400) Subject: cone/rearrangement.py: use generator expressions where applicable. X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=1babefcb417eede161345cf016c1c90f53c0ea61;p=sage.d.git cone/rearrangement.py: use generator expressions where applicable. --- diff --git a/mjo/cone/rearrangement.py b/mjo/cone/rearrangement.py index b329381..b2ccfcb 100644 --- a/mjo/cone/rearrangement.py +++ b/mjo/cone/rearrangement.py @@ -52,21 +52,21 @@ def rearrangement_cone(p,n): All rearrangement cones are proper:: - sage: all([ rearrangement_cone(p,n).is_proper() - ....: for n in range(10) - ....: for p in range(n) ]) + sage: all( rearrangement_cone(p,n).is_proper() + ....: for n in range(10) + ....: for p in range(n) ) True The Lyapunov rank of the rearrangement cone of order ``p`` in ``n`` dimensions is ``n`` for ``p == 1`` or ``p == n`` and one otherwise:: - sage: all([ rearrangement_cone(p,n).lyapunov_rank() == n - ....: for n in range(2, 10) - ....: for p in [1, n-1] ]) + sage: all( rearrangement_cone(p,n).lyapunov_rank() == n + ....: for n in range(2, 10) + ....: for p in [1, n-1] ) True - sage: all([ rearrangement_cone(p,n).lyapunov_rank() == 1 - ....: for n in range(3, 10) - ....: for p in range(2, n-1) ]) + sage: all( rearrangement_cone(p,n).lyapunov_rank() == 1 + ....: for n in range(3, 10) + ....: for p in range(2, n-1) ) True TESTS: @@ -77,7 +77,7 @@ def rearrangement_cone(p,n): sage: p = ZZ.random_element(1,n) sage: K = rearrangement_cone(p,n) sage: P = SymmetricGroup(n).random_element().matrix() - sage: all([ K.contains(P*r) for r in K.rays() ]) + sage: all( K.contains(P*r) for r in K ) True """ @@ -132,12 +132,15 @@ def has_rearrangement_property(v, p): Every element of a rearrangement cone should have the property:: - sage: for n in range(2,10): - ....: for p in range(1, n-1): - ....: K = rearrangement_cone(p,n) - ....: v = K.random_element() - ....: if not has_rearrangement_property(v,p): - ....: print(v) + sage: set_random_seed() + sage: all( has_rearrangement_property( + ....: rearrangement_cone(p,n).random_element(), + ....: p + ....: ) + ....: for n in range(2, 10) + ....: for p in range(1, n-1) + ....: ) + True """ components = sorted(v)[0:p]