# Use Sign Function in JuMP NLconstraint

**URL:** https://discourse.julialang.org/t/use-sign-function-in-jump-nlconstraint/33973
**Category:** Optimization (Mathematical)
**Tags:** question
**Created:** [January 30, 2020, 11:46am UTC](https://discourse.julialang.org/t/use-sign-function-in-jump-nlconstraint/33973 "2020-01-30T11:46:20Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![cupcc](https://avatars.discourse-cdn.com/v4/letter/c/e99b99/32.png) [@cupcc](https://discourse.julialang.org/u/cupcc)
#### Post date: [January 30, 2020, 11:46am UTC](https://discourse.julialang.org/t/use-sign-function-in-jump-nlconstraint/33973/1 "2020-01-30T11:46:20Z")

</div>

I’m currently trying to solve a problem in JuMP that has a nonlinear constraint that has the form  
y= (other expressions) + constant \* sign(x). This throws an error saying sign is not a recognized function. How do I fix this? (x can take the value of 0 as well, both x and y are continuous)

Thank you!

---

<div class="post-metadata">

### Author: ![frapac](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/frapac/32/6879_2.png) [@frapac](https://discourse.julialang.org/u/frapac)
#### Post date: [January 30, 2020, 2:04pm UTC](https://discourse.julialang.org/t/use-sign-function-in-jump-nlconstraint/33973/2 "2020-01-30T14:04:41Z")

</div>

Dear @cupcc,  
the function `sign ` is currently not implemented in current JuMP’s AD.  
I recommend reformulating your problem by using:  
`sign(x) = abs(x) / x`  
as the function `abs` is supported by JuMP. Your constraint would rewrite:

```julia
y * x = (other expressions) * x + constant * abs(x) 

```

(better to avoid divisions in constraints when using a NLP solver)

---

<div class="post-metadata">

### Author: ![cupcc](https://avatars.discourse-cdn.com/v4/letter/c/e99b99/32.png) [@cupcc](https://discourse.julialang.org/u/cupcc)
#### Post date: [January 30, 2020, 2:15pm UTC](https://discourse.julialang.org/t/use-sign-function-in-jump-nlconstraint/33973/3 "2020-01-30T14:15:06Z")

</div>

Thank you so much for the help!
