Skip to content

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

Open
orlitzky wants to merge 3 commits into
sagemath:developfrom
orlitzky:missing-giac-ui
Open

src/sage/symbolic/integration/integral.py: better giac errors#40405
orlitzky wants to merge 3 commits into
sagemath:developfrom
orlitzky:missing-giac-ui

Conversation

@orlitzky
Copy link
Copy Markdown
Contributor

@orlitzky orlitzky commented Jul 11, 2025

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 inserts libgiac into the default chain 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 feature rather than quietly doing nothing with the input:

sage: integrate(sin(x), x, algorithm="giac")
---------------------------------------------------------------------------
FeatureNotPresentError                    Traceback (most recent call last)
...
FeatureNotPresentError: sage.libs.giac is not available.
Optional backend for giac integration not installed.
No equivalent system packages for gentoo are known to Sage.

@nbruin
Copy link
Copy Markdown
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
Copy link
Copy Markdown
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.

@orlitzky
Copy link
Copy Markdown
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
Copy Markdown
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.

@orlitzky orlitzky force-pushed the missing-giac-ui branch 2 times, most recently from 5b6afc5 to abc4b61 Compare July 30, 2025 19:41
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Aug 10, 2025

Documentation preview for this PR (built with commit 3196bd6; changes) is ready! 🎉
This preview will update shortly after each push to this PR.

orlitzky added 3 commits May 30, 2026 17:21
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 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.
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.
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