Skip to content

Conversation

oscarbenjamin
Copy link
Collaborator

References to other Issues or PRs

Fixes #22428

See also the discussion about evaluation in the assumptions system here: #23488 (comment)

Brief description of what is fixed or changed

Avoid creating new expressions during assumptions queries. This makes the old assumptions slightly less powerful but at the same time faster and simpler and more robust. This also fixes a bug making it safe to query the old assumptions under evaluate(False).

Other comments

Release Notes

  • core
    • A bug preventing the use of the old assumptions under evaluate(False) was fixed.

@sympy-bot
Copy link

sympy-bot commented Jun 27, 2022

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:

  • core
    • A bug preventing the use of the old assumptions under evaluate(False) was fixed. (#23693 by @oscarbenjamin)

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

See also the discussion about evaluation in the assumptions system here: https://github.com/sympy/sympy/pull/23488#discussion_r903204398

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

Avoid creating new expressions during assumptions queries. This makes the old assumptions slightly less powerful but at the same time faster and simpler and more robust. This also fixes a bug making it safe to query the old assumptions under `evaluate(False)`.

#### 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 -->
* core
  * A bug preventing the use of the old assumptions under `evaluate(False)` was fixed.
<!-- END RELEASE NOTES -->

Update

The release notes on the wiki have been updated.

@github-actions
Copy link

github-actions bot commented Jun 28, 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
     [e0d6b5cf]       [24141c16]
-        95.0±2ms       62.6±0.8ms     0.66  integrate.TimeIntegrationRisch02.time_doit(10)
-        93.2±2ms       61.7±0.5ms     0.66  integrate.TimeIntegrationRisch02.time_doit_risch(10)

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

@oscarbenjamin
Copy link
Collaborator Author

The change here exposed a bug in solveset. I've improved the checking of solutions to equations with radicals and fixed some tests.

@oscarbenjamin oscarbenjamin mentioned this pull request Jul 8, 2022
44 tasks
@oscarbenjamin oscarbenjamin modified the milestones: SymPy 1.11, SymPy 1.12 Jul 11, 2022
@oscarbenjamin oscarbenjamin marked this pull request as draft November 24, 2022 21:07
@oscarbenjamin oscarbenjamin marked this pull request as ready for review January 27, 2023 19:59
@oscarbenjamin
Copy link
Collaborator Author

Thanks @smichr. I've incorporated your suggestions with small changes.

I'm marking this as ready for review.

elif a.is_Mul and S.ImaginaryUnit in a.args:
coeff, ai = a.as_coeff_mul(S.ImaginaryUnit)
if ai == (S.ImaginaryUnit,) and coeff.is_extended_real:
im_I.append(a*S.ImaginaryUnit)
Copy link
Member

Choose a reason for hiding this comment

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

This general pattern does still create an expression though, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It does. I want here with @smichr's suggestion that reduces the impact of the change slightly.

Thinking about it now im_I.append(Mul(*ai, evaluate=False)) would be better so that we know that we produce a smaller Mul without depending on evaluation.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Rather im_I.append(-coeff). If a = I*coeff then I*a = -coeff.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've just changed this to -coeff.

@asmeurer
Copy link
Member

The general idea here about removing recursive evaluation in assumptions is good.

But can we really rely on assumptions functioning in evaluate=False? Do we know that the basic canonicalization that is disabled by evaluate=False would never be implicitly assumed in an assumption handler?

@oscarbenjamin
Copy link
Collaborator Author

But can we really rely on assumptions functioning in evaluate=False? Do we know that the basic canonicalization that is disabled by evaluate=False would never be implicitly assumed in an assumption handler?

No, we don't know that but really that constraint should be respected by the assumptions system. Code in the assumptions system that does anything else should be changed (and there are many examples).

@oscarbenjamin
Copy link
Collaborator Author

This is the one remaining release blocker.

Can anyone review it?

If not I'll remove the milestone.

@smichr
Copy link
Member

smichr commented Mar 11, 2023

This looks ok to me (though I am sure I could be missing something in the Complements and ConditionSet logic. But I don't see a reason to hold this up. (I just happened to notice this in a look at recently changed PRs so just finished relooking at it.)

@smichr smichr merged commit 5cd4dad into sympy:master Mar 11, 2023
@oscarbenjamin
Copy link
Collaborator Author

Thanks!

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.

Upgrading to 1.9 broke assumptions with evaluate=False
4 participants