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

Commit 938beb0

Browse files
rwstjdemeyer
authored andcommitted
Trac #10483: deprecate the misuse of symbolic variables as polynomial variable
Also-by: Simon King <[email protected]>
1 parent 51ba1df commit 938beb0

10 files changed

+45
-35
lines changed

src/sage/rings/cfinite_sequence.py

+2
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ def CFiniteSequences(base_ring, names = None, category = None):
160160
names = ['x']
161161
elif len(names)>1:
162162
raise NotImplementedError("Multidimensional o.g.f. not implemented.")
163+
else:
164+
names = [str(names[0])]
163165
if category is None:
164166
category = Fields()
165167
if not(base_ring in (QQ, ZZ)):

src/sage/rings/polynomial/multi_polynomial.pyx

+3-3
Original file line numberDiff line numberDiff line change
@@ -457,12 +457,12 @@ cdef class MPolynomial(CommutativeRingElement):
457457
if R.ngens() <= 1:
458458
return self.univariate_polynomial()
459459

460-
other_vars = Z
461-
del other_vars[ind]
460+
del Z[ind]
461+
other_vars = [str(v) for v in Z]
462462

463463
# Make polynomial ring over all variables except var.
464464
S = R.base_ring()[tuple(other_vars)]
465-
ring = S[var]
465+
ring = S[str(var)]
466466
if not self:
467467
return ring(0)
468468

src/sage/rings/polynomial/multi_polynomial_libsingular.pyx

+4-3
Original file line numberDiff line numberDiff line change
@@ -5436,9 +5436,10 @@ cdef class MPolynomial_libsingular(MPolynomial):
54365436
# Trac ticket #11780: Create the polynomial ring over
54375437
# the integers using the (cached) polynomial ring constructor:
54385438
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
5439-
integer_polynomial_ring = PolynomialRing(ZZ,\
5440-
self.parent().ngens(), self.parent().gens(), order =\
5441-
self.parent().term_order())
5439+
integer_polynomial_ring = PolynomialRing(ZZ,
5440+
self.parent().ngens(),
5441+
self.parent().variable_names(),
5442+
order=self.parent().term_order())
54425443
return integer_polynomial_ring(self * self.denominator())
54435444
else:
54445445
return self * self.denominator()

