How do I correctly represent the following pseudocode in math notation?
EDIT1: Formula expanded. EDIT2: Clarification.
(a,b) represents a line segment on a 1D line. a <= b for each segment. The division show below is done as per the following T-SQL code (which I suppose could be represented as a function in the formula?):
Input: @a1 real, @b1 real, @an real, @bn real
DECLARE @Result real
if @a1 <= @an begin
SET @Result = @an - @b1
if @Result <= 0 RETURN 0
RETURN @Result / @an
end
SET @Result = @a1 - @bn
if @Result <= 0 RETURN 0
RETURN @Result / @a1
Formula:
if m = 1 then
if (a,b)_1 intersects (a,b)_n then
r = 1
else if (a,b)_1 < (a,b)_n then
r = (a,b)_1 / (a,b)_n
else
r = (a,b)_n / (a,b)_1
else if m = 2 then
if (a,b)_1 intersects (a,b)_n then
r = 1
else if (a,b)_1 < (a,b)_n then
r = (a,b)_1 / (a,b)_n
else
r = (a,b)_n / (a,b)_1
The m = 2 block is shown as being the same as the m = 1 one for simplicity's sake.
The divisions are against the two points that are closets to each other, unless the segments intersect, at which point r = 1.
In general, if you have "If $\varphi$ then $\psi$, otherwise $\tau$" you can write this as the following formula (or sentence, depending on $\varphi,\psi,\tau$):
$\left(\varphi\rightarrow\psi\right)\wedge\left(\neg\varphi\rightarrow\tau\right)$
If you have several cases, you can either nest them (i.e. $\tau$ would be "if second condition then, else ...") or if you can express them as $\varphi_1$ meaning only the first case holds, and none of the others as $(\varphi_1\rightarrow\psi_1)\wedge(\varphi_2\rightarrow\psi_2)\wedge\ldots$
Addendum:
$(a=b\rightarrow x=1)\wedge(a<b\rightarrow x=\frac{a}{b})\wedge(a>b\rightarrow x=\frac{b}{a})$
I have added $x$ as a variable, because writing just $\rightarrow 1$ seems very meaningless to me, you can of course replace $x$ by anything you'd like. The idea, essentially is that you express "IF ... THEN ... ELSE" structures using the $\rightarrow$ (or $\implies$ sometimes) and I gave you in my original post the method of doing so.