Chain rule in Symbolics.jl

Probably I’m blind,
but is there a way to get the transformation
\frac{d}{d t} x(y(t)) = \frac{\partial x}{\partial y}(y(t)) \frac{\partial y}{\partial t}(t)
where x and y are symbolic. (I want do do a symbolic transformation on a PDE).

using Symbolics
@variables t x(..) y(..)
Dt = Differential(t)

e = Dt(x(y(t)))
expand_derivatives(e) # == Differential(t)(x(y(t)))
# is there some way to get something like
# magic( e ) == Differential(y)(x) * Differential(t)(x)

I understand that x(..) implies that x(y) stays unevaluated. So, the above code does what it should. But I cannot find a symbolic way to trigger the chain rule. (I’m open to use other packages)

(Maybe related: differentiation chain rule · Issue #157 · JuliaSymbolics/Symbolics.jl · GitHub )

2 Likes

I found this in the source code of Symbolics.jl

     # The recursive expand_derivatives was not able to remove
     # a nested Differential. We can attempt to differentiate the
     # inner expression wrt to the outer iv. And leave the
     # unexpandable Differential outside.

I am not sure, but this could be the reason?
Symbolics.jl/src/diff.jl

Mr. @shashi wrote those lines of code, probably he could help.

1 Like

Thanks! This seems to answer the question in the sense that it’s not there yet.

I was also thinking already about implementing a function for that tasks myself. :slight_smile:

1 Like

@shashi said he was working on this example.

2 Likes

Apply chain rule on symbolic functions by shashi · Pull Request #273 · JuliaSymbolics/Symbolics.jl · GitHub should have this feature.

3 Likes

Amazing. Thanks a lot :slight_smile: