# Help with ForwardDiff2

**URL:** https://discourse.julialang.org/t/help-with-forwarddiff2/38384
**Category:** General Usage
**Created:** [April 28, 2020, 5:06pm UTC](https://discourse.julialang.org/t/help-with-forwarddiff2/38384 "2020-04-28T17:06:57Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![francesco.alemanno](https://avatars.discourse-cdn.com/v4/letter/f/e8c25b/32.png) [@francesco.alemanno](https://discourse.julialang.org/u/francesco.alemanno)
#### Post date: [April 28, 2020, 5:06pm UTC](https://discourse.julialang.org/t/help-with-forwarddiff2/38384/1 "2020-04-28T17:06:57Z")

</div>

I cant’s seem to make this kind of code work with ForwardDiff2

```julia

function gaussian(f,N)
    a=-8.38149 # exp(-x^2/2)/sqrt(2π) == eps(1.0)
    b=8.38149
    dx=(b-a)/(N)
    Δ=(b-a)/(2N)
    x=a+Δ
    I=(exp(-x*x/2).*f(x)).*dx
    for i in 2:N
        x=a+Δ*(2i-1)
        I=I.+(exp(-x*x/2).*f(x)).*dx
    end
    I/sqrt(2*π)
end

using ForwardDiff2: DI

f(α) = gaussian(x->tanh(x+α),100)

f(2.0) # 0.8646647167633871

DI(f)(2.0)

using StaticArrays

g(α) = gaussian(x->@SVector([tanh(2x+α),tanh(x+α)]),100)

g(2.0) # [0.6389517914690043, 0.8646647167633871]

DI(g)(2.0)

```

the error message it gives is about type promotion from Float64 to Dual

is there a known workaround?

thank you guys!

EDIT.

altough immensely inelegant, i managed to get excellent performance via manually using ForwardDiff Dual type.

---

<div class="post-metadata">

### Author: ![oriol.colomes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oriol.colomes/32/17651_2.png) [@oriol.colomes](https://discourse.julialang.org/u/oriol.colomes)
#### Post date: [July 17, 2020, 7:57am UTC](https://discourse.julialang.org/t/help-with-forwarddiff2/38384/2 "2020-07-17T07:57:28Z")

</div>

Hi @francesco.alemanno, could you post an example on how you solved the problem? Thank you
