Mathematical Programming

Positivity

What if we wanted to make sure our input was positive before we used it in a function?

To our rescue comes the absolute value function. By dividing the number by its magnitude, we can determine its direction.

xx{+1,1}\frac{\left|x\right|}{x}\Rightarrow\left\{+\rightarrow1, -\rightarrow-1\right\}

If positive, we'll get 1,1, and if negative, we will get 1.-1.

Now, we need to configure the positive-negative function to output binary, so that we can use it as a building block later. This means outputting 11 if it is positive, and 00 if it is negative.  

isPositive(x)=xx+1{+2,0}\text{isPositive}\left(x\right) = \frac{\left|x\right|}{x}+1\Rightarrow\left\{+\rightarrow2, -\rightarrow0\right\}
isPositive(xy)=xx+12{+1,0}\text{isPositive}\left(x-y\right) = \frac{\frac{\left|x\right|}{x}+1}{2}\Rightarrow\left\{+\rightarrow1, -\rightarrow 0 \right\}

Success!

© 2022 YMath.io owned and operated by Saumya Singhal