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

Improve the set handler #20650

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Improve the set handler #20650

wants to merge 4 commits into from

Conversation

sayandip18
Copy link
Contributor

@sayandip18 sayandip18 commented Dec 22, 2020

References to other Issues or PRs

Fixes #20535

Brief description of what is fixed or changed

The set handler can now deal with symbolic intervals

Other comments

Release Notes

NO ENTRY

@sympy-bot
Copy link

sympy-bot commented Dec 22, 2020

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.

  • No release notes entry will be added for this pull request.
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 #20535 

#### Brief description of what is fixed or changed
The set handler can now deal with symbolic intervals

#### Other comments


#### Release Notes

<!-- Write the release notes for this release below. 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 -->
NO ENTRY
<!-- END RELEASE NOTES -->

@sayandip18
Copy link
Contributor Author

Certain tests, for instance sympy/sets/tests/test_sets.py:test_intersect1, which are throwing error now need to be modified accordingly

else:
start = Max(a.start, b.start)
end = Min(a.end, b.end)
if a.start > b.start:
Copy link
Collaborator

Choose a reason for hiding this comment

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

This could raise for symbolic start and end. It could be if is_gt(a.start, a. end).

@sayandip18
Copy link
Contributor Author

>>> Intersection(Interval(1, x), Interval(2, 3)).contains(y)
(2 <= y) & (y <= Min(3, x))
>>> And(2<=y, y<= Min(3, x))
(y >= 2) & (y <= Min(3, x))
>>> Intersection(Interval(1, x), Interval(2, 3)).contains(y)==And(2<=y, y<= Min(3, x))
False

This should be True but I don't know why I'm getting False

@sayandip18
Copy link
Contributor Author

sayandip18 commented Dec 25, 2020

test_latex_intersection() of sympy/printing/tests/test_latex.py failed. latex(Intersection(Interval(0, 1), Interval(x, y))) now cannot work with raw string for some reason. Removing the r from the beginning of the string makes it work perfectly. Apparently, this change is somehow breaking certain things. Should I still continue @oscarbenjamin ?

@oscarbenjamin
Copy link
Collaborator

Apparently, this change is somehow breaking certain things. Should I still continue

Without knowing the cause of the breakage it's impossible to answer that question. What "breaks" and how?

@sayandip18
Copy link
Contributor Author

What "breaks" and how?

Both of my above comments.

@sayandip18
Copy link
Contributor Author

sayandip18 commented Dec 28, 2020

This test now returns False only if I treat the string as a normal string instead of a raw string, i.e. if I remove the r. and I'm still unable to figure out why this occurs.

@oscarbenjamin
Copy link
Collaborator

In [5]: 2 < y
Out[5]: y > 2

In [6]: S(2) < y
Out[6]: 2 < y

In [7]: Intersection(Interval(0, 1), Interval(x, y))
Out[7]: [Max(0, x), Min(1, y)]

@@ -889,7 +889,7 @@ def test_sympy__sets__sets__Intersection():
x = Symbol('x')
y = Symbol('y')
S = Intersection(Interval(0, x), Interval(y, 1))
assert isinstance(S, Intersection)
assert isinstance(S, Interval)
assert _test_args(S)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This test should is supposed to test Intersection so if it doesn't give an intersection then something else needs to be used as the arguments.

ucode_str = '[x, y] ∩ [z, w]'
ascii_str = '[x, y] n [z, w]'
ucode_str = '[Max(x, z), Min(w, y)]'
ascii_str = '[Max(x, z), Min(w, y)]'
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is supposed to be a test of printing an Intersection so if it doesn't give an intersection then something other than interval should be used as the arguments

@@ -917,7 +917,7 @@ def test_latex_union():

def test_latex_intersection():
assert latex(Intersection(Interval(0, 1), Interval(x, y))) == \
r"\left[0, 1\right] \cap \left[x, y\right]"
r"\left[\max\left(0, x\right), \min\left(1, y\right)\right]"
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is also a test for printing Intersection

@oscarbenjamin
Copy link
Collaborator

oscarbenjamin commented Jan 2, 2021

I'm not sure now whether having this evaluate automatically is a good idea or whether it should really be part of simplify or rewrite or something like that.

We do need a function that can rewrite an intersection of intervals using Max but that perhaps should not happen automatically when calling Intersection(interval1, interval1). If we had a function for doing that then it could be used by integrate.

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.

Error thrown by integrate
4 participants