# Chain rule in Symbolics.jl

**URL:** https://discourse.julialang.org/t/chain-rule-in-symbolics-jl/63146
**Category:** Modelling & Simulations
**Tags:** symbolic
**Created:** [June 18, 2021, 4:13pm UTC](https://discourse.julialang.org/t/chain-rule-in-symbolics-jl/63146 "2021-06-18T16:13:18Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![SteffenPL](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/steffenpl/32/206270_2.png) [@SteffenPL](https://discourse.julialang.org/u/SteffenPL)
#### Post date: [June 18, 2021, 4:13pm UTC](https://discourse.julialang.org/t/chain-rule-in-symbolics-jl/63146/1 "2021-06-18T16:13:18Z")

</div>

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).

```julia
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](https://github.com/JuliaSymbolics/Symbolics.jl/issues/157) )

---

<div class="post-metadata">

### Author: ![leonandonayre](https://avatars.discourse-cdn.com/v4/letter/l/da6949/32.png) [@leonandonayre](https://discourse.julialang.org/u/leonandonayre)
#### Post date: [June 19, 2021, 8:02pm UTC](https://discourse.julialang.org/t/chain-rule-in-symbolics-jl/63146/2 "2021-06-19T20:02:28Z")

</div>

I found this in the source code of Symbolics.jl

```julia
     # 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](https://github.com/JuliaSymbolics/Symbolics.jl/blob/master/src/diff.jl)

 ![imagen](https://global.discourse-cdn.com/julialang/original/3X/9/4/9437e18774c8efd2e73b4539c0bc7cbb020c844a.png)

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

---

<div class="post-metadata">

### Author: ![SteffenPL](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/steffenpl/32/206270_2.png) [@SteffenPL](https://discourse.julialang.org/u/SteffenPL)
#### Post date: [June 19, 2021, 8:23pm UTC](https://discourse.julialang.org/t/chain-rule-in-symbolics-jl/63146/3 "2021-06-19T20:23:49Z")

</div>

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. 🙂

---

<div class="post-metadata">

### Author: ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)
#### Post date: [June 19, 2021, 9:31pm UTC](https://discourse.julialang.org/t/chain-rule-in-symbolics-jl/63146/4 "2021-06-19T21:31:32Z")

</div>

@shashi said he was working on this example.

---

<div class="post-metadata">

### Author: ![shashi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/shashi/32/1824_2.png) [@shashi](https://discourse.julialang.org/u/shashi)
#### Post date: [June 22, 2021, 4:47pm UTC](https://discourse.julialang.org/t/chain-rule-in-symbolics-jl/63146/5 "2021-06-22T16:47:32Z")

</div>

[Apply chain rule on symbolic functions by shashi · Pull Request #273 · JuliaSymbolics/Symbolics.jl · GitHub](https://github.com/JuliaSymbolics/Symbolics.jl/pull/273) should have this feature.

---

<div class="post-metadata">

### Author: ![SteffenPL](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/steffenpl/32/206270_2.png) [@SteffenPL](https://discourse.julialang.org/u/SteffenPL)
#### Post date: [June 22, 2021, 5:05pm UTC](https://discourse.julialang.org/t/chain-rule-in-symbolics-jl/63146/6 "2021-06-22T17:05:29Z")

</div>

Amazing. Thanks a lot 🙂
