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

Add dontcare argument to simplify_logic #23986

Merged
merged 1 commit into from Sep 12, 2022

Conversation

oscargus
Copy link
Contributor

@oscargus oscargus commented Aug 28, 2022

References to other Issues or PRs

Another part of #22753

Brief description of what is fixed or changed

simplify_logic now has a dontcare keyword argument, so that one can simplify the expression under the assumption that the dontcare-expression does not matter. Useful in general, but especially for Piecewise simplification where one then can set the previous conditions to don't care.

Other comments

Release Notes

  • logic
    • simplify_logic now has a dontcare keyword argument for simplifying under don't care-conditions.

@oscargus oscargus added the logic label Aug 28, 2022
@sympy-bot
Copy link

sympy-bot commented Aug 28, 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:

  • logic
    • simplify_logic now has a dontcare keyword argument for simplifying under don't care-conditions. (#23986 by @oscargus)

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. -->

Another part of #22753

#### Brief description of what is fixed or changed
`simplify_logic` now has a `dontcare` keyword argument, so that one can simplify the expression under the assumption that the `dontcare`-expression does not matter. Useful in general, but especially for Piecewise simplification where one then can set the previous conditions to don't care.

#### 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 -->
* logic
    * `simplify_logic` now has a `dontcare` keyword argument for simplifying under don't care-conditions.
<!-- END RELEASE NOTES -->

Update

The release notes on the wiki have been updated.

@github-actions
Copy link

github-actions bot commented Aug 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
     [41d90958]       [fb7c59c1]
     <sympy-1.11.1^0>                 
-         950±2μs          611±1μs     0.64  solve.TimeSparseSystem.time_linear_eq_to_matrix(10)
-        2.75±0ms         1.14±0ms     0.42  solve.TimeSparseSystem.time_linear_eq_to_matrix(20)
-     5.49±0.02ms         1.68±0ms     0.31  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).

@@ -2769,20 +2769,24 @@ def simplify_logic(expr, form=None, deep=True, force=False):
made. By setting ``force`` to ``True``, this limit is removed. Be
aware that this can lead to very long simplification times.

dontcare : Boolean expression
Copy link
Contributor

Choose a reason for hiding this comment

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

Speaking as someone who only recently learned what "don't care" means in logic maybe it would be good to have a reference for this:
https://en.wikipedia.org/wiki/Don%27t-care_term

@oscarbenjamin
Copy link
Contributor

Looks good to me

@oscargus
Copy link
Contributor Author

oscargus commented Sep 11, 2022

Rebased, the link added in three relevant positions and some crosslinking between POSform and SOPform.

>>> b = (~x & ~y & ~z) | ( ~x & ~y & z)
>>> simplify_logic(b)
~x & ~y
>>> simplify_logic(x | y, dontcare=y)
x
Copy link
Contributor

Choose a reason for hiding this comment

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

I think a less trivial example would be better. Perhaps this:

In [6]: simplify_logic(x ^ y, dontcare=x & y)
Out[6]: x ∨ y

Here it is not as simple as just supposing that the dontcare is False.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can modify it as part of next PR. Agreed that it is probably better.

@oscarbenjamin
Copy link
Contributor

Looks good to me. +1 to merge.

@oscargus oscargus merged commit 4ba1d0e into sympy:master Sep 12, 2022
@oscargus oscargus deleted the dontcaresimplifylogic branch September 12, 2022 18:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants