# New differentiation rules for ForwardDiff

**URL:** https://discourse.julialang.org/t/new-differentiation-rules-for-forwarddiff/19012
**Category:** General Usage
**Tags:** differentiation
**Created:** [December 26, 2018, 9:17pm UTC](https://discourse.julialang.org/t/new-differentiation-rules-for-forwarddiff/19012 "2018-12-26T21:17:13Z")
**Posts on this page:** 1
**Page:** 1

<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 26, 2018, 9:17pm UTC](https://discourse.julialang.org/t/new-differentiation-rules-for-forwarddiff/19012/1 "2018-12-26T21:17:13Z")

</div>

Is there currently an “official” way to add differentiation rules to be used by `ForwardDiff`?  
This was discussed a few months ago here:

> [@Registering Analytical Derivative with ReverseDiff/ForwardDiff](https://discourse.julialang.org/t/registering-analytical-derivative-with-reversediff-forwarddiff/10543):
>
> Is there a way to register a derivative function similar to JuMP’s usage in ForwardDiff or ReverseDiff? I have a small function which solves a simple optimization problem using svd, which isn’t automatically differentiated. But I do know the derivative due to the original formulation.

which pointed to `DiffRules.@define_diffrule`.  
I managed to get my new rule to work with

```julia
using DiffRules: @define_diffrule
using ForwardDiff
@define_diffrule Main.q(s,r) = :(Main.qs($s,$r)), :(Main.qr($s,$r))
ForwardDiff.eval(ForwardDiff.binary_dual_definition(:Main,:q))

```

but that seems a bit hacky. Is there a better way?

My reason for defining a rule manually is that `q` is not auto-differentiable and I have several functions defined in terms of `q` that I would like to automatically differentiate using the “manually” computed derivatives of `q`.
