Skip to content

Commit 3a7528f

Browse files
Release Managervbraun
Release Manager
authored andcommitted
Trac #23337: Use variable names instead of symbolic variables
Where possible, use {{{QQ["x"]}}} instead of {{{QQ[x]}}} to construct polynomial rings. After #10483, the latter will be deprecated. URL: https://trac.sagemath.org/23337 Reported by: jdemeyer Ticket author(s): Simon King, Ralf Stephan, Jeroen Demeyer Reviewer(s): Jeroen Demeyer, Travis Scrimshaw
2 parents e4c0af6 + ee4548f commit 3a7528f

23 files changed

+54
-43
lines changed

src/sage/combinat/ncsf_qsym/qsym.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ def from_polynomial(self, f, check=True):
691691
if I not in z:
692692
z[I] = c
693693
out = self.Monomial()._from_dict(z)
694-
if check and out.expand(f.parent().ngens(), f.parent().gens()) != f:
694+
if check and out.expand(f.parent().ngens(), f.parent().variable_names()) != f:
695695
raise ValueError("%s is not a quasi-symmetric polynomial" % f)
696696
return out
697697

src/sage/combinat/root_system/root_lattice_realization_algebras.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -256,13 +256,13 @@ def demazure_operators(self):
256256
This is indeed a Schur function::
257257
258258
sage: s = SymmetricFunctions(QQ).s()
259-
sage: s[2,1].expand(3, P.gens())
259+
sage: s[2,1].expand(3, P.variable_names())
260260
x^2*y + x*y^2 + x^2*z + 2*x*y*z + y^2*z + x*z^2 + y*z^2
261261
262262
Let us check this systematically on Schur functions of degree 6::
263263
264264
sage: for p in Partitions(6, max_length=3).list():
265-
....: assert s.monomial(p).expand(3, P.gens()) == pi0(KL.monomial(L(tuple(p)))).expand(P.gens())
265+
....: assert s.monomial(p).expand(3, P.variable_names()) == pi0(KL.monomial(L(tuple(p)))).expand(P.gens())
266266
267267
We check systematically that these operators satisfy the Iwahori-Hecke algebra relations::
268268

src/sage/combinat/sf/monomial.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def from_polynomial(self, f, check=True):
174174
out = self.sum_of_terms((Partition(e), c)
175175
for (e,c) in six.iteritems(f.dict())
176176
if tuple(sorted(e)) == tuple(reversed(e)))
177-
if check and out.expand(f.parent().ngens(),f.parent().gens()) != f:
177+
if check and out.expand(f.parent().ngens(),f.parent().variable_names()) != f:
178178
raise ValueError("%s is not a symmetric polynomial"%f)
179179
return out
180180

src/sage/combinat/subset.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1144,7 +1144,7 @@ def generating_serie(self,variable='x'):
11441144
sage: l = [1,1,1,1,2,2,3]
11451145
sage: for k in range(len(l)):
11461146
....: S = Subsets(l,k,submultiset=True)
1147-
....: print(S.generating_serie(x) == S.cardinality()*x**k)
1147+
....: print(S.generating_serie('x') == S.cardinality()*x**k)
11481148
True
11491149
True
11501150
True

src/sage/functions/piecewise.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,7 @@ def critical_points(cls, self, parameters, variable):
873873
True
874874
"""
875875
from sage.calculus.calculus import maxima
876-
x = QQ[self.default_variable()].gen()
876+
x = self.default_variable()
877877
crit_pts = []
878878
for domain, f in parameters:
879879
for interval in domain:

src/sage/matrix/compute_J_ideal.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ def lifting(p, t, A, G):
195195

196196

197197
DX = A.parent().base()
198-
(X,) = DX.gens()
198+
(X,) = DX.variable_names()
199199
D = DX.base_ring()
200200
d = A.ncols()
201201
c = A.nrows()

src/sage/matrix/matrix2.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1647,7 +1647,7 @@ cdef class Matrix(Matrix1):
16471647
# resulted in further exceptions/ errors.
16481648
from sage.symbolic.ring import is_SymbolicExpressionRing
16491649

1650-
var = R('A0123456789') if is_SymbolicExpressionRing(R) else 'x'
1650+
var = 'A0123456789' if is_SymbolicExpressionRing(R) else 'x'
16511651
try:
16521652
c = self.charpoly(var, algorithm="df")[0]
16531653
except ValueError:

src/sage/matrix/matrix_symbolic_dense.pyx

+4
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,10 @@ cdef class Matrix_symbolic_dense(Matrix_generic_dense):
386386
"""
387387
Compute the characteristic polynomial of self, using maxima.
388388
389+
INPUT:
390+
391+
- ``var`` - (default: 'x') name of variable of charpoly
392+
389393
EXAMPLES::
390394
391395
sage: M = matrix(SR, 2, 2, var('a,b,c,d'))

src/sage/misc/latex.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1905,7 +1905,7 @@ def __call__(self, x, combine_all=False):
19051905
sage: from sage.misc.latex import MathJax
19061906
sage: MathJax()(3)
19071907
<html><script type="math/tex; mode=display">\newcommand{\Bold}[1]{\mathbf{#1}}3</script></html>
1908-
sage: str(MathJax().eval(ZZ[x], mode='display')) == str(MathJax()(ZZ[x]))
1908+
sage: str(MathJax().eval(ZZ['x'], mode='display')) == str(MathJax()(ZZ['x']))
19091909
True
19101910
"""
19111911
return self.eval(x, combine_all=combine_all)

src/sage/modules/free_module_element.pyx

+4-4
Original file line numberDiff line numberDiff line change
@@ -2803,28 +2803,28 @@ cdef class FreeModuleElement(Vector): # abstract base class
28032803
28042804
sage: parent(vector(QQ,[1,2,3,4]).pairwise_product(vector(ZZ['x'],[1,2,3,4])))
28052805
Ambient free module of rank 4 over the principal ideal domain Univariate Polynomial Ring in x over Rational Field
2806-
sage: parent(vector(ZZ[x],[1,2,3,4]).pairwise_product(vector(QQ,[1,2,3,4])))
2806+
sage: parent(vector(ZZ['x'],[1,2,3,4]).pairwise_product(vector(QQ,[1,2,3,4])))
28072807
Ambient free module of rank 4 over the principal ideal domain Univariate Polynomial Ring in x over Rational Field
28082808
28092809
::
28102810
28112811
sage: parent(vector(QQ,[1,2,3,4]).pairwise_product(vector(ZZ['x']['y'],[1,2,3,4])))
28122812
Ambient free module of rank 4 over the integral domain Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field
2813-
sage: parent(vector(ZZ[x][y],[1,2,3,4]).pairwise_product(vector(QQ,[1,2,3,4])))
2813+
sage: parent(vector(ZZ['x']['y'],[1,2,3,4]).pairwise_product(vector(QQ,[1,2,3,4])))
28142814
Ambient free module of rank 4 over the integral domain Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field
28152815
28162816
::
28172817
28182818
sage: parent(vector(QQ['x'],[1,2,3,4]).pairwise_product(vector(ZZ['x']['y'],[1,2,3,4])))
28192819
Ambient free module of rank 4 over the integral domain Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field
2820-
sage: parent(vector(ZZ[x][y],[1,2,3,4]).pairwise_product(vector(QQ['x'],[1,2,3,4])))
2820+
sage: parent(vector(ZZ['x']['y'],[1,2,3,4]).pairwise_product(vector(QQ['x'],[1,2,3,4])))
28212821
Ambient free module of rank 4 over the integral domain Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field
28222822
28232823
::
28242824
28252825
sage: parent(vector(QQ['y'],[1,2,3,4]).pairwise_product(vector(ZZ['x']['y'],[1,2,3,4])))
28262826
Ambient free module of rank 4 over the integral domain Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field
2827-
sage: parent(vector(ZZ[x][y],[1,2,3,4]).pairwise_product(vector(QQ['y'],[1,2,3,4])))
2827+
sage: parent(vector(ZZ['x']['y'],[1,2,3,4]).pairwise_product(vector(QQ['y'],[1,2,3,4])))
28282828
Ambient free module of rank 4 over the integral domain Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field
28292829
28302830
::

src/sage/numerical/interactive_simplex_method.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4116,7 +4116,7 @@ def add_row(self, nonbasic_coefficients, constant, basic_variable=None):
41164116
basic_variable = str(basic_variable)
41174117

41184118
R = PolynomialRing(
4119-
BR, list(B.base_ring().gens()) + [basic_variable], order="neglex")
4119+
BR, list(B.base_ring().variable_names()) + [basic_variable], order="neglex")
41204120
B = list(B) + [basic_variable]
41214121
B = map(R, B)
41224122
N = map(R, N)

src/sage/rings/complex_arb.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ Automatic coercions work as expected::
104104
105105
TESTS::
106106
107-
sage: polygen(CBF, x)^3
107+
sage: polygen(CBF, 'x')^3
108108
x^3
109109
110110
::

src/sage/rings/ideal.py

+10-8
Original file line numberDiff line numberDiff line change
@@ -963,9 +963,10 @@ def category(self):
963963
964964
EXAMPLES::
965965
966+
sage: P.<x> = ZZ[]
966967
sage: I = ZZ.ideal(7)
967-
sage: J = ZZ[x].ideal(7,x)
968-
sage: K = ZZ[x].ideal(7)
968+
sage: J = P.ideal(7,x)
969+
sage: K = P.ideal(7)
969970
sage: I.category()
970971
Category of ring ideals in Integer Ring
971972
sage: J.category()
@@ -1140,7 +1141,7 @@ def __repr__(self):
11401141
11411142
EXAMPLES::
11421143
1143-
sage: R = ZZ[x]
1144+
sage: R.<x> = ZZ[]
11441145
sage: I = R.ideal(x)
11451146
sage: I # indirect doctest
11461147
Principal ideal (x) of Univariate Polynomial Ring in x over Integer Ring
@@ -1158,7 +1159,7 @@ def is_principal(self):
11581159
Note that Sage automatically coerces ideals into
11591160
principal ideals during initialization::
11601161
1161-
sage: R = ZZ[x]
1162+
sage: R.<x> = ZZ[]
11621163
sage: I = R.ideal(x)
11631164
sage: J = R.ideal(2,x)
11641165
sage: K = R.base_extend(QQ).ideal(2,x)
@@ -1196,7 +1197,7 @@ def gen(self):
11961197
Note that the generator belongs to the ring from which the ideal
11971198
was initialized::
11981199
1199-
sage: R = ZZ[x]
1200+
sage: R.<x> = ZZ[]
12001201
sage: I = R.ideal(x)
12011202
sage: J = R.base_extend(QQ).ideal(2,x)
12021203
sage: a = I.gen(); a
@@ -1395,8 +1396,9 @@ def gcd(self, other):
13951396
13961397
::
13971398
1399+
sage: R.<x> = ZZ[]
13981400
sage: I = ZZ.ideal(7)
1399-
sage: J = ZZ[x].ideal(7,x)
1401+
sage: J = R.ideal(7,x)
14001402
sage: I.gcd(J)
14011403
Traceback (most recent call last):
14021404
...
@@ -1438,8 +1440,8 @@ def is_prime(self):
14381440
False
14391441
sage: ZZ.ideal(0).is_prime()
14401442
True
1441-
sage: R.<x>=QQ[]
1442-
sage: P=R.ideal(x^2+1); P
1443+
sage: R.<x> = QQ[]
1444+
sage: P = R.ideal(x^2+1); P
14431445
Principal ideal (x^2 + 1) of Univariate Polynomial Ring in x over Rational Field
14441446
sage: P.is_prime()
14451447
True

src/sage/rings/multi_power_series_ring_element.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ class MPowerSeries(PowerSeries):
282282
283283
Convert elements from polynomial rings::
284284
285-
sage: R = PolynomialRing(ZZ,5,T.gens())
285+
sage: R = PolynomialRing(ZZ,5,T.variable_names())
286286
sage: t = R.gens()
287287
sage: r = -t[2]*t[3] + t[3]^2 + t[4]^2
288288
sage: T(r)

src/sage/rings/polynomial/plural.pyx

+2-2
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ cdef class NCPolynomialRing_plural(Ring):
734734
return self._relations_commutative
735735

736736
from sage.algebras.free_algebra import FreeAlgebra
737-
A = FreeAlgebra( self.base_ring(), self.ngens(), self.gens() )
737+
A = FreeAlgebra( self.base_ring(), self.ngens(), self.variable_names() )
738738

739739
res = {}
740740
n = self.ngens()
@@ -748,7 +748,7 @@ cdef class NCPolynomialRing_plural(Ring):
748748
return self._relations
749749

750750
from sage.algebras.free_algebra import FreeAlgebra
751-
A = FreeAlgebra( self.base_ring(), self.ngens(), self.gens() )
751+
A = FreeAlgebra( self.base_ring(), self.ngens(), self.variable_names() )
752752

753753
res = {}
754754
n = self.ngens()

src/sage/rings/polynomial/polynomial_number_field.pyx

+3-2
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,12 @@ class Polynomial_absolute_number_field_dense(Polynomial_generic_dense_field):
102102
103103
EXAMPLES::
104104
105-
sage: f = QQ[I][x].random_element()
105+
sage: P.<x> = QQ[I][]
106+
sage: f = P.random_element()
106107
sage: from sage.rings.polynomial.polynomial_number_field import Polynomial_absolute_number_field_dense
107108
sage: isinstance(f, Polynomial_absolute_number_field_dense)
108109
True
109-
sage: a = QQ[I][x](x)
110+
sage: a = P(x)
110111
sage: a.is_gen()
111112
True
112113
"""

src/sage/rings/qqbar.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4587,7 +4587,7 @@ def _more_precision(self):
45874587
real which isn't the case without calling _ensure_real (see
45884588
:trac:`11728`)::
45894589
4590-
sage: P = AA[x](1+x^4); a1,a2 = P.factor()[0][0],P.factor()[1][0]; a1*a2
4590+
sage: P = AA['x'](1+x^4); a1,a2 = P.factor()[0][0],P.factor()[1][0]; a1*a2
45914591
x^4 + 1.000000000000000?
45924592
sage: a1,a2
45934593
(x^2 - 1.414213562373095?*x + 1, x^2 + 1.414213562373095?*x + 1)

src/sage/rings/quotient_ring.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,9 @@ def QuotientRing(R, I, names=None):
169169
With polynomial rings (note that the variable name of the quotient
170170
ring can be specified as shown below)::
171171
172-
sage: R.<xx> = QuotientRing(QQ[x], QQ[x].ideal(x^2 + 1)); R
172+
sage: P.<x> = QQ[]
173+
sage: R.<xx> = QuotientRing(P, P.ideal(x^2 + 1))
174+
sage: R
173175
Univariate Quotient Polynomial Ring in xx over Rational Field with modulus x^2 + 1
174176
sage: R.gens(); R.gen()
175177
(xx,)
@@ -860,7 +862,8 @@ def is_noetherian(self):
860862
sage: R.is_noetherian()
861863
True
862864
863-
sage: R = QuotientRing(QQ[x], x^2+1)
865+
sage: P.<x> = QQ[]
866+
sage: R = QuotientRing(P, x^2+1)
864867
sage: R.is_noetherian()
865868
True
866869
@@ -898,7 +901,8 @@ def cover_ring(self):
898901
899902
::
900903
901-
sage: Q = QuotientRing(QQ[x], x^2 + 1)
904+
sage: P.<x> = QQ[]
905+
sage: Q = QuotientRing(P, x^2 + 1)
902906
sage: Q.cover_ring()
903907
Univariate Polynomial Ring in x over Rational Field
904908
"""

src/sage/rings/real_arb.pyx

+2-2
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ TESTS::
163163
Full MatrixSpace of 3 by 3 dense matrices over Real ball field
164164
with 53 bits precision
165165
166-
sage: polygen(RBF, x)^3
166+
sage: polygen(RBF, 'x')^3
167167
x^3
168168
169169
::
@@ -374,7 +374,7 @@ class RealBallField(UniqueRepresentation, Field):
374374
375375
::
376376
377-
sage: (1/2*RBF(1)) + AA(sqrt(2)) - 1 + polygen(QQ, x)
377+
sage: (1/2*RBF(1)) + AA(sqrt(2)) - 1 + polygen(QQ, 'x')
378378
x + [0.914213562373095 +/- 4.10e-16]
379379
380380
TESTS::

src/sage/schemes/generic/algebraic_scheme.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -3339,8 +3339,8 @@ def dual(self):
33393339
R = PolynomialRing(K, 'x', n + 1)
33403340
Pd = sage.schemes.projective.projective_space.ProjectiveSpace(n, K, 'y')
33413341
Rd = Pd.coordinate_ring()
3342-
x = R.gens()
3343-
y = Rd.gens()
3342+
x = R.variable_names()
3343+
y = Rd.variable_names()
33443344
S = PolynomialRing(K, x + y + ('t',))
33453345
if S.has_coerce_map_from(I.ring()):
33463346
T = PolynomialRing(K, 'w', n + 1)
@@ -3789,7 +3789,7 @@ def segre_embedding(self, PP=None):
37893789
#create new subscheme
37903790
if PP is None:
37913791
from sage.schemes.projective.projective_space import ProjectiveSpace
3792-
PS = ProjectiveSpace(self.base_ring(), M, R.gens()[AS.ngens():])
3792+
PS = ProjectiveSpace(self.base_ring(), M, R.variable_names()[AS.ngens():])
37933793
Y = PS.subscheme(L)
37943794
else:
37953795
if PP.dimension_relative() != M:

src/sage/schemes/product_projective/space.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1062,7 +1062,7 @@ def segre_embedding(self, PP=None, var='u'):
10621062

10631063
#create new subscheme
10641064
if PP is None:
1065-
PS = ProjectiveSpace(self.base_ring(), M, R.gens()[self.ngens():])
1065+
PS = ProjectiveSpace(self.base_ring(), M, R.variable_names()[self.ngens():])
10661066
Y = PS.subscheme(L)
10671067
else:
10681068
if PP.dimension_relative() != M:

src/sage/schemes/projective/projective_homset.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def points(self, B=0, prec=53):
133133
N = PS.dimension_relative()
134134
BR = X.base_ring()
135135
#need a lexicographic ordering for elimination
136-
R = PolynomialRing(BR, N + 1, PS.gens(), order='lex')
136+
R = PolynomialRing(BR, N + 1, PS.variable_names(), order='lex')
137137
I = R.ideal(X.defining_polynomials())
138138
I0 = R.ideal(0)
139139
#Determine the points through elimination

src/sage/schemes/projective/projective_morphism.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1619,7 +1619,7 @@ def is_morphism(self):
16191619
F.extend(defpolys)
16201620
J = R.ideal(F)
16211621
else:
1622-
S = PolynomialRing(R.base_ring().fraction_field(), R.gens(), R.ngens())
1622+
S = PolynomialRing(R.base_ring().fraction_field(), R.variable_names(), R.ngens())
16231623
L = [S(f) for f in F] + [S(f) for f in defpolys]
16241624
J = S.ideal(L)
16251625
if J.dimension() > 0:
@@ -1798,7 +1798,7 @@ def primes_of_bad_reduction(self, check=True):
17981798
if R.base_ring().is_field():
17991799
J = R.ideal(F)
18001800
else:
1801-
S = PolynomialRing(R.base_ring().fraction_field(), R.gens(), R.ngens())
1801+
S = PolynomialRing(R.base_ring().fraction_field(), R.variable_names(), R.ngens())
18021802
J = S.ideal([S.coerce(F[i]) for i in range(R.ngens())])
18031803
if J.dimension() > 0:
18041804
raise TypeError("not a morphism")
@@ -1807,7 +1807,7 @@ def primes_of_bad_reduction(self, check=True):
18071807

18081808
#move the ideal to the ring of integers
18091809
if R.base_ring().is_field():
1810-
S = PolynomialRing(R.base_ring().ring_of_integers(), R.gens(), R.ngens())
1810+
S = PolynomialRing(R.base_ring().ring_of_integers(), R.variable_names(), R.ngens())
18111811
F = [F[i].change_ring(R.base_ring().ring_of_integers()) for i in range(len(F))]
18121812
J = S.ideal(F)
18131813
else:
@@ -1830,7 +1830,7 @@ def primes_of_bad_reduction(self, check=True):
18301830
if check:
18311831
index = 0
18321832
while index < len(badprimes): #figure out which primes are really bad primes...
1833-
S = PolynomialRing(GF(badprimes[index]), R.gens(), R.ngens())
1833+
S = PolynomialRing(GF(badprimes[index]), R.variable_names(), R.ngens())
18341834
J = S.ideal([S.coerce(F[j]) for j in range(R.ngens())])
18351835
if J.dimension() == 0:
18361836
badprimes.pop(index)

0 commit comments

Comments
 (0)