# ForwardDiff.jl: Compute J\_f(x) \* f(x)

**URL:** <https://discourse.julialang.org/t/forwarddiff-jl-compute-j-f-x-f-x/99704>\
**Category:** General Usage\
**Tags:** question\
**Created:** [June 1, 2023, 5:05am UTC](https://discourse.julialang.org/t/forwarddiff-jl-compute-j-f-x-f-x/99704 "2023-06-01T05:05:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ranocha](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ranocha/32/35588_2.png) [@ranocha](https://discourse.julialang.org/u/ranocha)\
**Post date:** [June 1, 2023, 5:05am UTC](https://discourse.julialang.org/t/forwarddiff-jl-compute-j-f-x-f-x/99704/1 "2023-06-01T05:05:11Z")

</div>

There are some discussions how to compute the Jacobian-vector product J\_f(x) \* y for a function f efficiently with ForwardDiff.jl, e.g., [Calculating J\_f(x) . y efficiently · Issue #319 · JuliaDiff/ForwardDiff.jl · GitHub](https://github.com/JuliaDiff/ForwardDiff.jl/issues/319)  
I have a use case where I would like to use the value f(x) for the vector y. Using the approach described there, I basically need to compute f(x) first and then the Jacobian-vector product J\_f(x) \* f(x). However, the latter will also compute f(x) as part of the expression, of course.

Does anybody know a more efficient way to compute the special Jacobian-vector product J\_f(x) \* f(x) using ForwardDiff.jl?

---

<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 1, 2023, 12:02pm UTC](https://discourse.julialang.org/t/forwarddiff-jl-compute-j-f-x-f-x/99704/2 "2023-06-01T12:02:37Z")

</div>

I’m not sure there will be an extra trick here, since you’d need to compute f(x) before the AD pass in order to seed it properly.

---

<div class="post-metadata">

**Author:** ![ranocha](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ranocha/32/35588_2.png) [@ranocha](https://discourse.julialang.org/u/ranocha)\
**Post date:** [June 1, 2023, 12:43pm UTC](https://discourse.julialang.org/t/forwarddiff-jl-compute-j-f-x-f-x/99704/3 "2023-06-01T12:43:15Z")

</div>

That’s my current guess, too, but I’m not an AD expert. That’s why I ask. There are sometimes really clever tricks people come up with, in particular in Julia forums like this 🙂
