New Math Functions in PHP

Posted
Comments None

The PHP code for the new 39 math functions of GeneXproTools is easily created form the C# code. We just have to get rid of all the type keywords (double, int, const) in the declaration of variables and constants and prefix all variables and constants with "$".

Then we just need to replace "else if" by "elseif" and "Math.Min" and "Math.Max" by "min" and "max" in the places where min and max values of just 2 numbers are evaluated; where min and max take 3 arguments, we simplified the code a bit by making good use of the more versatile implementation of the native min/max functions of PHP.

Also different in both programming languages are the function declarations, but again by using grammar templates we can easily replace the C# headers with the corresponding PHP headers.

Here's the PHP code for the new 39 math functions that were added to the built-in math functions of GeneXproTools 5.0 with Mini-Release 1:

function gepRamp1($x)
{
    if ($x > 0.0)
        return $x;
    else
        return 0.0;
}

function gepRamp2($x)
{
    if ($x > 0.0)
        return 0.0;
    else
        return $x;
}

function gepRamp3($x)
{
    if ($x > 0.0)
        return 0.0;
    else
        return -$x;
}

function gepRamp4($x)
{
    if ($x > 0.0)
        return -$x;
    else
        return 0.0;
}

function gepStep1($x)
{
    if ($x > 0.0)
        return 1.0;
    else
        return -1.0;
}

function gepStep2($x)
{
    if ($x > 0.0)
        return 1.0;
    else
        return 0.0;
}

function gepStep3($x)
{
    if ($x >= 1.0)
        return 1.0;
    elseif ($x <= -1.0)
        return -1.0;
    else
        return $x;
}

function gepStep4($x)
{
    if ($x >= 1.0)
        return 1.0;
    elseif ($x <= 0.0)
        return 0.0;
    else
        return $x;
}

function gepCL2A($x, $y)
{
    if ($x > 0.0 && $y > 0.0)
        return 1.0;
    else
        return -1.0;
}

function gepCL2B($x, $y)
{
    if ($x >= 0.0 && $y < 0.0)
        return -1.0;
    else
        return 1.0;
}

function gepCL2C($x, $y)
{
    if ($x > 1.0 && $y < -1.0)
        return -1.0;
    else
        return 1.0;
}

function gepCL2D($x, $y)
{
    if ($x > 0.0 && $y > 0.0)
        return 1.0;
    else
        return 0.0;
}

function gepCL2E($x, $y)
{
    if ($x >= 0.0 && $y <= 0.0)
        return 0.0;
    else
        return 1.0;
}

function gepCL2F($x, $y)
{
    if ($x > 1.0 && $y < -1.0)
        return 0.0;
    else
        return 1.0;
}

function gepCL3A($x, $y)
{
    if ($x > 0.0 && $y < 0.0)
        return 1.0;
    elseif ($x < 0.0 && $y > 0.0)
        return -1.0;
    else
        return 0.0;
}

function gepCL3B($x, $y)
{
    if ($x >= 1.0 && $y >= 1.0)
        return 1.0;
    elseif ($x <= -1.0 && $y <= -1.0)
        return -1.0;
    else
        return 0.0;
}

function gepCL3C($x, $y)
{
    if ($x > 0.0 && $y > 0.0)
        return 1.0;
    elseif ($x < 0.0 && $y < 0.0)
        return -1.0;
    else
        return 0.0;
}

function gepMap3A($x, $y)
{
    $SLACK = 10.0;
    $outVal = 0.0;
    if ($y < ($x - $SLACK))
        $outVal = -1.0;
    elseif ($y > ($x + $SLACK))
        $outVal = 1.0;
    return $outVal;
}

function gepMap3B($x, $y, $z)
{
    $minValue = min($x,$y);
    $maxValue = max($x,$y);
    $outVal = 0.0;
    if ($z < $minValue)
        $outVal = -1.0;
    elseif ($z > $maxValue)
        $outVal = 1.0;
    return $outVal;
}

