# Automatic differentiation of complex functions: simple workaround

**URL:** https://discourse.julialang.org/t/automatic-differentiation-of-complex-functions-simple-workaround/75775
**Category:** Specific Domains
**Tags:** differentiation
**Created:** [February 4, 2022, 5:27am UTC](https://discourse.julialang.org/t/automatic-differentiation-of-complex-functions-simple-workaround/75775 "2022-02-04T05:27:28Z")
**Posts on this page:** 1
**Showing post:** 7

<div class="post-metadata">

### Author: ![Mason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mason/32/2423_2.png) [@Mason](https://discourse.julialang.org/u/Mason)
#### Post date: [October 7, 2023, 11:55am UTC](https://discourse.julialang.org/t/automatic-differentiation-of-complex-functions-simple-workaround/75775/7 "2023-10-07T11:55:41Z")

</div>

We had a big thread about this a while ago: [Taking Complex Autodiff Seriously in ChainRules](https://discourse.julialang.org/t/taking-complex-autodiff-seriously-in-chainrules/39317/)

The TL:DR is that holomorphic functions are not the only functions which exist and are widely used, they’re actually a very very small subset of the functions that exist and are used. It would be a really bad idea if AD packages automatically assumed that functions are holomorphic. Derivatives of complex functions are still perfectly well defined even if the function is not holomorphic.

The approach that won out was just computing `pullback`s correctly, so that users could either construct the full jacobian from the pullback, or a wirtinger derivative ( that is, \partial \over \partial z) if they prefer. (explanation of the math here: [Taking Complex Autodiff Seriously in ChainRules - #52 by Mason](https://discourse.julialang.org/t/taking-complex-autodiff-seriously-in-chainrules/39317/52))

If you do indeed want to just deal with \partial \over \partial z alone, you can do that like so:

```julia
using Zygote

function ∂z(f, z)
  _, back = Zygote.pullback(f, z)
  du, dv = back(1)[1], back(im)[1]
  (du' + im*dv')/2
end

```

```julia-repl
julia> ∂z(f, 2+2im)
0.12000000000000002 + 0.16000000000000003im

```

Zygote.jl has docs on this here: [Complex Differentiation · Zygote](https://fluxml.ai/Zygote.jl/dev/complex/)  
And ChainRules.jl has docs on it here: [Complex numbers · ChainRules](https://juliadiff.org/ChainRulesCore.jl/stable/maths/complex.html)

---

_[View the full topic](https://discourse.julialang.org/t/automatic-differentiation-of-complex-functions-simple-workaround/75775)._
