Skip to content

Commit

Permalink
Trac #28314: fixing a few calls of all(list)
Browse files Browse the repository at this point in the history
for efficiency ; mostly in the doc

URL: https://trac.sagemath.org/28314
Reported by: chapoton
Ticket author(s): Frédéric Chapoton
Reviewer(s): Travis Scrimshaw
  • Loading branch information
Release Manager committed Aug 7, 2019
2 parents 41ec91a + cf68d2a commit b945d46
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 34 deletions.
10 changes: 5 additions & 5 deletions src/sage/manifolds/differentiable/tensorfield.py
Original file line number Diff line number Diff line change
Expand Up @@ -2848,15 +2848,15 @@ def contract(self, *args):
Check 1: components with respect to the manifold's default
frame (``eU``)::
sage: all([bool(s[i,j] == sum(a[i,k]*b[k,j] for k in M.irange()))
....: for j in M.irange()] for i in M.irange())
sage: all(bool(s[i,j] == sum(a[i,k]*b[k,j] for k in M.irange()))
....: for i in M.irange() for j in M.irange())
True
Check 2: components with respect to the frame ``eV``::
sage: all([bool(s[eV,i,j] == sum(a[eV,i,k]*b[eV,k,j]
....: for k in M.irange()))
....: for j in M.irange()] for i in M.irange())
sage: all(bool(s[eV,i,j] == sum(a[eV,i,k]*b[eV,k,j]
....: for k in M.irange()))
....: for i in M.irange() for j in M.irange())
True
Instead of the explicit call to the method :meth:`contract`, one
Expand Down
22 changes: 11 additions & 11 deletions src/sage/rings/finite_rings/integer_mod.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1131,7 +1131,7 @@ cdef class IntegerMod_abstract(FiniteRingElement):
[406444, 406444, 406444, 406444, 406444, 406444, 406444, 406444]
sage: v = R(169).sqrt(all=True); min(v), -max(v), len(v)
(13, 13, 104)
sage: all([x^2==169 for x in v])
sage: all(x^2 == 169 for x in v)
True
::
Expand Down Expand Up @@ -2895,7 +2895,7 @@ cdef class IntegerMod_int(IntegerMod_abstract):
[406444, 406444, 406444, 406444, 406444, 406444, 406444, 406444]
sage: v = R(169).sqrt(all=True); min(v), -max(v), len(v)
(13, 13, 104)
sage: all([x^2==169 for x in v])
sage: all(x^2 == 169 for x in v)
True
Modulo a power of 2::
Expand Down Expand Up @@ -3899,9 +3899,9 @@ cpdef square_root_mod_prime(IntegerMod_abstract a, p=None):
::
sage: from sage.rings.finite_rings.integer_mod import square_root_mod_prime # sqrt() uses brute force for small p
sage: all([square_root_mod_prime(a*a)^2 == a*a
....: for p in prime_range(100)
....: for a in Integers(p)])
sage: all(square_root_mod_prime(a*a)^2 == a*a
....: for p in prime_range(100)
....: for a in Integers(p))
True
"""
if not a or a.is_one():
Expand Down Expand Up @@ -3985,9 +3985,9 @@ def lucas_q1(mm, IntegerMod_abstract P):
TESTS::
sage: from sage.rings.finite_rings.integer_mod import lucas_q1
sage: all([lucas_q1(k, a) == BinaryRecurrenceSequence(a, -1, 2, a)(k)
....: for a in Integers(23)
....: for k in range(13)])
sage: all(lucas_q1(k, a) == BinaryRecurrenceSequence(a, -1, 2, a)(k)
....: for a in Integers(23)
....: for k in range(13))
True
"""
if mm == 0:
Expand Down Expand Up @@ -4053,8 +4053,8 @@ def lucas(k, P, Q=1, n=None):
sage: p = randint(0,100000)
sage: q = randint(0,100000)
sage: n = randint(0,100)
sage: all([lucas(k,p,q,n)[0] == Mod(lucas_number2(k,p,q),n)
....: for k in Integers(20)])
sage: all(lucas(k,p,q,n)[0] == Mod(lucas_number2(k,p,q),n)
....: for k in Integers(20))
True
sage: from sage.rings.finite_rings.integer_mod import lucas
sage: p = randint(0,100000)
Expand Down Expand Up @@ -4201,7 +4201,7 @@ cdef class IntegerMod_to_IntegerMod(IntegerMod_hom):
sage: [type(R(0)) for R in Rs]
[<type 'sage.rings.finite_rings.integer_mod.IntegerMod_int'>, <type 'sage.rings.finite_rings.integer_mod.IntegerMod_int'>, <type 'sage.rings.finite_rings.integer_mod.IntegerMod_int64'>, <type 'sage.rings.finite_rings.integer_mod.IntegerMod_int64'>, <type 'sage.rings.finite_rings.integer_mod.IntegerMod_gmp'>, <type 'sage.rings.finite_rings.integer_mod.IntegerMod_gmp'>]
sage: fs = [IntegerMod_to_IntegerMod(S, R) for R in Rs for S in Rs if S is not R and S.order() > R.order()]
sage: all([f(-1) == f.codomain()(-1) for f in fs])
sage: all(f(-1) == f.codomain()(-1) for f in fs)
True
sage: [f(-1) for f in fs]
[2, 2, 2, 2, 2, 728, 728, 728, 728, 177146, 177146, 177146, 43046720, 43046720, 10460353202]
Expand Down
2 changes: 1 addition & 1 deletion src/sage/rings/function_field/constructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def create_object(self,version,key,**extra_args):
k = base_field.constant_field()
if k.is_finite(): # then we are in positive characteristic
# irreducible and separable
if f.is_irreducible() and not all([e % k.characteristic() == 0 for e in f.exponents()]):
if f.is_irreducible() and not all(e % k.characteristic() == 0 for e in f.exponents()):
# monic and integral
if f.is_monic() and all(e in base_field.maximal_order() for e in f.coefficients()):
return function_field.FunctionField_global_integral(f, names)
Expand Down
2 changes: 1 addition & 1 deletion src/sage/rings/function_field/function_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -1326,7 +1326,7 @@ def monic_integral_model(self, names=None):
to_ret = self.hom( [L_to_ret(to_L(k.gen())) for k in self._intermediate_fields(self.rational_function_field())] )
return ret, from_ret, to_ret
else:
if self.polynomial().is_monic() and all([c.denominator().is_one() for c in self.polynomial()]):
if self.polynomial().is_monic() and all(c.denominator().is_one() for c in self.polynomial()):
# self is already monic and integral
if names is None or names == ():
names = (self.variable_name(),)
Expand Down
20 changes: 10 additions & 10 deletions src/sage/rings/integer.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -882,25 +882,25 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement):
sage: ilist = [-4r,-1r,0r,1r,2r,5r]
sage: llist = [-12345678901234567890123456788r, 12345678901234567890123456788r, 12345678901234567890123456900r]
sage: flist = [-21.8r, -1.2r, -.000005r, 0.0r, .999999r, 1000000000000.0r]
sage: all([(a < b) == (RR(a) < RR(b)) for (a, b) in zip(Ilist, ilist)])
sage: all((a < b) == (RR(a) < RR(b)) for (a, b) in zip(Ilist, ilist))
True
sage: all([(a > b) == (RR(a) > RR(b)) for (a, b) in zip(Ilist, ilist)])
sage: all((a > b) == (RR(a) > RR(b)) for (a, b) in zip(Ilist, ilist))
True
sage: all([(a == b) == (RR(a) == RR(b)) for (a, b) in zip(Ilist, ilist)])
sage: all((a == b) == (RR(a) == RR(b)) for (a, b) in zip(Ilist, ilist))
True
sage: all([(a <= b) == (RR(a) <= RR(b)) for (a, b) in zip(Ilist, ilist)])
sage: all((a <= b) == (RR(a) <= RR(b)) for (a, b) in zip(Ilist, ilist))
True
sage: all([(a >= b) == (RR(a) >= RR(b)) for (a, b) in zip(Ilist, ilist)])
sage: all((a >= b) == (RR(a) >= RR(b)) for (a, b) in zip(Ilist, ilist))
True
sage: all([(a != b) == (RR(a) != RR(b)) for (a, b) in zip(Ilist, ilist)])
sage: all((a != b) == (RR(a) != RR(b)) for (a, b) in zip(Ilist, ilist))
True
sage: all([(a < b) == (RR(a) < RR(b)) for (a, b) in zip(Ilist, llist)])
sage: all((a < b) == (RR(a) < RR(b)) for (a, b) in zip(Ilist, llist))
True
sage: all([(a > b) == (RR(a) > RR(b)) for (a, b) in zip(Ilist, llist)])
sage: all((a > b) == (RR(a) > RR(b)) for (a, b) in zip(Ilist, llist))
True
sage: all([(a < b) == (RR(a) < RR(b)) for (a, b) in zip(Ilist, flist)])
sage: all((a < b) == (RR(a) < RR(b)) for (a, b) in zip(Ilist, flist))
True
sage: all([(a > b) == (RR(a) > RR(b)) for (a, b) in zip(Ilist, flist)])
sage: all((a > b) == (RR(a) > RR(b)) for (a, b) in zip(Ilist, flist))
True
Verify that :trac:`12149` was fixed (and the fix is consistent
Expand Down
4 changes: 2 additions & 2 deletions src/sage/rings/padics/padic_ZZ_pX_CA_element.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2024,7 +2024,7 @@ cdef class pAdicZZpXCAElement(pAdicZZpXElement):
[a + (2*a^3 + 2*a^2 + 3*a + 4)*5 + (4*a^3 + 3*a^2 + 3*a + 2)*5^2 + (4*a^2 + 2*a + 2)*5^3 + O(5^4), (3*a^3 + 3*a^2 + 2*a + 1) + (a^3 + 4*a^2 + 1)*5 + (a^2 + 4*a + 4)*5^2 + O(5^3), (4*a^3 + 2*a^2 + a + 1) + (2*a^3 + 2*a^2 + 2*a + 4)*5 + O(5^2), (a^3 + a^2 + a + 4) + O(5)]
sage: sum([c * 5^i for i, c in enumerate(E)])
a + O(5^4)
sage: all([c^625 == c for c in E])
sage: all(c^625 == c for c in E)
True
sage: S.<x> = ZZ[]
Expand All @@ -2034,7 +2034,7 @@ cdef class pAdicZZpXCAElement(pAdicZZpXElement):
[1 + O(w^9), 5 + 5*w^3 + w^6 + 4*w^7 + O(w^8), 3 + 3*w^3 + O(w^7), 3 + 3*w^3 + O(w^6), O(w^5), 4 + 5*w^3 + O(w^4), 3 + O(w^3), 6 + O(w^2), 6 + O(w)]
sage: sum([w^i*L[i] for i in range(9)]) == b
True
sage: all([L[i]^(7^3) == L[i] for i in range(9)])
sage: all(L[i]^(7^3) == L[i] for i in range(9))
True
sage: L = W(3).teichmuller_expansion(); L
Expand Down
4 changes: 2 additions & 2 deletions src/sage/rings/padics/padic_ZZ_pX_CR_element.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2901,7 +2901,7 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement):
[a + (2*a^3 + 2*a^2 + 3*a + 4)*5 + (4*a^3 + 3*a^2 + 3*a + 2)*5^2 + (4*a^2 + 2*a + 2)*5^3 + O(5^4), (3*a^3 + 3*a^2 + 2*a + 1) + (a^3 + 4*a^2 + 1)*5 + (a^2 + 4*a + 4)*5^2 + O(5^3), (4*a^3 + 2*a^2 + a + 1) + (2*a^3 + 2*a^2 + 2*a + 4)*5 + O(5^2), (a^3 + a^2 + a + 4) + O(5)]
sage: sum([c * 5^i for i, c in enumerate(E)])
a + O(5^4)
sage: all([c^625 == c for c in E])
sage: all(c^625 == c for c in E)
True
sage: S.<x> = ZZ[]
Expand All @@ -2911,7 +2911,7 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement):
[1 + O(w^9), 5 + 5*w^3 + w^6 + 4*w^7 + O(w^8), 3 + 3*w^3 + O(w^7), 3 + 3*w^3 + O(w^6), O(w^5), 4 + 5*w^3 + O(w^4), 3 + O(w^3), 6 + O(w^2), 6 + O(w)]
sage: sum([w^i*L[i] for i in range(9)]) == b
True
sage: all([L[i]^(7^3) == L[i] for i in range(9)])
sage: all(L[i]^(7^3) == L[i] for i in range(9))
True
sage: L = W(3).teichmuller_expansion(); L
Expand Down
4 changes: 2 additions & 2 deletions src/sage/rings/padics/padic_ZZ_pX_FM_element.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1357,7 +1357,7 @@ cdef class pAdicZZpXFMElement(pAdicZZpXElement):
[a + (2*a^3 + 2*a^2 + 3*a + 4)*5 + (4*a^3 + 3*a^2 + 3*a + 2)*5^2 + (4*a^2 + 2*a + 2)*5^3, (3*a^3 + 3*a^2 + 2*a + 1) + (a^3 + 4*a^2 + 1)*5 + (a^2 + 4*a + 4)*5^2 + (4*a^2 + a + 3)*5^3, (4*a^3 + 2*a^2 + a + 1) + (2*a^3 + 2*a^2 + 2*a + 4)*5 + (3*a^3 + 2*a^2 + a + 1)*5^2 + (a^3 + a^2 + 2)*5^3, (a^3 + a^2 + a + 4) + (3*a^3 + 1)*5 + (3*a^3 + a + 2)*5^2 + (3*a^3 + 3*a^2 + 3*a + 1)*5^3]
sage: sum([c * 5^i for i, c in enumerate(E)])
a
sage: all([c^625 == c for c in E])
sage: all(c^625 == c for c in E)
True
sage: S.<x> = ZZ[]
Expand All @@ -1375,7 +1375,7 @@ cdef class pAdicZZpXFMElement(pAdicZZpXElement):
6 + w^3 + 5*w^7]
sage: sum([w^i*L[i] for i in range(len(L))]) == b
True
sage: all([L[i]^(7^3) == L[i] for i in range(9)])
sage: all(L[i]^(7^3) == L[i] for i in range(9))
True
sage: L = W(3).teichmuller_expansion(); L
Expand Down

0 comments on commit b945d46

Please sign in to comment.