ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 16 May 2013 16:10:45 -0500Exponent overflow in PolynomialRing(): need a work aroundhttp://ask.sagemath.org/question/10102/exponent-overflow-in-polynomialring-need-a-work-around/PolynomialRing() gives an OverflowError for exponents larger than 32768.
For example
sage: R = GF(2**28, 'a')
sage: a = R.gen()
sage: x = PolynomialRing(R, 'x', 4).gens()
sage: f = x[0]**32768
sage: f = x[0]**32769
...
OverflowError: Exponent overflow (32769).
I need to make a function containing `x[0]**(2**28 - 2)`.
How can I get Sage to do that?
I am using Sage Version 5.3, Release Date: 2012-09-08.Wed, 08 May 2013 02:53:01 -0500http://ask.sagemath.org/question/10102/exponent-overflow-in-polynomialring-need-a-work-around/Answer by Volker Braun for <p>PolynomialRing() gives an OverflowError for exponents larger than 32768.
For example</p>
<pre><code>sage: R = GF(2**28, 'a')
sage: a = R.gen()
sage: x = PolynomialRing(R, 'x', 4).gens()
sage: f = x[0]**32768
sage: f = x[0]**32769
...
OverflowError: Exponent overflow (32769).
</code></pre>
<p>I need to make a function containing <code>x[0]**(2**28 - 2)</code>.
How can I get Sage to do that?</p>
<p>I am using Sage Version 5.3, Release Date: 2012-09-08.</p>
http://ask.sagemath.org/question/10102/exponent-overflow-in-polynomialring-need-a-work-around/?answer=14901#post-id-14901See also http://trac.sagemath.org/sage_trac/ticket/11856. You either use less variables so that there is enough space for the bit-packed exponents
sage: R.<x,y> = QQ[]
sage: x**(2**28 - 2)
x^268435454
or you use the symbolic ring. Its not like you have memory for a dense polynomial of that degree anyways...Wed, 08 May 2013 22:59:37 -0500http://ask.sagemath.org/question/10102/exponent-overflow-in-polynomialring-need-a-work-around/?answer=14901#post-id-14901Comment by apeel for <p>See also <a href="http://trac.sagemath.org/sage_trac/ticket/11856">http://trac.sagemath.org/sage_trac/ti...</a>. You either use less variables so that there is enough space for the bit-packed exponents</p>
<pre><code>sage: R.<x,y> = QQ[]
sage: x**(2**28 - 2)
x^268435454
</code></pre>
<p>or you use the symbolic ring. Its not like you have memory for a dense polynomial of that degree anyways...</p>
http://ask.sagemath.org/question/10102/exponent-overflow-in-polynomialring-need-a-work-around/?comment=17678#post-id-17678Thanks. It looks like a fundamental limit arising from the implementation in singular.Thu, 16 May 2013 16:10:45 -0500http://ask.sagemath.org/question/10102/exponent-overflow-in-polynomialring-need-a-work-around/?comment=17678#post-id-17678Answer by ppurka for <p>PolynomialRing() gives an OverflowError for exponents larger than 32768.
For example</p>
<pre><code>sage: R = GF(2**28, 'a')
sage: a = R.gen()
sage: x = PolynomialRing(R, 'x', 4).gens()
sage: f = x[0]**32768
sage: f = x[0]**32769
...
OverflowError: Exponent overflow (32769).
</code></pre>
<p>I need to make a function containing <code>x[0]**(2**28 - 2)</code>.
How can I get Sage to do that?</p>
<p>I am using Sage Version 5.3, Release Date: 2012-09-08.</p>
http://ask.sagemath.org/question/10102/exponent-overflow-in-polynomialring-need-a-work-around/?answer=14894#post-id-14894Maybe there has been some changes in the later versions. It works here in sage-5.9 and sage-5.7 too.
sage: R = GF(2**28, 'a')
sage: a = R.gen()
sage: x = PolynomialRing(R, 'x', 4).gens()
sage: f = x[0]**32768
sage: f = x[0]**32769
sage: f
x0^32769
Wed, 08 May 2013 04:21:06 -0500http://ask.sagemath.org/question/10102/exponent-overflow-in-polynomialring-need-a-work-around/?answer=14894#post-id-14894Answer by tmonteil for <p>PolynomialRing() gives an OverflowError for exponents larger than 32768.
For example</p>
<pre><code>sage: R = GF(2**28, 'a')
sage: a = R.gen()
sage: x = PolynomialRing(R, 'x', 4).gens()
sage: f = x[0]**32768
sage: f = x[0]**32769
...
OverflowError: Exponent overflow (32769).
</code></pre>
<p>I need to make a function containing <code>x[0]**(2**28 - 2)</code>.
How can I get Sage to do that?</p>
<p>I am using Sage Version 5.3, Release Date: 2012-09-08.</p>
http://ask.sagemath.org/question/10102/exponent-overflow-in-polynomialring-need-a-work-around/?answer=14899#post-id-14899Actually, this does not work on sage-5.9 either. apeel seems to use a 32-bit system whereas ppurka seems to use a 64-bit system. On a 64-bit system, you will only be able to go twice further (`65536 = 2^16` instead of `32768 = 2^15`):
sage: f = x[0]**(2^16-1)
sage: f = x[0]**(2^16)
...
OverflowError: Exponent overflow (65536).
If you really need to work with such a big exponent, you could request it on the [trac server](http://trac.sagemath.org/sage_trac) and then on [singular](http://www.singular.uni-kl.de/) as well, though it is possible they won't change this limit due to a possible loss of performance (i didn't check the code, so it might be possible to go until `2^32` without much loss).
If you are looking for a mathematical workaround, you need to give more information on what is your function doing. For example, if you only use the variable `x[0]` in this function, you could try to transform your polynomial `f` as a univariate polynomial, and then work with it:
sage: P = f.univariate_polynomial()
Wed, 08 May 2013 11:05:38 -0500http://ask.sagemath.org/question/10102/exponent-overflow-in-polynomialring-need-a-work-around/?answer=14899#post-id-14899Comment by apeel for <p>Actually, this does not work on sage-5.9 either. apeel seems to use a 32-bit system whereas ppurka seems to use a 64-bit system. On a 64-bit system, you will only be able to go twice further (<code>65536 = 2^16</code> instead of <code>32768 = 2^15</code>):</p>
<pre><code>sage: f = x[0]**(2^16-1)
sage: f = x[0]**(2^16)
...
OverflowError: Exponent overflow (65536).
</code></pre>
<p>If you really need to work with such a big exponent, you could request it on the <a href="http://trac.sagemath.org/sage_trac">trac server</a> and then on <a href="http://www.singular.uni-kl.de/">singular</a> as well, though it is possible they won't change this limit due to a possible loss of performance (i didn't check the code, so it might be possible to go until <code>2^32</code> without much loss).</p>
<p>If you are looking for a mathematical workaround, you need to give more information on what is your function doing. For example, if you only use the variable <code>x[0]</code> in this function, you could try to transform your polynomial <code>f</code> as a univariate polynomial, and then work with it:</p>
<pre><code>sage: P = f.univariate_polynomial()
</code></pre>
http://ask.sagemath.org/question/10102/exponent-overflow-in-polynomialring-need-a-work-around/?comment=17680#post-id-17680Yes, I am using a 32 bit system.Thu, 16 May 2013 16:03:14 -0500http://ask.sagemath.org/question/10102/exponent-overflow-in-polynomialring-need-a-work-around/?comment=17680#post-id-17680Comment by apeel for <p>Actually, this does not work on sage-5.9 either. apeel seems to use a 32-bit system whereas ppurka seems to use a 64-bit system. On a 64-bit system, you will only be able to go twice further (<code>65536 = 2^16</code> instead of <code>32768 = 2^15</code>):</p>
<pre><code>sage: f = x[0]**(2^16-1)
sage: f = x[0]**(2^16)
...
OverflowError: Exponent overflow (65536).
</code></pre>
<p>If you really need to work with such a big exponent, you could request it on the <a href="http://trac.sagemath.org/sage_trac">trac server</a> and then on <a href="http://www.singular.uni-kl.de/">singular</a> as well, though it is possible they won't change this limit due to a possible loss of performance (i didn't check the code, so it might be possible to go until <code>2^32</code> without much loss).</p>
<p>If you are looking for a mathematical workaround, you need to give more information on what is your function doing. For example, if you only use the variable <code>x[0]</code> in this function, you could try to transform your polynomial <code>f</code> as a univariate polynomial, and then work with it:</p>
<pre><code>sage: P = f.univariate_polynomial()
</code></pre>
http://ask.sagemath.org/question/10102/exponent-overflow-in-polynomialring-need-a-work-around/?comment=17679#post-id-17679I need all of the variables. I am trying to make a resilient function to hash an input string. Each input symbol in the string becomes an input variable.Thu, 16 May 2013 16:06:36 -0500http://ask.sagemath.org/question/10102/exponent-overflow-in-polynomialring-need-a-work-around/?comment=17679#post-id-17679Comment by ppurka for <p>Actually, this does not work on sage-5.9 either. apeel seems to use a 32-bit system whereas ppurka seems to use a 64-bit system. On a 64-bit system, you will only be able to go twice further (<code>65536 = 2^16</code> instead of <code>32768 = 2^15</code>):</p>
<pre><code>sage: f = x[0]**(2^16-1)
sage: f = x[0]**(2^16)
...
OverflowError: Exponent overflow (65536).
</code></pre>
<p>If you really need to work with such a big exponent, you could request it on the <a href="http://trac.sagemath.org/sage_trac">trac server</a> and then on <a href="http://www.singular.uni-kl.de/">singular</a> as well, though it is possible they won't change this limit due to a possible loss of performance (i didn't check the code, so it might be possible to go until <code>2^32</code> without much loss).</p>
<p>If you are looking for a mathematical workaround, you need to give more information on what is your function doing. For example, if you only use the variable <code>x[0]</code> in this function, you could try to transform your polynomial <code>f</code> as a univariate polynomial, and then work with it:</p>
<pre><code>sage: P = f.univariate_polynomial()
</code></pre>
http://ask.sagemath.org/question/10102/exponent-overflow-in-polynomialring-need-a-work-around/?comment=17737#post-id-17737Indeed, I am on a 64bit system.Wed, 08 May 2013 15:23:36 -0500http://ask.sagemath.org/question/10102/exponent-overflow-in-polynomialring-need-a-work-around/?comment=17737#post-id-17737