How can I convert my C# code into a mathematical formula? I would like to use discrete mathematics and convert my code into a mathematical formula.
Here is the example C# code that I have written. The aim is to calculate a rank based on the positive and negative weight that is assigned to each variable. The positive weight is added to the rank if the variable is higher than 0. The negative weight is taken away from the rank if the variable is a negative number. Please keep in mind that each variable can have any negative or positive weight that can be configured differently.
var aPosWeight = 3;
var aNegativeWeight = -3;
var bPosWeight = 2;
var bNegativeWeight = -2;
var cPosWeight = 1;
var cNegativeWeight = -1;
var a = 1;
var b = 0;
var c = -1;
var rank = 0;
if (a > 0)
{
rank += aPosWeight;
}
else if (a < 0)
{
rank += aNegativeWeight;
}
if (b > 0)
{
rank += bPosWeight;
}
else if (b < 0)
{
rank += bNegativeWeight;
}
if (c > 0)
{
rank += cPosWeight;
}
else if (c < 0)
{
rank += cNegativeWeight;
}
Console.WriteLine(string.Format("Your final rank is {0}", rank));
Here is the mathematical formula that I have come up with that I think represents the C# code written above. My main concern is that the mathematical formula is completely wrong and can't be used to interpret the C# code that I've written above.
$$ f(x)=\begin{cases}\text{PosWeight},\quad\text{if }a>0\\ \text{NegWeight},\quad\text{if }a<0\\ 0\hphantom{egw.eight},\quad\text{if }a=0\end{cases} $$
$$ \text{sum}=\sum_{i=1}^3f(x_i) $$
Let $p,\,n$ denote the positive and negative weights, so $f(x)$ is $p[x>0]+n[x<0]$ in terms of Iverson brackets.