Skip to content
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

fix(integrals): handle degenerate case in Risch PRDE #23959

Merged
merged 1 commit into from Sep 2, 2022

Conversation

oscarbenjamin
Copy link
Contributor

References to other Issues or PRs

Fixes #23948

Brief description of what is fixed or changed

Ensure that while the matrix is still empty it has the right number of columns.

Other comments

Release Notes

  • integrals
    • A bug in the risch integration routine was fixed. Previously in certain conditions involving complicated integrands the routine would fail with AssertionError.

@sympy-bot
Copy link

sympy-bot commented Aug 22, 2022

Hi, I am the SymPy bot (v167). 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
    • A bug in the risch integration routine was fixed. Previously in certain conditions involving complicated integrands the routine would fail with AssertionError. (#23959 by @oscarbenjamin)

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

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 #23948

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

Ensure that while the matrix is still empty it has the right number of columns.

#### 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:

* solvers
  * Added a new solver for logarithmic equations.

* functions
  * Fixed a bug with log of integers.

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
   * A bug in the `risch` integration routine was fixed. Previously in certain conditions involving complicated integrands the routine would fail with `AssertionError`.
<!-- END RELEASE NOTES -->

Update

The release notes on the wiki have been updated.

@@ -344,7 +344,7 @@ def prde_no_cancel_b_large(b, Q, n, DE):

if all(qi.is_zero for qi in Q):
dc = -1
M = zeros(0, 2, DE.t)
M = zeros(0, m, DE.t)
else:
dc = max([qi.degree(DE.t) for qi in Q])
M = Matrix(dc + 1, m, lambda i, j: Q[j].nth(i), DE.t)
Copy link
Member

Choose a reason for hiding this comment

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

Not really sure why I ever did it like this since it isn't this way in the book, but this line can just be used for both cases. I think I just didn't have a clear understanding of how empty matrices work, or possibly there was some bug with how they behaved back then, I don't know.

This is page 234 in Bronstein's book, ParamPolyRishDENoCancel1, for anyone checking. Really these docstrings ought to reference the exact pseudocode + page number in the book to make this easier.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe you did it like this because:

(Pdb) p Q[0].degree(DE.t)
-oo

Copy link
Member

Choose a reason for hiding this comment

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

Oh to be clear, the dc = -1 part is there because that's how it's written in the book (and the ambiguity of degree(0) is clearly the reason). I meant I don't know why I put the matrix definition inside of the if. In the book, it's separate.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, I see what you mean. I've moved the matrix definition out.

@asmeurer
Copy link
Member

This line is also probably wrong

M = Matrix()

@asmeurer
Copy link
Member

Also I'm surprised that Matrix() with no arguments works (it creates a 0x0 matrix). I guess that's been around for some time, but IMO it's not great.

@oscarbenjamin
Copy link
Contributor Author

This line is also probably wrong

Can you think of a test-case that would hit that line?

Also I'm surprised that Matrix() with no arguments works

Nothing like this surprises me any more.

@github-actions
Copy link

github-actions bot commented Aug 23, 2022

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)

       before           after         ratio
     [26f7bdbe]       [5eb59bda]
     <sympy-1.11^0>                 
-     1.35±0.05ms         833±30μs     0.62  solve.TimeSparseSystem.time_linear_eq_to_matrix(10)
-      3.90±0.2ms      1.49±0.09ms     0.38  solve.TimeSparseSystem.time_linear_eq_to_matrix(20)
-      7.38±0.2ms       2.21±0.2ms     0.30  solve.TimeSparseSystem.time_linear_eq_to_matrix(30)

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

@jksuom
Copy link
Member

jksuom commented Sep 2, 2022

I think this is ready to be merged.

@jksuom jksuom merged commit b2452fd into sympy:master Sep 2, 2022
@oscarbenjamin oscarbenjamin deleted the pr_risch branch November 29, 2023 15:04
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.

Assertion error using integrate in sympy 1.10.1, Python 3.10.5
4 participants