function gepMap3C($a, $b, $c, $d)
{
    $minValue = min($a,$b,$c);
    $maxValue = max($a,$b,$c);
    $outVal = 0.0;
    if ($d < $minValue)
        $outVal = -1.0;
    elseif ($d > $maxValue)
        $outVal = 1.0;
    return $outVal;
}

function gepMap4A($x, $y)
{
    $SLACK = 10.0;
    $outVal = 0.0;
    if ($y < ($x - $SLACK))
        $outVal = 0.0;
    elseif ($y >= ($x - $SLACK) && $y < $x)
        $outVal = 1.0;
    elseif ($y >= $x && $y < ($x + $SLACK))
        $outVal = 2.0;
    elseif ($y >= ($x + $SLACK))
        $outVal = 3.0;
    return $outVal;
}

function gepMap4B($x, $y, $z)
{
    // evaluate minValue(x,y), maxValue(x,y) and midrange
    $minValue = min($x,$y);
    $maxValue = max($x,$y);
    $midrange = ($maxValue + $minValue)/2.0;
    
    $outVal = 0.0;
    if ($z < $minValue)
        $outVal = 0.0;
    elseif ($z >= $minValue && $z < $midrange)
        $outVal = 1.0;
    elseif ($z >= $midrange && $z < $maxValue)
        $outVal = 2.0;
    elseif ($z >= $maxValue)
        $outVal = 3.0;
    return $outVal;
}

function gepMap4C($a, $b, $c, $d)
{
    // evaluate minValue(a,b,c), maxValue(a,b,c) and midleValue(a,b,c)
    //
    // evaluate minValue(a,b,c)
    $minValue = $a;
    $argMin = 0;
    if ($minValue > $b)
    {
        $minValue = $b;
        $argMin = 1;
    }
    if ($minValue > $c)
    {
        $minValue = $c;
        $argMin = 2;
    }
    // evaluate maxValue(a,b,c)
    $maxValue = $a;
    $argMax = 0;
    if ($maxValue < $b)
    {
        $maxValue = $b;
        $argMax = 1;
    }
    if ($maxValue < $c)
    {
        $maxValue = $c;
        $argMax = 2;
    }
    // evaluate midleValue(a,b,c)
    $midleValue = $c;
    if (0 != $argMin && 0 != $argMax)
        $midleValue = $a;
    if (1 != $argMin && 1 != $argMax)
        $midleValue = $b;

    $outVal = 0.0;
    if ($d < $minValue)
        $outVal = 0.0;
    elseif ($d >= $minValue && $d < $midleValue)
        $outVal = 1.0;
    elseif ($d >= $midleValue && $d < $maxValue)
        $outVal = 2.0;
    elseif ($d >= $maxValue)
        $outVal = 3.0;
    return $outVal;
}

function gepMap5A($x, $y)
{
    $SLACK = 15.0;
    $outVal = 0.0;
    if ($y < ($x - $SLACK))
        $outVal = 0.0;
    elseif ($y >= ($x - $SLACK) && $y < ($x - $SLACK/3.0))
        $outVal = 1.0;
    elseif ($y >= ($x - $SLACK/3.0) && $y < ($x + $SLACK/3.0))
        $outVal = 2.0;
    elseif ($y >= ($x + $SLACK/3.0) && $y < ($x + $SLACK))
        $outVal = 3.0;
    elseif ($y >= ($x + $SLACK))
        $outVal = 4.0;
    return $outVal;
}

function gepMap5B($x, $y, $z)
{
    // evaluate minValue(x,y), maxValue(x,y), midpoint1, midpoint2
    $minValue = min($x,$y);
    $maxValue = max($x,$y);
    $intervalLength = ($maxValue - $minValue)/3.0;
    $midpoint1 = $minValue + $intervalLength;
    $midpoint2 = $minValue + 2.0*$intervalLength;
    
    $outVal = 0.0;
    if ($z < $minValue)
        $outVal = 0.0;
    elseif ($z >= $minValue && $z < $midpoint1)
        $outVal = 1.0;
    elseif ($z >= $midpoint1 && $z < $midpoint2)
        $outVal = 2.0;
    elseif ($z >= $midpoint2 && $z < $maxValue)
        $outVal = 3.0;
    elseif ($z >= $maxValue)
        $outVal = 4.0;
    return $outVal;
}

