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 7 commits into
base: master
Choose a base branch
from

Conversation

HansOlsson
Copy link
Collaborator

No description provided.

chapters/functions.tex Outdated Show resolved Hide resolved
Comment on lines 299 to 300
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 impure, or when using \lstinline!pure(expression)! to call an impure function in a pure function.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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 impure, or when using \lstinline!pure(expression)! to call an impure function in a pure function.
Comment: The exact 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.

I believe this was the intended idea.

Not a general undefined-behavior in C-terms (with nasal demons etc), but just the pragmatic point that you cannot solve an algebraic loop with an impure function that e.g., returns the current time in nano-seconds, and that you have no control of the number of external side-effects generated.

That's why it is non-normative.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about speaking of side-effect semantics? Wouldn't that then be nicely elaborated by the outputs-only-depending-on-inputs rule?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, makes sense.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have now done that.

chapters/functions.tex Outdated Show resolved Hide resolved
@@ -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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we manage to write the text clearly, there shouldn't be a need for this sentence, as the systems-of-equations rule should be perceived as one of the calling restrictions.

Copy link
Collaborator

@henrikt-ma henrikt-ma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main issue which I still find unresolved is that we both have

  1. It is an error if an impure function call is part of a systems of equations (including linear systems), even if called in agreement with the restrictions above.

and

  1. …if the function call of an impure function is part of an algebraic loop. … This can occur…

Could we avoid this contradiction by a more careful formulation of 1, something like this:

Inside systems of equations (including linear systems), an impure function call is only allowed in the deprecated case of an external function neither marked pure or impure, or when pure(…) is used to bypass purity checking. The system of equations shall then be solved as if all occurring functions were pure, but the side-effect semantics of the impure function calls are undefined. Specifically, the number of times an impure function is called when solving the equations is undefined.

@HansOlsson
Copy link
Collaborator Author

@henrikt-ma this should now handle the comments.

@HansOlsson
Copy link
Collaborator Author

@henrikt-ma is it ok now?

@HansOlsson HansOlsson added this to the 2024-November milestone Nov 6, 2024
chapters/functions.tex Outdated Show resolved Hide resolved
chapters/functions.tex Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants