# math#

gamspy.math.cos(x)[source]#

Cosine of x.

Returns:
Expression
Parameters:

x (Union[int, float, Symbol]) –

Return type:

Expression

gamspy.math.cosh(x)[source]#

Hyperbolic cosine of x.

Returns:
Expression
Parameters:

x (Union[int, float, Symbol]) –

Return type:

Expression

gamspy.math.sin(x)[source]#

Sine of x.

Returns:
Expression
Parameters:

x (Union[float, Symbol]) –

Return type:

Expression

gamspy.math.sinh(x)[source]#

Hyperbolic sine of x.

Returns:
Expression
Parameters:

x (Union[float, Symbol]) –

Return type:

Expression

gamspy.math.acos(x)[source]#

Inverse cosine of x.

Returns:
Expresion | float
Parameters:

x (Union[float, Symbol]) –

Return type:

Expression

gamspy.math.asin(x)[source]#

Inver sinus of x.

Returns:
Expression
Parameters:

x (Union[float, Symbol]) –

Return type:

Expression

gamspy.math.tan(x)[source]#

Tangent of x.

Returns:
Expression
Parameters:

x (Union[float, Symbol]) –

Return type:

Expression

gamspy.math.tanh(x)[source]#

Hyperbolic tangent of x.

Returns:
Expression
Parameters:

x (Union[float, Symbol]) –

Return type:

Expression

gamspy.math.atan(x)[source]#

Inverse tangent of x.

Returns:
Expression
Parameters:

x (Union[float, Symbol]) –

Return type:

Expression

gamspy.math.atan2(y, x)[source]#

Returns:
Expression
Parameters:
• y (Union[int, float, Symbol]) –

• x (Union[int, float, Symbol]) –

Return type:

Expression

gamspy.math.exp(x)[source]#

Exponential of x (i.e. e^x)

Returns:
Expression
Parameters:

x (Union[float, Symbol]) –

Return type:

Expression

gamspy.math.power(base, exponent)[source]#

Base to the exponent power (i.e. base ^ exponent)

Parameters:
basefloat | Symbol
exponentfloat | Symbol
Returns:
Expression
Parameters:
• base (Union[float, Symbol]) –

• exponent (Union[float, Symbol]) –

Return type:

Expression

gamspy.math.sqr(x)[source]#

Square of x

Parameters:
xfloat | Symbol
Returns:
Expression
Parameters:

x (Union[float, Symbol]) –

Return type:

Expression

gamspy.math.sqrt(x)[source]#

Square root of x

Returns:
Expression
Parameters:

x (Union[int, float, Symbol]) –

Return type:

Expression

gamspy.math.log(x)[source]#

Natural logarithm of x (i.e. logarithm base e of x)

Returns:
Expression
Parameters:

x (Union[int, float, Symbol]) –

Return type:

Expression

gamspy.math.log2(x)[source]#

Binary logarithm (i.e. logarithm base 2 of x)

Returns:
Expression
Parameters:

x (Union[float, Symbol]) –

Return type:

Expression

gamspy.math.log10(x)[source]#

Common logarithm (i.e. logarithm base 10 of x)

Returns:
Expression
Parameters:

x (Union[float, Symbol]) –

Return type:

Expression

gamspy.math.log_beta(x, y)[source]#

Log beta function

Returns:
Expression
Parameters:
• x (Union[int, float, Symbol]) –

• y (Union[int, float, Symbol]) –

Return type:

Expression

gamspy.math.log_gamma(x, y)[source]#

Log gamma function

Returns:
Expression
Parameters:
• x (Union[int, float, Symbol]) –

• y (Union[int, float, Symbol]) –

Return type:

Expression

gamspy.math.logit(x)[source]#

Natural logarithm of x (i.e. logarithm base e of x)

Returns:
Expression
Parameters:

x (Union[int, float, Symbol]) –

Return type:

Expression

gamspy.math.abs(x)[source]#

Absolute value of x (i.e. `|x|`)

Returns:
Expression
Parameters:

x (Union[int, float, Symbol]) –

Return type:

Expression

gamspy.math.ceil(x)[source]#

The smallest integer greater than or equal to x

Returns:
Expression
Parameters:

x (Union[int, float, Symbol]) –

Return type:

Expression

gamspy.math.dist(x1, x2)[source]#

L2 norm

Returns:
Expression
Raises:
Exception

In case both x1 and x2 are not a tuple or none.

Parameters:
• x1 (Union[Tuple[int, float], Symbol]) –

• x2 (Union[Tuple[int, float], Symbol]) –

Return type:

Expression

gamspy.math.div(dividend, divisor)[source]#

Dividing operation

Parameters:
dividendint | float | Symbol
divisorint | float | Symbol
Returns:
Expression
Parameters:
• dividend (Union[int, float, Symbol]) –

• divisor (Union[int, float, Symbol]) –

Return type:

Expression

gamspy.math.div0(dividend, divisor)[source]#

Dividing operation

Parameters:
dividendint | float | Symbol
divisorint | float | Symbol
Returns:
Expression
Parameters:
• dividend (Union[int, float, Symbol]) –

• divisor (Union[int, float, Symbol]) –

Return type:

Expression

gamspy.math.factorial(x)[source]#

Factorial of x

Returns:
Expression
Parameters:

x (Union[int, Symbol]) –

Return type:

Expression

gamspy.math.floor(x)[source]#

The greatest integer less than or equal to x

Returns:
Expression
Parameters:

x (Union[int, float, Symbol]) –

Return type:

Expression

gamspy.math.fractional(x)[source]#

Returns the fractional part of x

Returns:
Expression
Parameters:

x (Union[int, float, Symbol]) –

Return type:

Expression

gamspy.math.Min(*values)[source]#

Minimum value of the values, where the number of values may vary.

Returns:
Expression
Return type:

Expression

gamspy.math.Max(*values)[source]#

Maximum value of the values, where the number of values may vary.

Returns:
Expression
Return type:

Expression

gamspy.math.mod(x, y)[source]#

Remainder of x divided by y.

Returns:
Expression
Parameters:
• x (Union[float, Symbol]) –

• y (Union[float, Symbol]) –

Return type:

Expression

gamspy.math.Round(x, num_decimals=0)[source]#

Round x to num_decimals decimal places.

Parameters:
xfloat | Symbol
decimalint, optional
Returns:
Expression
Parameters:
• x (Union[float, Symbol]) –

• num_decimals (int) –

Return type:

Expression

gamspy.math.sign(x)[source]#

Sign of x returns 1 if x > 0, -1 if x < 0, and 0 if x = 0

Parameters:
xSymbol
Returns:
Expression
Parameters:

x (Symbol) –

Return type:

Expression

gamspy.math.binomial(n, k)[source]#

(Generalized) Binomial coefficient for n > -1, -1 < k < n + 1

Parameters:
nint | float | Symbol
kint | float | Symbol
Returns:
Expression
Parameters:
• n (Union[int, float, Symbol]) –

• k (Union[int, float, Symbol]) –

Return type:

Expression

gamspy.math.centropy(x, y, z=1e-20)[source]#

Cross-entropy. x . ln((x + z) / (y + z)

Parameters:
xfloat | Symbol
yfloat | Symbol
zfloat, optional
Returns:
Expression
Raises:
ValueError

if z is smaller than 0

Parameters:
• x (Union[int, float, Symbol]) –

• y (Union[int, float, Symbol]) –

• z (float) –

Return type:

Expression

gamspy.math.normal(mean, dev)[source]#

Generate a random number from the normal distribution with mean mean and standard deviation dev.

Parameters:
meanint | float
devint | float
Returns:
Expression
Parameters:
• mean (Union[int, float]) –

• dev (Union[int, float]) –

Return type:

Expression

gamspy.math.uniform(lower_bound, upper_bound)[source]#

Generates a random number from the uniform distribution between lower_bound and higher_bound

Parameters:
lower_boundfloat
upper_boundfloat
Returns:
Expression
Parameters:
• lower_bound (Union[float, Expression]) –

• upper_bound (Union[float, Expression]) –

Return type:

Expression

gamspy.math.uniformInt(lower_bound, upper_bound)[source]#

Generates an integer random number from the discrete uniform distribution whose outcomes are the integers between lower_bound and higher_bound.

Parameters:
lower_boundint | float
upper_boundint | float
Returns
——-
Expression
Parameters:
• lower_bound (Union[int, float]) –

• upper_bound (Union[int, float]) –

Return type:

Expression

gamspy.math.cv_power(base, exponent)[source]#

Real power (i.e. base ^ exponent where X >= 0)

Parameters:
basefloat | Symbol
exponentfloat | Symbol
Returns:
Expression
Parameters:
• base (Union[float, Symbol]) –

• exponent (Union[float, Symbol]) –

Return type:

Expression

gamspy.math.rpower(base, exponent)[source]#

Returns x^y for x > 0 and also for x = 0 and restricted values of y

Parameters:
basefloat | Symbol
exponentfloat | Symbol
Returns:
Expression
Parameters:
• base (Union[float, Symbol]) –

• exponent (Union[float, Symbol]) –

gamspy.math.sign_power(base, exponent)[source]#

Signed power for y > 0.

Parameters:
basefloat | Symbol
exponentfloat | Symbol
Returns:
Expression
Parameters:
• base (Union[float, Symbol]) –

• exponent (Union[float, Symbol]) –

gamspy.math.sllog10(x, S=1e-150)[source]#

Smooth (linear) logarithm base 10

Parameters:
xint | float | Symbol
Sint | float, by default 1.0e-150
Returns:
Expression
Parameters:
• x (Union[int, float, Symbol]) –

• S (Union[int, float]) –

Return type:

Expression

gamspy.math.sqlog10(x, S=1e-150)[source]#

Smooth (quadratic) logarithm base 10

Parameters:
xint | float | Symbol
Sint | float, by default 1.0e-150
Returns:
Expression
Parameters:
• x (Union[int, float, Symbol]) –

• S (Union[int, float]) –

Return type:

Expression

gamspy.math.vc_power(base, exponent)[source]#

Returns x^y for x >= 0

Parameters:
basefloat | Symbol
exponentfloat | Symbol
Returns:
Expression
Parameters:
• base (Union[float, Symbol]) –

• exponent (Union[float, Symbol]) –

gamspy.math.slexp(x, S=150)[source]#

Smooth (linear) exponential

Parameters:
xint | float | Symbol
Sint | float, by default 150
Returns:
Expression
Parameters:
• x (Union[int, float, Symbol]) –

• S (Union[int, float]) –

Return type:

Expression

gamspy.math.sqexp(x, S=150)[source]#

Parameters:
xint | float | Symbol
Sint | float, by default 150
Returns:
Expression
Parameters:
• x (Union[int, float, Symbol]) –

• S (Union[int, float]) –

Return type:

Expression

gamspy.math.truncate(x)[source]#

Returns the integer part of x

Returns:
Expression
Parameters:

x (Union[int, float, Symbol]) –

Return type:

Expression

gamspy.math.ifthen(condition, yes_return, no_return)[source]#

If the logical condition is true, the function returns iftrue, else it returns else

Parameters:
conditionExpression
yes_returnfloat | Expression
no_returnfloat | Expression
Returns:
Expression
Parameters:
• condition (Expression) –

• yes_return (Union[float, Expression]) –

• no_return (Union[float, Expression]) –

Return type:

Expression

Examples

```>>> from gamspy.math import ifthen
>>> import gamspy as gp
>>> m = gp.Container()
>>> tt = gp.Parameter(m, "tt", records=2)
>>> y = gp.Parameter(m, "y", records=2)
>>> x = ifthen(tt == 2, 3, 4 + y)
```
gamspy.math.beta(x, y)[source]#

Beta function

Parameters:
xint | float | Symbol
yint | float | Symbol
Returns:
Expression
Parameters:
• x (Union[int, float, Symbol]) –

• y (Union[int, float, Symbol]) –

Return type:

Expression

gamspy.math.regularized_beta(x, y, z)[source]#

Beta function

Parameters:
xint | float
yint | float
zint | float
Returns:
Expression
Parameters:
• x (Union[int, float]) –

• y (Union[int, float]) –

• z (Union[int, float]) –

Return type:

Expression

gamspy.math.gamma(x)[source]#

Gamma function

Parameters:
xint | float
Returns:
Expression
Parameters:

x (Union[int, float, Symbol]) –

Return type:

Expression

gamspy.math.regularized_gamma(x, a)[source]#

Gamma function

Parameters:
xint | float
aint | float
Returns:
Expression
Parameters:
• x (Union[int, float]) –

• a (Union[int, float]) –

Return type:

Expression

gamspy.math.entropy(x)[source]#

L2 Norm of x

Parameters:
xint | float | Symbol
Returns:
Expression
Parameters:

x (Union[int, float, Symbol]) –

Return type:

Expression

gamspy.math.lse_max(*xs)[source]#

Smoothed Max via the Logarithm of the Sum of Exponentials

Returns:
Expression
Return type:

Expression

gamspy.math.lse_max_sc(t, *xs)[source]#

Scaled smoothed Max via the Logarithm of the Sum of Exponentials

Returns:
Expression
Return type:

Expression

gamspy.math.lse_min(*xs)[source]#

Smoothed Min via the Logarithm of the Sum of Exponentials

Returns:
Expression
Return type:

Expression

gamspy.math.lse_min_sc(t, *xs)[source]#

Scaled smoothed Min via the Logarithm of the Sum of Exponentials

Returns:
Expression
Return type:

Expression

gamspy.math.ncp_cm(x, y, z)[source]#

Chen-Mangasarian smoothing

Parameters:
xSymbol
ySymbol
zint | float
Returns:
Expression
Parameters:
• x (Symbol) –

• y (Symbol) –

• z (Union[float, int]) –

Return type:

Expression

gamspy.math.ncp_f(x, y, z=0)[source]#

Fisher-Burmeister smoothing

Parameters:
xSymbol
ySymbol
zint | float, optional
Returns:
Expression
Parameters:
• x (Symbol) –

• y (Symbol) –

• z (Union[int, float]) –

Return type:

Expression

gamspy.math.ncpVUpow(r, s, mu=0)[source]#

NCP Veelken-Ulbrich: smoothed min(r,s)

Parameters:
rSymbol
sSymbol
muint | float, optional
Returns:
Expression
Parameters:
• r (Symbol) –

• s (Symbol) –

• mu (Union[int, float]) –

Return type:

Expression

gamspy.math.ncpVUsin(r, s, mu=0)[source]#

NCP Veelken-Ulbrich: smoothed min(r,s)

Parameters:
rSymbol
sSymbol
muint | float, optional
Returns:
Expression
Parameters:
• r (Symbol) –

• s (Symbol) –

• mu (Union[int, float]) –

Return type:

Expression

gamspy.math.poly(x, *args)[source]#

Polynomial function

Returns:
Expression
Return type:

Expression

gamspy.math.rand_binomial(n, p)[source]#

Generate a random number from the binomial distribution, where n is the number of trials and p the probability of success for each trial

Parameters:
nint | float
pint | float
Returns:
Expression
Parameters:
• n (Union[int, float]) –

• p (Union[int, float]) –

Return type:

Expression

gamspy.math.rand_linear(low, slope, high)[source]#

Generate a random number between low and high with linear distribution. slope must be greater than 2 / (high - low)

Parameters:
lowint | float
slopeint | float
highint | float
Returns:
Expression
Parameters:
• low (Union[int, float]) –

• slope (Union[int, float]) –

• high (Union[int, float]) –

Return type:

Expression

gamspy.math.rand_triangle(low, mid, high)[source]#

Generate a random number between low and high with triangular distribution. mid is the most probable number.

Parameters:
lowint | float
midint | float
highint | float
Returns:
Expression
Parameters:
• low (Union[int, float]) –

• mid (Union[int, float]) –

• high (Union[int, float]) –

Return type:

Expression

gamspy.math.slrec(x, S=1e-10)[source]#

Smooth (linear) reciprocal

Parameters:
xint | float | Symbol
Sint | float, by default 1e-10
Returns:
Expression
Parameters:
• x (Union[int, float, Symbol]) –

• S (Union[int, float]) –

Return type:

Expression

gamspy.math.sqrec(x, S=1e-10)[source]#

Parameters:
xint | float | Symbol
Sint | float, by default 1e-10
Returns:
Expression
Parameters:
• x (Union[int, float, Symbol]) –

• S (Union[int, float]) –

Return type:

Expression

gamspy.math.errorf(x)[source]#

Integral of the standard normal distribution

Parameters:
xint, float, Symbol
Returns:
Expression
Parameters:

x (Union[int, float, Symbol]) –

Return type:

Expression

gamspy.math.same_as(self, other)[source]#

Evaluates to true if this set is identical to the given set or alias, false otherwise.

Parameters:
otherSet | Alias
Returns:
Expression
Parameters:
Return type:

Expression

gamspy.math.sigmoid(x)[source]#

Sigmoid of x

Parameters:
xint | float | Symbol
Returns:
Expression
Parameters:

x (Union[int, float, Symbol]) –

Return type:

Expression

gamspy.math.bool_and(x, y)[source]#
Parameters:
• x (Union[int, Symbol]) –

• y (Union[int, Symbol]) –

Return type:

Expression

gamspy.math.bool_eqv(x, y)[source]#
Parameters:
• x (Union[int, Symbol]) –

• y (Union[int, Symbol]) –

Return type:

Expression

gamspy.math.bool_imp(x, y)[source]#
Parameters:
• x (Union[int, Symbol]) –

• y (Union[int, Symbol]) –

Return type:

Expression

gamspy.math.bool_not(x)[source]#
Parameters:

x (Union[int, Symbol]) –

Return type:

Expression

gamspy.math.bool_or(x, y)[source]#
Parameters:
• x (Union[int, Symbol]) –

• y (Union[int, Symbol]) –

Return type:

Expression

gamspy.math.bool_xor(x, y)[source]#
Parameters:
• x (Union[int, Symbol]) –

• y (Union[int, Symbol]) –

Return type:

Expression

gamspy.math.rel_eq(x, y)[source]#
Parameters:
• x (Union[int, Symbol]) –

• y (Union[int, Symbol]) –

Return type:

Expression

gamspy.math.rel_ge(x, y)[source]#
Parameters:
• x (Union[int, Symbol]) –

• y (Union[int, Symbol]) –

Return type:

Expression

gamspy.math.rel_gt(x, y)[source]#
Parameters:
• x (Union[int, Symbol]) –

• y (Union[int, Symbol]) –

Return type:

Expression

gamspy.math.rel_le(x, y)[source]#
Parameters:
• x (Union[int, Symbol]) –

• y (Union[int, Symbol]) –

Return type:

Expression

gamspy.math.rel_lt(x, y)[source]#
Parameters:
• x (Union[int, Symbol]) –

• y (Union[int, Symbol]) –

Return type:

Expression

gamspy.math.rel_ne(x, y)[source]#
Parameters:
• x (Union[int, Symbol]) –

• y (Union[int, Symbol]) –

Return type:

Expression