Converting my C# code into a mathematical formula 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 &gt; 0)
{
    rank += aPosWeight;
}
else if (a &lt; 0)
{
    rank += aNegativeWeight;
}

if (b &gt; 0)
{
    rank += bPosWeight;
}
else if (b &lt; 0)
{
    rank += bNegativeWeight;
}

if (c &gt; 0)
{
    rank += cPosWeight;
}
else if (c &lt; 0)
{
    rank += cNegativeWeight;
}

Console.WriteLine(string.Format(&quot;Your final rank is {0}&quot;, 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&gt;0\\
\text{NegWeight},\quad\text{if }a&lt;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&gt;0]+n[x&lt;0]$ in terms of Iverson brackets.
If you're trying to do this automatically, you could write a parser and input the specific 'final value' and then determine how it was composed by building a tree of derivation steps and then look at how it was used, the existence of datasets etc and tie these activities to mathematical symbols.
eg.
float inputa, inputb, finalvalue;
..
..
for (int x=0; x &lt; 5; x++)
{
inputa = inputb *x;
finalvalue+=inputb;
}
where finalvalue is the derived value.
in this case the for loop would look like a sum (sigma) from 0 to 5  with  bx as its term.
anyway, after doing this you could use a latex renderer to create a graphic of your equation, like they're doing above with their answers.