From 8698debba196d8746c1a32d8e6866085b6cb2161 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Sat, 7 Dec 2019 18:15:29 -0500 Subject: [PATCH] mjo: replace xrange() with range() for python-3.x compatibility. --- mjo/cone/doubly_nonnegative.py | 4 +-- mjo/cone/faces.py | 4 +-- mjo/cone/permutation_invariant.py | 4 +-- mjo/cone/rearrangement.py | 14 +++++------ mjo/cone/schur.py | 4 +-- mjo/eja/eja_algebra.py | 42 +++++++++++++++---------------- mjo/eja/eja_element.py | 2 +- mjo/interpolation.py | 14 +++++------ mjo/matrix_vector.py | 6 ++--- mjo/orthogonal_polynomials.py | 6 ++--- mjo/symbol_sequence.py | 6 ++--- 11 files changed, 53 insertions(+), 53 deletions(-) diff --git a/mjo/cone/doubly_nonnegative.py b/mjo/cone/doubly_nonnegative.py index a30a827..43a2f61 100644 --- a/mjo/cone/doubly_nonnegative.py +++ b/mjo/cone/doubly_nonnegative.py @@ -371,8 +371,8 @@ def is_extreme_doubly_nonnegative(A): # whenever we come across an index pair `$(i,j)$` with # `$A_{ij} = 0$`. spanning_set = [] - for j in xrange(A.ncols()): - for i in xrange(j): + for j in range(A.ncols()): + for i in range(j): if A[i,j] == 0: M = A.matrix_space() S = X.transpose() * (stdE(M,i,j) + stdE(M,j,i)) * X diff --git a/mjo/cone/faces.py b/mjo/cone/faces.py index 74b58c7..acd9802 100644 --- a/mjo/cone/faces.py +++ b/mjo/cone/faces.py @@ -53,7 +53,7 @@ def face_generated_by(K,S): sage: set_random_seed() sage: K = random_cone(max_ambient_dim=8, max_rays=10) - sage: S = ( K.random_element() for idx in xrange(5) ) + sage: S = ( K.random_element() for idx in range(5) ) sage: F = face_generated_by(K, S) sage: F.is_face_of(K) True @@ -62,7 +62,7 @@ def face_generated_by(K,S): sage: set_random_seed() sage: K = random_cone(max_ambient_dim=8, max_rays=10) - sage: S = ( K.random_element() for idx in xrange(5) ) + sage: S = ( K.random_element() for idx in range(5) ) sage: F = face_generated_by(K, S) sage: all(F.contains(x) for x in S) True diff --git a/mjo/cone/permutation_invariant.py b/mjo/cone/permutation_invariant.py index 1c72565..faa39f7 100644 --- a/mjo/cone/permutation_invariant.py +++ b/mjo/cone/permutation_invariant.py @@ -59,8 +59,8 @@ def is_permutation_invariant(K): The rearrangement cone is permutation-invariant:: sage: all( is_permutation_invariant(rearrangement_cone(p,n)) - ....: for n in xrange(3, 6) - ....: for p in xrange(1, n) ) + ....: for n in range(3, 6) + ....: for p in range(1, n) ) True As is the nonnegative orthant:: diff --git a/mjo/cone/rearrangement.py b/mjo/cone/rearrangement.py index fa232bc..c65316e 100644 --- a/mjo/cone/rearrangement.py +++ b/mjo/cone/rearrangement.py @@ -83,8 +83,8 @@ def rearrangement_cone(p,n,lattice=None): [Jeong]_ Proposition 5.2.1:: sage: all( rearrangement_cone(p,n).is_proper() - ....: for n in xrange(10) - ....: for p in xrange(1, n) ) + ....: for n in range(10) + ....: for p in range(1, n) ) True The Lyapunov rank of the rearrangement cone of order ``p`` in ``n`` @@ -92,12 +92,12 @@ def rearrangement_cone(p,n,lattice=None): by [Jeong]_ Corollary 5.2.4:: sage: all( rearrangement_cone(p,n).lyapunov_rank() == n - ....: for n in xrange(2, 10) + ....: 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 xrange(3, 10) - ....: for p in xrange(2, n-1) ) + ....: for n in range(3, 10) + ....: for p in range(2, n-1) ) True TESTS: @@ -123,8 +123,8 @@ def rearrangement_cone(p,n,lattice=None): ....: rearrangement_cone(p,n).random_element(), ....: p ....: ) - ....: for n in xrange(2, 10) - ....: for p in xrange(1, n-1) + ....: for n in range(2, 10) + ....: for p in range(1, n-1) ....: ) True diff --git a/mjo/cone/schur.py b/mjo/cone/schur.py index d9371fb..edf282d 100644 --- a/mjo/cone/schur.py +++ b/mjo/cone/schur.py @@ -69,7 +69,7 @@ def schur_cone(n, lattice=None): sage: n = ZZ.random_element(10) sage: K = schur_cone(n).dual() sage: x = K.random_element() - sage: all( x[i] >= x[i+1] for i in xrange(n-1) ) + sage: all( x[i] >= x[i+1] for i in range(n-1) ) True TESTS: @@ -84,7 +84,7 @@ def schur_cone(n, lattice=None): sage: set_random_seed() sage: def majorized_by(x,y): ....: return (all(sum(x[0:i]) <= sum(y[0:i]) - ....: for i in xrange(x.degree()-1)) + ....: for i in range(x.degree()-1)) ....: and sum(x) == sum(y)) sage: n = ZZ.random_element(10) sage: V = VectorSpace(QQ, n) diff --git a/mjo/eja/eja_algebra.py b/mjo/eja/eja_algebra.py index 0f2b655..dfb15c6 100644 --- a/mjo/eja/eja_algebra.py +++ b/mjo/eja/eja_algebra.py @@ -407,7 +407,7 @@ class FiniteDimensionalEuclideanJordanAlgebra(CombinatorialFreeModule): S = PolynomialRing(S, R.variable_names()) t = S(t) - return sum( a[k]*(t**k) for k in xrange(len(a)) ) + return sum( a[k]*(t**k) for k in range(len(a)) ) def inner_product(self, x, y): @@ -493,7 +493,7 @@ class FiniteDimensionalEuclideanJordanAlgebra(CombinatorialFreeModule): """ M = list(self._multiplication_table) # copy - for i in xrange(len(M)): + for i in range(len(M)): # M had better be "square" M[i] = [self.monomial(i)] + M[i] M = [["*"] + list(self.gens())] + M @@ -765,7 +765,7 @@ class FiniteDimensionalEuclideanJordanAlgebra(CombinatorialFreeModule): True """ - return tuple( self.random_element() for idx in xrange(count) ) + return tuple( self.random_element() for idx in range(count) ) def rank(self): @@ -944,8 +944,8 @@ class RealCartesianProductEJA(FiniteDimensionalEuclideanJordanAlgebra, """ def __init__(self, n, field=QQ, **kwargs): V = VectorSpace(field, n) - mult_table = [ [ V.gen(i)*(i == j) for j in xrange(n) ] - for i in xrange(n) ] + mult_table = [ [ V.gen(i)*(i == j) for j in range(n) ] + for i in range(n) ] fdeja = super(RealCartesianProductEJA, self) return fdeja.__init__(field, mult_table, rank=n, **kwargs) @@ -1099,9 +1099,9 @@ class MatrixEuclideanJordanAlgebra(FiniteDimensionalEuclideanJordanAlgebra): V = VectorSpace(field, dimension**2) W = V.span_of_basis( _mat2vec(s) for s in basis ) n = len(basis) - mult_table = [[W.zero() for j in xrange(n)] for i in xrange(n)] - for i in xrange(n): - for j in xrange(n): + mult_table = [[W.zero() for j in range(n)] for i in range(n)] + for i in range(n): + for j in range(n): mat_entry = (basis[i]*basis[j] + basis[j]*basis[i])/2 mult_table[i][j] = W.coordinate_vector(_mat2vec(mat_entry)) @@ -1272,8 +1272,8 @@ class RealSymmetricEJA(RealMatrixEuclideanJordanAlgebra, KnownRankEJA): # The basis of symmetric matrices, as matrices, in their R^(n-by-n) # coordinates. S = [] - for i in xrange(n): - for j in xrange(i+1): + for i in range(n): + for j in range(i+1): Eij = matrix(field, n, lambda k,l: k==i and l==j) if i == j: Sij = Eij @@ -1403,8 +1403,8 @@ class ComplexMatrixEuclideanJordanAlgebra(MatrixEuclideanJordanAlgebra): # Go top-left to bottom-right (reading order), converting every # 2-by-2 block we see to a single complex element. elements = [] - for k in xrange(n/2): - for j in xrange(n/2): + for k in range(n/2): + for j in range(n/2): submat = M[2*k:2*k+2,2*j:2*j+2] if submat[0,0] != submat[1,1]: raise ValueError('bad on-diagonal submatrix') @@ -1555,8 +1555,8 @@ class ComplexHermitianEJA(ComplexMatrixEuclideanJordanAlgebra, KnownRankEJA): # * The diagonal will (as a result) be real. # S = [] - for i in xrange(n): - for j in xrange(i+1): + for i in range(n): + for j in range(i+1): Eij = matrix(F, n, lambda k,l: k==i and l==j) if i == j: Sij = cls.real_embed(Eij) @@ -1693,8 +1693,8 @@ class QuaternionMatrixEuclideanJordanAlgebra(MatrixEuclideanJordanAlgebra): # 4-by-4 block we see to a 2-by-2 complex block, to a 1-by-1 # quaternion block. elements = [] - for l in xrange(n/4): - for m in xrange(n/4): + for l in range(n/4): + for m in range(n/4): submat = ComplexMatrixEuclideanJordanAlgebra.real_unembed( M[4*l:4*l+4,4*m:4*m+4] ) if submat[0,0] != submat[1,1].conjugate(): @@ -1846,8 +1846,8 @@ class QuaternionHermitianEJA(QuaternionMatrixEuclideanJordanAlgebra, # * The diagonal will (as a result) be real. # S = [] - for i in xrange(n): - for j in xrange(i+1): + for i in range(n): + for j in range(i+1): Eij = matrix(Q, n, lambda k,l: k==i and l==j) if i == j: Sij = cls.real_embed(Eij) @@ -1914,9 +1914,9 @@ class JordanSpinEJA(FiniteDimensionalEuclideanJordanAlgebra, KnownRankEJA): """ def __init__(self, n, field=QQ, **kwargs): V = VectorSpace(field, n) - mult_table = [[V.zero() for j in xrange(n)] for i in xrange(n)] - for i in xrange(n): - for j in xrange(n): + mult_table = [[V.zero() for j in range(n)] for i in range(n)] + for i in range(n): + for j in range(n): x = V.gen(i) y = V.gen(j) x0 = x[0] diff --git a/mjo/eja/eja_element.py b/mjo/eja/eja_element.py index b7061bf..f78af25 100644 --- a/mjo/eja/eja_element.py +++ b/mjo/eja/eja_element.py @@ -1315,7 +1315,7 @@ class FiniteDimensionalEuclideanJordanAlgebraElement(IndexedFreeModuleElement): # will be minimal for some natural number s... s = 0 minimal_dim = J.dimension() - for i in xrange(1, minimal_dim): + for i in range(1, minimal_dim): this_dim = (u**i).operator().matrix().image().dimension() if this_dim < minimal_dim: minimal_dim = this_dim diff --git a/mjo/interpolation.py b/mjo/interpolation.py index d3b406a..25fb11f 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 xrange(len(xs)) if j != k ) + return product( xs[k] - xs[j] for j in range(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 xrange(len(xs)) ] - return sum( ys[k] * ls[k] for k in xrange(len(xs)) ) + ls = [ lagrange_coefficient(k, x, xs) for k in range(len(xs)) ] + return sum( ys[k] * ls[k] for k in range(len(xs)) ) @@ -160,7 +160,7 @@ def divided_difference_coefficients(xs): [1/2/pi^2, -1/pi^2, 1/2/pi^2] """ - return [ ~lagrange_denominator(k, xs) for k in xrange(len(xs)) ] + return [ ~lagrange_denominator(k, xs) for k in range(len(xs)) ] def divided_difference(xs, ys): @@ -248,7 +248,7 @@ def newton_polynomial(x, xs, ys): """ return sum( divided_difference(xs[:k+1], ys[:k+1])*lagrange_psi(x, xs[:k]) - for k in xrange(len(xs)) ) + for k in range(len(xs)) ) def hermite_coefficient(k, x, xs): @@ -337,10 +337,10 @@ def hermite_interpolant(x, xs, ys, y_primes): """ s1 = sum( ys[k] * hermite_coefficient(k, x, xs) - for k in xrange(len(xs)) ) + for k in range(len(xs)) ) s2 = sum( y_primes[k] * hermite_deriv_coefficient(k, x, xs) - for k in xrange(len(xs)) ) + for k in range(len(xs)) ) return (s1 + s2) diff --git a/mjo/matrix_vector.py b/mjo/matrix_vector.py index 2a0e9e8..111712b 100644 --- a/mjo/matrix_vector.py +++ b/mjo/matrix_vector.py @@ -33,7 +33,7 @@ def isomorphism(matrix_space): sage: M = MatrixSpace(QQ,4,4) sage: (p, p_inv) = isomorphism(M) - sage: m = M(xrange(16)) + sage: m = M(range(16)) sage: p_inv(p(m)) == m True @@ -148,8 +148,8 @@ def matrix_of_transformation(T, V): return L(x) entries = [] - for j in xrange(n): - for i in xrange(n): + for j in range(n): + for i in range(n): entry = inner_product(apply(T,B[i]), B[j]) entries.append(entry) diff --git a/mjo/orthogonal_polynomials.py b/mjo/orthogonal_polynomials.py index 7544f65..15c6956 100644 --- a/mjo/orthogonal_polynomials.py +++ b/mjo/orthogonal_polynomials.py @@ -79,7 +79,7 @@ def legendre_p(n, x, a = -1, b = 1): ....: 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) ] + sage: legendre_basis = [ legendre_p(k, x, a, b) for k in range(4) ] sage: proj = project(legendre_basis, f) sage: proj.simplify_trig() 5/2*(7*(pi^2 - 15)*x^3 - 3*(pi^4 - 21*pi^2)*x)/pi^6 @@ -89,7 +89,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 range(20) ) # long time True We can evaluate the result of the zeroth polynomial:: @@ -193,6 +193,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 range(n+1) )/(2**n) return P diff --git a/mjo/symbol_sequence.py b/mjo/symbol_sequence.py index 3878b75..563bab6 100644 --- a/mjo/symbol_sequence.py +++ b/mjo/symbol_sequence.py @@ -38,7 +38,7 @@ class SymbolSequence: degree:: sage: a = SymbolSequence('a') - sage: p = sum( a[i]*x^i for i in xrange(5) ) + sage: p = sum( a[i]*x^i for i in range(5) ) sage: p a_4*x^4 + a_3*x^3 + a_2*x^2 + a_1*x + a_0 @@ -57,7 +57,7 @@ class SymbolSequence: a_0_1_2 sage: latex(a[0,1,2]) a_{0}_{1}_{2} - sage: [ a[i,j] for i in xrange(2) for j in xrange(2) ] + sage: [ a[i,j] for i in range(2) for j in range(2) ] [a_0_0, a_0_1, a_1_0, a_1_1] You can pass slices instead of integers to obtain a list of @@ -284,7 +284,7 @@ class SymbolSequence: # If the user asks for a slice, we'll be returning a list # of symbols. return [ self._subscript_integer_(idx) - for idx in xrange(start, s.stop, step) ] + for idx in range(start, s.stop, step) ] -- 2.44.2