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

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

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 are undefined in this case.
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 +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