Numerical Expressions
Constant numerical expressions
Like any expression in AIMMS, a numerical expression can either be a constant or a symbolic expression. Constant expressions are those that contain references to explicit set elements and values, but do not contain references to other identifiers. Constant expressions are mostly intended for the initialization of sets, parameters and variables. Such an initialization must conform to one of the following formats:
a scalar value,
a list expression,
a table expression, or
a composite table.
Table expressions and composite tables are mostly used for data initialization from external files. They are discussed in Format of Text Data Files.
Symbolic numerical expressions
Symbolic expressions are those expressions that contain references to
other AIMMS identifiers. They can be used in the Definition
attributes of sets, parameters and variables, or as the righthand side
of assignment statements. AIMMS provides a powerful notation for
expressions, and complicated numerical manipulations can be expressed in
a clear and concise manner.
Syntax
numericalexpression:
Real Values and Arithmetic Extensions
Extension of the real line
Traditional arithmetic is defined on the real line,
\(\mathbb{R}=(\infty,\infty)\), which does not contain either
\(+\infty\) or \(\infty\). AIMMS’ arithmetic is defined on the
set \(\mathbb{R}\cup\{{}\)INF
, INF
, NA
, UNDF
,
ZERO
\({}\}\) and summarized in this table.
The symbols INF
and INF
are mostly used to model unbounded
variables. The symbols NA
and UNDF
stand for not available and
undefined data values respectively. The symbol ZERO
denotes the
numerical value zero, but has the logical value true (not zero).
Symbol 
Description 
Logical value 
``MapVal`` value 

number 
any valid real number 
0 


undefined (result of an arithmetic error) 
1 
4 

not available 
1 
5 

\(+\infty\) 
1 
6 

\(\infty\) 
1 
7 

numerically indistinguishable from zero, but has the logical value of one. 
1 
8 
Numerical behavior
AIMMS treats these special symbols as ordinary real numbers, and the
results of the available arithmetic operations and functions on these
symbols are defined. The values INF
, INF
and ZERO
are
accessible by the user and are dealt with as expected:
\(1+{\texttt{INF}}\) evaluates to INF
, \(1/{\texttt{INF}}\)
to 0, \(1+{\texttt{ZERO}}\) to 1, etc. However, the values of
INF
and INF
are undetermined and therefore, it makes no sense
to consider \({\texttt{INF}}/{\texttt{INF}}\),
\({\texttt{INF}}+{\texttt{INF}}\), etc. These expressions are
therefore evaluated to UNDF
. A runtime error will occur if the value
UNDF
is assigned to an identifier.
The symbol ZERO
The symbol ZERO
behaves like zero numerically, but its logical value
is one. Using this symbol, you can make a distinction between the
default value of 0 and an assigned ZERO
. As an illustration,
consider a distance matrix with distances between selected factorydepot
combinations. A missing distance value evaluates to 0, and could mean
that the particular factorydepot combination should not be considered.
A ZERO
value in that case could be used to indicate that the
combination should be considered even though the corresponding distance
is zero because the depot and factory happen to be one facility.
Expressions with 0 and ZERO
Whenever the values 0 and ZERO
appear in the same expression with
equal priority, the value of ZERO
prevails. For example, the
expressions \(0+{\texttt{ZERO}}\) or max
(0,ZERO
) will
both result in a numerical value of ZERO
. In this way, the logically
distinctive effect of ZERO
is retained as long as possible. You
should note, however, that AIMMS will evaluate the multiplication of 0
with any special number to 0.
The symbol NA
The symbol NA
can be used for missing data. The interpretation is
“this number is not yet known”. Any operation that uses NA
and does
not use the symbol UNDF
will also produce the result NA
. AIMMS
can reason with this value as it propagates the value NA
through its
computations and assignments. The only exception is the condition in
control flow statements where it must be known whether the result of
that condition is equal to 0.0
or not, see also
Flow Control Statements.
The symbol UNDF
The symbol UNDF
cannot be input directly by a user, but is, besides
an error message, the result of an undefined or illegal arithmetic
operation. For example, 1/ZERO
, 0/0
, (2)^0.1
all result in
UNDF
. Any operation containing the UNDF
symbol evaluates to
UNDF
.
List Expressions
Elementvalue pairs
A list is a collection of elementvalue pairs. In a list a single element or range of elements is combined with a numerical, element, or stringvalued expression, separated by a colon. List expressions are the numerical extension of enumerated set expressions. The elements to which a value is assigned inside a list, are specified in exactly the same manner as in an enumerated set expression as explained in Enumerated Sets.
Syntax
enumeratedlist:
Constant versus symbolic
By preceding the list expression with the keyword DATA
, it becomes a
constant list expression, in a similar fashion as with constant set
expressions (see Enumerated Sets). In a constant list
expression, set elements need not be quoted and the assigned values must
be constants. All other list expressions are symbolic, in which both the
elements and the assigned values are the result of expression
evaluation.
Example
The following assignments illustrate the use of list expressions.
The following constant list expression assigns distances to tuples of cities.
Distance(i,j) := DATA { (Amsterdam, Rotterdam ) : 85 [km] , (Amsterdam, 'The Hague') : 65 [km] , (Rotterdam, 'The Hague') : 25 [km] } ;
The following symbolic list expression assigns a certain status to every node in a number of dynamically computed ranges.
NodeUsage(i) := { FirstNode .. FirstNode + Batch  1 : 'InUse' , FirstNode + Batch .. FirstNode + 2*Batch  1 : 'StandBy' , FirstNode + 2*Batch .. LastNode : 'Reserve' } ;
References
References
Sets, parameters and variables can be referred to by name resulting in a set, set element, stringvalued, or numerical quantity. A reference can be scalar or multidimensional, and index positions may contain either indices or element expressions. By specifying a case reference in front, a reference can refer to data from cases that are not in memory.
Syntax
reference:
identifierpart:
Scalar versus indexed
A scalar set, parameter or variable has no indexing (dimension) and is referenced simply by using its identifier. Indexed sets, parameters and variables have dimensions equal to the number of indices.
Example
The righthand sides of the following assignments are examples of references to scalar and indexed identifiers.
MainCity := 'Amsterdam' ;
DistanceFromMainCity(i) := Distance( MainCity, i );
SecondNextCity(i) := NextCity( NextCity(i) );
NextPeriodStock(t) := Stock( t + 1 );
Undefined references
The last two references, which make use of lag and lead operators and element parameters, may sometimes be undefined. When used in an expression such undefined references evaluate to the empty set, zero, the empty element, or the empty string, depending on the value type of the identifier. When an undefined lag or lead operator or element parameter occurs on the lefthand side of an assignment, the assignment is skipped. For more details, refer to Assignment Statements.
Referring to module identifiers
When your model contains one or more Modules
, your model will be
supplied multiple additional namespaces besides the global namespace,
one for each module. Identifiers declared within a module are, by
default, not contained in the global namespace. To refer to such
identifiers outside the module, you have to prefix the identifier name
with a modulespecific prefix and the ::
namespace resolution
operator. Modules
and the namespace resolution operator are
discussed in full detail in Module Declaration and Attributes.
Referring to other cases
When a reference is preceded by a case reference, AIMMS will not
retrieve the requested identifier data from the case in memory, but from
the case file associated with the case reference. Case references are
elements of the (predefined) set AllCases
, which contains all the
cases available in the data manager of AIMMS. Case Management
describes all the mechanisms that are available and functions that you
can use to let an enduser of your application select one or more cases
from the set of all available cases. Case referencing is useful when you
want to perform advanced case comparison over multiple cases.
Example
The following computes the differences of the values of the variable
Transport
in the current case compared to its values in all cases in
the set CurrentCaseSelection
.
for ( c in CurrentCaseSelection ) do
Difference(c,i,j) := c.Transport(i,j)  Transport(i,j) ;
endfor;
During execution, AIMMS will (temporarily) retrieve the values of
Transport
from all requested cases to compute the difference with
the data of the current case.
Arithmetic Functions
Standard functions
AIMMS provides the commonly used standard arithmetic functions such as the trigonometric functions, logarithms, and exponentiations. this table lists the available arithmetic functions with their arguments and result, where \(x\) is an extended range arithmetic expressions, \(m\), \(n\) are integer expressions, \(i\) is an index, \(l\) is a set element, \(I\) is a set identifier, and \(e\) is a scalar reference.
Function 
Meaning 


