-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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 force
to to_cnf
and to_dnf
; is_literal
made more general
#18912
Conversation
✅ Hi, I am the SymPy bot (v158). 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:
This will be added to https://github.com/sympy/sympy/wiki/Release-Notes-for-1.6. Note: This comment will be updated with the latest check if you edit the pull request. You need to reload the page to see it. Click here to see the pull request description that was parsed.
Update The release notes on the wiki have been updated. |
Codecov Report
@@ Coverage Diff @@
## master #18912 +/- ##
=============================================
+ Coverage 75.648% 75.679% +0.031%
=============================================
Files 647 647
Lines 168520 168535 +15
Branches 39710 39713 +3
=============================================
+ Hits 127483 127547 +64
+ Misses 35476 35439 -37
+ Partials 5561 5549 -12 |
What is the motivation for the literal_Not flag? The inclusion of Not is based on a standard definition of "literal". |
Hmm...I must have had a different problem when trying to detect the quick exit case for |
@@ -2782,6 +2793,16 @@ def simplify_logic(expr, form=None, deep=True, force=False): | |||
if form not in (None, 'cnf', 'dnf'): | |||
raise ValueError("form can be cnf or dnf only") | |||
expr = sympify(expr) | |||
# check for quick exit: right form and all args are |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reviewer: please check to see that this is the right logic for quick exit: if an expression is in the right form and all args are literal then there is nothing left to do.
return expr.args[0].is_Atom | ||
elif expr in (True, False) or expr.is_Atom: | ||
return True | ||
elif not isinstance(expr, BooleanFunction) and all( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
e.g. x < 3
is treated like a literal but x + y < 3
would not be a literal.
References to other Issues or PRs
fixes #9949
fixes #18904
Brief description of what is fixed or changed
When
to_cnf
is given an expression with more than 8 variables andsimplify=True
it will not simplify the expression -- and may not return it in cnf form and does so silently. Now, a ValueError is raised if simplification is requested andforce
is not True. The user has the option to not usesimplify
or to useforce
.In addition,
is_literal
andis_a_literal
were combined and made to recognize that things likex < 2
can be treated like a literal. This fixes issue 9949.Finally, a quick-exit is given to
simplify_logic
to deal with trivial cases that don't need simplification and are already in the correct, most implified form.Other comments
Release Notes
to_cnf
/to_dnf
(whensimplify=True) require
force=True` if there are more than 8 variablessimplify_logic
recognizes trivial simplified casesis_literal
can treatNot
as literal or not by using theliteral_Not
flag