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

remove bug and make it more robust #17442

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

remove bug and make it more robust #17442

wants to merge 3 commits into from

Conversation

RituRajSingh878
Copy link
Contributor

References to other Issues or PRs

Brief description of what is fixed or changed

During separation,separatesvarscheks each multiplicative factors of the equation and find out that the factor is separable or not and it seems good. But if we will send an equation with expand(eq) so all the factor of equation will destroy and now separatevars will may not able to separate the equation. So I have added factor(eq) so that we can make it a multiplicative equation if possible.

And second, think is a bug- passing of force into separatevars in the function _separatevars.

And the third thing is after getting a multiplicative equation when we are passing each factor again in separatevars then maybe after doing simplification of each factor we can get a better result.
I tried this and able to separate the more equations. (see added test case)

eg-
eq=exp(x**2+y**2)*(cos(x-y)+cos(x+y))

after passing this term we are getting one of the factors - (cos(x-y)+cos(x+y)) and passing this only in separatevars we are not able to separate it so I think we can pass simplify(factor) every time in separatevars so that we can get a simplified equation and then we can easily separate the equation.

Other comments

Release Notes

  • simplify
    • remove a bug from separatevars and make it more robust

@sympy-bot
Copy link

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.

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

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
During separation,` separatesvars `cheks each multiplicative factors of the equation and find out that the factor is separable or not and it seems good. But if we will send an equation with expand(eq) so all the factor of equation will destroy and now `separatevars` will may not able to separate the equation. So I have added factor(eq) so that we can make it a multiplicative equation if possible.

And second, think is a bug- passing of force into `separatevars `in the function `_separatevars.`

And the third thing is after getting a multiplicative equation when we are passing each factor again in `separatevars` then maybe after doing simplification of each factor we can get a better result.
I tried this and able to separate the more equations. (see added test case)

eg-
 `eq=exp(x**2+y**2)*(cos(x-y)+cos(x+y)) ` 

after passing this term we are getting one of the factors -  `(cos(x-y)+cos(x+y))` and passing this only in `separatevars` we are not able to separate it so I think we can pass simplify(factor) every time in `separatevars `so that we can get a simplified equation and then we can easily separate the equation.





### 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 -->
- simplify
  - remove a bug from separatevars and make it more robust
<!-- END RELEASE NOTES -->

@oscargus
Copy link
Contributor

It would be nice to see the impact on simplify here. Is there a test one can add that works now and not earlier that illustrates the benefit?

@RituRajSingh878
Copy link
Contributor Author

Is there a test one can add that works now and not earlier that illustrates the benefit?

the newly added test case was not working, now they are working

@RituRajSingh878
Copy link
Contributor Author

although we can separate the equation - eq=exp(x**2+y**2)*(cos(x-y)+cos(x+y) now but not able to separate this((cos(x-y)+cos(x+y)) equation. So I think We nedd to do some extra work. maybe we can try to separate the equation just by passing and if it not separable then we can try again by passing simplify(eq)

@oscarbenjamin
Copy link
Contributor

If this is going to call something like simplify then there probably needs to be an option to prevent that. At the moment separatevars is a fairly simple low-level routine which is used in a few places (not many) and we should be careful that this doesn't slow those cases down.

@oscarbenjamin
Copy link
Contributor

It's probably better to rewrite sin/cos as exp:

In [28]: e = cos(x+y)+cos(x-y)                                                                                                    

In [29]: factor(e.rewrite(exp)).rewrite(sin)                                                                                      
Out[29]: 2cos(x)cos(y)

@RituRajSingh878
Copy link
Contributor Author

It's probably better to rewrite sin/cos as exp:

In [28]: e = cos(x+y)+cos(x-y)                                                                                                    

In [29]: factor(e.rewrite(exp)).rewrite(sin)                                                                                      
Out[29]: 2cos(x)cos(y)

It may help but sometime it will make the equation very complex like-

In [28]: e=sin(x+y)/cos(x+y)

In [29]: factor(e.rewrite(exp)).rewrite(sin)
Out[29]:((-sin(x) + cos(x))(-sin(y) + cos(y)) - (ⅈsin(x) + cos(x))(ⅈsin(y) +
──────────────────────────────────────────────────────────────────────────────
  (-sin(x) + cos(x))(-sin(y) + cos(y)) + (ⅈsin(x) + cos(x))(ⅈsin(y) + 

 cos(y)))
─────────
cos(y))  

in this case, we have to deal with the more complex equation than given one so I think we can't do every time.

@oscarbenjamin
Copy link
Contributor

In [28]: e=sin(x+y)/cos(x+y)

Is this example separable?

@RituRajSingh878
Copy link
Contributor Author

In [28]: e=sin(x+y)/cos(x+y)

Is this example separable?

No
I am just taking an example to show that a simpler example can be a complex due to this.

@czgdp1807
Copy link
Member

Any news? Can it be taken over by somebody else?

@smichr
Copy link
Member

smichr commented Jun 22, 2020

I would recommend against making separatevars be too smart. Some routines should just do a straigtforward task fast and well. It is the user's (or high-level routine's) job to try rewriting to make it work.

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.

None yet

7 participants