Sage: Ticket #14334: integral of multivariate polynomial
https://trac.sagemath.org/ticket/14334
<p>
So far (in sage 5.10), the integral of multivariable polynomial is not clean, and belongs to the symbolic ring
</p>
<pre class="wiki">sage: x,y = polygen(QQ, ['x','y'])
sage: (x*y).integral(x)
Traceback (most recent call last)
...
AttributeError: 'sage.rings.polynomial.multi_polynomial_libsingular.MPolynomial_libsingular' object has no attribute 'integral'
</pre><p>
But one can do this:
</p>
<pre class="wiki">sage: integrate(x*y,x)
1/2*x^2*y
sage: integrate(x*y,x).parent()
Symbolic Ring
</pre><p>
It would be much better to have a .integral attribute and to stay within polynomial rings, like it happens with just one variable
</p>
<pre class="wiki">sage: x = polygen(QQ, 'x')
sage: x.integral().parent()
Univariate Polynomial Ring in x over Rational Field
</pre>en-usSagehttps://trac.sagemath.org/chrome/site/logo_sagemath_trac.png
https://trac.sagemath.org/ticket/14334
Trac 1.1.6chapotonFri, 22 Mar 2013 14:20:37 GMTstatus changed; author set
https://trac.sagemath.org/ticket/14334#comment:1
https://trac.sagemath.org/ticket/14334#comment:1
<ul>
<li><strong>status</strong>
changed from <em>new</em> to <em>needs_review</em>
</li>
<li><strong>author</strong>
set to <em>Frédéric Chapoton</em>
</li>
</ul>
<p>
Here is a patch.
</p>
<ul><li>implements integration in multi-polynomials
</li><li>implements integration with respect to any variable in polynomials and power series
</li></ul>
TicketnovoseltSun, 24 Mar 2013 05:04:07 GMT
https://trac.sagemath.org/ticket/14334#comment:2
https://trac.sagemath.org/ticket/14334#comment:2
<p>
What is the desired (and actual) behaviour if the variable does not belong to the base rings as well? I.e. can I integrate an element of <code>QQ[x,y]</code> with respect to <code>z</code>?
</p>
TicketchapotonMon, 25 Mar 2013 14:30:21 GMT
https://trac.sagemath.org/ticket/14334#comment:3
https://trac.sagemath.org/ticket/14334#comment:3
<p>
With the patch applied, this gives :
</p>
<pre class="wiki">AttributeError: 'AlgebraicNumber' object has no attribute 'integral'
</pre><p>
or
</p>
<pre class="wiki">AttributeError: 'sage.rings.rational.Rational' object has no attribute 'integral'
</pre><p>
Which means that once the bottom ring is reached, it just fails to provide an integral method. Do you think it is necessary to implement an integral method <strong>for any ring</strong> ? Maybe one just saying <code>"NotImplemented"</code> ?
</p>
TicketnovoseltMon, 25 Mar 2013 14:47:32 GMT
https://trac.sagemath.org/ticket/14334#comment:4
https://trac.sagemath.org/ticket/14334#comment:4
<p>
Well, I think that top level function <code>integral</code> should work in this case, perhaps with symbolic ring as parent. If integral method is called directly, it still would be better to have a less cryptic message than that rationals cannot be integrated.
</p>
<p>
Also, with the patch I get
</p>
<pre class="wiki">sage: ZZ["x, y"]("x*y+x-y").integral(x)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-5-c6379f42d83e> in <module>()
----> 1 ZZ["x, y"]("x*y+x-y").integral(x)
/home/novoselt/sage-5.9.beta0/local/lib/python2.7/site-packages/sage/structure/element.so in sage.structure.element.Element.__getattr__ (sage/structure/element.c:3637)()
/home/novoselt/sage-5.9.beta0/local/lib/python2.7/site-packages/sage/structure/misc.so in sage.structure.misc.getattr_from_other_class (sage/structure/misc.c:1507)()
AttributeError: 'sage.rings.polynomial.multi_polynomial_libsingular.MPolynomial_libsingular' object has no attribute 'integral'
</pre><p>
and somehow here it feels that the method should succeed, since
</p>
<pre class="wiki">sage: integrate(ZZ["x, y"]("x*y+x-y"), x)
1/2*x^2*y + 1/2*x^2 - x*y
</pre>
TicketchapotonMon, 25 Mar 2013 15:01:59 GMT
https://trac.sagemath.org/ticket/14334#comment:5
https://trac.sagemath.org/ticket/14334#comment:5
<p>
ok, one should also add an integral method in multi_polynomial_libsingular.pyx (TODO)
</p>
<p>
as far as I can tell, this does not exist in Singular, so it will not just be a matter of wrapping an existing method
</p>
TicketnovoseltMon, 25 Mar 2013 17:32:31 GMT
https://trac.sagemath.org/ticket/14334#comment:6
https://trac.sagemath.org/ticket/14334#comment:6
<p>
Part of the problem is that the result is not living in the original ring. Maybe, afterall, the best approach is to keep things as is, letting integral method fail if there are issues with coefficients. Those who want to integrate a potentially problematic polynomial should use integral function which will drop to symbolic ring if calling methods fails.
</p>
TicketchapotonTue, 26 Mar 2013 21:17:30 GMT
https://trac.sagemath.org/ticket/14334#comment:7
https://trac.sagemath.org/ticket/14334#comment:7
<p>
I did not manage to make the following example work
</p>
<pre class="wiki">sage: x,y = polygen(ZZ,['x','y'])
sage: (x*y).integral(x)
</pre><p>
The problem is that this is handled by singular. If the base ring is <strong>more complicated</strong>, everything works well.
</p>
<p>
If somebody is able to implement a working integral method in multi_polynomial_libsingular.pyx, please do !
</p>
TicketchapotonWed, 17 Jul 2013 14:52:18 GMTdescription changed
https://trac.sagemath.org/ticket/14334#comment:8
https://trac.sagemath.org/ticket/14334#comment:8
<ul>
<li><strong>description</strong>
modified (<a href="/ticket/14334?action=diff&version=8">diff</a>)
</li>
</ul>
TicketchapotonWed, 17 Jul 2013 14:54:32 GMT
https://trac.sagemath.org/ticket/14334#comment:9
https://trac.sagemath.org/ticket/14334#comment:9
<p>
ok, here is a patch that is doing the job. Needs review, please !
</p>
<p>
I have chosen to impose that the ring contains QQ, which seems a reasonable thing to do.
</p>
TicketnovoseltThu, 18 Jul 2013 21:53:50 GMTstatus changed; reviewer set
https://trac.sagemath.org/ticket/14334#comment:10
https://trac.sagemath.org/ticket/14334#comment:10
<ul>
<li><strong>status</strong>
changed from <em>needs_review</em> to <em>positive_review</em>
</li>
<li><strong>reviewer</strong>
set to <em>Andrey Novoseltsev</em>
</li>
</ul>
TicketjdemeyerSun, 21 Jul 2013 21:48:52 GMTmilestone changed
https://trac.sagemath.org/ticket/14334#comment:11
https://trac.sagemath.org/ticket/14334#comment:11
<ul>
<li><strong>milestone</strong>
changed from <em>sage-5.11</em> to <em>sage-5.12</em>
</li>
</ul>
TicketnovoseltTue, 13 Aug 2013 20:49:15 GMT
https://trac.sagemath.org/ticket/14334#comment:12
https://trac.sagemath.org/ticket/14334#comment:12
<p>
The patch does not apply for me on 5.11.rc1 because of empty lines conflict - probably needs rebasing!
</p>
TicketchapotonThu, 15 Aug 2013 13:50:36 GMTattachment set
https://trac.sagemath.org/ticket/14334
https://trac.sagemath.org/ticket/14334
<ul>
<li><strong>attachment</strong>
set to <em>trac_14334_integration_multipoly-fc.patch</em>
</li>
</ul>
TicketchapotonThu, 15 Aug 2013 13:50:56 GMT
https://trac.sagemath.org/ticket/14334#comment:13
https://trac.sagemath.org/ticket/14334#comment:13
<p>
rebased on 5.12.beta0
</p>
TicketnbruinThu, 15 Aug 2013 15:44:49 GMT
https://trac.sagemath.org/ticket/14334#comment:14
https://trac.sagemath.org/ticket/14334#comment:14
<p>
This can be done later as well: Isn't it a bit overly restrictive to demand QQ is a subfield? Everything should be fine as long as factorial(degree(f,x)) is invertible in the base ring.
</p>
<p>
Perhaps just try the computation:
</p>
<ul><li>If you end up with an exponent that is divisible by the characteristic, you'll get a <code>ZeroDivisionError</code>.
</li><li>If you try to convert the newly computed coefficient into the base ring, you'll get an error for things like <code>integrate(5*x^2*y,y)</code> in <code>ZZ[x,y]</code>, because <code>ZZ(5/3)</code> will fail.
</li></ul><p>
You could catch these errors and raise a <code>ValueError: polynomial does not have an antiderivative over this ring</code>.
</p>
TicketjdemeyerWed, 28 Aug 2013 06:52:21 GMTstatus changed; resolution, merged set
https://trac.sagemath.org/ticket/14334#comment:15
https://trac.sagemath.org/ticket/14334#comment:15
<ul>
<li><strong>status</strong>
changed from <em>positive_review</em> to <em>closed</em>
</li>
<li><strong>resolution</strong>
set to <em>fixed</em>
</li>
<li><strong>merged</strong>
set to <em>sage-5.12.beta4</em>
</li>
</ul>
Ticket