Opened 10 years ago

Closed 9 years ago

# integral of multivariate polynomial

Reported by: Owned by: chapoton malb major sage-5.12 commutative algebra integral of polynomials sage-5.12.beta4 Frédéric Chapoton Andrey Novoseltsev N/A

### Description (last modified by chapoton)

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
```

### comment:1 Changed 10 years ago by chapoton

Authors: → Frédéric Chapoton new → needs_review

Here is a patch.

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

### comment:2 Changed 10 years ago by novoselt

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 chapoton

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 novoselt

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 chapoton

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

Last edited 10 years ago by chapoton (previous) (diff)

### comment:6 Changed 10 years ago by novoselt

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 chapoton

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 !

Last edited 10 years ago by chapoton (previous) (diff)

### comment:8 Changed 10 years ago by chapoton

Description: modified (diff)

### comment:9 Changed 10 years ago by chapoton

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 10 years ago by novoselt

Reviewers: → Andrey Novoseltsev needs_review → positive_review

### comment:11 Changed 10 years ago by jdemeyer

Milestone: sage-5.11 → sage-5.12

### comment:12 Changed 9 years ago by novoselt

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

### Changed 9 years ago by chapoton

Attachment: trac_14334_integration_multipoly-fc.patch​ added

### comment:13 Changed 9 years ago by chapoton

rebased on 5.12.beta0

### comment:14 Changed 9 years ago by nbruin

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`.

### comment:15 Changed 9 years ago by jdemeyer

Merged in: → sage-5.12.beta4 → fixed positive_review → closed
Note: See TracTickets for help on using tickets.