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

[Don't Merge][Prototype] Defining ImageSet Union #17079

Open
wants to merge 6 commits into
base: master
from

Conversation

Projects
None yet
4 participants
@jmig5776
Copy link
Member

commented Jun 23, 2019

References to other Issues or PRs

Brief description of what is fixed or changed

This PR will define imageset union function for linear expression
Example:

>>> img1 = ImageSet(Lambda(n, 4*n + 4), S.Integers)
>>> img2 = ImageSet(Lambda(n, 4*n), S.Integers)
>>> Union(img1, img2)
ImageSet(Lambda(n, 4*n), S.Integers)

>>> img1 = ImageSet(Lambda(n, n + 5), S.Integers)
>>> img2 = ImageSet(Lambda(n, 3*n), S.Integers)
>>> Union(img1, img2)
S.Integers

>>> img1 = ImageSet(Lambda(n, 2 * n * pi + pi / 4), S.Integers)
>>> img2 = ImageSet(Lambda(n, 2 * n * pi + 5 * pi / 4), S.Integers)
>>> Union(img1, img2)
ImageSet(Lambda(n, n * pi + pi / 4), S.Integers)

Other comments

Release Notes

NO ENTRY

@sympy-bot

This comment has been minimized.

Copy link

commented Jun 23, 2019

Hi, I am the SymPy bot (v147). 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.

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.

<!-- 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://github.com/blog/1506-closing-issues-via-pull-requests . Please also
write a comment on that issue linking back to this pull request once it is
open. -->


#### Brief description of what is fixed or changed
This PR will define imageset union function for linear expression
Example:
```python
>>> img1 = ImageSet(Lambda(n, 4*n + 4), S.Integers)
>>> img2 = ImageSet(Lambda(n, 4*n), S.Integers)
>>> Union(img1, img2)
ImageSet(Lambda(n, 4*n), S.Integers)

>>> img1 = ImageSet(Lambda(n, n + 5), S.Integers)
>>> img2 = ImageSet(Lambda(n, 3*n), S.Integers)
>>> Union(img1, img2)
S.Integers

>>> img1 = ImageSet(Lambda(n, 2 * n * pi + pi / 4), S.Integers)
>>> img2 = ImageSet(Lambda(n, 2 * n * pi + 5 * pi / 4), S.Integers)
>>> Union(img1, img2)
ImageSet(Lambda(n, n * pi + pi / 4), S.Integers)
```

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

@jmig5776

This comment has been minimized.

Copy link
Member Author

commented Jun 23, 2019

@oscarbenjamin

This comment has been minimized.

Copy link
Contributor

commented Jun 23, 2019

Both of the examples you showed might be handled better in general if ImageSet evaluated linear maps to a canonical form. Currently we have

In [1]: ImageSet(Lambda(n, 4*n + 4), S.Integers)                                                                                  
Out[1]: {4⋅n + 4 | n ∊ ℤ}

which could just simplify to 4*n and

In [2]: ImageSet(Lambda(n, n + 5), S.Integers)                                                                                    
Out[2]: {n + 5 | n ∊ ℤ}

which could simplify to ℤ anyway.

@jmig5776

This comment has been minimized.

Copy link
Member Author

commented Jun 23, 2019

This PR is basically to get all of your opinions on the procedure to unify two ImageSet. The algorithm that is implemented here is most fundamental. Please bear with me

We have to unify two sets i.e a*n + b and c*n + d . So which means if both of these expressions can be written in a single x*n + y.
So what I do is I maintain a list1=[], p = lcm(a,c) in these following steps

  1. I insert all values of an +b for n = 0 to up to an + b < 2*p.
  2. In the same list I Insert all cn +d for n = 0 to up to cn + d < 2*p.
  3. Now from the list from first and second element I find the expression x*n + y which satisfies the pattern.
  4. I check if this expression gives correct values on the whole list1. If yes then it is the required expression otherwise it's not.

Please consider this point while reviewing the PR. This PR is meant to get a proper procedure first for defining imageset union and not the code. The code can be improved later on.

@jmig5776

This comment has been minimized.

Copy link
Member Author

commented Jun 23, 2019

@oscarbenjamin Please go through the tests in files changed. These were just basic examples. I will edit the PR description with complex examples.

@oscarbenjamin

This comment has been minimized.

Copy link
Contributor

commented Jun 23, 2019

@jmig5776 I realise that this PR handles more complicated cases as well. I just wanted to remark that related simplifications can happen in ImageSet.eval.

@oscargus

This comment has been minimized.

Copy link
Contributor

commented Jun 23, 2019

Look at #16033 and even more relevant the older PRs mentioned there. (Too tired at the moment to make a more relevant comment, but there are some good discussions there.)

@jmig5776

This comment has been minimized.

Copy link
Member Author

commented Jun 24, 2019

Yeah, @oscargus I went through all the PRs before. @Shekharrajak I would like to have your opinion here for the method involved here. @smichr Can you please guide me here how I can reduce code here if this method seems convinient to you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.