# Reverse rule in Enzyme for an implicit function

**URL:** https://discourse.julialang.org/t/reverse-rule-in-enzyme-for-an-implicit-function/131327
**Category:** Numerics
**Tags:** question, ad, enzyme
**Created:** [August 4, 2025, 9:23am UTC](https://discourse.julialang.org/t/reverse-rule-in-enzyme-for-an-implicit-function/131327 "2025-08-04T09:23:05Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [August 4, 2025, 9:23am UTC](https://discourse.julialang.org/t/reverse-rule-in-enzyme-for-an-implicit-function/131327/1 "2025-08-04T09:23:05Z")

</div>

Suppose H is the cdf of a distribution, A, B are real numbers, and p is defined by

p = H(p A + (1 - p) B)

This can be implemented simply in Julia as

```julia
using Roots, Distributions

struct Problem{T,S}
    H::T
    A::S
    B::S
end

function condition(problem::Problem, p)
    (; H, A, B) = problem
    cdf(H, p * A + (1 - p) * B) - p
end

solvep(problem::Problem) = find_zero(Base.Fix1(condition, problem), (0.0, 1.0))

```

However, I want to

1. AD through `solvep` using Enzyme.jl, (actually, I am ADing a larger function that calls `solvep`)

2. preferably in a way that works via a generic H, so I don’t have to commit to knowing its parameters etc.

My understanding is that I would have to manually call AD on the `H(...)` expression, but I don’t know how to hook into that. Any suggestions are welcome, even if they are not full solutions.

---

<div class="post-metadata">

### Author: ![yolhan\_mannes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yolhan_mannes/32/220485_2.png) [@yolhan\_mannes](https://discourse.julialang.org/u/yolhan_mannes)
#### Post date: [August 4, 2025, 11:04am UTC](https://discourse.julialang.org/t/reverse-rule-in-enzyme-for-an-implicit-function/131327/2 "2025-08-04T11:04:39Z")

</div>

not yet finished I think but it will be [FAQ · ImplicitDifferentiation.jl](https://juliadecisionfocusedlearning.github.io/ImplicitDifferentiation.jl/dev/faq/), works with Zygote.jl and ForwardDiff.jl and you may be able to define the rule with it and build the enzyme one after

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [August 4, 2025, 1:19pm UTC](https://discourse.julialang.org/t/reverse-rule-in-enzyme-for-an-implicit-function/131327/3 "2025-08-04T13:19:08Z")

</div>

As stated in the question, I want to work with Enzyme.jl. Also, cf

> <https://github.com/JuliaDecisionFocusedLearning/ImplicitDifferentiation.jl/issues/35>
>
> As of today, Enzyme supports \[custom rules\](https://enzymead.github.io/Enzyme.jl…/stable/generated/custom\_rule/), which means we could make ImplicitDifferentation compatible with this promising AD backend
