# ChainRules: Replacing DiffRules in the Julia AD world

**URL:** https://discourse.julialang.org/t/chainrules-replacing-diffrules-in-the-julia-ad-world/17608
**Category:** Package Announcements
**Tags:** package
**Created:** [November 16, 2018, 6:05pm UTC](https://discourse.julialang.org/t/chainrules-replacing-diffrules-in-the-julia-ad-world/17608 "2018-11-16T18:05:12Z")
**Posts on this page:** 4
**Page:** 3

<div class="post-metadata">

### Author: ![yha](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yha/32/3502_2.png) [@yha](https://discourse.julialang.org/u/yha)
#### Post date: [December 2, 2018, 12:47am UTC](https://discourse.julialang.org/t/chainrules-replacing-diffrules-in-the-julia-ad-world/17608/41 "2018-12-02T00:47:31Z")

</div>

Perhaps `DistributionalDerivative` or `GeneralizedDerivative` would be clearer than `ImpulseTrain`. If I saw `ImpulseTrain(f, x)`, I would probably be confused wondering why there is a function argument and how does this object relate to `f` and `x`.

---

<div class="post-metadata">

### Author: ![MikeInnes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mikeinnes/32/3656_2.png) [@MikeInnes](https://discourse.julialang.org/u/MikeInnes)
#### Post date: [December 2, 2018, 6:01pm UTC](https://discourse.julialang.org/t/chainrules-replacing-diffrules-in-the-julia-ad-world/17608/42 "2018-12-02T18:01:58Z")

</div>

Also, one thing I just started to work on is adding support for mutation in AD, and I’d be interested in any thinking you’ve done on handling that. For the most part you know when mutation is happening (e.g. `setindex!`, `mul!`), but there are also cases (e.g. `getindex`) where you want to be generic across array types but also take advantage of mutation where possible.

Of course, this might be a special-enough case that it can just be handled by individual AD frameworks, but it seemed worth raising.

---

<div class="post-metadata">

### Author: ![Per](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/per/32/10387_2.png) [@Per](https://discourse.julialang.org/u/Per)
#### Post date: [December 4, 2018, 9:56am UTC](https://discourse.julialang.org/t/chainrules-replacing-diffrules-in-the-julia-ad-world/17608/43 "2018-12-04T09:56:54Z")

</div>

I like the name `GeneralizedDerivative`. This would also imply that `F` is not necessarily piecewise constant.

One could have a syntax like

```julia
@weakrule(abs(x), sign(x))
@weakrule(sign(x), 0)

```

to signify that `abs` and `sign` only have derivatives in a weak sense.

Edit: Or, maybe

```julia
@rule(abs(x), @weak(sign(x)))
@rule(sign(x), @weak(0))

```

since functions might be differentiable for some arguments but not others.

---

<div class="post-metadata">

### Author: ![simeonschaub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simeonschaub/32/216566_2.png) [@simeonschaub](https://discourse.julialang.org/u/simeonschaub)
#### Post date: [March 12, 2019, 3:04pm UTC](https://discourse.julialang.org/t/chainrules-replacing-diffrules-in-the-julia-ad-world/17608/44 "2019-03-12T15:04:20Z")

</div>

Would it be possible to get some simple examples for calculating complex gradients for Functions f: \mathbb C^n \rightarrow \mathbb C via forward mode AD? I’m a bit lost at the moment and the above example doesn’t work for me with the most recent version. Any help would be much appreciated!

[Previous page](https://discourse.julialang.org/t/chainrules-replacing-diffrules-in-the-julia-ad-world/17608.md?page=2)