absolute value \(x\) 

\(e^x\) 

\(\log_e(x)\) for \(x>0\), 

\(\log_{10}(x)\) for \(x>0\), 

\(\max(x_1,\dots,x_n)\quad (n>1)\) 

\(\min(x_1,\dots,x_n)\quad (n>1)\) 

\(x_1 \bmod {x_2} \in [0,x_2)\) for \(x_2 > 0\) or \(\in(x_2,0]\) for \(x_2<0\) 

\(x_1\;\mathrm{div}\;{x_2}\) 

\(\mathrm{sign}(x)=+1\) if \(x>0\), \(1\) if \(x<0\) and \(0\) if \(x=0\) 

\(x^2\) 

\(\sqrt x\) for \(x\geq0\), 

\(x_1^{x_2}\), alternative for 

\({\frac{1}{\sqrt{2\pi}}}\int_{\infty}^x e^{{\frac{t^2}{2}}}\, dt\) 

\(\cos(x)\); \(x\) in radians 

\(\sin(x)\); \(x\) in radians 

\(\tan(x)\); \(x\) in radians 

\(\mathrm{arccos}(x)\); result in radians 

\(\mathrm{arcsin}(x)\); result in radians 

\(\mathrm{arctan}(x)\); result in radians 

converts \(x\) from radians to degrees 

converts \(x\) from degrees to radians 

\(\cosh(x)\) 

\(\sinh(x)\) 

\(\tanh(x)\) 

\(\mathrm{arccosh}(x)\) 

\(\mathrm{arcsinh}(x)\) 

\(\mathrm{arctanh}(x)\) 

cardinality of (suffix of) set, parameter or variable \(I\) 

ordinal number of index \(i\) in set \(I\) (see also this table) 

ordinal number of element \(l\) in set \(I\) 

\(\lceil x \rceil = \text{smallest integer} \geq x\) 

\(\lfloor x \rfloor = \text{largest integer} \leq x\) 

\(x\) rounded to \(n\) significant digits 

\(x\) rounded to nearest integer 

\(x\) rounded to \(n\) decimal places left (\(n<0\)) or right (\(n>0\)) of the decimal point 


\(\mathtt{NonDefault}(e)\) 
\(1\) if \(e\) is not at its default value, \(0\) otherwise 


Functions and extended arithmetic
Special caution is required when one or more of the arguments in the
functions are special symbols of AIMMS’ extended range arithmetic. If
the value of any of the arguments is UNDF
or NA
, then the result
will also be UNDF
or NA
. If the value of any of the arguments is
ZERO
and the numerical value of the result is zero, the function
will return ZERO
.
Numerical Operators
Using unary or binary numerical operators you can construct numerical expressions that consist of multiple terms and/or factors. The syntax follows.
Syntax
operatorexpression:
Standard numerical operators
The order of precedence of the standard numerical operators in AIMMS is given in this table. Parentheses may be used to override the precedence order. Expression evaluation is from left to right.
Operator 
Meaning 
Precedence 

Unary 


positive 
n/a 

negative 
n/a 
Binary 


exponentiation 
3 (high) 

multiplication 
2 

division 
2 

addition 
1 

