# Digamma not defined in JuMP nonlinear optimization

**URL:** <https://discourse.julialang.org/t/digamma-not-defined-in-jump-nonlinear-optimization/28824>\
**Category:** Optimization (Mathematical)\
**Tags:** question, jump\
**Created:** [September 16, 2019, 7:35pm UTC](https://discourse.julialang.org/t/digamma-not-defined-in-jump-nonlinear-optimization/28824 "2019-09-16T19:35:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![brwst](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brwst/32/6645_2.png) [@brwst](https://discourse.julialang.org/u/brwst)\
**Post date:** [September 16, 2019, 7:35pm UTC](https://discourse.julialang.org/t/digamma-not-defined-in-jump-nonlinear-optimization/28824/1 "2019-09-16T19:35:37Z")

</div>

Hello all,

I’m trying to familiarize myself with JuMP, especially in the context of using SpecialFunctions.

I’m struggling with `gamma()` and `lgamma()` specifically, so I’ve tried to implement the simple example from [JuMP.jl issue #407](https://github.com/JuliaOpt/JuMP.jl/issues/407) albeit with updated syntax:

```julia
using JuMP
using Ipopt
using SpecialFunctions

m = Model(with_optimizer(Ipopt.Optimizer))
@variable(m, 3.0 <= x <= 4.0)
@NLobjective(m, Max, lgamma(x))

optimize!(m) # expect lgamma(4.0)

```

Running this results in:

```julia
UndefVarError: digamma not defined

```

I notice that I get the same error if I do not use the `SpecialFunctions` module, but in that case I haven’t been able to find from where `lgamma()` is made available.

Package versions here are:

`JuMP v0.20.0`  
`Ipopt v0.6.0`  
`SpecialFunctions v0.7.2`  
`Calculus v0.5.0`

I feel that I’m missing something basic. Am I overlooking a module dependency or not understanding the functions which may be used in a nonlinear objective function? I’ve read through [the nonlinear modeling documentation](http://www.juliaopt.org/JuMP.jl/v0.20.0/nlp/#Nonlinear-Modeling-1) but I am inexperienced in this domain, so any links to relevant documentation are much appreciated.

---

<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:** [September 17, 2019, 1:09am UTC](https://discourse.julialang.org/t/digamma-not-defined-in-jump-nonlinear-optimization/28824/2 "2019-09-17T01:09:48Z")

</div>

See [https://github.com/JuliaOpt/JuMP.jl/issues/1803](https://github.com/JuliaOpt/JuMP.jl/issues/1803)

The cryptic comment to “register” the function means the following:

```julia
using JuMP, Ipopt, SpecialFunctions
m = Model(with_optimizer(Ipopt.Optimizer))
@variable(m, 3.0 <= x <= 4.0)
JuMP.register(m, :my_lgamma, 1, SpecialFunctions.lgamma, autodiff=true)
@NLobjective(m, Max, my_lgamma(x))
optimize!(m)

```

Here are the relevant docs: [Nonlinear Modeling · JuMP](https://www.juliaopt.org/JuMP.jl/v0.20.0/nlp/#User-defined-Functions-1)

---

<div class="post-metadata">

**Author:** ![brwst](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brwst/32/6645_2.png) [@brwst](https://discourse.julialang.org/u/brwst)\
**Post date:** [September 17, 2019, 2:00am UTC](https://discourse.julialang.org/t/digamma-not-defined-in-jump-nonlinear-optimization/28824/3 "2019-09-17T02:00:11Z")

</div>

Thanks for the links and the example @odow, the `register` method did the trick.
