I am trying to write a simple algorithm given below in mathematical notation. I wrote the formula up to a certain point, but I have no idea of restrictions. For example, I used the NULL statement even though it was not "else". It also needs a "break" statement or equivalent.
var thr = 0.5;
var M = 100;
var sum = 0;
var T = 0;
for i 0 to G
{
sum = sum + i;
if sum/M >= thr then
{
T = i;
break;
}
}
return T;
My math notations; I defined "sum" in equation as follows. $$sum = \sum_{j=0}^{i}j$$
(Eq.1)$$T = \sum_{i=0}^{G}f={ \begin{cases} i & \frac{\sum_{j=0}^{i}j}{M}\geq thr\\ \mathrm{NULL} & \text{otherwise} \end{cases}}$$ (Eq.2)$$T = \sum_{i=0,f\neq \mathrm{NULL}}^{G}f={ \begin{cases} i & \frac{\sum_{j=0}^{i}j}{M}\geq thr\\ \mathrm{NULL} & \text{otherwise} \end{cases}}$$
Thank you very much for your help already.
The idea here is that $T$ is equal to $i$, where $i$ is the first index in the loop for which $\verb|sum|\,/M \ge \verb|thr|$. This can be written in a formula as follows: $$ T = \begin{cases}0 &\tfrac1M\textstyle\sum_{j=0}^Gj<\verb|thr|\\\min\{i\mid i\in \{0,1,\dots,G\},\tfrac1M\textstyle\sum_{j=0}^ij\ge \verb|thr|\} & \text{Otherwise} \end{cases} $$ So you take the set of $i$ for which the loop would have stopped by the $i^\text{th}$ iteration, and declare $T$ to be the smallest (minimum) of this set.