From: Michael Orlitzky Date: Sun, 4 Nov 2018 06:15:07 +0000 (-0500) Subject: orthogonal_polynomials.py: use generator expressions where applicable. X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=df1756fe92d7967f005e96bf5b036f05fabb966a;p=sage.d.git orthogonal_polynomials.py: use generator expressions where applicable. --- diff --git a/mjo/orthogonal_polynomials.py b/mjo/orthogonal_polynomials.py index fd5fd75..589aa80 100644 --- a/mjo/orthogonal_polynomials.py +++ b/mjo/orthogonal_polynomials.py @@ -78,8 +78,8 @@ def legendre_p(n, x, a = -1, b = 1): ... return sqrt(inner_product(v,v)) ... sage: def project(basis, v): - ... return sum([ inner_product(v, b)*b/norm(b)**2 - ... for b in basis]) + ... return sum( inner_product(v, b)*b/norm(b)**2 + ... for b in basis) ... sage: f = sin(x) sage: legendre_basis = [ legendre_p(k, x, a, b) for k in xrange(4) ] @@ -92,7 +92,7 @@ def legendre_p(n, x, a = -1, b = 1): We should agree with Maxima for all `n`:: sage: eq = lambda k: bool(legendre_p(k,x) == legendre_P(k,x)) - sage: all([eq(k) for k in xrange(20) ]) # long time + sage: all( eq(k) for k in xrange(20) ) # long time True We can evaluate the result of the zeroth polynomial:: @@ -196,6 +196,6 @@ def legendre_p(n, x, a = -1, b = 1): # From Abramowitz & Stegun, (22.3.2) with alpha = beta = 0. # Also massaged to support finite field elements. - P = sum([ c(m)*g(m) for m in xrange(n+1) ])/(2**n) + P = sum( c(m)*g(m) for m in xrange(n+1) )/(2**n) return P