Ask Your Question
2

creating a polynomial ring

asked 2018-03-05 01:30:01 +0100

vincent.beck gravatar image

updated 2018-03-05 10:37:24 +0100

The following code

n=4
k=n*(n-1)/2
L=PolynomialRing(ZZ,"x",k)

produces the following error

if second arguments is a string with no commas, then there must be no other non-optional arguments...

If I replace k by 6 or binomial(n,2) everything works, I cannot understand why. Thanks for any help

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2018-03-05 11:13:46 +0100

tmonteil gravatar image

I did some code investigation and found the following explanation. The changes were introduced in trac ticket 23338, and you can see in the changes made on the polynomial_ring_constructor.py function, that before, your k was tested to be an integer (see the isinstance(arg1, integer_types + (Integer,)) tests), this is why you get an error since your k is a rational, not an integer:

sage: k
6
sage: k.parent()
Rational Field
sage: from six import integer_types
sage: isinstance(k, integer_types + (Integer,))
False

In the recent implementation, your k is transformed into an integer, see k = Integer(arg), this is why your code works on recent versions of Sage.

So, though i encourage you to upgrade your Sage installation, you can also transform your k into an integer:

sage: k = ZZ(n*(n-1)/2)

or

sage: k = Integer(n*(n-1)/2)
edit flag offensive delete link more

Comments

Thanks for this very clear explanation !

vincent.beck gravatar imagevincent.beck ( 2018-03-06 22:52:28 +0100 )edit
2

answered 2018-03-05 07:56:27 +0100

slelievre gravatar image

What version of Sage are you using?

It works for me in Sage 8.2.beta4.

sage: version()
'SageMath version 8.2.beta4, Release Date: 2018-01-27'
sage: n = 4
sage: k = n*(n-1)/2 
sage: L = PolynomialRing(ZZ, k, "x")
sage: L
Multivariate Polynomial Ring in x0, x1, x2, x3, x4, x5 over Integer Ring

What happens if you define k as a integer instead of a rational, as follows?

k = n*(n-1)//2

or

sage: k = binomial(n, 2)
edit flag offensive delete link more

Comments

It works with k=binomial(n,2). My sage version is 7.5.1. Thanks !

vincent.beck gravatar imagevincent.beck ( 2018-03-05 10:41:26 +0100 )edit

The problem is that n*(n-1)/2 returns a rational. Using binomial(n, 2) or n * (n-1) // 2, you get an integer. See @tmonteil's more in-depth explanation.

slelievre gravatar imageslelievre ( 2018-03-05 12:55:45 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2018-03-05 01:30:01 +0100

Seen: 638 times

Last updated: Mar 05 '18