Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Convert code to Python3.
Browse files Browse the repository at this point in the history
  • Loading branch information
tscrim committed Feb 28, 2021
1 parent 1c1fdf1 commit d6e1201
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 131 deletions.
6 changes: 3 additions & 3 deletions src/sage/combinat/multivariate_polynomials/all.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from multivariate_polynomials import MultivariatePolynomialAlgebra
#from double_multivariate_polynomials import DoubleMultivariatePolynomialAlgebra
from bases import SchubertPolynomialsOnVectors, DemazurePolynomials, DemazureHatPolynomials, GrothendieckPolynomials
from .multivariate_polynomials import MultivariatePolynomialAlgebra
#from .double_multivariate_polynomials import DoubleMultivariatePolynomialAlgebra
from .bases import SchubertPolynomialsOnVectors, DemazurePolynomials, DemazureHatPolynomials, GrothendieckPolynomials
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from sage.rings.integer import Integer
from sage.structure.unique_representation import UniqueRepresentation

from basis import PolynomialRingWithBasis, FinitePolynomialRingWithBasis, MonomialKeyWrapper
from .basis import PolynomialRingWithBasis, FinitePolynomialRingWithBasis, MonomialKeyWrapper

from sage.rings.integer_ring import ZZ
from sage.rings.rational_field import QQ
Expand Down Expand Up @@ -159,7 +159,7 @@ def divided_difference_on_basis(self,key):
as_key = key.ambient_space_element()
n = as_key.scalar(ambient_space.simple_coroot(i))
if n >= 0:
return self._module.sum_of_monomials((key.parent()(as_key-(j)*ambient_space.simple_root(i)-ambient_space.basis()[i-1]) for j in xrange(n)))
return self._module.sum_of_monomials((key.parent()(as_key-(j)*ambient_space.simple_root(i)-ambient_space.basis()[i-1]) for j in range(n)))
else:
return -self.divided_difference_on_basis(key.parent()(ambient_space.simple_reflection(i)(as_key)))

Expand Down Expand Up @@ -193,7 +193,7 @@ def si_on_basis(self, key):
@cached_method
def hecke_generator_on_basis(self, key):
if(self._module.group_type() != "A"):
raise NotImplementedError, "The hecke algebra operator is only implemented in type A"%()
raise NotImplementedError("the hecke algebra operator is only implemented in type A")
pi = self.isobaric_divided_difference_on_basis
res1 = pi(key) * (self._t1 + self._t2)
res2 = self._module(key)
Expand Down Expand Up @@ -267,7 +267,7 @@ def product_on_basis(self, key1, key2):
sage: # Fix a nice example
"""
return self.term( self._basis_keys(tuple(key1[i]+key2[i] for i in xrange(len(key1)))) )
return self.term( self._basis_keys(tuple(key1[i]+key2[i] for i in range(len(key1)))) )

def _to_monomial_on_basis(self, key):
r"""
Expand Down Expand Up @@ -380,5 +380,5 @@ def __invert__(self):
vect = l[0][0]
coef = l[0][1]
return coef**-1 * self.parent()( tuple(-v for v in vect) )
raise ValueError,"%s is not invertible in %s"%(self, self.parent())
raise ValueError("%s is not invertible in %s"%(self, self.parent()))

2 changes: 1 addition & 1 deletion src/sage/combinat/multivariate_polynomials/bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# http://www.gnu.org/licenses/
#*****************************************************************************

from multivariate_polynomials import MultivariatePolynomialAlgebra
from .multivariate_polynomials import MultivariatePolynomialAlgebra

