From 6e68bda35776924bee44e934b862540543335731 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Sun, 4 Nov 2018 01:00:56 -0500 Subject: [PATCH] mjo/interpolation.py: use xrange everywhere. --- mjo/interpolation.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/mjo/interpolation.py b/mjo/interpolation.py index dc06107..a5ad78d 100644 --- a/mjo/interpolation.py +++ b/mjo/interpolation.py @@ -18,7 +18,7 @@ def lagrange_denominator(k, xs): The product of all xs[j] with j != k. """ - return product([xs[k] - xs[j] for j in range(0, len(xs)) if j != k]) + return product([xs[k] - xs[j] for j in xrange(len(xs)) if j != k]) def lagrange_coefficient(k, x, xs): @@ -96,8 +96,8 @@ def lagrange_polynomial(x, xs, ys): True """ - ls = [ lagrange_coefficient(k, x, xs) for k in range(0, len(xs)) ] - sigma = sum([ ys[k] * ls[k] for k in range(0, len(xs)) ]) + ls = [ lagrange_coefficient(k, x, xs) for k in xrange(len(xs)) ] + sigma = sum([ ys[k] * ls[k] for k in xrange(len(xs)) ]) return sigma @@ -161,7 +161,7 @@ def divided_difference_coefficients(xs): [1/2/pi^2, -1/pi^2, 1/2/pi^2] """ - coeffs = [ QQ(1)/lagrange_denominator(k, xs) for k in range(0, len(xs)) ] + coeffs = [ QQ(1)/lagrange_denominator(k, xs) for k in xrange(len(xs)) ] return coeffs @@ -253,7 +253,7 @@ def newton_polynomial(x, xs, ys): N = SR(0) - for k in range(0, degree+1): + for k in xrange(degree+1): term = divided_difference(xs[:k+1], ys[:k+1]) term *= lagrange_psi(x, xs[:k]) N += term @@ -347,10 +347,10 @@ def hermite_interpolant(x, xs, ys, y_primes): """ s1 = sum([ ys[k] * hermite_coefficient(k, x, xs) - for k in range(0, len(xs)) ]) + for k in xrange(len(xs)) ]) s2 = sum([ y_primes[k] * hermite_deriv_coefficient(k, x, xs) - for k in range(0, len(xs)) ]) + for k in xrange(len(xs)) ]) return (s1 + s2) -- 2.44.2