function gepMap5C($a, $b, $c, $d)
{
    // evaluate minValue(a,b,c), maxValue(a,b,c), midleValue(a,b,c), midrange1, midrange2
    //
    // evaluate minValue(a,b,c)
    $minValue = $a;
    $argMin = 0;
    if ($minValue > $b)
    {
        $minValue = $b;
        $argMin = 1;
    }
    if ($minValue > $c)
    {
        $minValue = $c;
        $argMin = 2;
    }
    // evaluate maxValue(a,b,c)
    $maxValue = $a;
    $argMax = 0;
    if ($maxValue < $b)
    {
        $maxValue = $b;
        $argMax = 1;
    }
    if ($maxValue < $c)
    {
        $maxValue = $c;
        $argMax = 2;
    }
    // evaluate midleValue(a,b,c)
    $midleValue = $c;
    if (0 != $argMin && 0 != $argMax)
        $midleValue = $a;
    if (1 != $argMin && 1 != $argMax)
        $midleValue = $b;
    // evaluate midrange1 and midrange2
    $midrange1 = ($minValue + $midleValue)/2.0;
    $midrange2 = ($midleValue + $maxValue)/2.0;

    $outVal = 0.0;
    if ($d < $minValue)
        $outVal = 0.0;
    elseif ($d >= $minValue && $d < $midrange1)
        $outVal = 1.0;
    elseif ($d >= $midrange1 && $d < $midrange2)
        $outVal = 2.0;
    elseif ($d >= $midrange2 && $d < $maxValue)
        $outVal = 3.0;
    elseif ($d >= $maxValue)
        $outVal = 4.0;
    return $outVal;
}

function gepMap6A($x, $y)
{
    $SLACK = 10.0;
    $outVal = 0.0;
    if ($y < ($x - $SLACK))
        $outVal = 0.0;
    elseif ($y >= ($x - $SLACK) && $y < ($x - $SLACK/2.0))
        $outVal = 1.0;
    elseif ($y >= ($x - $SLACK/2.0) && $y < $x)
        $outVal = 2.0;
    elseif ($y >= $x && $y < ($x + $SLACK/2.0))
        $outVal = 3.0;
    elseif ($y >= ($x + $SLACK/2.0) && $y < ($x + $SLACK))
        $outVal = 4.0;
    elseif ($y >= ($x + $SLACK))
        $outVal = 5.0;
    return $outVal;
}

function gepMap6B($x, $y, $z)
{
    // evaluate minValue(x,y), maxValue(x,y), midrange, midpoint1, midpoint2
    $minValue = min($x,$y);
    $maxValue = max($x,$y);
    $midrange = ($minValue + $maxValue)/2.0;
    $midpoint1 = ($minValue + $midrange)/2.0;
    $midpoint2 = ($midrange + $maxValue)/2.0;
    
    $outVal = 0.0;
    if ($z < $minValue)
        $outVal = 0.0;
    elseif ($z >= $minValue && $z < $midpoint1)
        $outVal = 1.0;
    elseif ($z >= $midpoint1 && $z < $midrange)
        $outVal = 2.0;
    elseif ($z >= $midrange && $z < $midpoint2)
        $outVal = 3.0;
    elseif ($z >= $midpoint2 && $z < $maxValue)
        $outVal = 4.0;
    elseif ($z >= $maxValue)
        $outVal = 5.0;
    return $outVal;
}

function gepMap6C($a, $b, $c, $d)
{
    // evaluate minValue(a,b,c), maxValue(a,b,c), midleValue(a,b,c), midrange1, midrange2
    //
    // evaluate minValue(a,b,c)
    $minValue = $a;
    $argMin = 0;
    if ($minValue > $b)
    {
        $minValue = $b;
        $argMin = 1;
    }
    if ($minValue > $c)
    {
        $minValue = $c;
        $argMin = 2;
    }
    // evaluate maxValue(a,b,c)
    $maxValue = $a;
    $argMax = 0;
    if ($maxValue < $b)
    {
        $maxValue = $b;
        $argMax = 1;
    }
    if ($maxValue < $c)
    {
        $maxValue = $c;
        $argMax = 2;
    }
    // evaluate midleValue(a,b,c)
    $midleValue = $c;
    if (0 != $argMin && 0 != $argMax)
        $midleValue = $a;
    if (1 != $argMin && 1 != $argMax)
        $midleValue = $b;
    // evaluate midrange1 and midrange2
    $midrange1 = ($minValue + $midleValue)/2.0;
    $midrange2 = ($midleValue + $maxValue)/2.0;

    $outVal = 0.0;
    if ($d < $minValue)
        $outVal = 0.0;
    elseif ($d >= $minValue && $d < $midrange1)
        $outVal = 1.0;
    elseif ($d >= $midrange1 && $d < $midleValue)
        $outVal = 2.0;
    elseif ($d >= $midleValue && $d < $midrange2)
        $outVal = 3.0;
    elseif ($d >= $midrange2 && $d < $maxValue)
        $outVal = 4.0;
    elseif ($d >= $maxValue)
        $outVal = 5.0;
    return $outVal;
}

function gepECL3A($x, $y, $z)
{
    if ($y > $x && $z < $x)
        return 1.0;
    elseif ($y < $x && $z > $x)
        return -1.0;
    else return 0.0;
}

function gepECL3B($x, $y, $z)
{
    if ($y > $x && $z > $x)
        return 1.0;
    elseif ($y < $x && $z < $x)
        return -1.0;
    else return 0.0;
}

function gepECL3C($x, $y, $z)
{
    if ($y >= $x && $z >= $x)
        return 1.0;
    elseif ($y <= -$x && $z <= -$x)
        return -1.0;
    else return 0.0;
}

function gepECL3D($a, $b, $c, $d)
{
    $minValue = min($a,$b);
    $maxValue = max($a,$b);
    if ($c >= $maxValue && $d >= $maxValue)
        return 1.0;
    elseif ($c <= $minValue && $d <= $minValue)
        return -1.0;
    else return 0.0;
}

function gepAMin2($x, $y)
{
    if ($x < $y)
        return 0.0;
    else
        return 1.0;
}

function gepAMin3($x, $y, $z)
{
    $temp = $x;
    $argMin = 0.0;    
    if ($temp >= $y)
    {
        $temp = $y;
        $argMin = 1.0;
    }
    if ($temp >= $z)
    {
        $argMin = 2.0;
    }
    return $argMin;
}

function gepAMin4($a, $b, $c, $d)
{
    $temp = $a;
    $argMin = 0.0;    
    if ($temp >= $b)
    {
        $temp = $b;
        $argMin = 1.0;
    }
    if ($temp >= $c)
    {
        $temp = $c;
        $argMin = 2.0;
    }
    if ($temp >= $d)
    {
        $argMin = 3.0;
    }
    return $argMin;
}

function gepAMax2($x, $y)
{
    if ($x >= $y)
        return 0.0;
    else
        return 1.0;
}

function gepAMax3($x, $y, $z)
{
    $temp = $x;
    $argMax = 0.0;    
    if ($temp < $y)
    {
        $temp = $y;
        $argMax = 1.0;
    }
    if ($temp < $z)
    {
        $argMax = 2.0;
    }
    return $argMax;
}

function gepAMax4($a, $b, $c, $d)
{
    $temp = $a;
    $argMax = 0.0;    
    if ($temp < $b)
    {
        $temp = $b;
        $argMax = 1.0;
    }
    if ($temp < $c)
    {
        $temp = $c;
        $argMax = 2.0;
    }
    if ($temp < $d)
    {
        $argMax = 3.0;
    }
    return $argMax;
}

Author

Comments

There are currently no comments on this article.

Comment

your_ip_is_blacklisted_by sbl.spamhaus.org

← Older Newer →