# 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
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
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
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::
[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``
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:
....: 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
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:
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)
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):
"""
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
True
"""
- return tuple( self.random_element() for idx in xrange(count) )
+ return tuple( self.random_element() for idx in range(count) )
def rank(self):
"""
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)
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))
# 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
# 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')
# * 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)
# 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():
# * 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)
"""
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]
# 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
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):
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)) )
[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):
"""
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):
"""
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)
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
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)
....: 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
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::
# 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
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
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
# 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) ]