Skip to content

src/sage/symbolic/integration/integral.py: better giac errors #40405

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

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

orlitzky
Copy link
Contributor

If the optional sagemath-giac is not installed, requesting integration via giac "does nothing," i.e.

sage: integrate(sin(x), x, algorithm="giac")
integrate(sin(x), x)

This is due mainly to the fact that, when no algorithm is requested, ALL available integration routines are tried one after the other. Having the giac integrator do nothing so that the problem can be handed to the next integrator makes sense.

However, when algorithm="giac" is explicitly requested, this is confusing. This commit adds "giac" and "libgiac" to the list of integrators only when sagemath-giac is present. The end result is that passing algorithm="giac" to integrate() or integral() will raise an error about the missing algorithm rather than quietly doing nothing with the input:

sage: integral(sin(x), x, algorithm="giac")
Traceback (most recent call last)
...
ValueError: Unknown algorithm: giac

@nbruin
Copy link
Contributor

nbruin commented Jul 13, 2025

Perhaps too much work to implement, but perhaps consider specifying the error message to: "Optional backend for requested integration method not installed". When the error condition arises, the system would recognize that the "algorithm" is not in the recognized list but is in the wider "optional" list, so that a more specific error can be raised.

orlitzky added 2 commits July 14, 2025 10:10
If the optional sagemath-giac is not installed, requesting integration
via giac "does nothing," i.e.

  sage: integrate(sin(x), x, algorithm="giac")
  integrate(sin(x), x)

This is due mainly to the fact that, when no algorithm is requested,
ALL available integration routines are tried one after the
other. Having the giac integrator do nothing so that the problem can
be handed to the next integrator makes sense.

However, when algorithm="giac" is explicitly requested, this is
confusing. This commit adds "giac" and "libgiac" to the list of chain
of integration backends only when sagemath-giac is present. The end
result is that passing algorithm="giac" to integrate() or integral()
will raise an error about the missing feature rather than quietly
doing nothing with the input:

  FeatureNotPresentError: sage.libs.giac is not available.
  Optional backend for giac integration not installed.
  No equivalent system packages for gentoo are known to Sage.
First, mention that both algorithm="giac" and algorithm="libgiac"
require the optional sagemath-giac package to be installed. Then,
clarify that the default algorithm is None, and has special behavior.
@orlitzky
Copy link
Contributor Author

That's not too hard to do if we change the giac integrator to throw a FeatureNotPresentError, and then omit it from the list of integrators when sagemath-giac is not installed. The only minor annoyance is that the FeatureNotPresentError wants to complain about sage.libs.giac being missing and this is something a user won't understand. I was still able to append an additional reason to the error message however.

I haven't re-run all of the integration tests but hopefully nothing breaks in CI.

We have a doctest that is testing for an unevaluated integral:

  sage: A = integral(1/ ((x-4) * (x^4+x+1)), x); A
  integrate(1/((x^4 + x + 1)*(x - 4)), x)

This is now failing because we output the maxima answer,

  -1/261*integrate((x^3 + 4*x^2 + 16*x + 65)/(x^4 + x + 1), x)
  + 1/261*log(x - 4)

rather than the giac answer, which is completely unevaluated. In an
earlier commit, giac was removed from the default list of integration
backends whenever giac is not actually installed because this produces
better error messages. But, as a side effect, we are no longer
skipping over the partial maxima answer to accept the unevaluated giac
answer. (This is actually an improvement in the case where giac is not
installed and where sympy raises an error.)

There is no important result tested by these lines, so I think the
least confusing thing to do is re-word the surrounding paragraph a bit
and delete this test. There are still other tests nearby for partial
evaluation of hard integrals.
@orlitzky
Copy link
Contributor Author

Deleted a failing doctest to fix the CI.

The situation now is actually slightly improved: to check if an indefinite integral backend worked or not, we are checking for "integral()" or "integrate()" in the resulting expression. We always get a partial answer from maxima in the test I removed, but when giac is not installed, we see the maxima result as a failure and proceed to try giac, which is a no-op, but is the last engine that does not raise an error. So, ultimately, we throw out the partially evaluated answer for a completely unevaluated one.

I don't think the test is demonstrating anything terribly important (the very next test shows a partial answer from maxima) so I've simply removed the failing one.

@orlitzky
Copy link
Contributor Author

Remaining CI issues appear unrelated, but beware that I am unable to test with sagemath-giac installed (giac no longer builds on Gentoo, and no one is going to fix it.) I don't know if we have a CI runner with the optional package installed.

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

Successfully merging this pull request may close these issues.

3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy