Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify impure in systems of equations. #3571

Merged
merged 11 commits into from
Jan 17, 2025
11 changes: 6 additions & 5 deletions chapters/functions.tex
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,12 @@ \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.

It is still possible to call an impure function in a system of equations in specific ways.
Specifically for the deprecated case of external functions assumed to be impure, and when using \lstinline!pure(expression)! to call an impure function in a pure function.
HansOlsson marked this conversation as resolved.
Show resolved Hide resolved
The side-effect semantics are undefined in this case.
HansOlsson marked this conversation as resolved.
Show resolved Hide resolved
Specifically the number of calls with external side-effects is unspecified.
HansOlsson marked this conversation as resolved.
Show resolved Hide resolved
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 +300,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