Skip to content

Commit

Permalink
Clarify impure in systems of equations. (#3571)
Browse files Browse the repository at this point in the history
* Clarify impure in systems of equations.
* Update chapters/functions.tex
Co-authored-by: Henrik Tidefelt <henrikt@wolfram.com>
  • Loading branch information
HansOlsson authored Jan 17, 2025
1 parent 8a9ccf9 commit ce07d23
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions chapters/functions.tex
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,11 @@ \section{Pure Modelica Functions}\label{pure-modelica-functions}
The reason is that solving systems of equations generally requires expressions to be evaluated an unknown number of times.
This includes the special handling of \lstinline!when initial()! during initialization.

There are two ways in which an impure function could be called in a system of equations, namely in the deprecated case of external functions assumed to be impure, and when using \lstinline!pure($\ldots$)! to call an impure function from within a pure function.
The side-effect semantics of the function call are then undefined.
Specifically, the number of calls with external side-effects is unspecified.
However, for impure functions where the outputs only depend on the inputs the system of equations should be solved correctly.

\begin{nonnormative}
A tool is not allowed to perform any optimizations on function
calls to an impure function, e.g., reordering calls from different
Expand All @@ -294,11 +299,6 @@ \section{Pure Modelica Functions}\label{pure-modelica-functions}
By \cref{function-compatibility-or-function-subtyping-for-functions}, it follows that an impure function can only be passed as argument to a function formal parameter of impure type.
A function having a formal function parameter that is \lstinline!impure! must be marked \lstinline!pure! or \lstinline!impure!.

\begin{nonnormative}
Comment: The semantics are undefined if the function call of an
impure function is part of an algebraic loop.
\end{nonnormative}

\begin{example}
\begin{lstlisting}[language=modelica]
function evaluateLinear // pure function
Expand Down

0 comments on commit ce07d23

Please sign in to comment.