You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following reproducer generates incorrect code:
using Symbolics
x =only(@variables(x))
f =mod(x, 1.0)
df = Symbolics.derivative(f, x)
dfc = Symbolics.build_function(df, x; expression=Val(false))
dfc(0.5) # returns `Differential(x)(0.5)::SymbolicsUtils.BasicSymbolic{Float64}`)
The generated function returns Differential(x)(0.5)::SymbolicsUtils.BasicSymbolic{Float64}. I would have expected it to return 1.0::Float64. I understand that mod is not differentiable everywhere so maybe this is intended. But then an informative error would be preferred.
The text was updated successfully, but these errors were encountered:
The derivative of mod is not defined, so it's left as a symbolic derivative. Since none of the arguments x are D(x), it does not find and replace that to an argument. So then it errors as an improper function definition that has symbolics left in the built function. We should add a rule where if the generated expression has a symbolic piece left it should error at build_function time, but at least right now if not all of the symbolic elements are lifted to arguments it will error at call time or return a symbolic expression, which is at least safe but an earlier error would be more helpful.
Yes, we should probably define its derivative as something like ifelse(x==0,x,DomainError()), but that cannot be represented symbolically like that. Also, symbolic functions try to never error, they use NaNMath by default instead of erroring, so maybe ifelse(x==0,x,NaN) is the appropriate definition?
The following reproducer generates incorrect code:
The generated function returns
Differential(x)(0.5)::SymbolicsUtils.BasicSymbolic{Float64}
. I would have expected it to return1.0::Float64
. I understand thatmod
is not differentiable everywhere so maybe this is intended. But then an informative error would be preferred.The text was updated successfully, but these errors were encountered: