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
sympy.solve returns imaginary solutions contrary to given assumptions #9973
Comments
I should mention I'm interested in doing work on this, if someone can point me in the right direction. |
What does it return if no assumptions are set? |
Same result, though I don't really think that should be a problem, since x could certainly be imaginary in that case. |
The solver tries to determine solutions for x that don't violate assumptions. The two results are correct in that regard. The solver doesn't try to figure out what values of z will make the the solution match the assumptions on x, however, and I'm not sure that one should change "check_assumptions" to do so since solving for values satisfying the assumptions is beyond to scope of checking that the assumptions are not violated. But perhaps when there are assumptions on x (as in your case) another function which tries to reduce a set of expressions to the values that would make them true might be in order, e.g. given expressions (e1..en) univariate in x what values of x make them all real...or positive...or something else. For example, for a single expression:
|
I don't think I agree that this is out of scope. I am asking solve to take an expression, and to rearrange it based on the assumptions inherent in the variables. There's no difference in the expression I'm handing sympy between variables X, Y, and Z, so why should solve ignore the assumptions on one of them but not the other? To put another way, solve was given a well-posed problem with a unique, specific, solution, but it stopped halfway through solving it. Instead, solve should do everything possible to return the simplest possible answer. In this case, that is simple, since the product of an imaginary number and a non-zero real number will always be imaginary, and solve knows that is not a solution to the problem it was given. Individuals can certainly enforce this themselves, using something like the example you showed. Unfortunately, this is not really a good solution if you are using sympy for code generation or anything else that needs to be automatic.
|
I agree. I am just saying that it should probably be a function of its own, not an add-on to |
Given the assumptions for x, this result is clearly wrong. For this problem, I would expect something more like this:
The text was updated successfully, but these errors were encountered: