# Register array of symbolic functions

**URL:** <https://discourse.julialang.org/t/register-array-of-symbolic-functions/117602>\
**Category:** Optimization (Mathematical)\
**Tags:** jump\
**Created:** [July 29, 2024, 4:51pm UTC](https://discourse.julialang.org/t/register-array-of-symbolic-functions/117602 "2024-07-29T16:51:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Luca](https://avatars.discourse-cdn.com/v4/letter/l/51bf81/32.png) [@Luca](https://discourse.julialang.org/u/Luca)\
**Post date:** [July 29, 2024, 4:51pm UTC](https://discourse.julialang.org/t/register-array-of-symbolic-functions/117602/1 "2024-07-29T16:51:56Z")

</div>

Dear all,

I have the following issue with JuMP: I define an array of symbolic expression I want to use as constraint in a mathematical program. In particular, I have defined my function in the array gn and I want to write something like:

```julia

```

```julia
for k in 1:num_cnsts
 g = Symbol("g$(k)")
 register(model, g, num_vars, gn[k]; autodiff = true)
 @NLconstraint(model, :($g) <= 0)
end

```

I found an answer in [https://discourse.julialang.org/t/registering-an-array-of-functions-and-using-them-in-constraints-and-objectives/53294/2](https://discourse.julialang.org/t/registering-an-array-of-functions-and-using-them-in-constraints-and-objectives/53294/2), but it seems no longer working.

Thanks in advance for all your help.  
Best regards,  
Luca

---

<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:** [July 30, 2024, 2:26am UTC](https://discourse.julialang.org/t/register-array-of-symbolic-functions/117602/2 "2024-07-30T02:26:13Z")

</div>

JuMP v1.15 released a rewrite of the nonlinear interface that intended to fix the many issues related to the `@NL` interface: [ANN: JuMP v1.15 is released](https://discourse.julialang.org/t/ann-jump-v1-15-is-released/103875)

See the new docs:

- [Nonlinear Modeling · JuMP](https://jump.dev/JuMP.jl/stable/manual/nonlinear/#Function-tracing)
- [Nonlinear Modeling · JuMP](https://jump.dev/JuMP.jl/stable/manual/nonlinear/#Add-an-operator-without-macros)

If your functions support tracing, you may be able to do:

```Julia
@constraint(model, [k in 1:num_cnsts], gn[k](x...) <= 0)

```

otherwise, do:

```Julia
for k in 1:num_cnsts
    op_g = add_nonlinear_operator(model, num_vars, gn[k]; name = Symbol("g$k"))
    @constraint(model, op_g(x...) <= 0)
end

```
