# Printing non linear expression in model

**URL:** <https://discourse.julialang.org/t/printing-non-linear-expression-in-model/69505>\
**Category:** Optimization (Mathematical)\
**Tags:** question, jump\
**Created:** [October 10, 2021, 8:31am UTC](https://discourse.julialang.org/t/printing-non-linear-expression-in-model/69505 "2021-10-10T08:31:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![manoj.centura](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/manoj.centura/32/216443_2.png) [@manoj.centura](https://discourse.julialang.org/u/manoj.centura)\
**Post date:** [October 10, 2021, 8:31am UTC](https://discourse.julialang.org/t/printing-non-linear-expression-in-model/69505/1 "2021-10-10T08:31:00Z")

</div>

Hi All,  
is there a way to print non linear expression

```nohighlight
model=Model()
@variable(model,x)
exp1 =@NLexpression(model,x*x)
@NLconstraint(model,exp1<=10)

println("exp1",exp1)
output

 exp1"Reference to nonlinear expression #1"
 
i want the output as
exp1 x*x
```

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [October 10, 2021, 8:38pm UTC](https://discourse.julialang.org/t/printing-non-linear-expression-in-model/69505/2 "2021-10-10T20:38:48Z")

</div>

Do not know JuMP and a more direct way.

FWIW, the subexpression you need shows up in `println(exp1.m)`

It could be parsed:

```julia
s = split(split(string(exp1.m),"\n")[end-1], ": ")[2]
println("exp1 ", s)

```

---

<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:** [October 10, 2021, 10:01pm UTC](https://discourse.julialang.org/t/printing-non-linear-expression-in-model/69505/3 "2021-10-10T22:01:13Z")

</div>

Not without hacking some of the JuMP internals. Improving the printing of nonlinear information is on our TODO list.

You can do

```julia
julia> JuMP._nl_subexpression_string(JuMP.REPLMode, model)[exp1.index]
"subexpression[1]: x * x"

```

but this accesses a private method (beginning with `_`), so it may break in any future JuMP release.

---

<div class="post-metadata">

**Author:** ![manoj.centura](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/manoj.centura/32/216443_2.png) [@manoj.centura](https://discourse.julialang.org/u/manoj.centura)\
**Post date:** [October 11, 2021, 7:03am UTC](https://discourse.julialang.org/t/printing-non-linear-expression-in-model/69505/4 "2021-10-11T07:03:18Z")

</div>

> [@odow](#):
>
> `JuMP._nl_subexpression_string(JuMP.REPLMode, model)[exp1.index]`

Many thanks for the reply with Julia 1.2 and JuMP 0.21.1  
getting  
ERROR: UndefVarError: \_nl\_subexpression\_string not defined

---

<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:** [October 11, 2021, 7:10am UTC](https://discourse.julialang.org/t/printing-non-linear-expression-in-model/69505/5 "2021-10-11T07:10:09Z")

</div>

> with Julia 1.2 and JuMP 0.21.1

Please update to Julia 1.6 and JuMP 0.21.10.

---

<div class="post-metadata">

**Author:** ![manoj.centura](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/manoj.centura/32/216443_2.png) [@manoj.centura](https://discourse.julialang.org/u/manoj.centura)\
**Post date:** [October 11, 2021, 7:10am UTC](https://discourse.julialang.org/t/printing-non-linear-expression-in-model/69505/6 "2021-10-11T07:10:59Z")

</div>

thanks
