Skip to content

Commit b37c262

Browse files
author
Release Manager
committed
gh-40574: Re-enable abs_integrate for Maxima integration We used to have Maxima's `abs_integrate` package loaded by default, but it caused more problems than it solved, and was disabled in #12731. All known issues have been resolved, however: * https://sourceforge.net/p/maxima/code/ci/3ca4235b This PR cleans up some existing tests, debt left over from when `abs_integrate` was disabled, and then _re-enables_ it with a whole new collection of tests for the old problems. We do not gain as much as we used to (vanilla maxima has improved), but we do get some extra integrals for "free" now that the problems appear to be resolved. URL: #40574 Reported by: Michael Orlitzky Reviewer(s): Dima Pasechnik
2 parents 0bb40ed + e663349 commit b37c262

File tree

4 files changed

+55
-67
lines changed

4 files changed

+55
-67
lines changed

build/pkgs/maxima/SPKG.rst

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -47,24 +47,5 @@ Special Update/Build Instructions
4747
All patch files in the patches/ directory are applied. Descriptions of
4848
these patches are either in the patch files themselves or below.
4949

50-
- 0001-taylor2-Avoid-blowing-the-stack-when-diff-expand-isn.patch:
51-
Fix for Maxima bug #2520 (abs_integrate fails on abs(sin(x)) and
52-
abs(cos(x))). Introduced in Issue #13364 (Upgrade Maxima to
53-
5.29.1).
54-
55-
- build-fasl.patch: Build a fasl library for ecl in addition to an
56-
executable program. Introduced in Issue #16178 (Build maxima fasl
57-
without asdf).
58-
5950
- infodir.patch: Correct the path to the Info directory. Introduced
6051
in Issue #11348 (maxima test fails when install tree is moved).
61-
62-
- matrixexp.patch: Fix matrixexp(matrix([%i*%pi])), which broke after
63-
Maxima 5.29.1. Introduced in Issue #13973.
64-
65-
- maxima.system.patch: Set ``c::*compile-in-constants*`` to t.
66-
Introduced in Issue #11966 (OS X 10.7 Lion: Maxima fails to build).
67-
68-
- undoing_true_false_printing_patch.patch: Revert an upstream change
69-
causing '?' to be printed around some words. Introduced in Trac
70-
#13364 (Upgrade Maxima to 5.29.1).

src/sage/calculus/desolvers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ def desolve(de, dvar, ics=None, ivar=None, show_method=False, contrib_ode=False,
541541
sage: forget()
542542
sage: y = function('y')(x)
543543
sage: desolve(diff(y, x) == sqrt(abs(y)), dvar=y, ivar=x)
544-
integrate(1/sqrt(abs(y(x))), y(x)) == _C + x
544+
sqrt(-y(x))*(sgn(y(x)) - 1) + (sgn(y(x)) + 1)*sqrt(y(x)) == _C + x
545545
546546
AUTHORS:
547547

src/sage/functions/piecewise.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -799,16 +799,21 @@ def integral(self, parameters, variable, x=None, a=None, b=None, definite=False,
799799
y|-->1/2*y^2 + 3*y + 9/2 on (-3, 0),
800800
y|-->3*y + 9/2 on (0, +oo); y)
801801
802-
::
802+
The output from this can change a bit depending on the
803+
version of Maxima used, so we test for equality with a
804+
known result on the sole piece::
803805
806+
sage: # long time
804807
sage: f1(x) = e^(-abs(x))
805808
sage: f = piecewise([[(-infinity, infinity), f1]])
806809
sage: result = f.integral(definite=True)
807810
...
808811
sage: result
809812
2
810-
sage: f.integral()
811-
piecewise(x|-->-integrate(e^(-abs(x)), x, x, +Infinity) on (-oo, +oo); x)
813+
sage: actual = f.integral().expression_at(0) # only one piece
814+
sage: expected = -1/2*e^(-x)*sgn(x) - 1/2*e^x*sgn(x) - 1/2*e^(-x) + 1/2*e^x + sgn(x) - 1
815+
sage: bool(actual == expected)
816+
True
812817
813818
::
814819

src/sage/interfaces/maxima_lib.py

Lines changed: 46 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@
218218

219219
init_code = ['besselexpand : true', 'display2d : false', 'domain : complex', 'keepfloat : true',
220220
'load(to_poly_solve)', 'load(simplify_sum)',
221-
'load(diag)']
221+
'load(diag)', 'load(abs_integrate)']
222222

223223

224224
# Turn off the prompt labels, since computing them *very
@@ -726,58 +726,21 @@ def sr_integral(self, *args):
726726
sage: assumptions() # Check the assumptions really were forgotten
727727
[]
728728
729-
Make sure the abs_integrate package is being used,
730-
:issue:`11483`. The following are examples from the Maxima
731-
abs_integrate documentation::
729+
An example from the maxima documentation involving the
730+
absolute value::
732731
733-
sage: integrate(abs(x), x)
734-
1/2*x*abs(x)
735-
736-
::
737-
738-
sage: integrate(sgn(x) - sgn(1-x), x) # known bug
732+
sage: integrate(sgn(x) - sgn(1-x), x)
739733
abs(x - 1) + abs(x)
740734
741-
This is a known bug in Sage symbolic limits code, see
735+
This is a fixed bug in Sage symbolic limits code, see
742736
:issue:`17892` and https://sourceforge.net/p/maxima/bugs/3237/ ::
743737
744-
sage: integrate(1 / (1 + abs(x-5)), x, -5, 6) # not tested -- known bug
738+
sage: integrate(1 / (1 + abs(x-5)), x, -5, 6)
745739
log(11) + log(2)
746740
747-
::
748-
749-
sage: integrate(1/(1 + abs(x)), x) # known bug
750-
1/2*(log(x + 1) + log(-x + 1))*sgn(x) + 1/2*log(x + 1) - 1/2*log(-x + 1)
751-
752-
::
753-
754-
sage: integrate(cos(x + abs(x)), x) # known bug
755-
-1/2*x*sgn(x) + 1/4*(sgn(x) + 1)*sin(2*x) + 1/2*x
756-
757-
The last example relies on the following simplification::
758-
759-
sage: maxima("realpart(signum(x))")
760-
signum(x)
761-
762-
An example from sage-support thread e641001f8b8d1129::
763-
764-
sage: f = e^(-x^2/2)/sqrt(2*pi) * sgn(x-1)
765-
sage: integrate(f, x, -Infinity, Infinity) # known bug
766-
-erf(1/2*sqrt(2))
767-
768-
From :issue:`8624`::
769-
770-
sage: integral(abs(cos(x))*sin(x),(x,pi/2,pi))
771-
1/2
772-
773-
::
774-
775-
sage: integrate(sqrt(x + sqrt(x)), x).canonicalize_radical() # known bug
776-
1/12*((8*x - 3)*x^(1/4) + 2*x^(3/4))*sqrt(sqrt(x) + 1) + 1/8*log(sqrt(sqrt(x) + 1) + x^(1/4)) - 1/8*log(sqrt(sqrt(x) + 1) - x^(1/4))
777-
778741
And :issue:`11594`::
779742
780-
sage: integrate(abs(x^2 - 1), x, -2, 2) # known bug
743+
sage: integrate(abs(x^2 - 1), x, -2, 2)
781744
4
782745
783746
This definite integral returned zero (incorrectly) in at least
@@ -795,6 +758,45 @@ def sr_integral(self, *args):
795758
0.124756040961038
796759
sage: a.imag().abs() < 3e-17
797760
True
761+
762+
The following examples require Maxima's ``abs_integrate``
763+
package. Enabling ``abs_integrate`` globally caused several
764+
bugs (catalogued in :issue:`12731`) but most of these have
765+
been fixed, and ``abs_integrate`` has been re-enabled::
766+
767+
sage: integrate(1/(abs(x) + 1), x, algorithm="maxima")
768+
1/2*(log(x + 1) + log(-x + 1))*sgn(x) + 1/2*log(x + 1) - 1/2*log(-x + 1)
769+
sage: integrate(cos(x + abs(x)), x, algorithm="maxima")
770+
-1/4*(2*x - sin(2*x))*sgn(x) + 1/2*x + 1/4*sin(2*x)
771+
772+
Several examples where ``abs_integrate`` previously lead to
773+
incorrect results. This was once reported to be divergent in
774+
:issue:`13733`, and only in maxima-5.48 does it give the
775+
correct answer::
776+
777+
sage: # long time, not tested until maxima-5.48 is widespread
778+
sage: integral(log(cot(x)-1), x, 0, pi/4, algorithm="maxima")
779+
catalan + 1/2*I*dilog(1/2*I + 1/2) - 1/2*I*dilog(-1/2*I + 1/2)
780+
781+
This used to return ``1/2`` in :issue:`11590`::
782+
783+
sage: integrate(x * sgn(x^2 - 1/4), x, -1, 0, algorithm="maxima")
784+
-1/4
785+
786+
In :issue:`14591`, this incorrectly simplified to ``cosh(x)``::
787+
788+
sage: integrate(sqrt(1-1/4*cosh(x)^2), x, algorithm="maxima")
789+
integrate(sqrt(-1/4*cosh(x)^2 + 1), x)
790+
791+
In :issue:`17468`, this integral hangs::
792+
793+
sage: integral(log(abs(2*sin(x))), x, 0, pi/3, algorithm="maxima")
794+
1/36*I*pi^2 + I*dilog(1/2*I*sqrt(3) + 1/2) + I*dilog(-1/2*I*sqrt(3) - 1/2)
795+
796+
This used to return a *negative* answer in :issue:`17511`::
797+
798+
sage: integrate(abs(cos(x)), x, 0, pi, algorithm="maxima")
799+
2
798800
"""
799801
try:
800802
return max_to_sr(maxima_eval(([max_integrate],

0 commit comments

Comments
 (0)