def SchubertPolynomialsOnVectors(R, basis_name = None, basis_repr= "Y", **keywords):
r"""
Expand Down
102 changes: 51 additions & 51 deletions src/sage/combinat/multivariate_polynomials/basis.py

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
from sage.categories.morphism import SetMorphism
from sage.misc.cachefunc import cached_method
from sage.misc.misc_c import prod
from multivariate_polynomials import MultivariatePolynomialAlgebra
from basis import PolynomialRingWithBasis
from linear_basis_on_vectors import LinearBasisOnVectors, FiniteLinearBasisOnVectors
from .multivariate_polynomials import MultivariatePolynomialAlgebra
from .basis import PolynomialRingWithBasis
from .linear_basis_on_vectors import LinearBasisOnVectors, FiniteLinearBasisOnVectors

class DoubleMultivariatePolynomialAlgebra(MultivariatePolynomialAlgebra):
"""r
Expand Down Expand Up @@ -307,21 +307,21 @@ def __init__(self, abstract_polynomial_ring, ambient_space_basis, basis_name, ba

def cmp(self, key1, key2):
l = len(key1.parent()._basis_keys)
for i in xrange(l-1,-1,-1):
for i in range(l-1,-1,-1):
if (key1[i]>key2[i]):
return 1
if (key1[i]<key2[i]):
return -1
return 0

def on_basis_method(self, x, basis, call_back):
for i in xrange( len( x ) - 1 ):
for i in range( len( x ) - 1 ):
if( x[i]<x[i+1] ):
x[i], x[i+1] = x[i+1]+1, x[i]
return call_back(x).divided_difference(i+1)
basex = basis
basey = basex.basis_tower().equivalent_basis(basex.base_ring())
return prod( [basex.var(i+1) - basey.var(j+1) for i in xrange(len(x)) for j in xrange(x[i])], basex.one())
return prod( [basex.var(i+1) - basey.var(j+1) for i in range(len(x)) for j in range(x[i])], basex.one())



Expand Down Expand Up @@ -354,16 +354,16 @@ def __init__(self, abstract_polynomial_ring, ambient_space_basis, basis_name, ba


def on_basis_method(self, x, basis, call_back):
for i in xrange( len( x ) - 1 ):
for i in range( len( x ) - 1 ):
if( x[i]<x[i+1] ):
x[i], x[i+1] = x[i+1]+1, x[i]
return call_back(x).isobaric_divided_difference(i+1)
prod = basis.one()
basex = basis
basey = basex.basis_tower().equivalent_basis(basex.base_ring())
for i in xrange(len(x)):
for i in range(len(x)):
inv_x_i = basex.var(i+1)**(-1)
for j in xrange(x[i]):
for j in range(x[i]):
prod *= (basis.one() - basey.var(j+1) * inv_x_i)
return prod

Expand Down Expand Up @@ -424,7 +424,7 @@ def isobaric_divided_difference_on_basis(self, key):
"""
i = self._i
if(key[i-1] > key[i]):
key2 = [key[j] for j in xrange(self._module.nb_variables())]
key2 = [key[j] for j in range(self._module.nb_variables())]
key2[i-1], key2[i] = key2[i], key2[i-1]-1
return self._module(key2)
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from sage.combinat.sf.sf import SymmetricFunctions
from sage.structure.unique_representation import UniqueRepresentation

from basis import PolynomialRingWithBasisFromMorphism, FinitePolynomialRingWithBasisFromMorphism, PolynomialRingWithBasis
from .basis import PolynomialRingWithBasisFromMorphism, FinitePolynomialRingWithBasisFromMorphism, PolynomialRingWithBasis

class LinearBasisOnVectors(PolynomialRingWithBasisFromMorphism):
r"""
Expand All @@ -45,9 +45,11 @@ def __init__(self, abstract_polynomial_ring, monomial_basis_with_type, basis_nam
self._monomial_basis_with_type = monomial_basis_with_type
get_morphism_on_basis = self._get_morphism_on_basis

if(not keywords.has_key("triangular")): keywords["triangular"] = "upper"
if(not keywords["triangular"] is None):
if(not keywords.has_key("key")): keywords["key"] = self._basis_key
if "triangular" not in keywords:
keywords["triangular"] = "upper"
if keywords["triangular"] is not None:
if "key" not in keywords:
keywords["key"] = self._basis_key
self._keywords = keywords

self._extra_parameters = {}
Expand All @@ -69,7 +71,7 @@ def __init__(self, abstract_polynomial_ring, monomial_basis_with_type, basis_nam

def _basis_key(self, vec):
l = len(vec)
d = sum( [vec[i] for i in xrange(l)])
d = sum( [vec[i] for i in range(l)])
return (-d, tuple(reversed(vec)))

def _get_basis_keys(self, n):
Expand Down Expand Up @@ -146,9 +148,9 @@ def morphism_on_list(self, x):

@cached_method
def morphism_on_basis(self, key):
x = [key[i] for i in xrange(self._basis.nb_variables())]
x = [key[i] for i in range(self._basis.nb_variables())]
if(self._on_basis_method is None):
raise NotImplementedError,"No compute method has been implemented"%()
raise NotImplementedError("no compute method has been implemented")
else:
if (len(self._parameters)==0):
return self._on_basis_method(x, self._basis, self._call_back)
Expand Down Expand Up @@ -188,7 +190,7 @@ def equivalent_basis(self, abstract_polynomial_ring):


def on_basis_method(self, x, basis, call_back):
for i in xrange( len( x ) - 1 ):
for i in range( len( x ) - 1 ):
if( x[i]<x[i+1] ):
x[i], x[i+1] = x[i+1]+1, x[i]
return call_back(x).divided_difference(i+1)
Expand Down Expand Up @@ -227,8 +229,8 @@ def from_partition(self,part,nb_variables = None):
nb_variables = len(part)
if(nb_variables< len(part)):
return self(0)
key = [0 for i in xrange(nb_variables)]
for i in xrange(len(part)): key[i] = part[i]
key = [0 for i in range(nb_variables)]
for i in range(len(part)): key[i] = part[i]
key.reverse()
return self(key)

Expand Down Expand Up @@ -307,7 +309,7 @@ def divided_difference_on_basis(self,key):
"""
i = self._i
if(key[i-1] > key[i]):
key2 = [key[j] for j in xrange(len(key))]
key2 = [key[j] for j in range(len(key))]
key2[i-1], key2[i] = key2[i], key2[i-1]-1
return self._module(key2)
return self._module.zero()
Expand Down Expand Up @@ -342,7 +344,7 @@ def equivalent_basis(self, abstract_polynomial_ring):
return abstract_polynomial_ring.grothendieck_positive_basis_on_vectors(self.group_type())

def on_basis_method(self, x, basis, call_back):
for i in xrange( len( x ) - 1 ):
for i in range( len( x ) - 1 ):
if( x[i]<x[i+1] ):
x[i], x[i+1] = x[i+1]+1, x[i]
res = call_back(x)
Expand Down Expand Up @@ -383,12 +385,12 @@ def equivalent_basis(self, abstract_polynomial_ring):
return abstract_polynomial_ring.grothendieck_negative_basis_on_vectors(self.group_type())

def on_basis_method(self, x, basis, call_back):
for i in xrange( len( x ) - 1 ):
for i in range( len( x ) - 1 ):
if( x[i]<x[i+1] ):
x[i], x[i+1] = x[i+1]+1, x[i]
return call_back(x).isobaric_divided_difference(i+1)
prod = basis.one()
for i in xrange(len(x)):
for i in range(len(x)):
inv_x_i = basis.var(i+1)**(-1)
prod *= (basis.one() - inv_x_i)**x[i]
return prod
Expand Down Expand Up @@ -449,7 +451,7 @@ def isobaric_divided_difference_on_basis(self, key):
"""
i = self._i
if(key[i-1] > key[i]):
key2 = [key[j] for j in xrange(self._module.nb_variables())]
key2 = [key[j] for j in range(self._module.nb_variables())]
key2[i-1], key2[i] = key2[i], key2[i-1]-1
return self._module(key2)
else:
Expand Down Expand Up @@ -538,20 +540,20 @@ def equivalent_basis(self, abstract_polynomial_ring):

def _basis_key(self, vec):
l = len(vec.parent()._basis_keys)
d = sum( [vec[i] for i in xrange(l) ] )
d = sum( [vec[i] for i in range(l) ] )
return (d, tuple(sorted(vec,reverse=True)), tuple(vec))


def on_basis_method(self, u, basis, call_back, t1=1, t2=1, q=1):
size = len(u)
if(u[size-1] != 0):
temp = u[size-1]
for i in xrange(size-1,0,-1): u[i] = u[i-1]
for i in range(size-1,0,-1): u[i] = u[i-1]
u[0] = temp-1

res = call_back(u)

p = [i+2 for i in xrange(size)]
p = [i+2 for i in range(size)]
p[size-1] = 1
p = Permutation( p )
res = res.perm_vars(p)
Expand All @@ -560,15 +562,15 @@ def on_basis_method(self, u, basis, call_back, t1=1, t2=1, q=1):
res*= basis.var(size) - (-t2)**(size-1)
return res

for i in xrange(size-1):
for i in range(size-1):
if(u[i] > u[i+1]):
u[i], u[i+1] = u[i+1], u[i]
res = call_back(u)

res1 = res.hecke_generator(i+1,t1, t2)
w = Word( [u[j] for j in xrange(size-1,-1,-1) ] )
w = Word( [u[j] for j in range(size-1,-1,-1) ] )
p = w.standard_permutation()
u_spec = [ q**(u[j])*(-t1/t2)**(p(size-j) -1) for j in xrange(size) ]
u_spec = [ q**(u[j])*(-t1/t2)**(p(size-j) -1) for j in range(size) ]
res2 = res * (t1 + t2)/(u_spec[i+1]/u_spec[i] -1)
return res1 + res2

Expand Down Expand Up @@ -640,7 +642,7 @@ def equivalent_basis(self, abstract_polynomial_ring):
def on_basis_method(self, x, basis, call_back, method = "isobaric_divided_difference"):
otype = basis.group_type()
if(otype=="D"):
for i in xrange( len(x) - 1):
for i in range( len(x) - 1):
if( x[i]<x[i+1] ):
x[i], x[i+1] = x[i+1], x[i]
return getattr(call_back(x), method)(i+1)
Expand All @@ -650,7 +652,7 @@ def on_basis_method(self, x, basis, call_back, method = "isobaric_divided_differ
return getattr(call_back(x),method)(i+2)
return basis(x)
else:
for i in xrange( len( x ) - 1 ):
for i in range( len( x ) - 1 ):
if( x[i]<x[i+1] ):
x[i], x[i+1] = x[i+1], x[i]
return getattr(call_back(x), method)(i+1)
Expand Down
4 changes: 2 additions & 2 deletions src/sage/combinat/multivariate_polynomials/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def __init__(self, length):
sage: # Fix a nice test
"""
self._length = length
CombinatorialFreeModule.__init__(self, QQ, xrange(length))
CombinatorialFreeModule.__init__(self, QQ, range(length))

def __getitem__(self, x):
r"""
Expand Down Expand Up @@ -68,7 +68,7 @@ def coeffs_to_list(self):
sage: # Fix a nice test
"""
return [ self[i] for i in xrange(self.parent().length()) ]
return [ self[i] for i in range(self.parent().length()) ]

def _repr_(self):
r"""
Expand Down
Loading

0 comments on commit d6e1201

Please sign in to comment.