The lexical units are combined to form even larger building blocks such as expressions according to the rules given by the expression part of the Modelica grammar in Appendix B.
This chapter describes the evaluation rules for expressions, the concept of expression variability, builtin mathematical operators and functions, and the builtin special Modelica operators with function syntax.
Expressions can contain variables and constants, which have types, predefined or user defined. The predefined builtin types of Modelica are Real, Integer, Boolean, String, and enumeration types which are presented in more detail in section 4.8.
[The abbreviated predefined type information below is given as background information for the rest of the presentation.]
Modelica equations, assignments and declaration equations contain expressions.
Expressions can contain basic operations, +, , *, /, ^, etc. with normal precedence as defined in the Table in section 3.2 and the grammar in Appendix B. The semantics of the operations is defined for both scalar and array arguments in section 10.6.
It is also possible to define functions and call them in a normal fashion. The function call syntax for both positional and named arguments is described in section 12.4.1 and for vectorized calls in section 12.4.4. The builtin array functions are given in section 10.1.1 and other builtin operators in section 3.7.
Operator precedence determines the order of evaluation of operators in an expression. An operator with higher precedence is evaluated before an operator with lower precedence in the same expression.
The following table presents all the expression operators in order of precedence from highest to lowest, as derived from the Modelica grammar in Appendix B. All operators are binary except the postfix operators and those shown as unary together with expr, the conditional operator, the array construction operator { } and concatenation operator [ ], and the array range constructor which is either binary or ternary. Operators with the same precedence occur at the same line of the table:
Operator Group  Operator Syntax  Examples  

postfix array index operator  []  arr[index]  
postfix access operator  .  a.b  
postfix function call  $\colorbox[rgb]{1,1,1}{$\mathrm{funcName}$}$($\colorbox[rgb]{1,1,1}{$\mathrm{functionArguments}$}$)  sin(4.36)  
array construct/concat 



exponentiation  ^  2^3  
multiplicative and array elementwise multiplicative  * / .* ./ 


additive and array elementwise additive  +  +$\colorbox[rgb]{1,1,1}{$\mathrm{expr}$}$ $\colorbox[rgb]{1,1,1}{$\mathrm{expr}$}$ .+ .  [1,2;3,4].+[2,3;5,6]  
relational  < <= > >= == <>  a<b, a<=b, a>b, …  
unary negation  not $\colorbox[rgb]{1,1,1}{$\mathrm{expr}$}$  not b1  
logical and  and  b1 and b2  
logical or  or  b1 or b2  
array range 



conditional  if $\colorbox[rgb]{1,1,1}{$\mathrm{expr}$}$ then $\colorbox[rgb]{1,1,1}{$\mathrm{expr}$}$ else $\colorbox[rgb]{1,1,1}{$\mathrm{expr}$}$  if b then 3 else x  
named argument  $\colorbox[rgb]{1,1,1}{$\mathrm{ident}$}$ = $\colorbox[rgb]{1,1,1}{$\mathrm{expr}$}$  x = 2.26 
The conditional operator may also include elseifclauses. Equality = and assignment := are not expression operators since they are allowed only in equations and in assignment statements respectively. All binary expression operators are left associative, except exponentiation which is nonassociative. The array range operator is nonassociative.
[The unary minus and plus in Modelica is slightly different than in Mathematica and in MATLAB^{1}^{1} 1 MATLAB is a registered trademark of MathWorks Inc., since the following expressions are illegal (whereas in Mathematica^{2}^{2} 2 Mathematica is a registered trademark of Wolfram Research Inc. and in MATLAB these are valid expressions):
Nonassociative exponentiation and array range operator:
]
A tool is free to solve equations, reorder expressions and to not evaluate expressions if their values do not influence the result (e.g. shortcircuit evaluation of Boolean expressions). Ifstatements and ifexpressions guarantee that their clauses are only evaluated if the appropriate condition is true, but relational operators generating state or time events will during continuous integration have the value from the most recent event.
If a numeric operation overflows the result is undefined. For literals it is recommended to automatically convert the number to another type with greater precision.
[Example: If one wants to guard an expression against incorrect evaluation, it should be guarded by an if:
To guard square against square root of negative number use noEvent:
]
Modelica supports five binary arithmetic operators that operate on any numerical type:
^  Exponentiation 
*  Multiplication 
/  Division 
+  Addition 
  Subtraction 
Some of these operators can also be applied to a combination of a scalar type and an array type, see section 10.6.
The syntax of these operators is defined by the following rules from the Modelica grammar:
Modelica supports the standard set of relational and logical operators, all of which produce the standard boolean values true or false.
>  greater than 
>=  greater than or equal 
<  less than 
<=  less than or equal to 
==  equality within expressions 
<>  Inequality 
A single equals sign = is never used in relational expressions, only in equations (chapter 8, section 10.6.1) and in function calls using named parameter passing (section 12.4.1).
The following logical operators are defined:
not  negation, unary operator 
and  logical and 
or  logical or 
The grammar rules define the syntax of the relational and logical operators.
The following holds for relational operators:
Relational operators <, <=,>, >=, ==, <>, are only defined for scalar operands of simple types. The result is Boolean and is true or false if the relation is fulfilled or not, respectively.
For operands of type String, str1 op str2 is for each relational operator, op, defined in terms of the Cfunction strcmp as strcmp(str1,str2) op .
For operands of type Boolean, false < true.
For operands of enumeration types, the order is given by the order of declaration of the enumeration literals.
In relations of the form v1 == v2 or v1 <> v2, v1 or v2 shall, unless used in a function, not be a subtype of Real.
[The reason for this rule is that relations with Real arguments are transformed to state events (see Events, section 8.5) and this transformation becomes unnecessarily complicated for the == and <> relational operators (e.g. two crossing functions instead of one crossing function needed, epsilon strategy needed even at event instants). Furthermore, testing on equality of Real variables is questionable on machines where the number length in registers is different to number length in main memory.]
Relational operators can generate events, see section 3.8.3.
Modelica also contains a few builtin operators which are not standard arithmetic, relational, or logical operators. These are described below, including time, which is a builtin variable, not an operator.
Concatenation of strings (see the Modelica grammar) is denoted by the + operator in Modelica.
[Example: "a" + "b" becomes "ab".]
The array constructor operator { $\colorbox[rgb]{1,1,1}{$\mathrm{\dots}$}$ } is described in section 10.4.
The array concatenation operator [ $\colorbox[rgb]{1,1,1}{$\mathrm{\dots}$}$ ] is described in section 10.4.2.
The array range constructor operator : is described in section 10.4.3.
An expression
is one example of ifexpression. First expression1, which must be Boolean expression, is evaluated. If expression1 is true expression2 is evaluated and is the value of the ifexpression, else expression3 is evaluated and is the value of the ifexpression. The two expressions, expression2 and expression3, must be type compatible expressions (section 6.6) giving the type of the ifexpression. Ifexpressions with elseif are defined by replacing elseif by else if. For shortcircuit evaluation see section 3.3.
[elseif in expressions has been added to the Modelica language for symmetry with ifclauses.]
[Example:
]
It is possible to access members of a class instance using dot notation, i.e., the . operator.
[Example: R1.R for accessing the resistance component R of resistor R1. Another use of dot notation: local classes which are members of a class can of course also be accessed using dot notation on the name of the class, not on instances of the class.]
All declared variables are functions of the independent variable time. The variable time is a builtin variable available in all models and blocks, which is treated as an input variable. It is implicitly defined as:
The value of the start attribute of time is set to the time instant at which the simulation is started.
[Example:
]
Certain builtin operators of Modelica have the same syntax as a function call. However, they do not behave as a mathematical function, because the result depends not only on the input arguments but also on the status of the simulation.
There are also builtin functions that depend only on the input argument, but also may trigger events in addition to returning a value. Intrinsic means that they are defined at the Modelica language level, not in the Modelica library. The following builtin intrinsic operators/functions are available:
Mathematical functions and conversion functions, see section 3.7.1 below.
Derivative and special purpose operators with function syntax, see section 3.7.2 below.
Eventrelated operators with function syntax, see section 3.7.3 below.
Array operators/functions, see section 10.1.1.
Note that when the specification references a function having the name of a builtin function it references the builtin function, not a userdefined function having the same name, see also section 12.5. With exception of the builtin String operator, all operators in this section can only be called with positional arguments.
The following mathematical operators and functions, also including some conversion functions, are predefined in Modelica, and are vectorizable according to section 12.4.6, except for the String function. The functions which do not trigger events are described in the table below, whereas the eventtriggering mathematical functions are described in section 3.7.1.1.
abs(v)  Is expanded into noEvent(if v >= 0 then v else v). Argument v needs to be an Integer or Real expression.  
sign(v)  Is expanded into noEvent(if v>0 then 1 else if v<0 then 1 else 0). Argument v needs to be an Integer or Real expression.  
sqrt(v)  Returns the square root of v if v>=, otherwise an error occurs. Argument v needs to be an Integer or Real expression.  
Integer(e)  Returns the ordinal number of the expression e of enumeration type that evaluates to the enumeration value E.enumvalue, where Integer(E.e1)=1, Integer(E.en)=n, for an enumeration type E=enumeration(e1, ..., en). See also section 4.8.5.2.  
EnumTypeName(i)  For any enumeration type EnumTypeName, returns the enumeration value EnumTypeName.e such that Integer(EnumTypeName.e) = i. Refer to the definition of Integer above. It is an error to attempt to convert values of i that do not correspond to values of the enumeration type. See also section 4.8.5.3.  

