Ask Your Question

creating a polynomial ring

asked 2018-03-04 18:30:01 -0500

vincent.beck gravatar image

updated 2018-03-05 03:37:24 -0500

The following code


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

answered 2018-03-05 04:13:46 -0500

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 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
sage: k.parent()
Rational Field
sage: from six import integer_types
sage: isinstance(k, integer_types + (Integer,))

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)


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


Thanks for this very clear explanation !

vincent.beck gravatar imagevincent.beck ( 2018-03-06 15:52:28 -0500 )edit

answered 2018-03-05 00:56:27 -0500

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


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


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

vincent.beck gravatar imagevincent.beck ( 2018-03-05 03:41:26 -0500 )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 05:55:45 -0500 )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


Asked: 2018-03-04 18:30:01 -0500

Seen: 34 times

Last updated: Mar 05