# FiniteDiff.finite\_difference\_gradient changes input when it errors?

**URL:** <https://discourse.julialang.org/t/finitediff-finite-difference-gradient-changes-input-when-it-errors/43279>\
**Category:** Specific Domains\
**Tags:** differentiation\
**Created:** [July 18, 2020, 9:43am UTC](https://discourse.julialang.org/t/finitediff-finite-difference-gradient-changes-input-when-it-errors/43279 "2020-07-18T09:43:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![amrods](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/amrods/32/2543_2.png) [@amrods](https://discourse.julialang.org/u/amrods)\
**Post date:** [July 18, 2020, 9:43am UTC](https://discourse.julialang.org/t/finitediff-finite-difference-gradient-changes-input-when-it-errors/43279/1 "2020-07-18T09:43:04Z")

</div>

I ran into a surprising thing today. Consider the function `sumlog`:

```julia
function sumlog(x)
    sum(log(i) for i in x)
end

```

I’m interested in taking the gradient of `sumlog` at `x`:

```julia
using FiniteDiff

x = [1e-6, 1e-6]

FiniteDiff.finite_difference_gradient(sumlog, x)
#DomainError with -5.05545445239334e-6:
#log will only return a complex result if called with a complex argument. Try log(Complex(x)).

```

Naturally it errors, what surprised me is that now `x` changed:

```julia
x
#2-element Array{Float64,1}:
# -5.05545445239334e-6
# 1.0e-6

```

Is that expected? I’m using `FiniteDiff v2.5.0`.

The gradient error arises because I think it tries to compute the [symmetric difference quotient](https://en.wikipedia.org/wiki/Numerical_differentiation#Finite_differences) and in doing so it reaches for a point less than 0, so is there a way to request the gradient using simply the difference quotient (where the derivative is approximated using points greater than `x`)?

---

<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:** [July 18, 2020, 12:24pm UTC](https://discourse.julialang.org/t/finitediff-finite-difference-gradient-changes-input-when-it-errors/43279/2 "2020-07-18T12:24:39Z")

</div>

Can you open an issue on this?

---

<div class="post-metadata">

**Author:** ![amrods](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/amrods/32/2543_2.png) [@amrods](https://discourse.julialang.org/u/amrods)\
**Post date:** [July 18, 2020, 12:38pm UTC](https://discourse.julialang.org/t/finitediff-finite-difference-gradient-changes-input-when-it-errors/43279/3 "2020-07-18T12:38:13Z")

</div>

just did, do you know if FiniteDiff can compute non-symmetric difference quotients?

> [@amrods](#):
>
> The gradient error arises because I think it tries to compute the [symmetric difference quotient](https://en.wikipedia.org/wiki/Numerical_differentiation#Finite_differences) and in doing so it reaches for a point less than 0, so is there a way to request the gradient using simply the difference quotient (where the derivative is approximated using points greater than `x` )?

---

<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:** [July 18, 2020, 12:45pm UTC](https://discourse.julialang.org/t/finitediff-finite-difference-gradient-changes-input-when-it-errors/43279/4 "2020-07-18T12:45:01Z")

</div>

Not for the gradient IIRC