Convert a scalar nonString expression to a String representation. The
first argument may be a Boolean b, an Integer i, a Real r or an
Enumeration e (section 4.8.5.2). The other arguments must use named
arguments. The optional <options> are:
Integer minimumLength=: minimum length of the resulting string. If
necessary, the blank character is used to fill up unused space.
Boolean leftJustified = true: if true, the converted result is left
justified in the string; if false it is right justified in the string.
For Real expressions the output shall be according to the Modelica
grammar. Integer significantDigits=6: defines the number of significant
digits in the result string.
[Examples of Real values formatted with 6 significant digits: 12.3456, 0.0123456, 12345600, 1.23456E10.]
The format string corresponding to options is:

The builtin operators in this section trigger events if used outside of a whenclause and outside of a clocked discretetime partition (see section 16.8.1). These expression for div, ceil, floor, and integer are event generating expression. The event generating expression for mod(x,y) is floor(x/y), and for rem(x,y) it is div(x,y) — i.e. events are not generated when mod or rem changes continuously in an interval, but when they change discontinuously from one interval to the next.
[If this is not desired, the noEvent function can be applied to them. E.g. noEvent(integer(v)).]
div(x,y)  Returns the algebraic quotient x/y with any fractional part discarded (also known as truncation toward zero). [This is defined for / in C99; in C89 the result for negative numbers is implementationdefined, so the standard function div must be used.] Result and arguments shall have type Real or Integer. If either of the arguments is Real the result is Real otherwise Integer. 
mod(x,y)  Returns the integer modulus of x/y, i.e. mod(x,y)=xfloor(x/y)*y. Result and arguments shall have type Real or Integer. If either of the arguments is Real the result is Real otherwise Integer. [Note, outside of a whenclause state events are triggered when the return value changes discontinuously. Examples: mod(3,1.4)=0.2, mod(3,1.4)=1.2, mod(3,1.4)=1.2.] 
rem(x,y)  Returns the integer remainder of x/y, such that div(x,y)*y + rem(x, y) = x. Result and arguments shall have type Real or Integer. If either of the arguments is Real the result is Real otherwise Integer. [Note, outside of a whenclause state events are triggered when the return value changes discontinuously. Examples: rem(3,1.4)=0.2, rem(3,1.4)=0.2] 
ceil(x)  Returns the smallest integer not less than x. Result and argument shall have type Real. [Note, outside of a whenclause state events are triggered when the return value changes discontinuously.] 
floor(x)  Returns the largest integer not greater than x. Result and argument shall have type Real. [Note, outside of a whenclause state events are triggered when the return value changes discontinuously.] 
integer(x)  Returns the largest integer not greater than x. The argument shall have type Real. The result has type Integer. [Note, outside of a whenclause state events are triggered when the return value changes discontinuously.] 
The following builtin mathematical functions are available in Modelica and can be called directly without any package prefix added to the function name. They are also available as external builtin functions in the Modelica.Math library.
sin(x)  sine 
cos(x)  cosine 
tan(x)  tangent ($x$ shall not be: …, $\pi $/2, $\pi $/2, 3$\pi $/2, …) 
asin(x)  inverse sine (1 $\le x\le $ 1) 
acos(x)  inverse cosine (1 $\le x\le $ 1) 
atan(x)  inverse tangent 
atan2(y, x)  the atan2(y, x) function calculates the principal value of the arc tangent of $y/x$, using the signs of the two arguments to determine the quadrant of the result 
sinh(x)  hyperbolic sine 
cosh(x)  hyperbolic cosine 
tanh(x)  hyperbolic tangent 
exp(x)  exponential, base $e$ 
log(x)  natural (base $e$) logarithm ($x>0$) 
log10(x)  base 10 logarithm ($x>0$) 
The following derivative operator and special purpose operators with function syntax are predefined. The special purpose operators with function syntax where the call below uses named arguments can be called with named arguments (with the specified names), or with positional arguments (the inputs of the functions are in the order given in the calls below).
der(expr)  The time derivative of expr. If the expression expr is a scalar it needs to be a subtype of Real. The expression and all its timevarying subexpressions must be continuous and semidifferentiable. If expr is an array, the operator is applied to all elements of the array. For nonscalar arguments the function is vectorized according to section 10.6.12. [For Real parameters and constants the result is a zero scalar or array of the same size as the variable.]  

