From d1ffdc43d4258e04c6d05f2cddd11ced9ffec4ce Mon Sep 17 00:00:00 2001 From: HOS Date: Thu, 12 Sep 2024 17:28:49 +0200 Subject: [PATCH 01/10] Clarify impure in systems of equations. --- chapters/functions.tex | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/chapters/functions.tex b/chapters/functions.tex index 60b1c1c2a..a3a35ba9f 100644 --- a/chapters/functions.tex +++ b/chapters/functions.tex @@ -232,6 +232,7 @@ \section{Pure Modelica Functions}\label{pure-modelica-functions} If a function is declared as \lstinline!impure! any function extending from it shall be declared as \lstinline!impure!. \item A deprecated semantics is that external functions (and functions defined in Modelica directly or indirectly calling them) without \lstinline!pure! or \lstinline!impure! keyword are assumed to be impure, but without any restriction on calling them. + Similarly they can be part of systems of equations without restrictions. Except for the function \lstinline!Modelica.Utilities.Streams.print!, a diagnostic must be given if called in a simulation model. \end{itemize} @@ -295,8 +296,8 @@ \section{Pure Modelica Functions}\label{pure-modelica-functions} 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. +Comment: The semantics are undefined if the function call of an impure function is part of an algebraic loop. +This can occur for the deprecated case of external functions assumed to be pure, or when using \lstinline!pure(expression)! to call an impure function in a pure function. \end{nonnormative} \begin{example} From 7b3ed765b25fc41ba22175d9e74ca13345eedd88 Mon Sep 17 00:00:00 2001 From: Hans Olsson Date: Tue, 17 Sep 2024 09:10:01 +0200 Subject: [PATCH 02/10] Update chapters/functions.tex Typo --- chapters/functions.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chapters/functions.tex b/chapters/functions.tex index a3a35ba9f..8a1378edd 100644 --- a/chapters/functions.tex +++ b/chapters/functions.tex @@ -297,7 +297,7 @@ \section{Pure Modelica Functions}\label{pure-modelica-functions} \begin{nonnormative} Comment: The semantics are undefined if the function call of an impure function is part of an algebraic loop. -This can occur for the deprecated case of external functions assumed to be pure, or when using \lstinline!pure(expression)! to call an impure function in a pure function. +This can occur for the deprecated case of external functions assumed to be impure, or when using \lstinline!pure(expression)! to call an impure function in a pure function. \end{nonnormative} \begin{example} From 8373b96f499b8f02be16aedfa74efc3699597511 Mon Sep 17 00:00:00 2001 From: Hans Olsson Date: Tue, 15 Oct 2024 11:16:18 +0200 Subject: [PATCH 03/10] Update chapters/functions.tex Co-authored-by: Henrik Tidefelt --- chapters/functions.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chapters/functions.tex b/chapters/functions.tex index 8a1378edd..e9a8a2c09 100644 --- a/chapters/functions.tex +++ b/chapters/functions.tex @@ -296,7 +296,7 @@ \section{Pure Modelica Functions}\label{pure-modelica-functions} 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. +The semantics are undefined if the function call of an impure function is part of an algebraic loop. This can occur for the deprecated case of external functions assumed to be impure, or when using \lstinline!pure(expression)! to call an impure function in a pure function. \end{nonnormative} From 360e96d323ba6667e50dec8a9b71e5c73031c43e Mon Sep 17 00:00:00 2001 From: HOS Date: Tue, 15 Oct 2024 11:56:10 +0200 Subject: [PATCH 04/10] AsSuggested --- chapters/functions.tex | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/chapters/functions.tex b/chapters/functions.tex index e9a8a2c09..e912bf6a7 100644 --- a/chapters/functions.tex +++ b/chapters/functions.tex @@ -296,7 +296,9 @@ \section{Pure Modelica Functions}\label{pure-modelica-functions} A function having a formal function parameter that is \lstinline!impure! must be marked \lstinline!pure! or \lstinline!impure!. \begin{nonnormative} -The semantics are undefined if the function call of an impure function is part of an algebraic loop. +The side-effect semantics are undefined if the function call of an impure function is part of an algebraic loop. +Specifically the number of calls with external side-effects is unspecified. +However, for impure functions where the outputs only depend on the inputs the algebraic loop should be solved correctly. This can occur for the deprecated case of external functions assumed to be impure, or when using \lstinline!pure(expression)! to call an impure function in a pure function. \end{nonnormative} From f9338b8a288fcdf25dc954ca08ae393d5631ca3e Mon Sep 17 00:00:00 2001 From: HOS Date: Tue, 15 Oct 2024 16:57:01 +0200 Subject: [PATCH 05/10] Reorganize --- chapters/functions.tex | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/chapters/functions.tex b/chapters/functions.tex index e912bf6a7..05d687bdf 100644 --- a/chapters/functions.tex +++ b/chapters/functions.tex @@ -232,7 +232,6 @@ \section{Pure Modelica Functions}\label{pure-modelica-functions} If a function is declared as \lstinline!impure! any function extending from it shall be declared as \lstinline!impure!. \item A deprecated semantics is that external functions (and functions defined in Modelica directly or indirectly calling them) without \lstinline!pure! or \lstinline!impure! keyword are assumed to be impure, but without any restriction on calling them. - Similarly they can be part of systems of equations without restrictions. Except for the function \lstinline!Modelica.Utilities.Streams.print!, a diagnostic must be given if called in a simulation model. \end{itemize} @@ -281,9 +280,15 @@ \section{Pure Modelica Functions}\label{pure-modelica-functions} Binding equations for external objects. \end{itemize} -For initial equations, initial algorithms, and bindings it is an error -if the function calls are part of systems of equations and thus have to -be called multiple times. +For initial equations, initial algorithms, and bindings it is an error if the function calls are part of systems of equations and thus have to be called multiple times. + +\begin{nonnormative} +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. +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. +\end{nonnormative} \begin{nonnormative} A tool is not allowed to perform any optimizations on function @@ -295,13 +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} -The side-effect semantics are undefined if the function call of an impure function is part of an algebraic loop. -Specifically the number of calls with external side-effects is unspecified. -However, for impure functions where the outputs only depend on the inputs the algebraic loop should be solved correctly. -This can occur for the deprecated case of external functions assumed to be impure, or when using \lstinline!pure(expression)! to call an impure function in a pure function. -\end{nonnormative} - \begin{example} \begin{lstlisting}[language=modelica] function evaluateLinear // pure function From cd720e192461a1d1a1edecab3f53b1510230cc6b Mon Sep 17 00:00:00 2001 From: Hans Olsson Date: Thu, 7 Nov 2024 17:18:53 +0100 Subject: [PATCH 06/10] Apply suggestions from code review --- chapters/functions.tex | 2 -- 1 file changed, 2 deletions(-) diff --git a/chapters/functions.tex b/chapters/functions.tex index 14878cb5d..0c46a5d6a 100644 --- a/chapters/functions.tex +++ b/chapters/functions.tex @@ -284,13 +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. -\begin{nonnormative} 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. 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. -\end{nonnormative} \begin{nonnormative} A tool is not allowed to perform any optimizations on function From 32d6a03251512542bb089b2a2e93135f85a4d462 Mon Sep 17 00:00:00 2001 From: Hans Olsson Date: Fri, 29 Nov 2024 15:52:10 +0100 Subject: [PATCH 07/10] Update chapters/functions.tex Co-authored-by: Henrik Tidefelt --- chapters/functions.tex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chapters/functions.tex b/chapters/functions.tex index 0c46a5d6a..16e587d09 100644 --- a/chapters/functions.tex +++ b/chapters/functions.tex @@ -284,8 +284,8 @@ \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. +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. From e31c6b23dd3f784e2f40cff4d3c63bd07bd36dc5 Mon Sep 17 00:00:00 2001 From: Hans Olsson Date: Thu, 9 Jan 2025 14:38:37 +0100 Subject: [PATCH 08/10] Update chapters/functions.tex Co-authored-by: Henrik Tidefelt --- chapters/functions.tex | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/chapters/functions.tex b/chapters/functions.tex index 16e587d09..5b0fad9a2 100644 --- a/chapters/functions.tex +++ b/chapters/functions.tex @@ -284,8 +284,7 @@ \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. +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. From d002fa07227da5462bf14397ee127a8629b37952 Mon Sep 17 00:00:00 2001 From: Hans Olsson Date: Fri, 17 Jan 2025 16:35:56 +0100 Subject: [PATCH 09/10] Update chapters/functions.tex Co-authored-by: Henrik Tidefelt --- chapters/functions.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chapters/functions.tex b/chapters/functions.tex index 5b0fad9a2..3c6becc06 100644 --- a/chapters/functions.tex +++ b/chapters/functions.tex @@ -286,7 +286,7 @@ \section{Pure Modelica Functions}\label{pure-modelica-functions} 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. +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} From 9abd58f3af23db9b9ae58fd57efb53d908228c6a Mon Sep 17 00:00:00 2001 From: Hans Olsson Date: Fri, 17 Jan 2025 16:36:23 +0100 Subject: [PATCH 10/10] Update chapters/functions.tex Co-authored-by: Henrik Tidefelt --- chapters/functions.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chapters/functions.tex b/chapters/functions.tex index 3c6becc06..b18f58c36 100644 --- a/chapters/functions.tex +++ b/chapters/functions.tex @@ -285,7 +285,7 @@ \section{Pure Modelica Functions}\label{pure-modelica-functions} 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. +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.