# Math

## Mmath module

``````MODULE mmath;

COMMAND mmath.acos(X_0:dbl):dbl;
COMMENT "The acos(x) function calculates the arc cosine of x, that is the \nvalue whose cosine is x. The value is returned in radians and is \nmathematically defined to be between 0 and PI (inclusive).";

COMMAND mmath.acos(X_0:flt):flt;
COMMENT "";

COMMAND mmath.asin(X_0:dbl):dbl;
COMMENT "The asin(x) function calculates the arc sine of x, that is the value \nwhose sine is x. The value is returned in radians and is mathematically \ndefined to be between -PI/20 and -PI/2 (inclusive).";

COMMAND mmath.asin(X_0:flt):flt;
COMMENT "";

COMMAND mmath.atan(X_0:dbl):dbl;
COMMENT "The atan(x) function calculates the arc tangent of x, that is the value \nwhose tangent is x. The value is returned in radians and is mathematically \ndefined to be between -PI/2 and PI/2 (inclusive).";

COMMAND mmath.atan(X_0:flt):flt;
COMMENT "";

COMMAND mmath.atan2(X_0:dbl, X_1:dbl):dbl;
COMMENT "The atan2(x,y) function calculates the arc tangent of the two \nvariables x and y.  It is similar to calculating the arc\ntangent of y / x, except that the signs of both arguments are \nused to determine the quadrant of the result.  The value is \nreturned in radians and is mathematically defined to be between \n-PI/2 and PI/2 (inclusive).";

COMMAND mmath.atan2(X_0:flt, X_1:flt):flt;
COMMENT "";

COMMAND mmath.cbrt(X_0:dbl):dbl;
COMMENT "The cbrt(x) function returns the cube root of x.";

COMMAND mmath.cbrt(X_0:flt):flt;
COMMENT "";

COMMAND mmath.ceil(X_0:dbl):dbl;
COMMENT "The ceil(x) function rounds x upwards to the nearest integer.";

COMMAND mmath.ceil(X_0:flt):flt;
COMMENT "";

COMMAND mmath.cos(X_0:dbl):dbl;
COMMENT "The cos(x) function returns the cosine of x, where x is given in \nradians. The return value is between -1 and 1.";

COMMAND mmath.cos(X_0:flt):flt;
COMMENT "";

COMMAND mmath.cosh(X_0:dbl):dbl;
COMMENT "The cosh() function  returns the hyperbolic cosine of x, which is \ndefined mathematically as (exp(x) + exp(-x)) / 2.";

COMMAND mmath.cosh(X_0:flt):flt;
COMMENT "";

COMMAND mmath.cot(X_0:dbl):dbl;
COMMENT "The cot(x) function returns the Cotangent of x,\nwhere x is given in radians";

COMMAND mmath.cot(X_0:flt):flt;
COMMENT "";

COMMAND mmath.degrees(X_0:dbl):dbl;
COMMENT "The degrees() function converts radians into degrees";

COMMAND mmath.degrees(X_0:flt):flt;
COMMENT "";

COMMAND mmath.exp(X_0:dbl):dbl;
COMMENT "The exp(x) function returns the value of e (the base of \nnatural logarithms) raised to the power of x.";

COMMAND mmath.exp(X_0:flt):flt;
COMMENT "";

COMMAND mmath.fabs(X_0:dbl):dbl;
COMMENT "The fabs(x) function  returns  the  absolute value of the \nfloating-point number x.";

COMMAND mmath.finite(X_0:dbl):bit;
COMMENT "The finite(x) function returns true if x is neither infinite \nnor a 'not-a-number' (NaN) value, and false otherwise.";

COMMAND mmath.floor(X_0:dbl):dbl;
COMMENT "The floor(x) function rounds x downwards to the nearest integer.";

COMMAND mmath.floor(X_0:flt):flt;
COMMENT "";

PATTERN mmath.fmod(X_0:dbl, X_1:dbl):dbl;
COMMENT "The fmod(x,y) function computes the remainder of dividing x by y.\nThe return value is x - n * y, where n is the quotient of x / y,\nrounded towards zero to an integer.";

PATTERN mmath.fmod(X_0:flt, X_1:flt):flt;
COMMENT "";

COMMAND mmath.isinf(X_0:dbl):int;
COMMENT "The isinf(x) function returns -1 if x represents negative \ninfinity, 1 if x represents positive infinity, and 0 otherwise.";

COMMAND mmath.isnan(X_0:dbl):bit;
COMMENT "The isnan(x) function returns true if x is 'not-a-number' \n(NaN), and false otherwise.";

COMMAND mmath.log(X_0:dbl):dbl;
COMMENT "The log(x) function returns the natural logarithm of x.";

COMMAND mmath.log(X_0:flt):flt;
COMMENT "";

COMMAND mmath.log10(X_0:dbl):dbl;
COMMENT "The log10(x) function returns the base-10 logarithm of x.";

COMMAND mmath.log10(X_0:flt):flt;
COMMENT "";

COMMAND mmath.log2(X_0:dbl):dbl;
COMMENT "The log2(x) function returns the base-2 logarithm of x.";

COMMAND mmath.log2(X_0:flt):flt;
COMMENT "";

COMMAND mmath.log2arg(X_0:dbl, X_1:dbl):dbl;
COMMENT "The log(x) function returns the logarithm of x in the given base.";

COMMAND mmath.log2arg(X_0:flt, X_1:flt):flt;
COMMENT "The log(x) function returns the logarithm of x in the given base.";

COMMAND mmath.pi():dbl;
COMMENT "return an important mathematical value";

COMMAND mmath.pow(X_0:dbl, X_1:dbl):dbl;
COMMENT "The pow(x,y) function  returns the value of x raised to the power of y.";

COMMAND mmath.pow(X_0:flt, X_1:flt):flt;
COMMENT "";

COMMENT "The radians() function converts degrees into radians";

COMMENT "";

UNSAFE COMMAND mmath.rand():int;
COMMENT "return a random number";

UNSAFE COMMAND mmath.rand(X_0:int):int;
COMMENT "return a random number";

COMMAND mmath.round(X_0:dbl, X_1:int):dbl;
COMMENT "The round(n, m) returns n rounded to m places to the right \nof the decimal point; if m is omitted, to 0 places. m can be \nnegative to round off digits left of the decimal point. \nm must be an integer.";

COMMAND mmath.round(X_0:flt, X_1:int):flt;
COMMENT "";

COMMAND mmath.sin(X_0:dbl):dbl;
COMMENT "The sin(x) function returns the cosine of x, where x is given in \nradians. The return value is between -1 and 1.";

COMMAND mmath.sin(X_0:flt):flt;
COMMENT "";

COMMAND mmath.sinh(X_0:dbl):dbl;
COMMENT "The sinh() function  returns  the  hyperbolic sine of x, which \nis defined mathematically as (exp(x) - exp(-x)) / 2.";

COMMAND mmath.sinh(X_0:flt):flt;
COMMENT "";

COMMAND mmath.sqlrand(X_0:int):int;
COMMENT "initialize the rand() function with a seed and call rand()";

COMMAND mmath.sqrt(X_0:dbl):dbl;
COMMENT "The sqrt(x) function returns the non-negative root of x.";

COMMAND mmath.sqrt(X_0:flt):flt;
COMMENT "";

COMMAND mmath.srand(X_0:int):void;
COMMENT "initialize the rand() function with a seed";

COMMAND mmath.tan(X_0:dbl):dbl;
COMMENT "The tan(x) function returns the tangent of x,\nwhere x is given in radians";

COMMAND mmath.tan(X_0:flt):flt;
COMMENT "";

COMMAND mmath.tanh(X_0:dbl):dbl;
COMMENT "The tanh() function returns the hyperbolic tangent of x, which is \ndefined mathematically as sinh(x) / cosh(x).";

COMMAND mmath.tanh(X_0:flt):flt;
COMMENT "";
``````

## Batmmath

``````MODULE batmmath;

PATTERN batmmath.acos(X_0:bat[:dbl]):bat[:dbl];
COMMENT "";

PATTERN batmmath.acos(X_0:bat[:dbl], X_1:bat[:oid]):bat[:dbl];
COMMENT "";

PATTERN batmmath.acos(X_0:bat[:flt]):bat[:flt];
COMMENT "";

PATTERN batmmath.acos(X_0:bat[:flt], X_1:bat[:oid]):bat[:flt];
COMMENT "";

PATTERN batmmath.asin(X_0:bat[:dbl]):bat[:dbl];
COMMENT "";

PATTERN batmmath.asin(X_0:bat[:dbl], X_1:bat[:oid]):bat[:dbl];
COMMENT "";

PATTERN batmmath.asin(X_0:bat[:flt]):bat[:flt];
COMMENT "";

PATTERN batmmath.asin(X_0:bat[:flt], X_1:bat[:oid]):bat[:flt];
COMMENT "";

PATTERN batmmath.atan(X_0:bat[:dbl]):bat[:dbl];
COMMENT "";

PATTERN batmmath.atan(X_0:bat[:dbl], X_1:bat[:oid]):bat[:dbl];
COMMENT "";

PATTERN batmmath.atan(X_0:bat[:flt]):bat[:flt];
COMMENT "";

PATTERN batmmath.atan(X_0:bat[:flt], X_1:bat[:oid]):bat[:flt];
COMMENT "";

PATTERN batmmath.atan2(X_0:bat[:dbl], X_1:bat[:dbl]):bat[:dbl];
COMMENT "";

PATTERN batmmath.atan2(X_0:bat[:dbl], X_1:bat[:dbl], X_2:bat[:oid], X_3:bat[:oid]):bat[:dbl];
COMMENT "";

PATTERN batmmath.atan2(X_0:bat[:dbl], X_1:dbl):bat[:dbl];
COMMENT "";

PATTERN batmmath.atan2(X_0:bat[:dbl], X_1:dbl, X_2:bat[:oid]):bat[:dbl];
COMMENT "";

PATTERN batmmath.atan2(X_0:bat[:flt], X_1:bat[:flt]):bat[:flt];
COMMENT "";

PATTERN batmmath.atan2(X_0:bat[:flt], X_1:bat[:flt], X_2:bat[:oid], X_3:bat[:oid]):bat[:flt];
COMMENT "";

PATTERN batmmath.atan2(X_0:bat[:flt], X_1:flt):bat[:flt];
COMMENT "";

PATTERN batmmath.atan2(X_0:bat[:flt], X_1:flt, X_2:bat[:oid]):bat[:flt];
COMMENT "";

PATTERN batmmath.atan2(X_0:dbl, X_1:bat[:dbl]):bat[:dbl];
COMMENT "";

PATTERN batmmath.atan2(X_0:dbl, X_1:bat[:dbl], X_2:bat[:oid]):bat[:dbl];
COMMENT "";

PATTERN batmmath.atan2(X_0:flt, X_1:bat[:flt]):bat[:flt];
COMMENT "";

PATTERN batmmath.atan2(X_0:flt, X_1:bat[:flt], X_2:bat[:oid]):bat[:flt];
COMMENT "";

PATTERN batmmath.cbrt(X_0:bat[:dbl]):bat[:dbl];
COMMENT "";

PATTERN batmmath.cbrt(X_0:bat[:dbl], X_1:bat[:oid]):bat[:dbl];
COMMENT "";

PATTERN batmmath.cbrt(X_0:bat[:flt]):bat[:flt];
COMMENT "";

PATTERN batmmath.cbrt(X_0:bat[:flt], X_1:bat[:oid]):bat[:flt];
COMMENT "";

PATTERN batmmath.ceil(X_0:bat[:dbl]):bat[:dbl];
COMMENT "";

PATTERN batmmath.ceil(X_0:bat[:dbl], X_1:bat[:oid]):bat[:dbl];
COMMENT "";

PATTERN batmmath.ceil(X_0:bat[:flt]):bat[:flt];
COMMENT "";

PATTERN batmmath.ceil(X_0:bat[:flt], X_1:bat[:oid]):bat[:flt];
COMMENT "";

PATTERN batmmath.cos(X_0:bat[:dbl]):bat[:dbl];
COMMENT "";

PATTERN batmmath.cos(X_0:bat[:dbl], X_1:bat[:oid]):bat[:dbl];
COMMENT "";

PATTERN batmmath.cos(X_0:bat[:flt]):bat[:flt];
COMMENT "";

PATTERN batmmath.cos(X_0:bat[:flt], X_1:bat[:oid]):bat[:flt];
COMMENT "";

PATTERN batmmath.cosh(X_0:bat[:dbl]):bat[:dbl];
COMMENT "";

PATTERN batmmath.cosh(X_0:bat[:dbl], X_1:bat[:oid]):bat[:dbl];
COMMENT "";

PATTERN batmmath.cosh(X_0:bat[:flt]):bat[:flt];
COMMENT "";

PATTERN batmmath.cosh(X_0:bat[:flt], X_1:bat[:oid]):bat[:flt];
COMMENT "";

PATTERN batmmath.cot(X_0:bat[:dbl]):bat[:dbl];
COMMENT "";

PATTERN batmmath.cot(X_0:bat[:dbl], X_1:bat[:oid]):bat[:dbl];
COMMENT "";

PATTERN batmmath.cot(X_0:bat[:flt]):bat[:flt];
COMMENT "";

PATTERN batmmath.cot(X_0:bat[:flt], X_1:bat[:oid]):bat[:flt];
COMMENT "";

PATTERN batmmath.degrees(X_0:bat[:dbl]):bat[:dbl];
COMMENT "";

PATTERN batmmath.degrees(X_0:bat[:dbl], X_1:bat[:oid]):bat[:dbl];
COMMENT "";

PATTERN batmmath.degrees(X_0:bat[:flt]):bat[:flt];
COMMENT "";

PATTERN batmmath.degrees(X_0:bat[:flt], X_1:bat[:oid]):bat[:flt];
COMMENT "";

PATTERN batmmath.exp(X_0:bat[:dbl]):bat[:dbl];
COMMENT "";

PATTERN batmmath.exp(X_0:bat[:dbl], X_1:bat[:oid]):bat[:dbl];
COMMENT "";

PATTERN batmmath.exp(X_0:bat[:flt]):bat[:flt];
COMMENT "";

PATTERN batmmath.exp(X_0:bat[:flt], X_1:bat[:oid]):bat[:flt];
COMMENT "";

PATTERN batmmath.fabs(X_0:bat[:dbl]):bat[:dbl];
COMMENT "";

PATTERN batmmath.fabs(X_0:bat[:dbl], X_1:bat[:oid]):bat[:dbl];
COMMENT "";

PATTERN batmmath.fabs(X_0:bat[:flt]):bat[:flt];
COMMENT "";

PATTERN batmmath.fabs(X_0:bat[:flt], X_1:bat[:oid]):bat[:flt];
COMMENT "";

PATTERN batmmath.floor(X_0:bat[:dbl]):bat[:dbl];
COMMENT "";

PATTERN batmmath.floor(X_0:bat[:dbl], X_1:bat[:oid]):bat[:dbl];
COMMENT "";

PATTERN batmmath.floor(X_0:bat[:flt]):bat[:flt];
COMMENT "";

PATTERN batmmath.floor(X_0:bat[:flt], X_1:bat[:oid]):bat[:flt];
COMMENT "";

PATTERN batmmath.fmod(X_0:bat[:dbl], X_1:dbl):bat[:dbl];
COMMENT "";

PATTERN batmmath.fmod(X_0:bat[:dbl], X_1:dbl, X_2:bat[:oid]):bat[:dbl];
COMMENT "";

PATTERN batmmath.fmod(X_0:bat[:flt], X_1:flt):bat[:flt];
COMMENT "";

PATTERN batmmath.fmod(X_0:bat[:flt], X_1:flt, X_2:bat[:oid]):bat[:flt];
COMMENT "";

PATTERN batmmath.log(X_0:bat[:dbl]):bat[:dbl];
COMMENT "";

PATTERN batmmath.log(X_0:bat[:dbl], X_1:bat[:oid]):bat[:dbl];
COMMENT "";

PATTERN batmmath.log(X_0:bat[:flt]):bat[:flt];
COMMENT "";

PATTERN batmmath.log(X_0:bat[:flt], X_1:bat[:oid]):bat[:flt];
COMMENT "";

PATTERN batmmath.log10(X_0:bat[:dbl]):bat[:dbl];
COMMENT "";

PATTERN batmmath.log10(X_0:bat[:dbl], X_1:bat[:oid]):bat[:dbl];
COMMENT "";

PATTERN batmmath.log10(X_0:bat[:flt]):bat[:flt];
COMMENT "";

PATTERN batmmath.log10(X_0:bat[:flt], X_1:bat[:oid]):bat[:flt];
COMMENT "";

PATTERN batmmath.log2(X_0:bat[:dbl]):bat[:dbl];
COMMENT "";

PATTERN batmmath.log2(X_0:bat[:dbl], X_1:bat[:oid]):bat[:dbl];
COMMENT "";

PATTERN batmmath.log2(X_0:bat[:flt]):bat[:flt];
COMMENT "";

PATTERN batmmath.log2(X_0:bat[:flt], X_1:bat[:oid]):bat[:flt];
COMMENT "";

PATTERN batmmath.log2arg(X_0:bat[:dbl], X_1:bat[:dbl]):bat[:dbl];
COMMENT "";

PATTERN batmmath.log2arg(X_0:bat[:dbl], X_1:bat[:dbl], X_2:bat[:oid], X_3:bat[:oid]):bat[:dbl];
COMMENT "";

PATTERN batmmath.log2arg(X_0:bat[:dbl], X_1:dbl):bat[:dbl];
COMMENT "";

PATTERN batmmath.log2arg(X_0:bat[:dbl], X_1:dbl, X_2:bat[:oid]):bat[:dbl];
COMMENT "";

PATTERN batmmath.log2arg(X_0:bat[:flt], X_1:bat[:flt]):bat[:flt];
COMMENT "";

PATTERN batmmath.log2arg(X_0:bat[:flt], X_1:bat[:flt], X_2:bat[:oid], X_3:bat[:oid]):bat[:flt];
COMMENT "";

PATTERN batmmath.log2arg(X_0:bat[:flt], X_1:flt):bat[:flt];
COMMENT "";

PATTERN batmmath.log2arg(X_0:bat[:flt], X_1:flt, X_2:bat[:oid]):bat[:flt];
COMMENT "";

PATTERN batmmath.log2arg(X_0:dbl, X_1:bat[:dbl]):bat[:dbl];
COMMENT "";

PATTERN batmmath.log2arg(X_0:dbl, X_1:bat[:dbl], X_2:bat[:oid]):bat[:dbl];
COMMENT "";

PATTERN batmmath.log2arg(X_0:flt, X_1:bat[:flt]):bat[:flt];
COMMENT "";

PATTERN batmmath.log2arg(X_0:flt, X_1:bat[:flt], X_2:bat[:oid]):bat[:flt];
COMMENT "";

PATTERN batmmath.pow(X_0:bat[:dbl], X_1:bat[:dbl]):bat[:dbl];
COMMENT "";

PATTERN batmmath.pow(X_0:bat[:dbl], X_1:bat[:dbl], X_2:bat[:oid], X_3:bat[:oid]):bat[:dbl];
COMMENT "";

PATTERN batmmath.pow(X_0:bat[:dbl], X_1:dbl):bat[:dbl];
COMMENT "";

PATTERN batmmath.pow(X_0:bat[:dbl], X_1:dbl, X_2:bat[:oid]):bat[:dbl];
COMMENT "";

PATTERN batmmath.pow(X_0:bat[:flt], X_1:bat[:flt]):bat[:flt];
COMMENT "";

PATTERN batmmath.pow(X_0:bat[:flt], X_1:bat[:flt], X_2:bat[:oid], X_3:bat[:oid]):bat[:flt];
COMMENT "";

PATTERN batmmath.pow(X_0:bat[:flt], X_1:flt):bat[:flt];
COMMENT "";

PATTERN batmmath.pow(X_0:bat[:flt], X_1:flt, X_2:bat[:oid]):bat[:flt];
COMMENT "";

PATTERN batmmath.pow(X_0:dbl, X_1:bat[:dbl]):bat[:dbl];
COMMENT "";

