# \[SOLVED\] Nothing returned in the Zygote derivative

**URL:** https://discourse.julialang.org/t/solved-nothing-returned-in-the-zygote-derivative/52748
**Category:** New to Julia
**Tags:** zygote
**Created:** [January 2, 2021, 10:11pm UTC](https://discourse.julialang.org/t/solved-nothing-returned-in-the-zygote-derivative/52748 "2021-01-02T22:11:26Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![sheevy](https://avatars.discourse-cdn.com/v4/letter/s/dc4da7/32.png) [@sheevy](https://discourse.julialang.org/u/sheevy)
#### Post date: [January 2, 2021, 10:11pm UTC](https://discourse.julialang.org/t/solved-nothing-returned-in-the-zygote-derivative/52748/1 "2021-01-02T22:11:26Z")

</div>

In my mind the following definitions are equivalent:

```julia
function test_working(x)
    return max(x - 1.0, 0.0)
end

function test_not_working(x)
    if x > 1.0
        return x - 1.0
    else
        return 0.0
    end
end

```

And indeed they give identical results as expected:

```julia
test_working(2.0) # 1.0 as expected
test_not_working(2.0) # 1.0 as expected

test_working(0.0) # 0.0 as expected
test_not_working(0.0) # 0.0 as expected

```

However the derivative of the second function gives unexpected result in the `return 0.0` branch:

```julia
using Zygote

test_working'(2.0) # 1.0 as expected
test_not_working'(2.0) # 1.0 as expected

test_working'(0.0) # 0.0 as expected
test_not_working'(0.0) # nothing not as expected. I was expecting to see 0.0

```

Any idea why?

Thanks

---

<div class="post-metadata">

### Author: ![simeonschaub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simeonschaub/32/216566_2.png) [@simeonschaub](https://discourse.julialang.org/u/simeonschaub)
#### Post date: [January 2, 2021, 11:56pm UTC](https://discourse.julialang.org/t/solved-nothing-returned-in-the-zygote-derivative/52748/2 "2021-01-02T23:56:54Z")

</div>

Zygote treats `nothing` like a zero, so although this might be a bit confusing, it is expected. You can use `something` to convert `nothing` to a numerical zero.
