Polynomial ring extension inconsistencies

58 views
Skip to first unread message

Stefan

unread,
Jan 13, 2017, 9:14:29 PM1/13/17
to sage-devel
Hi all,

Consider the following sequence of constructions:

sage: R = PolynomialRing(ZZ, ['x1', 'x2', 'x3'])
sage: S = PolynomialRing(R, ['x4'])
sage: T = S.extend_variables(['x5', 'x6'])
sage: type(R)
<type 'sage.rings.polynomial.multi_polynomial_libsingular.MPolynomialRing_libsingular'>
sage: type(S)
<class 'sage.rings.polynomial.polynomial_ring.PolynomialRing_integral_domain_with_category'>
sage: type(T)
<class 'sage.rings.polynomial.multi_polynomial_ring.MPolynomialRing_polydict_with_category'>

What I'd like: extend R with a few extra variables. I also have a matrix over R that I'd like to interpret as a matrix over R-with-a-few-extra-variables.
What I get: only the ring S has the method extend_variables. Neither R nor T have it. Why is that? What's the proper way to extend R?

Cheers,

Stefan.

Nils Bruin

unread,
Jan 13, 2017, 10:17:07 PM1/13/17
to sage-devel
On Friday, January 13, 2017 at 6:14:29 PM UTC-8, Stefan wrote:
What I'd like: extend R with a few extra variables. I also have a matrix over R that I'd like to interpret as a matrix over R-with-a-few-extra-variables.
What I get: only the ring S has the method extend_variables. Neither R nor T have it. Why is that? What's the proper way to extend R?

Does this what you want?

sage: R=ZZ['x1','x2','x3']
sage: S=ZZ[R.gens()+('x4','x5')]
sage: M=matrix(R,[1,2,3])
sage: M.change_ring(S)
[1 2 3]

Variable names actually matter in sage, so there is automatically a coercion from R into S.

I would expect that, unless you have particular reasons to construct ZZ['x1','x2','x3']['x4','x5'], you're better off with the flatter version.

I don't see a particular advantage in the "extend_variables" method. I would expect we could just deprecate that without ill effect.
Message has been deleted

Stefan

unread,
Jan 16, 2017, 11:09:59 PM1/16/17
to sage-devel

Does this what you want?

sage: R=ZZ['x1','x2','x3']
sage: S=ZZ[R.gens()+('x4','x5')]
sage: M=matrix(R,[1,2,3])
sage: M.change_ring(S)
[1 2 3]

Variable names actually matter in sage, so there is automatically a coercion from R into S.


That does EXACTLY what I want, but now I run into a bug:

R1 = ZZ['x0','x1']
x = R1(1)
R2 = ZZ[tuple('x'+str(i) for i in range(967))]
y = R2('x0')
x*y

gives a RuntimeError: maximum recursion depth exceeded.

The 967 is the smallest number in the Notebook that gives an error; on the command line the error shows up a little sooner even. 

Stefan

unread,
Jan 16, 2017, 11:17:54 PM1/16/17
to sage-devel

That does EXACTLY what I want, but now I run into a bug:

R1 = ZZ['x0','x1']
x = R1(1)
R2 = ZZ[tuple('x'+str(i) for i in range(967))]
y = R2('x0')
x*y

gives a RuntimeError: maximum recursion depth exceeded.

The 967 is the smallest number in the Notebook that gives an error; on the command line the error shows up a little sooner even. 

This is now Ticket #22194 
Reply all
Reply to author
Forward
0 new messages