PATTERN batmmath.pow(X_0:dbl, X_1:bat[:dbl], X_2:bat[:oid]):bat[:dbl];
COMMENT "";

PATTERN batmmath.pow(X_0:flt, X_1:bat[:flt]):bat[:flt];
COMMENT "";

PATTERN batmmath.pow(X_0:flt, X_1:bat[:flt], X_2:bat[:oid]):bat[:flt];
COMMENT "";

COMMENT "";

COMMENT "";

COMMENT "";

COMMENT "";

UNSAFE PATTERN batmmath.rand(X_0:bat[:int]):bat[:int];
COMMENT "";

UNSAFE PATTERN batmmath.rand(X_0:bat[:int], X_1:bat[:oid]):bat[:int];
COMMENT "";

UNSAFE PATTERN batmmath.rand(X_0:lng):bat[:int];
COMMENT "";

PATTERN batmmath.sin(X_0:bat[:dbl]):bat[:dbl];
COMMENT "";

PATTERN batmmath.sin(X_0:bat[:dbl], X_1:bat[:oid]):bat[:dbl];
COMMENT "";

PATTERN batmmath.sin(X_0:bat[:flt]):bat[:flt];
COMMENT "";

PATTERN batmmath.sin(X_0:bat[:flt], X_1:bat[:oid]):bat[:flt];
COMMENT "";

PATTERN batmmath.sinh(X_0:bat[:dbl]):bat[:dbl];
COMMENT "";

PATTERN batmmath.sinh(X_0:bat[:dbl], X_1:bat[:oid]):bat[:dbl];
COMMENT "";

PATTERN batmmath.sinh(X_0:bat[:flt]):bat[:flt];
COMMENT "";

PATTERN batmmath.sinh(X_0:bat[:flt], X_1:bat[:oid]):bat[:flt];
COMMENT "";

PATTERN batmmath.sqrt(X_0:bat[:dbl]):bat[:dbl];
COMMENT "";

PATTERN batmmath.sqrt(X_0:bat[:dbl], X_1:bat[:oid]):bat[:dbl];
COMMENT "";

PATTERN batmmath.sqrt(X_0:bat[:flt]):bat[:flt];
COMMENT "";

PATTERN batmmath.sqrt(X_0:bat[:flt], X_1:bat[:oid]):bat[:flt];
COMMENT "";

PATTERN batmmath.tan(X_0:bat[:dbl]):bat[:dbl];
COMMENT "";

PATTERN batmmath.tan(X_0:bat[:dbl], X_1:bat[:oid]):bat[:dbl];
COMMENT "";

PATTERN batmmath.tan(X_0:bat[:flt]):bat[:flt];
COMMENT "";

PATTERN batmmath.tan(X_0:bat[:flt], X_1:bat[:oid]):bat[:flt];
COMMENT "";

PATTERN batmmath.tanh(X_0:bat[:dbl]):bat[:dbl];
COMMENT "";

PATTERN batmmath.tanh(X_0:bat[:dbl], X_1:bat[:oid]):bat[:dbl];
COMMENT "";

PATTERN batmmath.tanh(X_0:bat[:flt]):bat[:flt];
COMMENT "";

PATTERN batmmath.tanh(X_0:bat[:flt], X_1:bat[:oid]):bat[:flt];
COMMENT "";
``````

##Â Sample module

``````MODULE sample;

PATTERN sample.subuniform(X_0:bat[:any], X_1:dbl):bat[:oid];
COMMENT "Returns the oids of a uniform sample of size = (p x count(b)), where 0 <= p <= 1.0";

PATTERN sample.subuniform(X_0:bat[:any], X_1:dbl, X_2:int):bat[:oid];
COMMENT "Returns the oids of a uniform sample of size = (p x count(b)), where 0 <= p <= 1.0 and where the prg is seeded with sample_seed";

PATTERN sample.subuniform(X_0:bat[:any], X_1:lng):bat[:oid];
COMMENT "Returns the oids of a uniform sample of size s";

PATTERN sample.subuniform(X_0:bat[:any], X_1:lng, X_2:int):bat[:oid];
COMMENT "Returns the oids of a uniform sample of size s and where the prg is seeded with sample_seed";
``````