# JuMP/Simplex - basic question: derivatives

**URL:** <https://discourse.julialang.org/t/jump-simplex-basic-question-derivatives/55416>\
**Category:** Optimization (Mathematical)\
**Tags:** jump\
**Created:** [February 16, 2021, 7:45pm UTC](https://discourse.julialang.org/t/jump-simplex-basic-question-derivatives/55416 "2021-02-16T19:45:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheMEGuy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/themeguy/32/19862_2.png) [@TheMEGuy](https://discourse.julialang.org/u/TheMEGuy)\
**Post date:** [February 16, 2021, 7:45pm UTC](https://discourse.julialang.org/t/jump-simplex-basic-question-derivatives/55416/1 "2021-02-16T19:45:03Z")

</div>

Hi,

I am new to optimization and I have a question for you:  
these might be naive questions but when I register a nonlinear function I have two options:

1. to provide JuMP with the first two derivations
2. to use the auto differentiation

Why isn’t it necessary to provide JuMP/Gurobi with derivatives of a regular linear function?  
For a linear problem, does the solver even need derivates?  
As far as I know, the regular simplex algorithm doesn’t use derivatives, but I am not sure.

Thanks.

---

<div class="post-metadata">

**Author:** ![Elmo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elmo/32/17979_2.png) [@Elmo](https://discourse.julialang.org/u/Elmo)\
**Post date:** [February 16, 2021, 8:02pm UTC](https://discourse.julialang.org/t/jump-simplex-basic-question-derivatives/55416/2 "2021-02-16T20:02:26Z")

</div>

Hi,

For linear programming (LP) a variety of techniques may be used, including the simplex and interior point methods. Gurobi can use both as far as I am aware (see [here](https://www.gurobi.com/resource/linear-programming-basics/)). As for solving LPs, derivatives are not needed when using the simplex method. Essentially the method moves from vertex to vertex in the feasible space until it cannot improve the objective anymore. This is a mostly algebraic procedure, e.g. see [here](https://vanderbei.princeton.edu/542/lectures/lec2.pdf).

However, finding gradients of linear or even quadratic functions is really simple so if they are required they can likely be calculated automatically exactly without much fuss. I hope this clears it up!

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [February 16, 2021, 10:19pm UTC](https://discourse.julialang.org/t/jump-simplex-basic-question-derivatives/55416/3 "2021-02-16T22:19:50Z")

</div>

To provide a bit more context:

- JuMP (and MOI) have a special type for linear functions (`ScalarAffineFunction`) and quadratic functions (`ScalarQuadraticFunction`).
- If you know a function is linear, then for `f(x) = a' * x + b`, it’s trivial to write `∇f(x) = a`! Derivatives for quadratic functions are also easy
- Some solvers, such as Ipopt, need derivatives.
- However, you don’t need to provide the derivatives because we compute them.
  - Here’s the `ScalarAffineFunction` code:  
[https://github.com/jump-dev/Ipopt.jl/blob/31a7ac15675f73ff68ea02f07a0b9eebdd8f6aac/src/MOI\_wrapper.jl#L1057-L1062](https://github.com/jump-dev/Ipopt.jl/blob/31a7ac15675f73ff68ea02f07a0b9eebdd8f6aac/src/MOI_wrapper.jl#L1057-L1062)
  - Here’s the `ScalarQuadraticFunction` code:  
[https://github.com/jump-dev/Ipopt.jl/blob/31a7ac15675f73ff68ea02f07a0b9eebdd8f6aac/src/MOI\_wrapper.jl#L1064-L1080](https://github.com/jump-dev/Ipopt.jl/blob/31a7ac15675f73ff68ea02f07a0b9eebdd8f6aac/src/MOI_wrapper.jl#L1064-L1080)

---

<div class="post-metadata">

**Author:** ![TheMEGuy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/themeguy/32/19862_2.png) [@TheMEGuy](https://discourse.julialang.org/u/TheMEGuy)\
**Post date:** [February 16, 2021, 10:27pm UTC](https://discourse.julialang.org/t/jump-simplex-basic-question-derivatives/55416/4 "2021-02-16T22:27:47Z")

</div>

Thank you @Elmo & @odow.

you really helped me 😃
