Opened 10 years ago
Closed 9 years ago
#14334 closed defect (fixed)
integral of multivariate polynomial
Reported by: | Frédéric Chapoton | Owned by: | Martin Albrecht |
---|---|---|---|
Priority: | major | Milestone: | sage-5.12 |
Component: | commutative algebra | Keywords: | integral of polynomials |
Cc: | Merged in: | sage-5.12.beta4 | |
Authors: | Frédéric Chapoton | Reviewers: | Andrey Novoseltsev |
Report Upstream: | N/A | Work issues: | |
Branch: | Commit: | ||
Dependencies: | Stopgaps: |
Description (last modified by )
So far (in sage 5.10), the integral of multivariable polynomial is not clean, and belongs to the symbolic ring
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'
But one can do this:
sage: integrate(x*y,x) 1/2*x^2*y sage: integrate(x*y,x).parent() Symbolic Ring
It would be much better to have a .integral attribute and to stay within polynomial rings, like it happens with just one variable
sage: x = polygen(QQ, 'x') sage: x.integral().parent() Univariate Polynomial Ring in x over Rational Field
Attachments (1)
Change History (16)
comment:1 Changed 10 years ago by
Authors: | → Frédéric Chapoton |
---|---|
Status: | new → needs_review |
comment:2 Changed 10 years ago by
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 QQ[x,y]
with respect to z
?
comment:3 Changed 10 years ago by
With the patch applied, this gives :
AttributeError: 'AlgebraicNumber' object has no attribute 'integral'
or
AttributeError: 'sage.rings.rational.Rational' object has no attribute 'integral'
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 for any ring ? Maybe one just saying "NotImplemented"
?
comment:4 Changed 10 years ago by
Well, I think that top level function integral
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.
Also, with the patch I get
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'
and somehow here it feels that the method should succeed, since
sage: integrate(ZZ["x, y"]("x*y+x-y"), x) 1/2*x^2*y + 1/2*x^2 - x*y
comment:5 Changed 10 years ago by
ok, one should also add an integral method in multi_polynomial_libsingular.pyx (TODO)
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
comment:6 Changed 10 years ago by
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.
comment:7 Changed 10 years ago by
I did not manage to make the following example work
sage: x,y = polygen(ZZ,['x','y']) sage: (x*y).integral()
The problem is that this is handled by singular. If the base ring is more complicated, everything works well.
If somebody is able to implement a working integral method in multi_polynomial_libsingular.pyx, please do !
comment:8 Changed 9 years ago by
Description: | modified (diff) |
---|
comment:9 Changed 9 years ago by
ok, here is a patch that is doing the job. Needs review, please !
I have chosen to impose that the ring contains QQ, which seems a reasonable thing to do.
comment:10 Changed 9 years ago by
Reviewers: | → Andrey Novoseltsev |
---|---|
Status: | needs_review → positive_review |
comment:11 Changed 9 years ago by
Milestone: | sage-5.11 → sage-5.12 |
---|
comment:12 Changed 9 years ago by
The patch does not apply for me on 5.11.rc1 because of empty lines conflict - probably needs rebasing!
Changed 9 years ago by
Attachment: | trac_14334_integration_multipoly-fc.patch added |
---|
comment:14 Changed 9 years ago by
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.
Perhaps just try the computation:
- If you end up with an exponent that is divisible by the characteristic, you'll get a
ZeroDivisionError
. - If you try to convert the newly computed coefficient into the base ring, you'll get an error for things like
integrate(5*x^2*y,y)
inZZ[x,y]
, becauseZZ(5/3)
will fail.
You could catch these errors and raise a ValueError: polynomial does not have an antiderivative over this ring
.
comment:15 Changed 9 years ago by
Merged in: | → sage-5.12.beta4 |
---|---|
Resolution: | → fixed |
Status: | positive_review → closed |
Here is a patch.