# About how to extract signs

**URL:** <https://discuss.ampl.com/t/about-how-to-extract-signs/989>\
**Category:** Support\
**Created:** [March 8, 2024, 11:35am UTC](https://discuss.ampl.com/t/about-how-to-extract-signs/989 "2024-03-08T11:35:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![liangzilu\_liangzilu](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/liangzilu_liangzilu/32/408_2.png) [@liangzilu\_liangzilu](https://discuss.ampl.com/u/liangzilu_liangzilu)\
**Post date:** [March 8, 2024, 11:35am UTC](https://discuss.ampl.com/t/about-how-to-extract-signs/989/1 "2024-03-08T11:35:37Z")

</div>

Hello, I have the following formula,  
 ![image](https://us1.discourse-cdn.com/flex019/uploads/ampl/original/1X/952f9e9ed23c709f3e72f9f96b408ba92f3677f0.png)

I just want to get the sign of the expression, 12-yf[i,j]  
but if I divide the absolute value like this, (12-yf[i,j])/abs(12-yf[i,j])  
when yf[i,j]=12, the denominator will appear to be 0,and ampl may report an error, what should I do？

---

<div class="post-metadata">

**Author:** ![4er](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/4er/32/530_2.png) [@4er](https://discuss.ampl.com/u/4er)\
**Post date:** [March 8, 2024, 5:49pm UTC](https://discuss.ampl.com/t/about-how-to-extract-signs/989/2 "2024-03-08T17:49:10Z")

</div>

How is `yr` defined in your model? It makes a difference whether `yr` is a param or a var, and whether it is continuous or integer-valued.

---

<div class="post-metadata">

**Author:** ![liangzilu\_liangzilu](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/liangzilu_liangzilu/32/408_2.png) [@liangzilu\_liangzilu](https://discuss.ampl.com/u/liangzilu_liangzilu)\
**Post date:** [March 9, 2024, 4:34am UTC](https://discuss.ampl.com/t/about-how-to-extract-signs/989/3 "2024-03-09T04:34:07Z")

</div>

![image](https://us1.discourse-cdn.com/flex019/uploads/ampl/original/1X/6a5d43d77e85a27f9e0caefcb0838713599d8a79.png)

var and continuous

---

<div class="post-metadata">

**Author:** ![4er](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/4er/32/530_2.png) [@4er](https://discuss.ampl.com/u/4er)\
**Post date:** [March 11, 2024, 5:21pm UTC](https://discuss.ampl.com/t/about-how-to-extract-signs/989/4 "2024-03-11T17:21:43Z")

</div>

Is this the mathematical description of the function that you are trying to use in your constraint?

-log\_{10} (exp(200\times sign(12-yr\_{ij}))+10^{12})

Rounded to 10 decimal places, it can take only two values:

if yr\_{ij} \< 12 then -log\_{10} (exp(200)+10^{12}) = -86.8588963807  
if yr\_{ij} = 12 then -log\_{10} (exp(0)+10^{12}) = -12  
if yr\_{ij} \> 12 then -log\_{10} (exp(-200)+10^{12}) = -12

This would be easy to write using an AMPL if-then-else expression:

```auto
(xr[i,j] - large_radius) >=
   if yr[i,j] >= 12 then -12 else -86.8588963807

```
