JuliaSymbolics / Symbolics.jl

Symbolic programming for the next generation of numerical software
https://docs.sciml.ai/Symbolics/stable/
Other
1.36k stars 153 forks source link

Derivatives of registered functions on array variables ignored #439

Open baggepinnen opened 2 years ago

baggepinnen commented 2 years ago

In the example below, the unknown derivative of the registered function fun is completely ignored in the jacobian,

using Symbolics
@variables t x[1:2]
@register fun(x::Symbolics.Arr, t)
xp = fun(x, x[1])
ex = [xp^2]
Symbolics.jacobian(ex, [x])

julia> Symbolics.jacobian(ex, [x])
1×1 Matrix{Num}:
 0

However, if I do the same thing with scalars, it produces the desired results.

@variables x
@register fun(x)
xp = fun(x)
ex = [xp^2]
Symbolics.jacobian(ex, [x])

julia> Symbolics.jacobian(ex, [x])
1×1 Matrix{Num}:
 2fun(x)*Differential(x)(fun(x))

┆Issue is synchronized with this Trello card by Unito

baggepinnen commented 2 years ago

This issue can currently be worked around by the manual registering of https://github.com/JuliaSymbolics/Symbolics.jl/pull/445/files#diff-e7ba25de6eb72839907438ab2ca39a49fdd7025e031c7b6c95ad1a6842e1e613R74-R84