src/sage/rings/polynomial/multi_polynomial_sequence.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -645,16 +645,16 @@ def algebraic_dependence(self):
645645
"""
646646
R = self.ring()
647647
K = R.base_ring()
648-
Xs = list(R.gens())
648+
Xs = R.variable_names()
649649
r = len(self)
650650
d = len(Xs)
651651

652652
# Expand R by r new variables.
653653
T = 'T'
654-
while T in [str(x) for x in Xs]:
654+
while T in Xs:
655655
T = T+'T'
656656
Ts = [T + str(j) for j in range(r)]
657-
RR = PolynomialRing(K,d+r,tuple(Xs+Ts))
657+
RR = PolynomialRing(K, d+r, Xs+tuple(Ts))
658658
Vs = list(RR.gens())
659659
Xs = Vs[0 :d]
660660
Ts = Vs[d:]
@@ -670,7 +670,7 @@ def algebraic_dependence(self):
670670

671671
# Coerce JJ into `K[T_1,\ldots,T_r]`.
672672
# Choosing the negdeglex order simply because i find it useful in my work.
673-
RRR = PolynomialRing(K,r,tuple(Ts),order='negdeglex')
673+
RRR = PolynomialRing(K, r, RR.variable_names()[d:], order='negdeglex')
674674
return RRR.ideal(JJ.gens())
675675

676676
def coefficient_matrix(self, sparse=True):

src/sage/rings/polynomial/polynomial_ring_constructor.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,14 @@ def PolynomialRing(base_ring, *args, **kwds):
9191
implemented with ``'NTL'`` or ``'FLINT'``; default is ``'FLINT'``).
9292
For many base rings, the ``"singular"`` implementation is available.
9393
94+
REMARK:
95+
96+
In earlier versions of Sage, the names have not necessarily been
97+
strings. Some users provided a symbolic variable instead of a string,
98+
and expected that this symbolic variable is the same as the generator
99+
of the resulting polynomial ring, which is of course not the case.
100+
This common mistake is now deprecated.
101+
94102
.. NOTE::
95103
96104
The following rules were introduced in :trac:`9944`, in order
@@ -426,13 +434,6 @@ def PolynomialRing(base_ring, *args, **kwds):
426434
sage: R.0 == 0
427435
True
428436
429-
We verify that :trac:`13187` is fixed::
430-
431-
sage: var('t')
432-
t
433-
sage: PolynomialRing(ZZ, name=t) == PolynomialRing(ZZ, name='t')
434-
True
435-
436437
We verify that polynomials with interval coefficients from
437438
:trac:`7712` and :trac:`13760` are fixed::
438439

src/sage/rings/quotient_ring.py

+8
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,14 @@ def QuotientRing(R, I, names=None):
139139
- ``names`` -- (optional) a list of strings to be used as names for
140140
the variables in the quotient ring `R/I`.
141141
142+
REMARK:
143+
144+
In earlier versions of Sage, the names have not necessarily been
145+
strings. Some users provided a symbolic variable instead of a string,
146+
and expected that this symbolic variable is the same as the generator
147+
of the resulting quotient ring, which is of course not the case.
148+
This common mistake is now deprecated.
149+
142150
OUTPUT: `R/I` - the quotient ring `R` mod the ideal `I`
143151
144152
ASSUMPTION:

src/sage/schemes/product_projective/wehlerK3.py

+12-14
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ def is_degenerate(self):
741741
R = PP.coordinate_ring()
742742
PS = PP[0] #check for x fibers
743743
vars = list(PS.gens())
744-
R0 = PolynomialRing(K, 3, vars) #for dimension calculation to work,
744+
R0 = PolynomialRing(K, 3, PS.variable_names()) #for dimension calculation to work,
745745
#must be done with Polynomial ring over a field
746746
#Degenerate is equivalent to a common zero, see Prop 1.4 in [CaSi]_
747747
I = R.ideal(self.Gpoly(1, 0), self.Gpoly(1, 1), self.Gpoly(1, 2), self.Hpoly(1, 0, 1),
@@ -752,8 +752,7 @@ def is_degenerate(self):
752752
return True
753753

754754
PS = PP[1] #check for y fibers
755-
vars = list(PS.gens())
756-
R0 = PolynomialRing(K,3,vars) #for dimension calculation to work,
755+
R0 = PolynomialRing(K, 3, PS.variable_names()) #for dimension calculation to work,
757756
#must be done with Polynomial ring over a field
758757
#Degenerate is equivalent to a common zero, see Prop 1.4 in [CaSi]_
759758
I = R.ideal(self.Gpoly(0, 0), self.Gpoly(0, 1), self.Gpoly(0, 2), self.Hpoly(0, 0, 1),
@@ -824,15 +823,15 @@ def degenerate_fibers(self):
824823
PSX = PP[0];
825824
vars = list(PSX.gens())
826825
K = FractionField(PSX.base_ring())
827-
R0 = PolynomialRing(K, 3, vars)
826+
R0 = PolynomialRing(K, 3, PSX.variable_names())
828827
I = R.ideal(self.Gpoly(1, 0), self.Gpoly(1, 1), self.Gpoly(1, 2), self.Hpoly(1, 0,1 ), \
829828
self.Hpoly(1, 0, 2), self.Hpoly(1, 1, 2))
830-
phi = R.hom(vars + [0, 0, 0], R0)
829+
phi = R.hom(list(PSX.gens()) + [0, 0, 0], R0)
831830
I = phi(I)
832831
xFibers = []
833832
#check affine charts
834833
for n in range(3):
835-
affvars = list(R0.gens())
834+
affvars = list(R0.variable_names())
836835
del affvars[n]
837836
R1 = PolynomialRing(K, 2, affvars, order = 'lex')
838837
mapvars = list(R1.gens())
@@ -853,17 +852,16 @@ def degenerate_fibers(self):
853852
if MP not in xFibers:
854853
xFibers.append(MP)
855854
PSY = PP[1]
856-
vars = list(PSY.gens())
857855
K = FractionField(PSY.base_ring())
858-
R0 = PolynomialRing(K, 3, vars)
856+
R0 = PolynomialRing(K, 3, PSY.variable_names())
859857
I = R.ideal(self.Gpoly(0, 0), self.Gpoly(0, 1), self.Gpoly(0, 2), self.Hpoly(0, 0, 1), \
860858
self.Hpoly(0, 0, 2), self.Hpoly(0, 1, 2))
861-
phi = PP.coordinate_ring().hom([0, 0, 0] + vars, R0)
859+
phi = PP.coordinate_ring().hom([0, 0, 0] + list(PSY.gens()), R0)
862860
I = phi(I)
863861
yFibers = []
864862
#check affine charts
865863
for n in range(3):
866-
affvars = list(R0.gens())
864+
affvars = list(R0.variable_names())
867865
del affvars[n]
868866
R1 = PolynomialRing(K, 2, affvars, order = 'lex')
869867
mapvars = list(R1.gens())
@@ -937,7 +935,7 @@ def degenerate_primes(self,check = True):
937935
PSX = PP[0]
938936
vars = list(PSX.gens())
939937
K = PSX.base_ring()
940-
R = PolynomialRing(K, 3, vars)
938+
R = PolynomialRing(K, 3, PSX.variable_names())
941939
I = RR.ideal(self.Gpoly(1, 0), self.Gpoly(1, 1), self.Gpoly(1, 2), self.Hpoly(1, 0, 1),
942940
self.Hpoly(1, 0, 2), self.Hpoly(1, 1, 2))
943941
phi = PP.coordinate_ring().hom(vars + [0, 0, 0], R)
@@ -946,7 +944,7 @@ def degenerate_primes(self,check = True):
946944

947945
#move the ideal to the ring of integers
948946
if R.base_ring().is_field():
949-
S = PolynomialRing(R.base_ring().ring_of_integers(),R.gens(),R.ngens())
947+
S = PolynomialRing(R.base_ring().ring_of_integers(),R.variable_names(),R.ngens())
950948
I = S.ideal(I.gens())
951949
GB = I.groebner_basis()
952950
#get the primes dividing the coefficients of the monomials x_i^k_i
@@ -963,14 +961,14 @@ def degenerate_primes(self,check = True):
963961
PSY = PP[1]
964962
vars = list(PSY.gens())
965963
K = PSY.base_ring()
966-
R = PolynomialRing(K, 3, vars)
964+
R = PolynomialRing(K, 3, PSY.variable_names())
967965
I = RR.ideal(self.Gpoly(0, 0), self.Gpoly(0, 1), self.Gpoly(0, 2), self.Hpoly(0, 0, 1),
968966
self.Hpoly(0, 0, 2), self.Hpoly(0, 1, 2))
969967
phi = PP.coordinate_ring().hom([0, 0, 0] + vars, R)
970968
I = phi(I)
971969
#move the ideal to the ring of integers
972970
if R.base_ring().is_field():
973-
S = PolynomialRing(R.base_ring().ring_of_integers(),R.gens(),R.ngens())
971+
S = PolynomialRing(R.base_ring().ring_of_integers(),R.variable_names(),R.ngens())
974972
I = S.ideal(I.gens())
975973
GB = I.groebner_basis()
976974
#get the primes dividing the coefficients of the monomials x_i^k_i

src/sage/symbolic/expression.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -6734,7 +6734,7 @@ cdef class Expression(CommutativeRingElement):
67346734
nu = ring.SR(self.numerator()).polynomial(base_ring)
67356735
de = ring.SR(self.denominator()).polynomial(base_ring)
67366736
vars = sorted(set(nu.variables() + de.variables()), key=repr)
6737-
R = FractionField(PolynomialRing(base_ring, vars))
6737+
R = FractionField(PolynomialRing(base_ring, list(str(v) for v in vars)))
67386738
return R(self.numerator())/R(self.denominator())
67396739

67406740
def power_series(self, base_ring):

src/sage/symbolic/expression_conversions.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1029,7 +1029,7 @@ def __init__(self, ex, base_ring=None, ring=None):
10291029
self.base_ring = base_ring
10301030
elif base_ring is not None:
10311031
self.base_ring = base_ring
1032-
vars = self.ex.variables()
1032+
vars = [str(x) for x in self.ex.variables()]
10331033
if len(vars) == 0:
10341034
vars = ['x']
10351035
from sage.rings.all import PolynomialRing

src/sage/symbolic/relation.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1007,7 +1007,7 @@ def solve_mod(eqns, modulus, solution_dict = False):
10071007
if modulus < 1:
10081008
raise ValueError("the modulus must be a positive integer")
10091009
vars = list(set(sum([list(e.variables()) for e in eqns], [])))
1010-
vars.sort(key=repr)
1010+
vars.sort(key=str)
10111011

10121012
if modulus == 1: # degenerate case
10131013
ans = [tuple(Integers(1)(0) for v in vars)]
@@ -1119,7 +1119,7 @@ def _solve_mod_prime_power(eqns, p, m, vars):
11191119
for mi in range(m):
11201120
mrunning *= p
11211121
R = Integers(mrunning)
1122-
S = PolynomialRing(R, len(vars), vars)
1122+
S = PolynomialRing(R, len(vars), [str(var) for var in vars])
11231123
eqns_mod = [S(eq) for eq in eqns]
11241124
if mi == 0:
11251125
possibles = cartesian_product_iterator([range(len(R)) for _ in range(len(vars))])

0 commit comments

Comments
 (0)