subtraction 
1 (low) 
Example
The expression
p1 + p2 * p3 / p4^p5
is parsed by AIMMS as if it had been written
p1 + [(p2 * p3) / (p4^p5)]
In general, it is better to use parentheses than to rely on the precedence and associativity of the operators. Not only because it prevents you from making unwanted mistakes, but also because it makes your intentions clearer.
Exponential operator
Special restrictions apply to the exponential operator ^
. AIMMS
accepts the following combinations of lefthand side operand (called the
base), and righthand side operand (called the exponent):
a positive base with a real exponent,
a negative base with an integer exponent,
a zero base with a positive exponent, and
a zero base with a zero exponent results in one (as controlled by the option
power_0_0
).
Numerical Iterative Operators
Arithmetic iterative operators
Iterative operators are used to express repeated arithmetic operations, such as summation, in a concise manner. The arithmetic iterative operators supported by AIMMS are listed in this table. The second column in this table refers to the required number of expression arguments following the binding domain argument, while the last column refers to the result of the operator in case of an empty domain.
Name 
# Expr. 
Computes over all elements in the domain 
Default 


1 
the sum of the expression 
0 

1 
the product of the expression 
1 

0 
the total number of elements in the domain 
0 
1 
the minimum value of the expression 


1 
the maximum value of the expression 

Compared expressions
The Min
and Max
operators return the minimum or maximum value of
an expression. The allowed expressions are:
numerical expressions, in which case AIMMS returns the lowest or highest numerical values,
string expressions, in which case AIMMS returns the strings which are first or last with respect to the normal alphabetic ordering, and
element expressions, in which case AIMMS returns the elements with the lowest or highest ordinal numbers (see also Intrinsic Functions for Sets and Set Elements).
Example
The following assignments are valid examples of the use of the arithmetic iterative operators.
NumberOfRoutes := Count( (i,j)  Distance(i,j) ) ;
NettoTransport(i) := Sum( j, Transport(i,j)  Transport(j,i) ) ;
MaximumTransport(i) := Max( j, Transport(i,j) ) ;
Statistical Functions and Operators
Distributions
AIMMS provides the most commonly used distributions. They are listed in this table, together with the required type of arguments and a description of the result. You can find a more detailed description of these distributions in Discrete Distributions and Continuous Distributions. When called as functions inside your model, they behave as random number generators.
Distribution 
Meaning 


Binomial distribution with probability \(p\) and number of trials \(n\) 

Negative Binomial distribution with probability \(p\) and number of successes \(r\) 

Poisson distribution with rate \(\lambda\) 

Geometric distribution with probability \(p\) 

Hypergeometric distribution with initial probability of success \(p\), number of trials \(n\) and population size \(N\) 

Uniform distribution with lower bound min and upper bound max 

Triangular distribution with shape \(\beta\), lower bound min, and upper bound max, where \(\beta=(x_{\text{peak}}{min})/({max}{min})\) 

Beta distribution with shapes \(\alpha\), \(\beta\), lower bound min, and upper bound max 

Lognormal distribution with shape \(\beta\), lower bound min, and scale \(s\) 

Exponential distribution with lower bound min and scale \(s\) 

Gamma distribution with shape \(\beta\), lower bound min, and scale \(s\) 

Weibull distribution with shape \(\beta\), lower bound min, and scale \(s\) 

Pareto distribution with shape \(\beta\), location \(l\), and scale \(s\) (\(\text{lower bound} = l + s\)) 

Normal distribution with mean \(\mu\) and standard deviation \(\sigma\) 

Logistic distribution with mean \(\mu\) and scale \(s\) 

Extreme Value distribution with location \(l\) and scale \(s\) 
Setting the seed
You can set the seed of the random number generators for all
distributions using the execution option seed
. By setting the seed
explicitly you can guarantee that your model results are reproducible.
Cumulative distributions and their derivatives
Each distribution in this table can be used as an
argument for four operators: DistributionCumulative
and
DistributionInverseCumulative
, and their derivatives
DistributionDensity
and DistributionInverseDensity
. In the
explanation below it is assumed that \(\alpha \in [0,1]\),
\(x \in (\infty,\infty)\), and \(X\) a random variable
distributed according to the given distribution distr.
DistributionCumulative
(distr,\(x\)) computes the probability \(P(X\leq x)\).DistributionInverseCumulative
(distr,\(\alpha\)) computes the smallest \(x\) such that the probability \(P(X\leq x) \geq \alpha\), except for \(\alpha = 0\) which returns the lowest possible value for \(X\).DistributionDensity
(distr,\(x\)) computes for continuous distributions the probability density \(\lim_{\alpha \downarrow 0}P(x \leq X\leq x+\alpha)/\alpha\). For discrete distributions, the operator is only defined for integer values of \(x\) and returns \(P(X = x)\).DistributionInverseDensity
(distr,\(\alpha\)) is the derivative ofDistributionInverseCumulative
. For more details you are referred to Distribution Operators.
Use in constraints
For the continuous distributions in this table, AIMMS can compute the derivatives of the cumulative and inverse cumulative distribution functions. As a consequence, you may use these functions in the constraints of a nonlinear model when the second argument is a variable.
Example
The following statements demonstrate how the distributions can be used to perform statistical tasks.
Draw a random number from a distribution.
Draw := Normal(0,1); Draw := Uniform(LowestValue, HighestValue);
Compute the probability of at most 10 successes out of 50 trials, with a 0.25 probability of success.
Probability := DistributionCumulative( Binomial(0.25,50), 10 );
Compute a twosided 90% confidence interval of a Normal(0,1) distribution.
LeftBound := DistributionInverseCumulative( Normal(0,1), 0.05); RightBound := DistributionInverseCumulative( Normal(0,1), 0.95);
Statistical operators
The distributions, listed in this table, make it possible for you to execute a stochastic experiment based on your model representation. In order to analyze the subsequent results, AIMMS provides a number of statistical iterative operators which are listed in this table. The second column in this table refers to the required number of expression arguments following the binding domain argument. For the most common sample operators, AIMMS provides distribution operators to calculate the corresponding expected values, assuming the sample is drawn from a given distribution. These distribution operators are listed in this table. A more detailed description of these operators is provided in Distributions, Statistical Operators and Histogram Functions.
Name 
# Expr. 
Computes over all elements in the domain 


1 
the (arithmetic) mean 

1 
the geometric mean 

1 
the harmonic mean 

1 
the root mean square 

1 
the median 

1 
the standard deviation of a sample 

1 
the standard deviation of a population 

1 
the coefficient of skewness 

1 
the coefficient of kurtosis 

2 
the correlation coefficient 

2 
the rank correlation coefficient 
Name 
Computes for a given distribution 

the (arithmetic) mean 

the (standard) deviation 

the variance (the square of the deviation) 

the coefficient of skewness 

the coefficient of kurtosis 
Example
Assume that p
is an index into a set that has been used to index a
number of experiments resulting in observables x(p)
and y(p)
.
Then the following assignments demonstrate the use of the statistical
operators in AIMMS.
MeanX := Mean(p, x(p));
MeanX := Mean(p  x(p), x(p));
DeviationX := SampleDeviation(p, x(p));
CorrelationXY := Correlation(p, x(p), y(p));
In case the \(x\) values are drawn from a Binomial(0.6,8)
distribution the expected value of MeanX
is given by
ExpectedMeanX := DistributionMean(Binomial(0.6,8));
Units of measurement
For all distributions, the units of measurement (see also Units of Measurement) of parameters and result should be consistent. The unit relationships for each distribution are described in Distributions, Statistical Operators and Histogram Functions in full detail. In the presence of units of measurement within your model, AIMMS will perform a unit consistency check.
Histogram support
For easy visualization of statistical data, AIMMS offers support for creating histograms based on a large collection of observed values. Through a number of predefined procedures and functions, AIMMS allows you to flexibly create intervalbased histogram data, which can easily be displayed, for instance, using the standard (graphical) AIMMS bar chart object. For further information about creating and displaying histograms, as well as an illustrative example, you are referred to Creating Histograms in the Appendix.
Combinatoric functions
In addition to the distribution and statistical operators listed above, AIMMS also offers support for the most common combinatoric calculations. this table contains the list of combinatoric functions that are available in AIMMS.
Function 
Meaning 


\(n!\) 

\(\binom{n}{m}\) 

\(m!\cdot{\binom{n}{m}}\) 
Financial Functions
Financial functions
AIMMS provides an extensive library of financial functions for a variety of financial applications. The available functions can be classified as follows.
Functions for the computation of the depreciation of assets using various methods such as fixeddeclining balance method, doubledeclining balance method, etc.
Functions for computing various quantities regarding investments that consist of a series of constant or variable periodic cash flows. The computed quantities include present value, net present value, future value, internal rate of return, interest and principal payments, etc.
Functions for computing various securityrelated quantities of, for instance, discounted securities, securities that pay periodic interest and securities that pay interest at maturity. The computed quantities include yield, interest rate, redemption, price, accrued interest, etc.
Consult the online function reference
The precise description of all financial functions available in AIMMS is not included in this Language Reference. A complete list of the available financial functions can be found in Financial Functions of the AIMMS Function Reference. The Function Reference provides a description as well as the prototype of every financial function present in AIMMS.
Conditional Expressions
Two conditional expressions
There are two ways to specify expressions that adopt different values
depending on one or more logical conditions. The ONLYIF
operator is
the simpler and operates as it sounds. The IFTHENELSE
expression
is more powerful in its ability to distinguish several cases.
Syntax
conditionalexpression:
The ONLYIF
operator
The simplest way of specifying a conditional expression is to use the
ONLYIF
operator. Its syntax is given by
onlyifexpression:
The ONLYIF
expression evaluates to the arithmetic expression in the
first argument if the logical condition of the second argument is true.
Otherwise, it is zero. The $
symbol can be used as a synonym for
the ONLYIF
operator.
Example
A simple example of the use of the ONLYIF
operator is given by the
assignment
AverageVelocity := (Distance / TravelTime) ONLYIF TravelTime ;
or equivalently, using the $
operator,
AverageVelocity := (Distance / TravelTime) $ TravelTime ;
Both expressions evaluate to Distance / TravelTime
if TravelTime
assumes a nonzero value, or to zero otherwise. In
Modifying the Sparsity you will see that this particular
expression can be written even more concisely using the sparsity
modifier $
.
IFTHENELSE
expressions
A much more flexible way for specifying conditional expressions is given
by the IFTHENELSE
operator. The syntax of the IFTHENELSE
expression is given below.
Syntax
ifthenelseexpression:
Explanation
The IFTHENELSE
expression works like a switch statementa series
of ELSEIF
s can be used to denote numerous special cases. The value
of the IFTHENELSE
expression is the first numerical expression for
which the corresponding logical condition is true. If none of the
conditions are true, then the value will be the numerical expression
after the ELSE
keyword if present or zero otherwise.
Example
A simple illustration of the use of the IFTHENELSE
construction is
given by the assignments
AverageVelocity := IF TravelTime THEN Distance / TravelTime ENDIF ;
which is equivalent to the ONLYIF
expression above. A more elaborate
example is given by the assignment
WeightedDistance(i) :=
IF Distance(i) <= 100 THEN Distance(i)
ELSEIF Distance(i) <= 200 THEN (100 + Distance(i)) / 2
ELSEIF Distance(i) <= 300 THEN (250 + Distance(i)) / 3
ELSE 550 / 3
ENDIF ;
The expression takes the value associated with the first logical expression that is true.