# How can I check if a function is always positive?

**URL:** <https://discourse.julialang.org/t/how-can-i-check-if-a-function-is-always-positive/48405>\
**Category:** General Usage\
**Tags:** question\
**Created:** [October 15, 2020, 2:26am UTC](https://discourse.julialang.org/t/how-can-i-check-if-a-function-is-always-positive/48405 "2020-10-15T02:26:50Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [October 15, 2020, 4:20am UTC](https://discourse.julialang.org/t/how-can-i-check-if-a-function-is-always-positive/48405/8 "2020-10-15T04:20:40Z")

</div>

In general the over-estimation of the range comes when a variable is repeated more than once in an expression, as is the case for x^2 - 2x. This is due to the definition of subtraction of two intervals as

X - Y := \{x - y: x \in X, y \in Y \}

So that if e.g. X = [0, 1] then X - X = [-1, 1] instead of 0. This is known as the **dependency effect**. It is difficult to get rid of, unfortunately.

In the case of g(x) = x^2 - 2x you can do the following:

```julia
julia> g(X.lo)
9800.0

julia> ForwardDiff.derivative(g, X)
[198, ∞]

```

Since the derivative is positive everywhere in X, the function is increasing. Since it starts out positive, it remains positive.

But then

```julia
julia> h(x) = x^3 - 3x^2
h (generic function with 1 method)

julia> ForwardDiff.derivative(h, X)
[-∞, ∞]

```

so in that case you would need to go to the _second_ derivative.

For a complicated transcendental function I’m not sure what you would do.

---

_[View the full topic](https://discourse.julialang.org/t/how-can-i-check-if-a-function-is-always-positive/48405)._