Returns: expr(timedelayTime) for time>time.start + delayTime and expr(time.start) for time <= time.start + delayTime. The arguments, i.e., expr, delayTime and delayMax, need to be subtypes of Real. delayMax needs to be additionally a parameter expression. The following relation shall hold: 0 <= delayTime <= delayMax, otherwise an error occurs. If delayMax is not supplied in the argument list, delayTime needs to be a parameter expression. See also section 3.7.2.1. For nonscalar arguments the function is vectorized according to section 10.6.12.  
cardinality(c)  [This is a deprecated operator. It should no longer be used, since it will be removed in one of the next Modelica releases.] Returns the number of (inside and outside) occurrences of connector instance c in a connectequation as an Integer number. See also section 3.7.2.3.  
homotopy(actual=actual,  
simplified=simplified)  The scalar expressions actual and simplified are subtypes of
Real. A Modelica translator should map this operator into either of the two forms:



Returns: smooth(0, if x>=0 then positiveSlope*x else negativeSlope*x). The result is of type Real. See section 3.7.2.5 (especially in the case when $x=0$). For nonscalar arguments the function is vectorized according to section 10.6.12.  
inStream(v)  inStream(v) is only allowed for stream variables v defined in stream connectors, and is the value of the stream variable v close to the connection point assuming that the flow is from the connection point into the component. This value is computed from the stream connection equations of the flow variables and of the stream variables. The operator is vectorizable. For more details see section 15.2.  
actualStream(v)  actualStream(v) returns the actual value of the stream variable v for any flow direction. The operator is vectorizable. For more details, see section 15.3.  

spatialDistribution allows approximation of variablespeed transport of properties, see section 3.7.2.2.  
getInstanceName()  Returns a string with the name of the model/block that is simulated, appended with the fully qualified name of the instance in which this function is called, see section 3.7.2.6. 
A few of these operators are described in more detail in the following.
[delay allows a numerical sound implementation by interpolating in the (internal) integrator polynomials, as well as a more simple realization by interpolating linearly in a buffer containing past values of expression expr. Without further information, the complete time history of the delayed signals needs to be stored, because the delay time may change during simulation. To avoid excessive storage requirements and to enhance efficiency, the maximum allowed delay time has to be given via delayMax.
This gives an upper bound on the values of the delayed signals which have to be stored. For realtime simulation where fixed step size integrators are used, this information is sufficient to allocate the necessary storage for the internal buffer before the simulation starts. For variable step size integrators, the buffer size is dynamic during integration. In principle, delay could break algebraic loops. For simplicity, this is not supported because the minimum delay time has to be give as additional argument to be fixed at compile time. Furthermore, the maximum step size of the integrator is limited by this minimum delay time in order to avoid extrapolation in the delay buffer.]
[Many applications involve the modelling of variablespeed transport of properties. One option to model this infinitedimensional system is to approximate it by an ODE, but this requires a large number of state variables and might introduce either numerical diffusion or numerical oscillations. Another option is to use a builtin operator that keeps track of the spatial distribution of $z\mathit{}\mathrm{(}x\mathrm{,}t\mathrm{)}$, by suitable sampling, interpolation, and shifting of the stored distribution. In this case, the internal state of the operator is hidden from the ODE solver.]
spatialDistribution allows to approximate efficiently the solution of the infinitedimensional problem
$\frac{\partial z(y,t)}{\partial t}}+v(t){\displaystyle \frac{\partial z(y,t)}{\partial y}$  $=0.0$  
$z(0.0,t)$  $={\mathrm{in}}_{0}(t)\text{if}v\ge 0$  
$z(1.0,t)$  $$ 
where $z(y,t)$ is the transported quantity, $y$ is the normalized spatial coordinate ($0.0\le y\le 1.0$), $t$ is the time, $v(t)=\mathrm{der}(x)$ is the normalized transport velocity and the boundary conditions are set at either $y=0.0$ or $y=1.0$, depending on the sign of the velocity. The calling syntax is:
where in0, in1, out0, out1, x, v are all subtypes of Real, positiveVelocity is a Boolean, initialPoints and initialValues are arrays of subtypes of Real of equal size, containing the y coordinates and the $z$ values of a finite set of points describing the initial distribution of $z(y,\mathit{t0})$. The out0 and out1 are given by the solutions at $z(0.0,t)$ and $z(1.0,t)$; and in0 and in1 are the boundary conditions at $z(0.0,t)$ and $z(1.0,t)$ (at each point in time only one of in0 and in1 is used). Elements in the initialPoints array must be sorted in nondescending order. The operator can not be vectorized according to the vectorization rules described in section 12.4.6. The operator can be vectorized only with respect to the arguments in0 and in1 (which must have the same size), returning vectorized outputs out0 and out1 of the same size; the arguments initialPoints and initialValues are vectorized accordingly.
The solution, $z$, can be described in terms of characteristics:
$$z(y+{\int}_{t}^{t+\beta}v(\alpha )d\alpha ,t+\beta )=z(y,t),\text{for all}\beta \text{as long as staying inside the domain}$$ 
This allows to directly compute the solution based on interpolating the boundary conditions.
spatialDistribution can be described in terms of the pseudocode given as a block:
[Note that the implementation has an internal state and thus cannot be described as a function in Modelica; initialPoints and initialValues are declared as parameters to indicate that they are only used during initialization.
The infinitedimensional problem stated above can then be formulated in the following way:
Events are generated at the exact instants when the velocity changes sign — if this is not needed, noEvent can be used to suppress event generation.
If the velocity is known to be always positive, then out0 can be omitted, e.g.:
Technically relevant use cases for the use of spatialDistribution are modeling of electrical transmission lines, pipelines and pipeline networks for gas, water and district heating, sprinkler systems, impulse propagation in elongated bodies, conveyor belts, and hydraulic systems. Vectorization is needed for pipelines where more than one quantity is transported with velocity v in the example above.]
[cardinality is deprecated for the following reasons and will be removed in a future release:
Reflective operator may make early type checking more difficult.
Almost always abused in strange ways
Not used for Bond graphs even though it was originally introduced for that purpose.
]
[cardinality allows the definition of connection dependent equations in a model, for example:
]
The cardinality is counted after removing conditional components, and may not be applied to expandable connectors, elements in expandable connectors, or to arrays of connectors (but can be applied to the scalar elements of array of connectors). cardinality should only be used in the condition of assert and ifstatements – that do not contain connect (and similar operators – see section 16.8.1).
[During the initialization phase of a dynamic simulation problem, it often happens that large nonlinear systems of equations must be solved by means of an iterative solver. The convergence of such solvers critically depends on the choice of initial guesses for the unknown variables. The process can be made more robust by providing an alternative, simplified version of the model, such that convergence is possible even without accurate initial guess values, and then by continuously transforming the simplified model into the actual model. This transformation can be formulated using expressions of this kind:
$$\lambda \cdot \text{\mathit{a}\mathit{c}\mathit{t}\mathit{u}\mathit{a}\mathit{l}}+(1\lambda )\cdot \text{\mathit{s}\mathit{i}\mathit{m}\mathit{p}\mathit{l}\mathit{i}\mathit{f}\mathit{i}\mathit{e}\mathit{d}}$$ 
in the formulation of the system equations, and is usually called a homotopy transformation. If the simplified expression is chosen carefully, the solution of the problem changes continuously with $\lambda $, so by taking small enough steps it is possible to eventually obtain the solution of the actual problem.
The operator can be called with ordered arguments or preferably with named arguments for improved readability.
It is recommended to perform (conceptually) one homotopy iteration over the whole model, and not several homotopy iterations over the respective nonlinear algebraic equation systems. The reason is that the following structure can be present:
Here, a nonlinear equation system ${f}_{\mathrm{2}}$ is present. homotopy is, however used on a variable that is an “input” to the nonlinear algebraic equation system, and modifies the characteristics of the nonlinear algebraic equation system. The only useful way is to perform the homotopy iteration over ${f}_{\mathrm{1}}$ and ${f}_{\mathrm{2}}$ together.
The suggested approach is “conceptual”, because more efficient implementations are possible, e.g. by determining the smallest iteration loop, that contains the equations of the first BLT block in which homotopy is present and all equations up to the last BLT block that describes a nonlinear algebraic equation system.
A trivial implementation of homotopy is obtained by defining the following function in the global scope:
]
[Example 1: In electrical systems it is often difficult to solve nonlinear algebraic equations if switches are part of the algebraic loop. An idealized diode model might be implemented in the following way, by starting with a “flat” diode characteristic and then move with homotopy to the desired “steep” characteristic:
]
[Example 2: In electrical systems it is often useful that all voltage sources start with zero voltage and all current sources with zero current, since steady state initialization with zero sources can be easily obtained. A typical voltage source would then be defined as:
]
[Example 3: In fluid system modelling, the pressure/flowrate relationships are highly nonlinear due to the quadratic terms and due to the dependency on fluid properties. A simplified linear model, tuned on the nominal operating point, can be used to make the overall model less nonlinear and thus easier to solve without accurate start values. Named arguments are used here in order to further improve the readability.
]
[Example 4: Note that homotopy shall not be used to combine unrelated expressions, since this can generate singular systems from combining two welldefined systems.
The initial equation is expanded into
$$0=\lambda *\mathrm{der}(x)+(1\lambda )(x{x}_{0})$$ 
and you can solve the two equations to give
$$x=\frac{\lambda +(\lambda 1){x}_{0}}{2\lambda 1}$$ 
which has the correct value of ${x}_{\mathrm{0}}$ at $\lambda \mathrm{=}\mathrm{0}$ and of 1 at $\lambda \mathrm{=}\mathrm{1}$, but unfortunately has a singularity at $\lambda \mathrm{=}\mathrm{0.5}$.]
(See definition of semiLinear in section 3.7.2). In some situations, equations with semiLinear become underdetermined if the first argument (x) becomes zero, i.e., there are an infinite number of solutions. It is recommended that the following rules are used to transform the equations during the translation phase in order to select one meaningful solution in such cases:
The equations
may be replaced by
[For symbolic transformations, the following property is useful (this follows from the definition):
is identical to:
The semiLinear function is designed to handle reversing flow in fluid systems, such as
i.e., the enthalpy flow rate H_flow is computed from the mass flow rate m_flow and the upstream specific enthalpy depending on the flow direction.]
Returns a string with the name of the model/block that is simulated, appended with the fully qualified name of the instance in which this function is called.
[Example:
If MyLib.Vehicle is simulated, the call of getInstanceName() returns "Vehicle.engine.controller".]
If this function is not called inside a model or block (e.g. the function is called in a function or in a constant of a package), the return value is not specified.
[The simulation result should not depend on the return value of this function.]
The following eventrelated operators with function syntax are supported. The operators noEvent, pre, edge, and change, are vectorizable according to section 12.4.6
initial()  Returns true during the initialization phase and false otherwise. [Hereby, initial() triggers a time event at the beginning of a simulation.] 
terminal()  Returns true at the end of a successful analysis. [Hereby, terminal() ensures an event at the end of successful simulation.] 
noEvent(expr)  Real elementary relations within expr are taken literally, i.e., no state or time event is triggered. See also section 3.7.3.2 and section 8.5. 
smooth(p, expr)  If $p\ge 0$ smooth(p,expr) returns expr and states that expr is p times continuously differentiable, i.e.: expr is continuous in all real variables appearing in the expression and all partial derivatives with respect to all appearing real variables exist and are continuous up to order p. The argument p should be a scalar integer parameter expression. The only allowed types for expr in smooth are: real expressions, arrays of allowed expressions, and records containing only components of allowed expressions. See also section 3.7.3.2. 
sample(start, interval)  Returns true and triggers time events at time instants start + i*interval (i=0,1,...), and is only true during the first event iteration at those times. At event iterations after the first one at each event and during continuous integration the operator always returns false. The starting time start and the sample interval interval must be parameter expressions and need to be a subtype of Real or Integer. The sample interval interval must be a positive number. 
pre(y)  Returns the left limit $y({t}^{})$ of variable $y(t)$ at a time instant $t$. At an event instant, $y({t}^{})$ is the value of $y$ after the last event iteration at time instant $t$ (see comment below). Any subscripts in the component expression $y$ must be parameter expressions. pre can be applied if the following three conditions are fulfilled simultaneously: (a) variable $y$ is either a subtype of a simple type or is a record component, (b) $y$ is a discretetime expression (c) the operator is not applied in a function class. [This can be applied to continuoustime variables in whenclauses, see section 3.8.3 for the definition of discretetime expression.] The first value of pre(y) is determined in the initialization phase. See also section 3.7.3.1. 
edge(b)  Is expanded into (b and not pre(b)) for Boolean variable b. The same restrictions as for pre apply (e.g. not to be used in function classes). 
change(v)  Is expanded into (v<>pre(v)). The same restrictions as for pre apply. 
reinit(x, expr)  In the body of a when clause, reinitializes x with expr at an event instant. x is a scalar or array Real variable that is implicitly defined to have StateSelect.always. [It is an error if the variable cannot be selected as a state.] expr needs to be typecompatible with x. reinit can only be applied once for the same variable — either as an individual variable or as part of an array of variables. It can only be applied in the body of a when clause in an equation section. See also section 8.3.6. 
A few of these operators are described in more detail in the following.
A new event is triggered if there is at least for one variable v such that pre(v)<> v after the active model equations are evaluated at an event instant. In this case the model is at once reevaluated. This evaluation sequence is called event iteration. The integration is restarted, if for all v used in preoperators the following condition holds: pre(v) == v.
[If v and pre(v) are only used in whenclauses, the translator might mask event iteration for variable v since v cannot change during event iteration. It is a quality of implementation to find the minimal loops for event iteration, i.e., not all parts of the model need to be reevaluated.
The language allows mixed algebraic systems of equations where the unknown variables are of type Real, Integer, Boolean, or an enumeration. These systems of equations can be solved by a global fix point iteration scheme, similarly to the event iteration, by fixing the Boolean, Integer, and/or enumeration unknowns during one iteration. Again, it is a quality of implementation to solve these systems more efficiently, e.g., by applying the fix point iteration scheme to a subset of the model equations.]
noEvent implies that real elementary relations/functions are taken literally instead of generating crossing functions, section 8.5. smooth should be used instead of noEvent, in order to avoid events for efficiency reasons. A tool is free to not generate events for expressions inside smooth. However, smooth does not guarantee that no events will be generated, and thus it can be necessary to use noEvent inside smooth.
[Note that smooth does not guarantee a smooth output if any of the occurring variables change discontinuously.]
[Example:
]
The concept of variability of an expression indicates to what extent the expression can vary over time. See also section 4.4.4 regarding the concept of variability. There are four levels of variability of expressions, starting from the least variable:
constant variability
parameter variability
discretetime variability
continuoustime variability
While many invalid models can be rejected based on the declared variabilities of variables alone (without the concept of expression variability), the following rules both help enforcing compliance of computed solutions to declared variability, and impose additional restrictions that simplify reasoning and reporting of errors:
For an assignment v:=expr or binding equation v=expr, v must be declared to be at least as variable as expr.
When determining whether an equation can contribute to solving for a variable v (for instance, when applying the perfect matching rule, see section 8.4), the equation can only be considered contributing if the resulting solution would be at most as variable as v.
The righthand side expression in a binding equation (that is, expr) of a parameter component and of the base type attributes (such as start) needs to be a parameter or constant expression.
If v is a discretetime component then expr needs to be a discretetime expression.
Constant expressions are:
Real, Integer, Boolean, String, and enumeration literals.
Variables declared as constant.
Except for the special builtin operators initial, terminal, der, edge, change, sample, and pre, a function or operator with constant subexpressions as argument (and no parameters defined in the function) is a constant expression.
Some function calls are constant expressions regardless of the arguments:
ndims(A)
Components declared as constant shall have an associated declaration equation with a constant expression, if the constant is directly in the simulation model, or used in the simulation model. The value of a constant can be modified after it has been given a value, unless the constant is declared final or modified with a final modifier. A constant without an associated declaration equation can be given one by using a modifier.
Parameter expressions are:
Constant expressions.
Variables declared as parameter.
Input variables in functions behave as though they were parameter expressions.
Except for the special builtin operators initial, terminal, der, edge, change, sample, and pre, a function or operator with parameter subexpressions is a parameter expression.
Some function calls are parameter expressions even if the arguments are not:
cardinality(c), see restrictions for use in section 3.7.2.3.
end in A[$\colorbox[rgb]{1,1,1}{$\mathrm{\dots}$}$ end $\colorbox[rgb]{1,1,1}{$\mathrm{\dots}$}$] if A is variable declared in a nonfunction class.
size(A) (including size(A, j) where j is parameter expression) if A is variable declared in a nonfunction class.
Connections.isRoot(A.R)
Connections.rooted(A.R)
Discretetime expressions are:
Parameter expressions.
Discretetime variables, i.e., Integer, Boolean, String variables and enumeration variables, as well as Real variables assigned in whenclauses
Function calls where all input arguments of the function are discretetime expressions.
Expressions where all the subexpressions are discretetime expressions.
Expressions in the body of a whenclause, initial equation, or initial algorithm.
Unless inside noEvent: Ordered relations (>,<,>=,<=)and the event generating functions ceil, floor, div, and integer, if at least one argument is nondiscrete time expression and subtype of Real.
[These will generate events, see section 8.5. Note that rem and mod generate events but are not discretetime expressions. In other words, relations inside noEvent, such as noEvent(x>1), are not discretetime expressions.]
The functions pre, edge, and change result in discretetime expressions.
Expressions in functions behave as though they were discretetime expressions.
For an equation expr1 = expr2 where neither expression is of base type Real, both expressions must be discretetime expressions. For record equations the equation is split into basic types before applying this test.
[This restriction guarantees that noEvent cannot be applied to Boolean, Integer, String, or enumeration equations outside of a whenclause, because then one of the two expressions is not discretetime.]
Inside an ifexpression, ifclause, whilestatement or forclause, that is controlled by a nondiscretetime (that is continuoustime, but not discretetime) switching expression and not in the body of a whenclause, it is not legal to have assignments to discrete variables, equations between discretetime expressions, or real elementary relations/functions that should generate events.
[The restriction above is necessary in order to guarantee that all equations for discrete variable are discretetime expressions, and to ensure that crossing functions do not become active between events.]
[Example: The (underdetermined) model Test below illustrates two kinds of consequences due to variability constraints. First, it contains variability errors for declaration equations and assignments. Second, it illustrates the impact of variability on the matching of equations to variables, which can lead to violation of the perfect matching rule.
]
All expressions are continuoustime expressions including constant, parameter and discrete expressions. The term nondiscretetime expression refers to expressions that are not constant, parameter or discrete expressions.