From 574ae9a7c54b602e78ba5e9c80affc389ba944d5 Mon Sep 17 00:00:00 2001 From: HOS Date: Wed, 6 May 2026 15:27:12 +0200 Subject: [PATCH 01/21] Try to clean up clause-meaning. Closes #3840 --- chapters/classes.tex | 5 +++-- chapters/equations.tex | 26 +++++++++++++------------- chapters/operatorsandexpressions.tex | 18 +++++++++--------- chapters/statements.tex | 9 ++++----- 4 files changed, 29 insertions(+), 29 deletions(-) diff --git a/chapters/classes.tex b/chapters/classes.tex index f7a9a2cf5..dbb889bd3 100644 --- a/chapters/classes.tex +++ b/chapters/classes.tex @@ -425,8 +425,9 @@ \section{Component Variability}\label{component-variability} For \lstinline!Real! variables we can distinguish two subtly different categories: discrete-time and piecewise constant, where the discrete-time variables are a subset of all piecewise constant variables. The \lstinline!Real! variables declared with the prefix \lstinline!discrete! is a subset of the discrete-time \lstinline!Real! variables. -For a \lstinline!Real! variable, being discrete-time is equivalent to being assigned in a \lstinline!when!-clause. -A variable used as argument to \lstinline!pre! outside a \lstinline!when!-clause must be discrete-time. +For a \lstinline!Real! variable, being discrete-time is equivalent to being assigned in (the body of) a \lstinline!when!-clause. +% The (the body of) is redundant (as assignments cannot be placed anywhere else in when-clauses). Might reformulate +A variable used as argument to \lstinline!pre! outside the body of any \lstinline!when!-clause must be discrete-time. \begin{lstlisting}[language=modelica] model PiecewiseConstantReals diff --git a/chapters/equations.tex b/chapters/equations.tex index 4d02023cc..85e649632 100644 --- a/chapters/equations.tex +++ b/chapters/equations.tex @@ -127,10 +127,10 @@ \subsection{Connect-Equations}\label{connect-equations} \subsection{If-Equations}\label{if-equations} The syntax of an \lstinline!if!-equations\index{if@\robustinline{if}!equation}\index{then@\robustinline{then}!if-equation@\robustinline{if}-equation}\index{else@\robustinline{else}!if-equation@\robustinline{if}-equation}\index{elseif@\robustinline{elseif}!if-equation@\robustinline{if}-equation} is given by \productionref{if-equation} in the grammar. -Here, each \productionref{expression} in the grammar (representing the condition of an \lstinline!if!- or \lstinline!elseif!-clause) must be a scalar \lstinline!Boolean! expression. -One \lstinline!if!-clause, and zero or more \lstinline!elseif!-clauses, and an optional \lstinline!else!-clause together form a list of branches. -One or zero of the bodies of these \lstinline!if!-, \lstinline!elseif!- and \lstinline!else!-clauses is selected, by evaluating the conditions of the \lstinline!if!- and \lstinline!elseif!-clauses sequentially until a condition that evaluates to true is found. -If none of the conditions evaluate to true the body of the \lstinline!else!-clause is selected (if an \lstinline!else!-clause exists, otherwise no body is selected). +Here, each \productionref{expression} in the grammar (representing the condition of any branch of an \lstinline!if!-clause) must be a scalar \lstinline!Boolean! expression. +An \lstinline!if!-clause is seen as a list of branches: one \lstinline!if!-branch, and zero or more \lstinline!elseif!-branches, and an optional \lstinline!else!-branch. +One or zero of the bodies of these branches is selected, by evaluating their conditions sequentially until a condition that evaluates to true is found. +If none of the conditions evaluate to true the body of the \lstinline!else!-branch is selected if it exists, otherwise no body is selected. In an equation section, the equations in the body are seen as equations that must be satisfied. The bodies that are not selected have no effect on that model evaluation. @@ -196,7 +196,7 @@ \subsubsection{Defining When-Equations by If-Expressions in Equality Equations}\ \end{lstlisting} \begin{nonnormative} -The equivalence is conceptual since \lstinline!pre($\ldots$)! of a non discrete-time \lstinline!Real! variable or expression can only be used within a \lstinline!when!-clause. +The equivalence is conceptual since \lstinline!pre($\ldots$)! of a non discrete-time \lstinline!Real! variable or expression can only be used within the body of a \lstinline!when!-clause. Example: \begin{lstlisting}[language=modelica] /* discrete */ Real x; @@ -211,7 +211,7 @@ \subsubsection{Defining When-Equations by If-Expressions in Equality Equations}\ Here, \lstinline!x! is a discrete-time variable (whether it is declared with the \lstinline!discrete! prefix or not), but \lstinline!u! and \lstinline!y! cannot be discrete-time variables (since they are not assigned in \lstinline!when!-clauses). -However, \lstinline!pre(u)! is legal within the \lstinline!when!-clause, since the body of the \lstinline!when!-clause is only evaluated at events, and thus all expressions are discrete-time expressions. +However, \lstinline!pre(u)! is legal within the body of the \lstinline!when!-clause, since the body is only evaluated at events, and thus all expressions are discrete-time expressions. \end{nonnormative} The start values of the introduced \lstinline!Boolean! variables are defined by the taking the start value of the when-condition, as above where \lstinline!b! is a parameter variable. @@ -409,15 +409,15 @@ \subsection{reinit}\label{reinit} The operator reinitializes \lstinline!x! with \lstinline!expr! at an event instant. \lstinline!x! is a component-reference (where any subscripts are evaluable) referring to a \lstinline!Real! variable (or an array of \lstinline!Real! variables) that must be selected as a state (resp., states), i.e., \lstinline!reinit! on \lstinline!x! implies \lstinline!stateSelect = StateSelect.always! on \lstinline!x!. \lstinline!expr! needs to be type-compatible with \lstinline!x!. -For any given variable (possibly an array variable), \lstinline!reinit! can only be applied (either to an individual variable or to a part of an array variable) in one \lstinline!when!-equation (applying \lstinline!reinit! to a variable in several \lstinline!when!- or \lstinline!elsewhen!-clauses of the same \lstinline!when!-equation is allowed). -If there are multiple \lstinline!reinit! for a variable inside the same \lstinline!when!- or \lstinline!elsewhen!-clause, they must appear in different branches of an \lstinline!if!-equation (in order that at most one \lstinline!reinit! for the variable is active at any event). +For any given variable (possibly an array variable), \lstinline!reinit! can only be applied (either to an individual variable or to a part of an array variable) in one \lstinline!when!-clause (applying \lstinline!reinit! to a variable in several \lstinline!when!- or \lstinline!elsewhen!-branches of the same \lstinline!when!-equation is allowed). +If there are multiple \lstinline!reinit! for a variable inside one body of a \lstinline!when!-clause, they must appear in different branches of an \lstinline!if!-equation (in order that at most one \lstinline!reinit! for the variable is active at any event). In case of \lstinline!reinit! active during initialization (due to \lstinline!when initial()!), see \cref{initialization-initial-equation-and-initial-algorithm}. \lstinline!reinit! does not break the single assignment rule, because \lstinline!reinit(x, expr)! in equations evaluates \lstinline!expr! to a value, then at the end of the current event iteration step it assigns this value to \lstinline!x! (this copying from values to reinitialized state(s) is done after all other evaluations of the model and before copying \lstinline!x! to \lstinline!pre(x)!). \begin{example} If a higher index system is present, i.e., constraints between state variables, some state variables need to be redefined to non-state variables. -During simulation, non-state variables should be chosen in such a way that variables with an applied \lstinline!reinit! are selected as states at least when the corresponding \lstinline!when!-clauses become active. +During simulation, non-state variables should be chosen in such a way that variables with an applied \lstinline!reinit! are selected as states at least when the corresponding bodies of the \lstinline!when!-clauses become active. If this is not possible, an error occurs, since otherwise \lstinline!reinit! would be applied to a non-state variable. Example for the usage of \lstinline!reinit! (bouncing ball): @@ -643,7 +643,7 @@ \section{Events and Synchronization}\label{events-and-synchronization} Clocked discrete-time partitions are also treated this way, see \cref{clocked-discrete-time-and-clocked-discretized-continuous-time-partition}. \begin{nonnormative} -Using state events in \lstinline!when!-clauses is unnecessary because the body of a \lstinline!when!-clause is not evaluated during continuous integration. +Using state events in the body of a \lstinline!when!-clause is unnecessary because the body of a \lstinline!when!-clause is not evaluated during continuous integration. \end{nonnormative} \begin{example} @@ -715,7 +715,7 @@ \section{Events and Synchronization}\label{events-and-synchronization} end when; \end{lstlisting} -The \lstinline!slowSample! \lstinline!when!-clause is evaluated at every 5th occurrence of the \lstinline!fastSample! \lstinline!when!-clause. +The body of the \lstinline!slowSample! \lstinline!when!-clause is evaluated at every 5th occurrence of the evaluating the body of the \lstinline!fastSample! \lstinline!when!-clause. \end{nonnormative} \begin{nonnormative} @@ -744,7 +744,7 @@ \section{Initialization, initial equation, and initial algorithm}\label{initiali The algorithmic statements within a \lstinline!when!-statement are active during initialization, if and only if they are explicitly enabled with \lstinline!initial()!, and only in one of the two forms \lstinline!when initial() then! or \lstinline!when {$\ldots$, initial(), $\ldots$} then!. In this case, the algorithmic statements within the \lstinline!when!-statement remain active during the whole initialization phase. -An active \lstinline!when!-clause inactivates the following \lstinline!elsewhen! (similarly to \lstinline!when!-clauses during simulation), but apart from that the first \lstinline!elsewhen initial() then! or \lstinline!elsewhen {$\ldots$, initial(), $\ldots$} then! is similarly active during initialization as \lstinline!when initial() then! or \lstinline!when {$\ldots$, initial(), $\ldots$} then!. +An active condition of a branch of a \lstinline!when!-clause inactivates the following \lstinline!elsewhen! (similarly to \lstinline!when!-clauses during simulation), but apart from that the first \lstinline!elsewhen initial() then! or \lstinline!elsewhen {$\ldots$, initial(), $\ldots$} then! is similarly active during initialization as \lstinline!when initial() then! or \lstinline!when {$\ldots$, initial(), $\ldots$} then!. \begin{nonnormative} That means that any subsequent \lstinline!elsewhen initial()! has no effect, similarly to \lstinline!when false then!. @@ -946,7 +946,7 @@ \section{Initialization, initial equation, and initial algorithm}\label{initiali \end{lstlisting} After solving the initialization problem, both \lstinline!b! and \lstinline!pre(b)! are false. During transient analysis, \lstinline!initial()! is false, so \lstinline!b! changes from falso to true during the first round of the initial event iteration. -This triggers the \lstinline!when!-clause, and \lstinline!x! gets reinitialized. +This triggers the body of the \lstinline!when!-clause, and \lstinline!x! gets reinitialized. \end{example} diff --git a/chapters/operatorsandexpressions.tex b/chapters/operatorsandexpressions.tex index 5c678b066..6ef313821 100644 --- a/chapters/operatorsandexpressions.tex +++ b/chapters/operatorsandexpressions.tex @@ -621,7 +621,7 @@ \subsection{Event-Triggering Mathematical Functions}\label{event-triggering-math Result and arguments shall have type \lstinline!Real! or \lstinline!Integer!. If either of the arguments is \lstinline!Real! the result is \lstinline!Real! otherwise \lstinline!Integer!. \begin{nonnormative} -Note, outside of a \lstinline!when!-clause state events are triggered when the return value changes discontinuously. +Note, outside of a body of a \lstinline!when!-clause state events are triggered when the return value changes discontinuously. Examples: \lstinline!mod(3, 1.4) = 0.2!, \lstinline!mod(-3, 1.4) = 1.2!, \lstinline!mod(3, -1.4) = -1.2!. \end{nonnormative} \end{semantics} @@ -636,7 +636,7 @@ \subsection{Event-Triggering Mathematical Functions}\label{event-triggering-math Result and arguments shall have type \lstinline!Real! or \lstinline!Integer!. If either of the arguments is \lstinline!Real! the result is \lstinline!Real! otherwise \lstinline!Integer!. \begin{nonnormative} -Note, outside of a \lstinline!when!-clause state events are triggered when the return value changes discontinuously. +Note, outside of a body of a \lstinline!when!-clause state events are triggered when the return value changes discontinuously. Examples: \lstinline!rem(3, 1.4) = 0.2!, \lstinline!rem(-3, 1.4) = -0.2!. \end{nonnormative} \end{semantics} @@ -650,7 +650,7 @@ \subsection{Event-Triggering Mathematical Functions}\label{event-triggering-math Smallest integer not less than $x$. Result and argument shall have type \lstinline!Real!. \begin{nonnormative} -Note, outside of a \lstinline!when!-clause state events are triggered when the return value changes discontinuously. +Note, outside of a body of a \lstinline!when!-clause state events are triggered when the return value changes discontinuously. \end{nonnormative} \end{semantics} \end{operatordefinition} @@ -663,7 +663,7 @@ \subsection{Event-Triggering Mathematical Functions}\label{event-triggering-math Largest integer not greater than $x$. Result and argument shall have type \lstinline!Real!. \begin{nonnormative} -Note, outside of a \lstinline!when!-clause state events are triggered when the return value changes discontinuously. +Note, outside of a body of a \lstinline!when!-clause state events are triggered when the return value changes discontinuously. \end{nonnormative} \end{semantics} \end{operatordefinition} @@ -677,7 +677,7 @@ \subsection{Event-Triggering Mathematical Functions}\label{event-triggering-math The argument shall have type \lstinline!Real!. The result has type \lstinline!Integer!. \begin{nonnormative} -Note, outside of a \lstinline!when!-clause state events are triggered when the return value changes discontinuously. +Note, outside of a body of a \lstinline!when!-clause state events are triggered when the return value changes discontinuously. \end{nonnormative} \end{semantics} \end{operatordefinition} @@ -1463,7 +1463,7 @@ \subsection{Event-Related Operators with Function Syntax}\label{event-related-op The operator is not allowed inside \lstinline!function! classes. \lstinline!pre! can be applied to the variable $y$ only if $y$ is a discrete-time expression and $y$ is either a subtype of a simple type or is a record component. \begin{nonnormative} -This can be applied to continuous-time variables in \lstinline!when!-clauses, see \cref{discrete-time-expressions} for the definition of discrete-time expression. +This can be applied to continuous-time variables in the bodies of \lstinline!when!-clauses, see \cref{discrete-time-expressions} for the definition of discrete-time expression. \end{nonnormative} The first value of \lstinline!pre($y$)! is determined in the initialization phase. @@ -1473,10 +1473,10 @@ \subsection{Event-Related Operators with Function Syntax}\label{event-related-op When no more round of model equation evaluation is triggered, the processing of the event is completed and the transient analysis may proceed forward in time. For purposes of event iteration, each scalar expression in a \lstinline!when!-clause condition is treated as an implicit variable \lstinline!v!. -Since the \lstinline!when!-clause is triggered when \lstinline!v and not pre(v)!, the implicit variable is considered wrapped in \lstinline!pre($\ldots$)! and becomes part of the event iteration convergence criterion. +Since the body of a \lstinline!when!-clause is triggered when \lstinline!v and not pre(v)!, the implicit variable is considered wrapped in \lstinline!pre($\ldots$)! and becomes part of the event iteration convergence criterion. \begin{nonnormative} -If \lstinline!v! and \lstinline!pre(v)! are only used in \lstinline!when!-clauses, the translator might mask event iteration for variable \lstinline!v! since \lstinline!v! cannot change during event iteration. +If \lstinline!v! and \lstinline!pre(v)! are only used in bodies of \lstinline!when!-clauses, the translator might mask event iteration for variable \lstinline!v! since \lstinline!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. A consequence of the implicit \lstinline!when!-clause condition variables is that every time a \lstinline!when!-clause is triggered, there is a variable with \lstinline!v <> pre(v)!, meaning that another round of the iteration is triggered. @@ -1712,7 +1712,7 @@ \subsection{Discrete-Time Expressions}\label{discrete-time-expressions} Expressions in functions not having annotation \lstinline!GenerateEvents = true! (\cref{modelica:GenerateEvents}), behave as though they were discrete-time expressions. \end{itemize} -Inside an \lstinline!if!-expression, \lstinline!if!-clause, \lstinline!while!-statement or \lstinline!for!-clause, that is controlled by a non-discrete-time (that is continuous-time, but not discrete-time) switching expression and not in the body of a \lstinline!when!-clause, it is not legal to have assignments to discrete-time variables, equations between discrete-time expressions, or real elementary relations/functions that should generate events. +Inside an \lstinline!if!-expression; or in the body of an \lstinline!if!-clause, a \lstinline!while!-statement, or a \lstinline!for!-clause, that is controlled by a non-discrete-time (that is continuous-time, but not discrete-time) switching expression and not in the body of a \lstinline!when!-clause, it is not legal to have assignments to discrete-time variables, equations between discrete-time expressions, or real elementary relations/functions that should generate events. \begin{nonnormative} The restriction above is necessary in order to guarantee that all equations for discrete-time variable are discrete-time expressions, and to ensure that crossing functions do not become active between events. diff --git a/chapters/statements.tex b/chapters/statements.tex index e5f1b4630..ac26434db 100644 --- a/chapters/statements.tex +++ b/chapters/statements.tex @@ -319,14 +319,13 @@ \subsection{Return-Statements}\label{return-statements} \subsection{If-Statement}\label{if-statement} The syntax of an \lstinline!if!-statements\index{if@\robustinline{if}!statement}\index{then@\robustinline{then}!if-statement@\robustinline{if}-statement}\index{else@\robustinline{else}!if-statement@\robustinline{if}-statement}\index{elseif@\robustinline{elseif}!if-statement@\robustinline{if}-statement} is given by \productionref{if-statement} in the grammar. -Here, each \productionref{expression} in the grammar (representing the condition of an \lstinline!if!- or \lstinline!elseif!-clause) must be a scalar \lstinline!Boolean! expression. -One \lstinline!if!-clause, and zero or more \lstinline!elseif!-clauses, and an optional \lstinline!else!-clause together form a list of branches. -One or zero of the bodies of these \lstinline!if!-, \lstinline!elseif!- and \lstinline!else!-clauses is selected, by evaluating the conditions of the \lstinline!if!- and \lstinline!elseif!-clauses sequentially until a condition that evaluates to true is found. -If none of the conditions evaluate to true the body of the \lstinline!else!-clause is selected (if an \lstinline!else!-clause exists, otherwise no body is selected). +Here, each \productionref{expression} in the grammar (representing any condition of an \lstinline!if!-clause) must be a scalar \lstinline!Boolean! expression. +An \lstinline!if!-clause is seen as a list of branches: one \lstinline!if!-branch, and zero or more \lstinline!elseif!-branches, and an optional \lstinline!else!-branch. +One or zero of the bodies of these branches is selected, by evaluating their conditions sequentially until a condition that evaluates to true is found. +If none of the conditions evaluate to true the body of the \lstinline!else!-branch is selected if it exists, otherwise no body is selected. In an algorithm section, the selected body is then executed. The bodies that are not selected have no effect on that model evaluation. - \subsection{When-Statements}\label{when-statements} The syntax of a \lstinline!when!-statement\index{when@\robustinline{when}!statement}\index{then@\robustinline{then}!when-statement@\robustinline{when}-statement}\index{elsewhen@\robustinline{elsewhen}!when-statement@\robustinline{when}-statement} is given by \productionref{when-statement} in the grammar. From 219fdaf7047ba47d8a382774ceba6a67485957f1 Mon Sep 17 00:00:00 2001 From: HOS Date: Wed, 6 May 2026 15:34:56 +0200 Subject: [PATCH 02/21] Try to have a clear meaning of clause as in #3840. Closes #3840 --- chapters/equations.tex | 8 ++++---- chapters/statements.tex | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/chapters/equations.tex b/chapters/equations.tex index 85e649632..20b2e2e4f 100644 --- a/chapters/equations.tex +++ b/chapters/equations.tex @@ -129,10 +129,10 @@ \subsection{If-Equations}\label{if-equations} The syntax of an \lstinline!if!-equations\index{if@\robustinline{if}!equation}\index{then@\robustinline{then}!if-equation@\robustinline{if}-equation}\index{else@\robustinline{else}!if-equation@\robustinline{if}-equation}\index{elseif@\robustinline{elseif}!if-equation@\robustinline{if}-equation} is given by \productionref{if-equation} in the grammar. Here, each \productionref{expression} in the grammar (representing the condition of any branch of an \lstinline!if!-clause) must be a scalar \lstinline!Boolean! expression. An \lstinline!if!-clause is seen as a list of branches: one \lstinline!if!-branch, and zero or more \lstinline!elseif!-branches, and an optional \lstinline!else!-branch. -One or zero of the bodies of these branches is selected, by evaluating their conditions sequentially until a condition that evaluates to true is found. -If none of the conditions evaluate to true the body of the \lstinline!else!-branch is selected if it exists, otherwise no body is selected. -In an equation section, the equations in the body are seen as equations that must be satisfied. -The bodies that are not selected have no effect on that model evaluation. +One or zero of the branches is selected, by evaluating their conditions sequentially until a condition that evaluates to true is found. +If none of the conditions evaluate to true the \lstinline!else!-branch is selected if it exists, otherwise no branch is selected. +In an equation section, the equations in the body of the selected branch are seen as equations that must be satisfied. +The bodies of the branches that are not selected have no effect on that model evaluation. The \lstinline!if!-equations which do not have exclusively evaluable expressions as switching conditions shall satisfy the following: \begin{itemize} diff --git a/chapters/statements.tex b/chapters/statements.tex index ac26434db..0ac181d3b 100644 --- a/chapters/statements.tex +++ b/chapters/statements.tex @@ -321,10 +321,10 @@ \subsection{If-Statement}\label{if-statement} The syntax of an \lstinline!if!-statements\index{if@\robustinline{if}!statement}\index{then@\robustinline{then}!if-statement@\robustinline{if}-statement}\index{else@\robustinline{else}!if-statement@\robustinline{if}-statement}\index{elseif@\robustinline{elseif}!if-statement@\robustinline{if}-statement} is given by \productionref{if-statement} in the grammar. Here, each \productionref{expression} in the grammar (representing any condition of an \lstinline!if!-clause) must be a scalar \lstinline!Boolean! expression. An \lstinline!if!-clause is seen as a list of branches: one \lstinline!if!-branch, and zero or more \lstinline!elseif!-branches, and an optional \lstinline!else!-branch. -One or zero of the bodies of these branches is selected, by evaluating their conditions sequentially until a condition that evaluates to true is found. -If none of the conditions evaluate to true the body of the \lstinline!else!-branch is selected if it exists, otherwise no body is selected. -In an algorithm section, the selected body is then executed. -The bodies that are not selected have no effect on that model evaluation. +One or zero of these branches is selected, by evaluating their conditions sequentially until a condition that evaluates to true is found. +If none of the conditions evaluate to true the \lstinline!else!-branch is selected if it exists, otherwise no branch is selected. +In an algorithm section, the body of the selected branch is then executed. +The bodies of the branches that are not selected have no effect on that model evaluation. \subsection{When-Statements}\label{when-statements} From f91a8161089429dbbcee5ff536532835083cf3f0 Mon Sep 17 00:00:00 2001 From: HOS Date: Wed, 6 May 2026 17:30:55 +0200 Subject: [PATCH 03/21] AsDiscussedInIssue --- chapters/equations.tex | 1 + 1 file changed, 1 insertion(+) diff --git a/chapters/equations.tex b/chapters/equations.tex index 20b2e2e4f..91e81fb0a 100644 --- a/chapters/equations.tex +++ b/chapters/equations.tex @@ -227,6 +227,7 @@ \subsubsection{Where a When-Equation May Occur}\label{restrictions-on-where-a-wh \lstinline!when!-equations cannot be nested. \item \lstinline!when!-equations can only occur within \lstinline!if!-equations and \lstinline!for!-equations if the controlling expressions are exclusively evaluable expressions. + For \lstinline!if!-equations this requires that the condition of the branch containing the \lstinline!when!-equation and the conditions of all preceding branches are evaluable. \end{itemize} \begin{example} From 079cb762c3e01267b91b62f2ac1c222b875c0596 Mon Sep 17 00:00:00 2001 From: HOS Date: Thu, 7 May 2026 15:09:24 +0200 Subject: [PATCH 04/21] ClauseBody --- chapters/classes.tex | 5 ++--- chapters/equations.tex | 18 +++++++++--------- chapters/operatorsandexpressions.tex | 24 ++++++++++++------------ chapters/statements.tex | 2 +- 4 files changed, 24 insertions(+), 25 deletions(-) diff --git a/chapters/classes.tex b/chapters/classes.tex index dbb889bd3..a4d24f4ed 100644 --- a/chapters/classes.tex +++ b/chapters/classes.tex @@ -425,9 +425,8 @@ \section{Component Variability}\label{component-variability} For \lstinline!Real! variables we can distinguish two subtly different categories: discrete-time and piecewise constant, where the discrete-time variables are a subset of all piecewise constant variables. The \lstinline!Real! variables declared with the prefix \lstinline!discrete! is a subset of the discrete-time \lstinline!Real! variables. -For a \lstinline!Real! variable, being discrete-time is equivalent to being assigned in (the body of) a \lstinline!when!-clause. -% The (the body of) is redundant (as assignments cannot be placed anywhere else in when-clauses). Might reformulate -A variable used as argument to \lstinline!pre! outside the body of any \lstinline!when!-clause must be discrete-time. +For a \lstinline!Real! variable, being discrete-time is equivalent to being assigned in a \lstinline!when!-clause body. +A variable used as argument to \lstinline!pre! outside any \lstinline!when!-clause body must be discrete-time. \begin{lstlisting}[language=modelica] model PiecewiseConstantReals diff --git a/chapters/equations.tex b/chapters/equations.tex index 91e81fb0a..e94c548ee 100644 --- a/chapters/equations.tex +++ b/chapters/equations.tex @@ -74,7 +74,7 @@ \subsubsection{Explicit Iteration Ranges of For-Equations}\label{explicit-iterat The expression of a \lstinline!for!-equation shall be evaluable. The iteration range of a \lstinline!for!-equation can also be specified as \lstinline!Boolean! or as an enumeration type, see \cref{types-as-iteration-ranges} for more information. The loop-variable (\lstinline!IDENT!) is in scope inside the loop-construct and shall not be assigned to. -For each element of the evaluated vector expression, in the normal order, the loop-variable gets the value of that element and that is used to evaluate the body of the \lstinline!for!-loop. +For each element of the evaluated vector expression, in the normal order, the loop-variable gets the value of that element and that is used to evaluate the \lstinline!for!-loop body. \begin{example} \begin{lstlisting}[language=modelica] @@ -196,7 +196,7 @@ \subsubsection{Defining When-Equations by If-Expressions in Equality Equations}\ \end{lstlisting} \begin{nonnormative} -The equivalence is conceptual since \lstinline!pre($\ldots$)! of a non discrete-time \lstinline!Real! variable or expression can only be used within the body of a \lstinline!when!-clause. +The equivalence is conceptual since \lstinline!pre($\ldots$)! of a non discrete-time \lstinline!Real! variable or expression can only be used within a \lstinline!when!-clause body. Example: \begin{lstlisting}[language=modelica] /* discrete */ Real x; @@ -211,7 +211,7 @@ \subsubsection{Defining When-Equations by If-Expressions in Equality Equations}\ Here, \lstinline!x! is a discrete-time variable (whether it is declared with the \lstinline!discrete! prefix or not), but \lstinline!u! and \lstinline!y! cannot be discrete-time variables (since they are not assigned in \lstinline!when!-clauses). -However, \lstinline!pre(u)! is legal within the body of the \lstinline!when!-clause, since the body is only evaluated at events, and thus all expressions are discrete-time expressions. +However, \lstinline!pre(u)! is legal within the \lstinline!when!-clause body, since the body is only evaluated at events, and thus all expressions are discrete-time expressions. \end{nonnormative} The start values of the introduced \lstinline!Boolean! variables are defined by the taking the start value of the when-condition, as above where \lstinline!b! is a parameter variable. @@ -401,7 +401,7 @@ \subsubsection{Single Assignment Rule Applied to When-Equations}\label{applicati \subsection{reinit}\label{reinit} -\lstinline!reinit! can only be used in the body of a \lstinline!when!-equation. +\lstinline!reinit! can only be used in a \lstinline!when!-equation body. It has the following syntax: \begin{lstlisting}[language=modelica] reinit(x, expr); @@ -411,14 +411,14 @@ \subsection{reinit}\label{reinit} \lstinline!x! is a component-reference (where any subscripts are evaluable) referring to a \lstinline!Real! variable (or an array of \lstinline!Real! variables) that must be selected as a state (resp., states), i.e., \lstinline!reinit! on \lstinline!x! implies \lstinline!stateSelect = StateSelect.always! on \lstinline!x!. \lstinline!expr! needs to be type-compatible with \lstinline!x!. For any given variable (possibly an array variable), \lstinline!reinit! can only be applied (either to an individual variable or to a part of an array variable) in one \lstinline!when!-clause (applying \lstinline!reinit! to a variable in several \lstinline!when!- or \lstinline!elsewhen!-branches of the same \lstinline!when!-equation is allowed). -If there are multiple \lstinline!reinit! for a variable inside one body of a \lstinline!when!-clause, they must appear in different branches of an \lstinline!if!-equation (in order that at most one \lstinline!reinit! for the variable is active at any event). +If there are multiple \lstinline!reinit! for a variable inside one \lstinline!when!-clause body, they must appear in different branches of an \lstinline!if!-equation (in order that at most one \lstinline!reinit! for the variable is active at any event). In case of \lstinline!reinit! active during initialization (due to \lstinline!when initial()!), see \cref{initialization-initial-equation-and-initial-algorithm}. \lstinline!reinit! does not break the single assignment rule, because \lstinline!reinit(x, expr)! in equations evaluates \lstinline!expr! to a value, then at the end of the current event iteration step it assigns this value to \lstinline!x! (this copying from values to reinitialized state(s) is done after all other evaluations of the model and before copying \lstinline!x! to \lstinline!pre(x)!). \begin{example} If a higher index system is present, i.e., constraints between state variables, some state variables need to be redefined to non-state variables. -During simulation, non-state variables should be chosen in such a way that variables with an applied \lstinline!reinit! are selected as states at least when the corresponding bodies of the \lstinline!when!-clauses become active. +During simulation, non-state variables should be chosen in such a way that variables with an applied \lstinline!reinit! are selected as states at least when the corresponding \lstinline!when!-clause bodies become active. If this is not possible, an error occurs, since otherwise \lstinline!reinit! would be applied to a non-state variable. Example for the usage of \lstinline!reinit! (bouncing ball): @@ -644,7 +644,7 @@ \section{Events and Synchronization}\label{events-and-synchronization} Clocked discrete-time partitions are also treated this way, see \cref{clocked-discrete-time-and-clocked-discretized-continuous-time-partition}. \begin{nonnormative} -Using state events in the body of a \lstinline!when!-clause is unnecessary because the body of a \lstinline!when!-clause is not evaluated during continuous integration. +Using state events in a \lstinline!when!-clause body is unnecessary because the \lstinline!when!-clause body is not evaluated during continuous integration. \end{nonnormative} \begin{example} @@ -716,7 +716,7 @@ \section{Events and Synchronization}\label{events-and-synchronization} end when; \end{lstlisting} -The body of the \lstinline!slowSample! \lstinline!when!-clause is evaluated at every 5th occurrence of the evaluating the body of the \lstinline!fastSample! \lstinline!when!-clause. +The \lstinline!slowSample! \lstinline!when!-clause body is evaluated at every 5th occurrence of the evaluating the \lstinline!fastSample! \lstinline!when!-clause body. \end{nonnormative} \begin{nonnormative} @@ -947,7 +947,7 @@ \section{Initialization, initial equation, and initial algorithm}\label{initiali \end{lstlisting} After solving the initialization problem, both \lstinline!b! and \lstinline!pre(b)! are false. During transient analysis, \lstinline!initial()! is false, so \lstinline!b! changes from falso to true during the first round of the initial event iteration. -This triggers the body of the \lstinline!when!-clause, and \lstinline!x! gets reinitialized. +This triggers the \lstinline!when!-clause body, and \lstinline!x! gets reinitialized. \end{example} diff --git a/chapters/operatorsandexpressions.tex b/chapters/operatorsandexpressions.tex index 6ef313821..cfb02cb6b 100644 --- a/chapters/operatorsandexpressions.tex +++ b/chapters/operatorsandexpressions.tex @@ -621,7 +621,7 @@ \subsection{Event-Triggering Mathematical Functions}\label{event-triggering-math Result and arguments shall have type \lstinline!Real! or \lstinline!Integer!. If either of the arguments is \lstinline!Real! the result is \lstinline!Real! otherwise \lstinline!Integer!. \begin{nonnormative} -Note, outside of a body of a \lstinline!when!-clause state events are triggered when the return value changes discontinuously. +Note, outside of a \lstinline!when!-clause body state events are triggered when the return value changes discontinuously. Examples: \lstinline!mod(3, 1.4) = 0.2!, \lstinline!mod(-3, 1.4) = 1.2!, \lstinline!mod(3, -1.4) = -1.2!. \end{nonnormative} \end{semantics} @@ -636,7 +636,7 @@ \subsection{Event-Triggering Mathematical Functions}\label{event-triggering-math Result and arguments shall have type \lstinline!Real! or \lstinline!Integer!. If either of the arguments is \lstinline!Real! the result is \lstinline!Real! otherwise \lstinline!Integer!. \begin{nonnormative} -Note, outside of a body of a \lstinline!when!-clause state events are triggered when the return value changes discontinuously. +Note, outside of a \lstinline!when!-clause body state events are triggered when the return value changes discontinuously. Examples: \lstinline!rem(3, 1.4) = 0.2!, \lstinline!rem(-3, 1.4) = -0.2!. \end{nonnormative} \end{semantics} @@ -650,7 +650,7 @@ \subsection{Event-Triggering Mathematical Functions}\label{event-triggering-math Smallest integer not less than $x$. Result and argument shall have type \lstinline!Real!. \begin{nonnormative} -Note, outside of a body of a \lstinline!when!-clause state events are triggered when the return value changes discontinuously. +Note, outside of a \lstinline!when!-clause body state events are triggered when the return value changes discontinuously. \end{nonnormative} \end{semantics} \end{operatordefinition} @@ -663,7 +663,7 @@ \subsection{Event-Triggering Mathematical Functions}\label{event-triggering-math Largest integer not greater than $x$. Result and argument shall have type \lstinline!Real!. \begin{nonnormative} -Note, outside of a body of a \lstinline!when!-clause state events are triggered when the return value changes discontinuously. +Note, outside of a \lstinline!when!-clause body state events are triggered when the return value changes discontinuously. \end{nonnormative} \end{semantics} \end{operatordefinition} @@ -677,7 +677,7 @@ \subsection{Event-Triggering Mathematical Functions}\label{event-triggering-math The argument shall have type \lstinline!Real!. The result has type \lstinline!Integer!. \begin{nonnormative} -Note, outside of a body of a \lstinline!when!-clause state events are triggered when the return value changes discontinuously. +Note, outside of a \lstinline!when!-clause body state events are triggered when the return value changes discontinuously. \end{nonnormative} \end{semantics} \end{operatordefinition} @@ -1463,7 +1463,7 @@ \subsection{Event-Related Operators with Function Syntax}\label{event-related-op The operator is not allowed inside \lstinline!function! classes. \lstinline!pre! can be applied to the variable $y$ only if $y$ is a discrete-time expression and $y$ is either a subtype of a simple type or is a record component. \begin{nonnormative} -This can be applied to continuous-time variables in the bodies of \lstinline!when!-clauses, see \cref{discrete-time-expressions} for the definition of discrete-time expression. +This can be applied to continuous-time variables in \lstinline!when!-clause bodies, see \cref{discrete-time-expressions} for the definition of discrete-time expression. \end{nonnormative} The first value of \lstinline!pre($y$)! is determined in the initialization phase. @@ -1473,10 +1473,10 @@ \subsection{Event-Related Operators with Function Syntax}\label{event-related-op When no more round of model equation evaluation is triggered, the processing of the event is completed and the transient analysis may proceed forward in time. For purposes of event iteration, each scalar expression in a \lstinline!when!-clause condition is treated as an implicit variable \lstinline!v!. -Since the body of a \lstinline!when!-clause is triggered when \lstinline!v and not pre(v)!, the implicit variable is considered wrapped in \lstinline!pre($\ldots$)! and becomes part of the event iteration convergence criterion. +Since a \lstinline!when!-clause body is triggered when \lstinline!v and not pre(v)!, the implicit variable is considered wrapped in \lstinline!pre($\ldots$)! and becomes part of the event iteration convergence criterion. \begin{nonnormative} -If \lstinline!v! and \lstinline!pre(v)! are only used in bodies of \lstinline!when!-clauses, the translator might mask event iteration for variable \lstinline!v! since \lstinline!v! cannot change during event iteration. +If \lstinline!v! and \lstinline!pre(v)! are only used in \lstinline!when!-clause bodies, the translator might mask event iteration for variable \lstinline!v! since \lstinline!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. A consequence of the implicit \lstinline!when!-clause condition variables is that every time a \lstinline!when!-clause is triggered, there is a variable with \lstinline!v <> pre(v)!, meaning that another round of the iteration is triggered. @@ -1513,14 +1513,14 @@ \subsection{Event-Related Operators with Function Syntax}\label{event-related-op reinit($x$, $\mathit{expr}$) \end{lstlisting}\end{synopsis} \begin{semantics} -In the body of a \lstinline!when!-clause, reinitializes $x$ with $\mathit{expr}$ at an event instant. +In a \lstinline!when!-clause body, reinitializes $x$ with $\mathit{expr}$ at an event instant. $x$ is a scalar or array \lstinline!Real! variable that is implicitly defined to have \lstinline!StateSelect.always!. \begin{nonnormative} It is an error if the variable cannot be selected as a state. \end{nonnormative} $\mathit{expr}$ needs to be type-compatible with $x$. \lstinline!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 \lstinline!when!-clause in an equation section. +It can only be applied in a \lstinline!when!-clause body in an equation section. See also \cref{reinit}. \end{semantics} \end{operatordefinition} @@ -1689,7 +1689,7 @@ \subsection{Discrete-Time Expressions}\label{discrete-time-expressions} \item Expressions where all the subexpressions are discrete-time expressions. \item - Expressions in the body of a \lstinline!when!-clause, \lstinline!initial equation!, or \lstinline!initial algorithm!. + Expressions in the a \lstinline!when!-clause body, \lstinline!initial equation!, or \lstinline!initial algorithm!. \item Expressions in a clocked discrete-time partition, see \cref{clocked-discrete-time-and-clocked-discretized-continuous-time-partition}. \item @@ -1712,7 +1712,7 @@ \subsection{Discrete-Time Expressions}\label{discrete-time-expressions} Expressions in functions not having annotation \lstinline!GenerateEvents = true! (\cref{modelica:GenerateEvents}), behave as though they were discrete-time expressions. \end{itemize} -Inside an \lstinline!if!-expression; or in the body of an \lstinline!if!-clause, a \lstinline!while!-statement, or a \lstinline!for!-clause, that is controlled by a non-discrete-time (that is continuous-time, but not discrete-time) switching expression and not in the body of a \lstinline!when!-clause, it is not legal to have assignments to discrete-time variables, equations between discrete-time expressions, or real elementary relations/functions that should generate events. +Inside an \lstinline!if!-expression; or in an \lstinline!if!-clause body, a \lstinline!while!-statement, or a \lstinline!for!-clause, that is controlled by a non-discrete-time (that is continuous-time, but not discrete-time) switching expression and not in the \lstinline!when!-clause body, it is not legal to have assignments to discrete-time variables, equations between discrete-time expressions, or real elementary relations/functions that should generate events. \begin{nonnormative} The restriction above is necessary in order to guarantee that all equations for discrete-time variable are discrete-time expressions, and to ensure that crossing functions do not become active between events. diff --git a/chapters/statements.tex b/chapters/statements.tex index 0ac181d3b..718ae10f2 100644 --- a/chapters/statements.tex +++ b/chapters/statements.tex @@ -429,7 +429,7 @@ \subsubsection{Defining When-Statements by If-Statements}\label{defining-when-st end if; \end{lstlisting} with \lstinline!edge(A) = A and not pre(A)! and the additional guarantee, that the statements within this special \lstinline!if!-statement are only evaluated at event instants. -The difference compared to the when-statements is that, e.g., \lstinline!pre! may only be used on continuous-time real variables inside the body of a \lstinline!when!-clause and not inside these if-statements. +The difference compared to the when-statements is that, e.g., \lstinline!pre! may only be used on continuous-time real variables inside a \lstinline!when!-clause body and not inside these if-statements. \subsection{Special Statements}\label{special-statements} From 1ecd6f9e00807cb937d61cc41b0fe87805ec94c7 Mon Sep 17 00:00:00 2001 From: HOS Date: Thu, 7 May 2026 15:10:19 +0200 Subject: [PATCH 05/21] Syntax --- chapters/statements.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chapters/statements.tex b/chapters/statements.tex index 718ae10f2..6ccce07f7 100644 --- a/chapters/statements.tex +++ b/chapters/statements.tex @@ -429,7 +429,7 @@ \subsubsection{Defining When-Statements by If-Statements}\label{defining-when-st end if; \end{lstlisting} with \lstinline!edge(A) = A and not pre(A)! and the additional guarantee, that the statements within this special \lstinline!if!-statement are only evaluated at event instants. -The difference compared to the when-statements is that, e.g., \lstinline!pre! may only be used on continuous-time real variables inside a \lstinline!when!-clause body and not inside these if-statements. +The difference compared to the \lstinline!when!-statements is that, e.g., \lstinline!pre! may only be used on continuous-time real variables inside a \lstinline!when!-clause body and not inside these \lstinline!if!-statements. \subsection{Special Statements}\label{special-statements} From 35ffdf9e230070713b94177b509c224d888cf916 Mon Sep 17 00:00:00 2001 From: HOS Date: Thu, 7 May 2026 15:10:23 +0200 Subject: [PATCH 06/21] ClauseBody2 --- chapters/scoping.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chapters/scoping.tex b/chapters/scoping.tex index 226c98244..b511e2960 100644 --- a/chapters/scoping.tex +++ b/chapters/scoping.tex @@ -62,7 +62,7 @@ \subsection{Simple Name Lookup}\label{simple-name-lookup} In the latter case the lookup stops except for the predefined types, functions and operators defined in this specification. For these cases the lookup continues in the global scope, where they are defined. -The iteration variables are the implicitly declared iteration variable(s) if inside the body of a \lstinline!for!-loop, \cref{for-equations-repetitive-equation-structures} and \cref{for-statement}, or the body of a reduction expression, \cref{reduction-functions-and-operators}. +The iteration variables are the implicitly declared iteration variable(s) if inside a \lstinline!for!-loop body, \cref{for-equations-repetitive-equation-structures} and \cref{for-statement}, or the body of a reduction expression, \cref{reduction-functions-and-operators}. Reference to variables successfully looked up in an enclosing class is only allowed for variables declared as \lstinline!constant!. The values of modifiers are thus resolved in the \emph{instance} scope of which the modifier appears; if the use is in a modifier on a short class definition, see \cref{short-class-definitions}. From 9460dcf7a387840bf9b26547c8ec7761578fd3b4 Mon Sep 17 00:00:00 2001 From: HOS Date: Thu, 7 May 2026 15:10:56 +0200 Subject: [PATCH 07/21] RestoreBlankLine --- chapters/statements.tex | 1 + 1 file changed, 1 insertion(+) diff --git a/chapters/statements.tex b/chapters/statements.tex index 6ccce07f7..3161b5c81 100644 --- a/chapters/statements.tex +++ b/chapters/statements.tex @@ -326,6 +326,7 @@ \subsection{If-Statement}\label{if-statement} In an algorithm section, the body of the selected branch is then executed. The bodies of the branches that are not selected have no effect on that model evaluation. + \subsection{When-Statements}\label{when-statements} The syntax of a \lstinline!when!-statement\index{when@\robustinline{when}!statement}\index{then@\robustinline{then}!when-statement@\robustinline{when}-statement}\index{elsewhen@\robustinline{elsewhen}!when-statement@\robustinline{when}-statement} is given by \productionref{when-statement} in the grammar. From 195d06f7d04bdbfad217be194116beb1176c9676 Mon Sep 17 00:00:00 2001 From: HOS Date: Thu, 7 May 2026 15:13:28 +0200 Subject: [PATCH 08/21] RestoreA --- chapters/classes.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chapters/classes.tex b/chapters/classes.tex index a4d24f4ed..6033e026c 100644 --- a/chapters/classes.tex +++ b/chapters/classes.tex @@ -426,7 +426,7 @@ \section{Component Variability}\label{component-variability} For \lstinline!Real! variables we can distinguish two subtly different categories: discrete-time and piecewise constant, where the discrete-time variables are a subset of all piecewise constant variables. The \lstinline!Real! variables declared with the prefix \lstinline!discrete! is a subset of the discrete-time \lstinline!Real! variables. For a \lstinline!Real! variable, being discrete-time is equivalent to being assigned in a \lstinline!when!-clause body. -A variable used as argument to \lstinline!pre! outside any \lstinline!when!-clause body must be discrete-time. +A variable used as argument to \lstinline!pre! outside a \lstinline!when!-clause body must be discrete-time. \begin{lstlisting}[language=modelica] model PiecewiseConstantReals From 1b4d7c8b877d96314ae52cb0f98a6fc0cf353b68 Mon Sep 17 00:00:00 2001 From: Hans Olsson Date: Thu, 7 May 2026 16:40:15 +0200 Subject: [PATCH 09/21] Update chapters/equations.tex Co-authored-by: Henrik Tidefelt --- chapters/equations.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chapters/equations.tex b/chapters/equations.tex index e94c548ee..a209ef488 100644 --- a/chapters/equations.tex +++ b/chapters/equations.tex @@ -196,7 +196,7 @@ \subsubsection{Defining When-Equations by If-Expressions in Equality Equations}\ \end{lstlisting} \begin{nonnormative} -The equivalence is conceptual since \lstinline!pre($\ldots$)! of a non discrete-time \lstinline!Real! variable or expression can only be used within a \lstinline!when!-clause body. +The equivalence is conceptual since \lstinline!pre($\ldots$)! of a non-discrete-time \lstinline!Real! variable or expression can only be used within a \lstinline!when!-clause body. Example: \begin{lstlisting}[language=modelica] /* discrete */ Real x; From 3303338b5b7bb3b6eb62b39c9625d53e6123caac Mon Sep 17 00:00:00 2001 From: Hans Olsson Date: Thu, 7 May 2026 16:51:07 +0200 Subject: [PATCH 10/21] Update chapters/equations.tex Co-authored-by: Henrik Tidefelt --- chapters/equations.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chapters/equations.tex b/chapters/equations.tex index a209ef488..e7812f0c0 100644 --- a/chapters/equations.tex +++ b/chapters/equations.tex @@ -716,7 +716,7 @@ \section{Events and Synchronization}\label{events-and-synchronization} end when; \end{lstlisting} -The \lstinline!slowSample! \lstinline!when!-clause body is evaluated at every 5th occurrence of the evaluating the \lstinline!fastSample! \lstinline!when!-clause body. +The \lstinline!slowSample! \lstinline!when!-clause body is evaluated at every 5th evaluation of the \lstinline!fastSample! \lstinline!when!-clause body. \end{nonnormative} \begin{nonnormative} From 3a932567dfb70e25289770f4e63d4c1428da4f40 Mon Sep 17 00:00:00 2001 From: Hans Olsson Date: Thu, 7 May 2026 16:56:51 +0200 Subject: [PATCH 11/21] Apply suggestions from code review Co-authored-by: Henrik Tidefelt --- chapters/equations.tex | 2 +- chapters/operatorsandexpressions.tex | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/chapters/equations.tex b/chapters/equations.tex index e7812f0c0..9c7039686 100644 --- a/chapters/equations.tex +++ b/chapters/equations.tex @@ -745,7 +745,7 @@ \section{Initialization, initial equation, and initial algorithm}\label{initiali The algorithmic statements within a \lstinline!when!-statement are active during initialization, if and only if they are explicitly enabled with \lstinline!initial()!, and only in one of the two forms \lstinline!when initial() then! or \lstinline!when {$\ldots$, initial(), $\ldots$} then!. In this case, the algorithmic statements within the \lstinline!when!-statement remain active during the whole initialization phase. -An active condition of a branch of a \lstinline!when!-clause inactivates the following \lstinline!elsewhen! (similarly to \lstinline!when!-clauses during simulation), but apart from that the first \lstinline!elsewhen initial() then! or \lstinline!elsewhen {$\ldots$, initial(), $\ldots$} then! is similarly active during initialization as \lstinline!when initial() then! or \lstinline!when {$\ldots$, initial(), $\ldots$} then!. +An active \lstinline!when!-clause branch condition inactivates the following \lstinline!elsewhen! (similarly to \lstinline!when!-clauses during simulation), but apart from that the first \lstinline!elsewhen initial() then! or \lstinline!elsewhen {$\ldots$, initial(), $\ldots$} then! is similarly active during initialization as \lstinline!when initial() then! or \lstinline!when {$\ldots$, initial(), $\ldots$} then!. \begin{nonnormative} That means that any subsequent \lstinline!elsewhen initial()! has no effect, similarly to \lstinline!when false then!. diff --git a/chapters/operatorsandexpressions.tex b/chapters/operatorsandexpressions.tex index cfb02cb6b..1717e3af1 100644 --- a/chapters/operatorsandexpressions.tex +++ b/chapters/operatorsandexpressions.tex @@ -621,7 +621,7 @@ \subsection{Event-Triggering Mathematical Functions}\label{event-triggering-math Result and arguments shall have type \lstinline!Real! or \lstinline!Integer!. If either of the arguments is \lstinline!Real! the result is \lstinline!Real! otherwise \lstinline!Integer!. \begin{nonnormative} -Note, outside of a \lstinline!when!-clause body state events are triggered when the return value changes discontinuously. +Note, outside of \lstinline!when!-clause bodies, state events are triggered when the return value changes discontinuously. Examples: \lstinline!mod(3, 1.4) = 0.2!, \lstinline!mod(-3, 1.4) = 1.2!, \lstinline!mod(3, -1.4) = -1.2!. \end{nonnormative} \end{semantics} @@ -636,7 +636,7 @@ \subsection{Event-Triggering Mathematical Functions}\label{event-triggering-math Result and arguments shall have type \lstinline!Real! or \lstinline!Integer!. If either of the arguments is \lstinline!Real! the result is \lstinline!Real! otherwise \lstinline!Integer!. \begin{nonnormative} -Note, outside of a \lstinline!when!-clause body state events are triggered when the return value changes discontinuously. +Note, outside of \lstinline!when!-clause bodies, state events are triggered when the return value changes discontinuously. Examples: \lstinline!rem(3, 1.4) = 0.2!, \lstinline!rem(-3, 1.4) = -0.2!. \end{nonnormative} \end{semantics} @@ -650,7 +650,7 @@ \subsection{Event-Triggering Mathematical Functions}\label{event-triggering-math Smallest integer not less than $x$. Result and argument shall have type \lstinline!Real!. \begin{nonnormative} -Note, outside of a \lstinline!when!-clause body state events are triggered when the return value changes discontinuously. +Note, outside of \lstinline!when!-clause bodies, state events are triggered when the return value changes discontinuously. \end{nonnormative} \end{semantics} \end{operatordefinition} @@ -663,7 +663,7 @@ \subsection{Event-Triggering Mathematical Functions}\label{event-triggering-math Largest integer not greater than $x$. Result and argument shall have type \lstinline!Real!. \begin{nonnormative} -Note, outside of a \lstinline!when!-clause body state events are triggered when the return value changes discontinuously. +Note, outside of \lstinline!when!-clause bodies, state events are triggered when the return value changes discontinuously. \end{nonnormative} \end{semantics} \end{operatordefinition} @@ -677,7 +677,7 @@ \subsection{Event-Triggering Mathematical Functions}\label{event-triggering-math The argument shall have type \lstinline!Real!. The result has type \lstinline!Integer!. \begin{nonnormative} -Note, outside of a \lstinline!when!-clause body state events are triggered when the return value changes discontinuously. +Note, outside of \lstinline!when!-clause bodies, state events are triggered when the return value changes discontinuously. \end{nonnormative} \end{semantics} \end{operatordefinition} From fe3027ceb520fb22937cd1e16907cc772880294e Mon Sep 17 00:00:00 2001 From: Hans Olsson Date: Thu, 7 May 2026 17:12:55 +0200 Subject: [PATCH 12/21] Apply suggestions from code review Co-authored-by: Henrik Tidefelt --- chapters/equations.tex | 2 +- chapters/operatorsandexpressions.tex | 8 ++++---- chapters/statements.tex | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/chapters/equations.tex b/chapters/equations.tex index 9c7039686..0a7292aaf 100644 --- a/chapters/equations.tex +++ b/chapters/equations.tex @@ -128,7 +128,7 @@ \subsection{If-Equations}\label{if-equations} The syntax of an \lstinline!if!-equations\index{if@\robustinline{if}!equation}\index{then@\robustinline{then}!if-equation@\robustinline{if}-equation}\index{else@\robustinline{else}!if-equation@\robustinline{if}-equation}\index{elseif@\robustinline{elseif}!if-equation@\robustinline{if}-equation} is given by \productionref{if-equation} in the grammar. Here, each \productionref{expression} in the grammar (representing the condition of any branch of an \lstinline!if!-clause) must be a scalar \lstinline!Boolean! expression. -An \lstinline!if!-clause is seen as a list of branches: one \lstinline!if!-branch, and zero or more \lstinline!elseif!-branches, and an optional \lstinline!else!-branch. +An \lstinline!if!-statement is seen as a list of branches: one \lstinline!if!-branch, and zero or more \lstinline!elseif!-branches, and an optional \lstinline!else!-branch. One or zero of the branches is selected, by evaluating their conditions sequentially until a condition that evaluates to true is found. If none of the conditions evaluate to true the \lstinline!else!-branch is selected if it exists, otherwise no branch is selected. In an equation section, the equations in the body of the selected branch are seen as equations that must be satisfied. diff --git a/chapters/operatorsandexpressions.tex b/chapters/operatorsandexpressions.tex index 1717e3af1..ec7d39f9f 100644 --- a/chapters/operatorsandexpressions.tex +++ b/chapters/operatorsandexpressions.tex @@ -1513,14 +1513,14 @@ \subsection{Event-Related Operators with Function Syntax}\label{event-related-op reinit($x$, $\mathit{expr}$) \end{lstlisting}\end{synopsis} \begin{semantics} -In a \lstinline!when!-clause body, reinitializes $x$ with $\mathit{expr}$ at an event instant. +Re-initializes $x$ with $\mathit{expr}$. +Only allowed in a \lstinline!when!-equation body, meaning that re-initialization will only occur at events. $x$ is a scalar or array \lstinline!Real! variable that is implicitly defined to have \lstinline!StateSelect.always!. \begin{nonnormative} It is an error if the variable cannot be selected as a state. \end{nonnormative} $\mathit{expr}$ needs to be type-compatible with $x$. \lstinline!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 a \lstinline!when!-clause body in an equation section. See also \cref{reinit}. \end{semantics} \end{operatordefinition} @@ -1689,7 +1689,7 @@ \subsection{Discrete-Time Expressions}\label{discrete-time-expressions} \item Expressions where all the subexpressions are discrete-time expressions. \item - Expressions in the a \lstinline!when!-clause body, \lstinline!initial equation!, or \lstinline!initial algorithm!. + Expressions in a \lstinline!when!-clause body, \lstinline!initial equation!, or \lstinline!initial algorithm!. \item Expressions in a clocked discrete-time partition, see \cref{clocked-discrete-time-and-clocked-discretized-continuous-time-partition}. \item @@ -1712,7 +1712,7 @@ \subsection{Discrete-Time Expressions}\label{discrete-time-expressions} Expressions in functions not having annotation \lstinline!GenerateEvents = true! (\cref{modelica:GenerateEvents}), behave as though they were discrete-time expressions. \end{itemize} -Inside an \lstinline!if!-expression; or in an \lstinline!if!-clause body, a \lstinline!while!-statement, or a \lstinline!for!-clause, that is controlled by a non-discrete-time (that is continuous-time, but not discrete-time) switching expression and not in the \lstinline!when!-clause body, it is not legal to have assignments to discrete-time variables, equations between discrete-time expressions, or real elementary relations/functions that should generate events. +Inside an \lstinline!if!-expression or in an \lstinline!if!-clause body, a \lstinline!while!-statement or a \lstinline!for!-clause, that is controlled by a non-discrete-time (that is continuous-time, but not discrete-time) switching expression and not in the \lstinline!when!-clause body, it is not legal to have assignments to discrete-time variables, equations between discrete-time expressions, or real elementary relations/functions that should generate events. \begin{nonnormative} The restriction above is necessary in order to guarantee that all equations for discrete-time variable are discrete-time expressions, and to ensure that crossing functions do not become active between events. diff --git a/chapters/statements.tex b/chapters/statements.tex index 3161b5c81..f38840bb2 100644 --- a/chapters/statements.tex +++ b/chapters/statements.tex @@ -320,7 +320,7 @@ \subsection{If-Statement}\label{if-statement} The syntax of an \lstinline!if!-statements\index{if@\robustinline{if}!statement}\index{then@\robustinline{then}!if-statement@\robustinline{if}-statement}\index{else@\robustinline{else}!if-statement@\robustinline{if}-statement}\index{elseif@\robustinline{elseif}!if-statement@\robustinline{if}-statement} is given by \productionref{if-statement} in the grammar. Here, each \productionref{expression} in the grammar (representing any condition of an \lstinline!if!-clause) must be a scalar \lstinline!Boolean! expression. -An \lstinline!if!-clause is seen as a list of branches: one \lstinline!if!-branch, and zero or more \lstinline!elseif!-branches, and an optional \lstinline!else!-branch. +An \lstinline!if!-statement is seen as a list of branches: one \lstinline!if!-branch, and zero or more \lstinline!elseif!-branches, and an optional \lstinline!else!-branch. One or zero of these branches is selected, by evaluating their conditions sequentially until a condition that evaluates to true is found. If none of the conditions evaluate to true the \lstinline!else!-branch is selected if it exists, otherwise no branch is selected. In an algorithm section, the body of the selected branch is then executed. From a18d419d3837c11ce84a274f55c005feb7fad390 Mon Sep 17 00:00:00 2001 From: Hans Olsson Date: Thu, 7 May 2026 23:09:59 +0200 Subject: [PATCH 13/21] Update chapters/equations.tex Co-authored-by: Henrik Tidefelt --- chapters/equations.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chapters/equations.tex b/chapters/equations.tex index 0a7292aaf..d628d1bea 100644 --- a/chapters/equations.tex +++ b/chapters/equations.tex @@ -410,7 +410,7 @@ \subsection{reinit}\label{reinit} The operator reinitializes \lstinline!x! with \lstinline!expr! at an event instant. \lstinline!x! is a component-reference (where any subscripts are evaluable) referring to a \lstinline!Real! variable (or an array of \lstinline!Real! variables) that must be selected as a state (resp., states), i.e., \lstinline!reinit! on \lstinline!x! implies \lstinline!stateSelect = StateSelect.always! on \lstinline!x!. \lstinline!expr! needs to be type-compatible with \lstinline!x!. -For any given variable (possibly an array variable), \lstinline!reinit! can only be applied (either to an individual variable or to a part of an array variable) in one \lstinline!when!-clause (applying \lstinline!reinit! to a variable in several \lstinline!when!- or \lstinline!elsewhen!-branches of the same \lstinline!when!-equation is allowed). +For any given variable (possibly an array variable), \lstinline!reinit! can only be applied (either to an individual variable or to a part of an array variable) in one \lstinline!when!-equation (applying \lstinline!reinit! to a variable in several \lstinline!when!- or \lstinline!elsewhen!-branches of the same \lstinline!when!-equation is allowed). If there are multiple \lstinline!reinit! for a variable inside one \lstinline!when!-clause body, they must appear in different branches of an \lstinline!if!-equation (in order that at most one \lstinline!reinit! for the variable is active at any event). In case of \lstinline!reinit! active during initialization (due to \lstinline!when initial()!), see \cref{initialization-initial-equation-and-initial-algorithm}. From 48ae3eaeca07544c705989f92161be87a2437f2d Mon Sep 17 00:00:00 2001 From: Hans Olsson Date: Thu, 7 May 2026 23:46:11 +0200 Subject: [PATCH 14/21] Update chapters/equations.tex Co-authored-by: Henrik Tidefelt --- chapters/equations.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chapters/equations.tex b/chapters/equations.tex index d628d1bea..1ce037c69 100644 --- a/chapters/equations.tex +++ b/chapters/equations.tex @@ -410,7 +410,7 @@ \subsection{reinit}\label{reinit} The operator reinitializes \lstinline!x! with \lstinline!expr! at an event instant. \lstinline!x! is a component-reference (where any subscripts are evaluable) referring to a \lstinline!Real! variable (or an array of \lstinline!Real! variables) that must be selected as a state (resp., states), i.e., \lstinline!reinit! on \lstinline!x! implies \lstinline!stateSelect = StateSelect.always! on \lstinline!x!. \lstinline!expr! needs to be type-compatible with \lstinline!x!. -For any given variable (possibly an array variable), \lstinline!reinit! can only be applied (either to an individual variable or to a part of an array variable) in one \lstinline!when!-equation (applying \lstinline!reinit! to a variable in several \lstinline!when!- or \lstinline!elsewhen!-branches of the same \lstinline!when!-equation is allowed). +For any given variable (possibly an array variable), \lstinline!reinit! can only be applied (either to an individual variable or to a part of an array variable) in one \lstinline!when!-equation (applying \lstinline!reinit! to a variable in several branches of the same \lstinline!when!-equation is allowed). If there are multiple \lstinline!reinit! for a variable inside one \lstinline!when!-clause body, they must appear in different branches of an \lstinline!if!-equation (in order that at most one \lstinline!reinit! for the variable is active at any event). In case of \lstinline!reinit! active during initialization (due to \lstinline!when initial()!), see \cref{initialization-initial-equation-and-initial-algorithm}. From b2a1a9ae6efb65300b4e96cf36f070458485ee56 Mon Sep 17 00:00:00 2001 From: Hans Olsson Date: Thu, 7 May 2026 23:46:57 +0200 Subject: [PATCH 15/21] Update chapters/equations.tex Co-authored-by: Henrik Tidefelt --- chapters/equations.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chapters/equations.tex b/chapters/equations.tex index 1ce037c69..2764fb5d9 100644 --- a/chapters/equations.tex +++ b/chapters/equations.tex @@ -418,7 +418,7 @@ \subsection{reinit}\label{reinit} \begin{example} If a higher index system is present, i.e., constraints between state variables, some state variables need to be redefined to non-state variables. -During simulation, non-state variables should be chosen in such a way that variables with an applied \lstinline!reinit! are selected as states at least when the corresponding \lstinline!when!-clause bodies become active. +During simulation, non-state variables should be chosen in such a way that variables with an applied \lstinline!reinit! are selected as states at least during the events when the \lstinline!reinit!-equation is active. If this is not possible, an error occurs, since otherwise \lstinline!reinit! would be applied to a non-state variable. Example for the usage of \lstinline!reinit! (bouncing ball): From d63f5157f2d77184d15ba869eb7d1feef43afb34 Mon Sep 17 00:00:00 2001 From: Hans Olsson Date: Fri, 8 May 2026 00:00:34 +0200 Subject: [PATCH 16/21] Update chapters/statements.tex Co-authored-by: Henrik Tidefelt --- chapters/statements.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chapters/statements.tex b/chapters/statements.tex index f38840bb2..0a036ecd6 100644 --- a/chapters/statements.tex +++ b/chapters/statements.tex @@ -318,7 +318,7 @@ \subsection{Return-Statements}\label{return-statements} \subsection{If-Statement}\label{if-statement} -The syntax of an \lstinline!if!-statements\index{if@\robustinline{if}!statement}\index{then@\robustinline{then}!if-statement@\robustinline{if}-statement}\index{else@\robustinline{else}!if-statement@\robustinline{if}-statement}\index{elseif@\robustinline{elseif}!if-statement@\robustinline{if}-statement} is given by \productionref{if-statement} in the grammar. +The syntax of an \lstinline!if!-statement\index{if@\robustinline{if}!statement}\index{then@\robustinline{then}!if-statement@\robustinline{if}-statement}\index{else@\robustinline{else}!if-statement@\robustinline{if}-statement}\index{elseif@\robustinline{elseif}!if-statement@\robustinline{if}-statement} is given by \productionref{if-statement} in the grammar. Here, each \productionref{expression} in the grammar (representing any condition of an \lstinline!if!-clause) must be a scalar \lstinline!Boolean! expression. An \lstinline!if!-statement is seen as a list of branches: one \lstinline!if!-branch, and zero or more \lstinline!elseif!-branches, and an optional \lstinline!else!-branch. One or zero of these branches is selected, by evaluating their conditions sequentially until a condition that evaluates to true is found. From e572a1ef736caaa2cd983038101bf8c612b21a6f Mon Sep 17 00:00:00 2001 From: Hans Olsson Date: Fri, 8 May 2026 09:35:09 +0200 Subject: [PATCH 17/21] Update chapters/equations.tex Co-authored-by: Henrik Tidefelt --- chapters/equations.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chapters/equations.tex b/chapters/equations.tex index 2764fb5d9..ae4260700 100644 --- a/chapters/equations.tex +++ b/chapters/equations.tex @@ -644,7 +644,7 @@ \section{Events and Synchronization}\label{events-and-synchronization} Clocked discrete-time partitions are also treated this way, see \cref{clocked-discrete-time-and-clocked-discretized-continuous-time-partition}. \begin{nonnormative} -Using state events in a \lstinline!when!-clause body is unnecessary because the \lstinline!when!-clause body is not evaluated during continuous integration. +Expressions in \lstinline!when!-clause bodies do not trigger state events since they are not active during during continuous integration. \end{nonnormative} \begin{example} From 22aa705d0b5b85587a940c6adeeb6695f19b2a08 Mon Sep 17 00:00:00 2001 From: Hans Olsson Date: Fri, 8 May 2026 09:36:12 +0200 Subject: [PATCH 18/21] Update chapters/equations.tex Co-authored-by: Henrik Tidefelt --- chapters/equations.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chapters/equations.tex b/chapters/equations.tex index ae4260700..b76592da1 100644 --- a/chapters/equations.tex +++ b/chapters/equations.tex @@ -126,7 +126,7 @@ \subsection{Connect-Equations}\label{connect-equations} \subsection{If-Equations}\label{if-equations} -The syntax of an \lstinline!if!-equations\index{if@\robustinline{if}!equation}\index{then@\robustinline{then}!if-equation@\robustinline{if}-equation}\index{else@\robustinline{else}!if-equation@\robustinline{if}-equation}\index{elseif@\robustinline{elseif}!if-equation@\robustinline{if}-equation} is given by \productionref{if-equation} in the grammar. +The syntax of an \lstinline!if!-equation\index{if@\robustinline{if}!equation}\index{then@\robustinline{then}!if-equation@\robustinline{if}-equation}\index{else@\robustinline{else}!if-equation@\robustinline{if}-equation}\index{elseif@\robustinline{elseif}!if-equation@\robustinline{if}-equation} is given by \productionref{if-equation} in the grammar. Here, each \productionref{expression} in the grammar (representing the condition of any branch of an \lstinline!if!-clause) must be a scalar \lstinline!Boolean! expression. An \lstinline!if!-statement is seen as a list of branches: one \lstinline!if!-branch, and zero or more \lstinline!elseif!-branches, and an optional \lstinline!else!-branch. One or zero of the branches is selected, by evaluating their conditions sequentially until a condition that evaluates to true is found. From f07b4d34e9b8973aa256b1425d8d92fb8344e41e Mon Sep 17 00:00:00 2001 From: Hans Olsson Date: Fri, 8 May 2026 09:39:29 +0200 Subject: [PATCH 19/21] Apply suggestions from code review Moving and adjusting line. Co-authored-by: Henrik Tidefelt --- chapters/statements.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chapters/statements.tex b/chapters/statements.tex index 0a036ecd6..05de59804 100644 --- a/chapters/statements.tex +++ b/chapters/statements.tex @@ -319,12 +319,12 @@ \subsection{Return-Statements}\label{return-statements} \subsection{If-Statement}\label{if-statement} The syntax of an \lstinline!if!-statement\index{if@\robustinline{if}!statement}\index{then@\robustinline{then}!if-statement@\robustinline{if}-statement}\index{else@\robustinline{else}!if-statement@\robustinline{if}-statement}\index{elseif@\robustinline{elseif}!if-statement@\robustinline{if}-statement} is given by \productionref{if-statement} in the grammar. -Here, each \productionref{expression} in the grammar (representing any condition of an \lstinline!if!-clause) must be a scalar \lstinline!Boolean! expression. An \lstinline!if!-statement is seen as a list of branches: one \lstinline!if!-branch, and zero or more \lstinline!elseif!-branches, and an optional \lstinline!else!-branch. One or zero of these branches is selected, by evaluating their conditions sequentially until a condition that evaluates to true is found. If none of the conditions evaluate to true the \lstinline!else!-branch is selected if it exists, otherwise no branch is selected. In an algorithm section, the body of the selected branch is then executed. The bodies of the branches that are not selected have no effect on that model evaluation. +Each branch condition (represented by \productionref{expression} in the grammar) must be a scalar \lstinline!Boolean! expression. \subsection{When-Statements}\label{when-statements} From e33b150549a999e60ffe2ecb5cd5c45afd412ec7 Mon Sep 17 00:00:00 2001 From: Hans Olsson Date: Fri, 8 May 2026 09:53:05 +0200 Subject: [PATCH 20/21] Apply suggestions from code review Move modified line Co-authored-by: Henrik Tidefelt --- chapters/equations.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chapters/equations.tex b/chapters/equations.tex index b76592da1..3efa3b956 100644 --- a/chapters/equations.tex +++ b/chapters/equations.tex @@ -127,12 +127,12 @@ \subsection{Connect-Equations}\label{connect-equations} \subsection{If-Equations}\label{if-equations} The syntax of an \lstinline!if!-equation\index{if@\robustinline{if}!equation}\index{then@\robustinline{then}!if-equation@\robustinline{if}-equation}\index{else@\robustinline{else}!if-equation@\robustinline{if}-equation}\index{elseif@\robustinline{elseif}!if-equation@\robustinline{if}-equation} is given by \productionref{if-equation} in the grammar. -Here, each \productionref{expression} in the grammar (representing the condition of any branch of an \lstinline!if!-clause) must be a scalar \lstinline!Boolean! expression. An \lstinline!if!-statement is seen as a list of branches: one \lstinline!if!-branch, and zero or more \lstinline!elseif!-branches, and an optional \lstinline!else!-branch. One or zero of the branches is selected, by evaluating their conditions sequentially until a condition that evaluates to true is found. If none of the conditions evaluate to true the \lstinline!else!-branch is selected if it exists, otherwise no branch is selected. In an equation section, the equations in the body of the selected branch are seen as equations that must be satisfied. The bodies of the branches that are not selected have no effect on that model evaluation. +Each branch condition (represented by \productionref{expression} in the grammar) must be a scalar \lstinline!Boolean! expression. The \lstinline!if!-equations which do not have exclusively evaluable expressions as switching conditions shall satisfy the following: \begin{itemize} From e984b2c9cba8694c1e98149793a128ebbb554828 Mon Sep 17 00:00:00 2001 From: Hans Olsson Date: Mon, 18 May 2026 14:49:21 +0200 Subject: [PATCH 21/21] Update chapters/equations.tex Co-authored-by: Henrik Tidefelt --- chapters/equations.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chapters/equations.tex b/chapters/equations.tex index 3efa3b956..38dae97d3 100644 --- a/chapters/equations.tex +++ b/chapters/equations.tex @@ -946,7 +946,7 @@ \section{Initialization, initial equation, and initial algorithm}\label{initiali end when; \end{lstlisting} After solving the initialization problem, both \lstinline!b! and \lstinline!pre(b)! are false. -During transient analysis, \lstinline!initial()! is false, so \lstinline!b! changes from falso to true during the first round of the initial event iteration. +During transient analysis, \lstinline!initial()! is false, so \lstinline!b! changes from false to true during the first round of the initial event iteration. This triggers the \lstinline!when!-clause body, and \lstinline!x! gets reinitialized. \end{example}