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.