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

Simplification of degenerate ifelse #170

Closed
philbit opened this issue Apr 1, 2021 · 2 comments
Closed

Simplification of degenerate ifelse #170

philbit opened this issue Apr 1, 2021 · 2 comments
Labels
good first issue Good for newcomers

Comments

@philbit
Copy link
Contributor

philbit commented Apr 1, 2021

Some symbolic operations (e.g., differentiation of functions like max) yield IfElse.ifelse constructs to tell apart the different cases. However, these can lead to extraneous ifelses if the different cases end up being the same expression:

julia> @variables x
julia> ∂ₓ = Differential(x)
julia> expr = expand_derivatives(∂ₓ(∂ₓ(max(1,x))))
IfElse.ifelse(1 > x, 0, 0)

Perhaps this shouldn't even be here in the first place (because the differentiation could detect this), but at least it should be possible to simplify it 0, but it doesn't:

julia> simplify(expr)
IfElse.ifelse(1 > x, 0, 0)

(I am not even talking about the other, much deeper problem that this is not even mathematically correct. Technically, the second derivative is that of a discontinuous function, so a delta distribution is missing here, which could come back to bite you if this was used for a numerical scheme.)

┆Issue is synchronized with this Trello card by Unito

@YingboMa
Copy link
Member

YingboMa commented Apr 1, 2021

Haha, I always receive multiple requests of the same thing around the same time.

Regarding the derivative of non-smooth functions, using the delta distribution is not gonna work for numerical methods either. We plan to add a regularization pass that smooths discontinuous derivatives so that numerical methods can work.

@philbit
Copy link
Contributor Author

philbit commented Apr 1, 2021

Oh, definitely, that's a separate issue. I just mentioned it here out of interest (and to make it clear that I don't think ∂ₓ(∂ₓ(max(1,x))) should really be 0).

But independent of how to deal with derivatives, IfElse.ifelse(condition, y, y) should still simplify to y...

@YingboMa YingboMa added the good first issue Good for newcomers label Apr 25, 2021
shashi added a commit to JuliaSymbolics/SymbolicUtils.jl that referenced this issue Mar 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants