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
Bug: Solveset with piecewise constant functions #18939
Comments
For invert see (https://github.com/sympy/sympy/blob/70381f282f2d9d039da860e391fe51649df2779d/sympy/solvers/solveset.py#L176-L181 I think for more vivid solution , it's under development :) |
Thanks a lot for the reference to |
You can also use plain |
Actually, looking into the code I found the source of the error, so I would like to "promote" this issue to a bug report. >>> solveset(y - Heaviside(x), x, Reals)
EmptySet I manually executed the lines of the function solveset in the current main branch. sympy/sympy/solvers/solveset.py Lines 2026 to 2034 in 0e22875
in which y - Heaviside(x) is rewritten as Piecewise((y, x < 0), (y - Heaviside(0), Eq(x, 0)), (y - 1, x > 0)) and then is passed to _solveset .It first skips all checks until this one: sympy/sympy/solvers/solveset.py Lines 934 to 941 in 0e22875
in which it is split into pieces, and thus solver(expr=y, symbol=x, in_set=Interval.open(-oo, 0)) is called with the first piece of the piecewise function, where sympy/sympy/solvers/solveset.py Lines 915 to 918 in 0e22875
Other pieces follow the same faith. I think that one would like to return a ConditionSet(x = y) in this case, which at least would give meaningful results in this case, but it might break lots of stuffs elsewhere. I would like to submit a Pull Request for this, since I need it such functionality, and also because I would like to familiarize myself with sympy repo. |
You're of course free to submit a pull request. I don't know what the fix should look like. Someone more familiar with the solvers code will have to comment. |
Yes, I will wait for someone who known the solvers code to answer. sympy/sympy/solvers/solveset.py Lines 915 to 918 in 0e22875
with a return ConditionSet(symbol, Eq(f, 0), domain) and no test broke.
It should now only be a matter of deciding how to return such results as sets, since they involve more than one variable. |
This reminds me of #16861 and in particular #16861 (comment). |
Hi! I couldn't find a procedure to call for inverting a specified real-valued function.$f(x) = x^2$ I would like to have returned $(g_1(y) = \sqrt{y}, y \in [0, \infty])$ and $(g_2(y) = - \sqrt{y}, y \in [0, \infty])$ .
For inverting I mean that it should return the different branches of the inverse, i.e. if I would ask it to invert
The "trick" of using solveset as in
seems not to specify the validity domain of the returned functions (i.e. in the example above does not return the result as Image(x -> sqrt(x), [0, \infty]) but only returns sqrt(x), sqrt(-x)).
Moreover it also appears to have major difficulties in dealing with the inversion of piecewise constant functions, such as the Heaviside function:
returns emptyset, while I would expect it to return a piecewise definition such as:
Is there any function that does this that I have overlooked? How difficult would it be to integrate such functionality (returning more appropriate information from solveset in functional form) into sympy?
The text was updated successfully, but these errors were encountered: