-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
feat: allow assumptions to be taken for equality query #21203
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
Conversation
Allow assumptions to Q.eq query
Add getter parameters to is_lt and other functions Assumptions for these functions do not work yet
✅ Hi, I am the SymPy bot (v161). 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.9. Click here to see the pull request description that was parsed.
Update The release notes on the wiki have been updated. |
Inspired by your comment in #21055, I came up with the design to implement refine logic without having duplicate code. The idea is to pass different getter functions as parameter. In I tried with that approach here to let |
I have thought about something like this. We do need to be clear about whether it does slow some things down though e.g.: In [12]: x = S.Zero
In [13]: getter = lambda obj, key: getattr(obj, 'is_%s' % key)
In [14]: %timeit x.is_zero
86.7 ns ± 0.865 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)
In [15]: %timeit getter(x, 'zero')
785 ns ± 60.3 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each) Also the approach here requires putting Another approach I thought about was to make a wrapper class that wraps an object with assumptions and then presents the interface of the old assumptions e.g.: def func(obj, assumptions=None):
objq = AssumptionsWrapper(obj, assumptions):
if objq.is_positive:
... The idea here is that if assumptions are not given then AssumptionsWrapper can just return the object unmodified so that def _eval_is_positive(self):
return ask(Q.positive(self.obj), self.assumptions) |
That is an interesting idea. I will open a discussion i mailing list. |
@oscarbenjamin |
Remove experimental features Code is parallel to is_eq for now
Make is_neq take assumptions
Remove parallel code in equality.py
Fix ExtendedRealHandler
Enhance is_eq
This PR is an improvement of what was introduced in #21235. I will wait for a few days for review and merge this. |
References to other Issues or PRs
Brief description of what is fixed or changed
Fix handler for
Q.extended_real
Allow
is_neq
to take assumptions.Apply the change from #21235 to
Q.eq
andQ.neq
.In the future, facts will modified so that assuming binary predicates such as
x != y
orx > y
can return the appropriate result.Other comments
Release Notes
is_neq
now takes assumptionsEq
andNe
can be refined by predicates such asQ.positive
,Q.zero
, etc.