Skip to content

Conversation

maliesen
Copy link
Contributor

@maliesen maliesen commented Feb 4, 2024

References to other Issues or PRs

Fixes #25786

Brief description of what is fixed or changed

fix substitution formula in meijerint

Other comments

Release Notes

  • integrals
    • Fixed a bug with integrating over negative real numbers using meijerint algorithm. Formerly, integrate(exp(-x**2), (x,-5,0), meijerg=True) incorrectly gave -sqrt(pi)/2 * erf(5) instead of sqrt(pi)/2 * erf(5).

@sympy-bot
Copy link

sympy-bot commented Feb 4, 2024

Hi, I am the SymPy bot. I'm here to help you write a release notes entry. Please read the guide on how to write release notes.

Your release notes are in good order.

Here is what the release notes will look like:

  • integrals
    • Fixed a bug with integrating over negative real numbers using meijerint algorithm. Formerly, integrate(exp(-x**2), (x,-5,0), meijerg=True) incorrectly gave -sqrt(pi)/2 * erf(5) instead of sqrt(pi)/2 * erf(5). (#26173 by @maliesen)

This will be added to https://github.com/sympy/sympy/wiki/Release-Notes-for-1.13.

Click here to see the pull request description that was parsed.
<!-- Your title above should be a short description of what
was changed. Do not include the issue number in the title. -->

#### References to other Issues or PRs
<!-- If this pull request fixes an issue, write "Fixes #NNNN" in that exact
format, e.g. "Fixes #1234" (see
https://tinyurl.com/auto-closing for more information). Also, please
write a comment on that issue linking back to this pull request once it is
open. -->

Fixes #25786 

#### Brief description of what is fixed or changed

fix substitution formula in meijerint


#### Other comments


#### Release Notes

<!-- Write the release notes for this release below between the BEGIN and END
statements. The basic format is a bulleted list with the name of the subpackage
and the release note for this PR. For example:


* integrals
  * Fixed a bug with integrating over negative real numbers using meijerint algorithm. Formerly, `integrate(exp(-x**2), (x,-5,0), meijerg=True)` incorrectly gave `-log(x)`.

* physics.units
  * Corrected a semantical error in the conversion between volt and statvolt which
    reported the volt as being larger than the statvolt.

or if no release note(s) should be included use:

NO ENTRY

See https://github.com/sympy/sympy/wiki/Writing-Release-Notes for more
information on how to write release notes. The bot will check your release
notes automatically to see if they are formatted correctly. -->

<!-- BEGIN RELEASE NOTES -->
* integrals
  * Fixed a bug with integrating over negative real numbers using meijerint algorithm. Formerly, `integrate(exp(-x**2), (x,-5,0), meijerg=True)` incorrectly gave `-sqrt(pi)/2 * erf(5)` instead of `sqrt(pi)/2 * erf(5)`.
<!-- END RELEASE NOTES -->

Update

The release notes on the wiki have been updated.

@oscarbenjamin
Copy link
Collaborator

The tests that fails involves some integral of singularity functions that should probably not be handled by meijerg. Perhaps meijerg should reject such integrals to let another method take over.

Copy link

github-actions bot commented Feb 4, 2024

Benchmark results from GitHub Actions

Lower numbers are good, higher numbers are bad. A ratio less than 1
means a speed up and greater than 1 means a slowdown. Green lines
beginning with + are slowdowns (the PR is slower then master or
master is slower than the previous release). Red lines beginning
with - are speedups.

Significantly changed benchmark results (PR vs master)

Significantly changed benchmark results (master vs previous release)

| Change   | Before [a00718ba]    | After [d447356b]    |   Ratio | Benchmark (Parameter)                                                |
|----------|----------------------|---------------------|---------|----------------------------------------------------------------------|
| -        | 69.1±1ms             | 44.7±0.3ms          |    0.65 | integrate.TimeIntegrationRisch02.time_doit(10)                       |
| -        | 67.8±0.5ms           | 44.3±0.5ms          |    0.65 | integrate.TimeIntegrationRisch02.time_doit_risch(10)                 |
| +        | 18.6±0.4μs           | 30.9±0.5μs          |    1.67 | integrate.TimeIntegrationRisch03.time_doit(1)                        |
| -        | 5.35±0.03ms          | 2.84±0.01ms         |    0.53 | logic.LogicSuite.time_load_file                                      |
| -        | 73.1±0.6ms           | 28.9±0.1ms          |    0.4  | polys.TimeGCD_GaussInt.time_op(1, 'dense')                           |
| -        | 25.7±0.1ms           | 17.0±0.1ms          |    0.66 | polys.TimeGCD_GaussInt.time_op(1, 'expr')                            |
| -        | 73.3±0.3ms           | 29.2±0.2ms          |    0.4  | polys.TimeGCD_GaussInt.time_op(1, 'sparse')                          |
| -        | 256±0.8ms            | 125±0.2ms           |    0.49 | polys.TimeGCD_GaussInt.time_op(2, 'dense')                           |
| -        | 251±3ms              | 126±0.5ms           |    0.5  | polys.TimeGCD_GaussInt.time_op(2, 'sparse')                          |
| -        | 647±2ms              | 376±3ms             |    0.58 | polys.TimeGCD_GaussInt.time_op(3, 'dense')                           |
| -        | 651±1ms              | 375±2ms             |    0.58 | polys.TimeGCD_GaussInt.time_op(3, 'sparse')                          |
| -        | 497±1μs              | 289±1μs             |    0.58 | polys.TimeGCD_LinearDenseQuadraticGCD.time_op(1, 'dense')            |
| -        | 1.77±0.01ms          | 1.06±0ms            |    0.6  | polys.TimeGCD_LinearDenseQuadraticGCD.time_op(2, 'dense')            |
| -        | 5.86±0.02ms          | 3.16±0.03ms         |    0.54 | polys.TimeGCD_LinearDenseQuadraticGCD.time_op(3, 'dense')            |
| -        | 447±1μs              | 235±2μs             |    0.53 | polys.TimeGCD_QuadraticNonMonicGCD.time_op(1, 'dense')               |
| -        | 1.48±0.01ms          | 703±6μs             |    0.48 | polys.TimeGCD_QuadraticNonMonicGCD.time_op(2, 'dense')               |
| -        | 4.89±0.09ms          | 1.67±0.01ms         |    0.34 | polys.TimeGCD_QuadraticNonMonicGCD.time_op(3, 'dense')               |
| -        | 374±4μs              | 208±0.8μs           |    0.56 | polys.TimeGCD_SparseGCDHighDegree.time_op(1, 'dense')                |
| -        | 2.48±0.02ms          | 1.28±0.01ms         |    0.52 | polys.TimeGCD_SparseGCDHighDegree.time_op(3, 'dense')                |
| -        | 10.0±0.05ms          | 4.45±0.02ms         |    0.44 | polys.TimeGCD_SparseGCDHighDegree.time_op(5, 'dense')                |
| -        | 361±2μs              | 173±0.5μs           |    0.48 | polys.TimeGCD_SparseNonMonicQuadratic.time_op(1, 'dense')            |
| -        | 2.55±0.05ms          | 925±2μs             |    0.36 | polys.TimeGCD_SparseNonMonicQuadratic.time_op(3, 'dense')            |
| -        | 9.63±0.03ms          | 2.70±0.02ms         |    0.28 | polys.TimeGCD_SparseNonMonicQuadratic.time_op(5, 'dense')            |
| -        | 1.02±0.01ms          | 429±2μs             |    0.42 | polys.TimePREM_LinearDenseQuadraticGCD.time_op(3, 'dense')           |
| -        | 1.72±0.01ms          | 497±1μs             |    0.29 | polys.TimePREM_LinearDenseQuadraticGCD.time_op(3, 'sparse')          |
| -        | 5.85±0.04ms          | 1.86±0.01ms         |    0.32 | polys.TimePREM_LinearDenseQuadraticGCD.time_op(5, 'dense')           |
| -        | 8.40±0.06ms          | 1.48±0.01ms         |    0.18 | polys.TimePREM_LinearDenseQuadraticGCD.time_op(5, 'sparse')          |
| -        | 286±2μs              | 64.4±0.4μs          |    0.22 | polys.TimePREM_QuadraticNonMonicGCD.time_op(1, 'sparse')             |
| -        | 3.47±0.03ms          | 398±4μs             |    0.11 | polys.TimePREM_QuadraticNonMonicGCD.time_op(3, 'dense')              |
| -        | 4.03±0.03ms          | 277±0.5μs           |    0.07 | polys.TimePREM_QuadraticNonMonicGCD.time_op(3, 'sparse')             |
| -        | 6.94±0.04ms          | 1.30±0.01ms         |    0.19 | polys.TimePREM_QuadraticNonMonicGCD.time_op(5, 'dense')              |
| -        | 8.69±0.07ms          | 835±4μs             |    0.1  | polys.TimePREM_QuadraticNonMonicGCD.time_op(5, 'sparse')             |
| -        | 5.00±0.03ms          | 2.98±0.01ms         |    0.6  | polys.TimeSUBRESULTANTS_LinearDenseQuadraticGCD.time_op(2, 'sparse') |
| -        | 12.0±0.05ms          | 6.97±0.04ms         |    0.58 | polys.TimeSUBRESULTANTS_LinearDenseQuadraticGCD.time_op(3, 'dense')  |
| -        | 22.0±0.07ms          | 9.02±0.03ms         |    0.41 | polys.TimeSUBRESULTANTS_LinearDenseQuadraticGCD.time_op(3, 'sparse') |
| -        | 5.24±0.02ms          | 862±2μs             |    0.16 | polys.TimeSUBRESULTANTS_QuadraticNonMonicGCD.time_op(1, 'sparse')    |
| -        | 12.6±0.1ms           | 6.97±0.01ms         |    0.55 | polys.TimeSUBRESULTANTS_QuadraticNonMonicGCD.time_op(2, 'sparse')    |
| -        | 102±0.9ms            | 26.9±0.09ms         |    0.26 | polys.TimeSUBRESULTANTS_QuadraticNonMonicGCD.time_op(3, 'dense')     |
| -        | 166±1ms              | 53.6±0.1ms          |    0.32 | polys.TimeSUBRESULTANTS_QuadraticNonMonicGCD.time_op(3, 'sparse')    |
| -        | 174±0.9μs            | 114±0.6μs           |    0.65 | polys.TimeSUBRESULTANTS_SparseGCDHighDegree.time_op(1, 'dense')      |
| -        | 359±2μs              | 216±1μs             |    0.6  | polys.TimeSUBRESULTANTS_SparseGCDHighDegree.time_op(1, 'sparse')     |
| -        | 4.28±0.02ms          | 877±4μs             |    0.21 | polys.TimeSUBRESULTANTS_SparseGCDHighDegree.time_op(3, 'dense')      |
| -        | 5.18±0.05ms          | 379±2μs             |    0.07 | polys.TimeSUBRESULTANTS_SparseGCDHighDegree.time_op(3, 'sparse')     |
| -        | 20.0±0.2ms           | 2.95±0.01ms         |    0.15 | polys.TimeSUBRESULTANTS_SparseGCDHighDegree.time_op(5, 'dense')      |
| -        | 23.1±0.3ms           | 622±2μs             |    0.03 | polys.TimeSUBRESULTANTS_SparseGCDHighDegree.time_op(5, 'sparse')     |
| -        | 480±2μs              | 134±0.8μs           |    0.28 | polys.TimeSUBRESULTANTS_SparseNonMonicQuadratic.time_op(1, 'sparse') |
| -        | 4.74±0.04ms          | 648±6μs             |    0.14 | polys.TimeSUBRESULTANTS_SparseNonMonicQuadratic.time_op(3, 'dense')  |
| -        | 5.23±0.03ms          | 137±0.7μs           |    0.03 | polys.TimeSUBRESULTANTS_SparseNonMonicQuadratic.time_op(3, 'sparse') |
| -        | 13.4±0.2ms           | 1.37±0.01ms         |    0.1  | polys.TimeSUBRESULTANTS_SparseNonMonicQuadratic.time_op(5, 'dense')  |
| -        | 14.1±0.07ms          | 141±1μs             |    0.01 | polys.TimeSUBRESULTANTS_SparseNonMonicQuadratic.time_op(5, 'sparse') |
| -        | 133±0.6μs            | 76.6±0.4μs          |    0.57 | solve.TimeMatrixOperations.time_rref(3, 0)                           |
| -        | 248±0.3μs            | 89.2±0.3μs          |    0.36 | solve.TimeMatrixOperations.time_rref(4, 0)                           |
| -        | 24.1±0.1ms           | 10.2±0.04ms         |    0.42 | solve.TimeSolveLinSys189x49.time_solve_lin_sys                       |
| -        | 28.0±0.1ms           | 15.5±0.1ms          |    0.55 | solve.TimeSparseSystem.time_linsolve_Aaug(20)                        |
| -        | 54.3±0.4ms           | 25.0±0.04ms         |    0.46 | solve.TimeSparseSystem.time_linsolve_Aaug(30)                        |
| -        | 27.9±0.1ms           | 15.3±0.04ms         |    0.55 | solve.TimeSparseSystem.time_linsolve_Ab(20)                          |
| -        | 54.4±0.3ms           | 24.8±0.08ms         |    0.46 | solve.TimeSparseSystem.time_linsolve_Ab(30)                          |

Full benchmark results can be found as artifacts in GitHub Actions
(click on checks at the top of the PR).

@maliesen maliesen marked this pull request as ready for review February 4, 2024 14:09
Comment on lines 756 to 758
def test_indefinite_1_bug():
assert integrate((b + t)**(-a), t, meijerg=True
) == -b**(1 - a)*(1 + t/b)**(1 - a)/(a - 1)
).equals(-b**(1 - a)*(1 + t/b)**(1 - a)/(a - 1))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to change this test answer to show what is now returned.

The old result was:

In [4]: a, b, c = symbols("a b c")

In [5]: integrate((b + t)**(-a), t, meijerg=True)
Out[5]: 
               1 - a 
  1 - at-b     ⋅⎜1 + ─⎟      
        ⎝    b⎠      
─────────────────────
        a - 1 

The new result is

In [2]: integrate((b + t)**(-a), t, meijerg=True)
Out[2]: 
          1 - at-b⋅⎜1 + ─⎟      
   ⎝    b⎠      
────────────────
      a    a    
   ab  - b 

@oscarbenjamin
Copy link
Collaborator

Looks like this also fixed gh-25949. A test could be added.

@oscarbenjamin
Copy link
Collaborator

I had wondered if this fixed gh-25137 but it does not seem to.

@oscarbenjamin
Copy link
Collaborator

This looks good. Thanks for this.

This is the kind of bug that could linger for a long time and I'm sure it took some work to find the proper fix.

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.

Wrong result for a simple integral
3 participants