Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

integral of multivariate polynomial #14334

Closed
fchapoton opened this issue Mar 22, 2013 · 16 comments
Closed

integral of multivariate polynomial #14334

fchapoton opened this issue Mar 22, 2013 · 16 comments

Comments

@fchapoton
Copy link
Contributor

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

Component: commutative algebra

Keywords: integral of polynomials

Author: Frédéric Chapoton

Reviewer: Andrey Novoseltsev

Merged: sage-5.12.beta4

Issue created by migration from https://trac.sagemath.org/ticket/14334

@fchapoton
Copy link
Contributor Author

Author: Frédéric Chapoton

@fchapoton
Copy link
Contributor Author

comment:1

Here is a patch.

  • implements integration in multi-polynomials
  • implements integration with respect to any variable in polynomials and power series

@novoselt
Copy link
Member

comment:2

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?

@fchapoton
Copy link
Contributor Author

comment:3

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" ?

@novoselt
Copy link
Member

comment:4

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

@fchapoton
Copy link
Contributor Author

comment:5

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

@novoselt
Copy link
Member

comment:6

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.

@fchapoton
Copy link
Contributor Author

comment:7

I did not manage to make the following example work

sage: x,y = polygen(ZZ,['x','y'])
sage: (x*y).integral(x)

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 !

@fchapoton

This comment has been minimized.

@fchapoton
Copy link
Contributor Author

comment:9

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.

@novoselt
Copy link
Member

Reviewer: Andrey Novoseltsev

@novoselt
Copy link
Member

comment:12

The patch does not apply for me on 5.11.rc1 because of empty lines conflict - probably needs rebasing!

@fchapoton
Copy link
Contributor Author

@fchapoton
Copy link
Contributor Author

comment:13

rebased on 5.12.beta0

@nbruin
Copy link
Contributor

nbruin commented Aug 15, 2013

comment:14

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) in ZZ[x,y], because ZZ(5/3) will fail.
    You could catch these errors and raise a ValueError: polynomial does not have an antiderivative over this ring.

@jdemeyer
Copy link
Contributor

Merged: sage-5.12.beta4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants