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

Add variability change for these functions. #3610

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
6 changes: 5 additions & 1 deletion chapters/operatorsandexpressions.tex
Original file line number Diff line number Diff line change
Expand Up @@ -1644,10 +1644,14 @@ \subsection{Discrete-Time Expressions}\label{discrete-time-expressions}
Note that \lstinline!rem! and \lstinline!mod! generate events but are not discrete-time expressions.
In other words, relations inside \lstinline!noEvent!, such as \lstinline!noEvent(x>1)!, are not discrete-time expressions.
\end{nonnormative}
\item
Unless inside \lstinline!noEvent!: Function calls where the function has annotation \lstinline!GenerateEvents = true! (\Cref{modelica:GenerateEvents}) and the output does not contain a subtype of \lstinline!Real!.
For a function call returning multiple return values (see \cref{output-formal-parameters-of-functions}) the variability is decided separately for each output.
These calls will generate events, \Cref{modelica:GenerateEvents}.
\item
The functions \lstinline!pre!, \lstinline!edge!, and \lstinline!change! result in discrete-time expressions.
\item
Expressions in functions behave as though they were discrete-time expressions.
Expressions in functions not having annotation \lstinline!GenerateEvents = true! (\Cref{modelica:GenerateEvents}), behave as though they were discrete-time expressions.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't we need more specification of variability inside functions that do have GenerateEvents = true? We don't want all expressions inside such function bodies to get non-discrete-time variability, right?

Copy link
Collaborator

@henrikt-ma henrikt-ma Nov 29, 2024

Choose a reason for hiding this comment

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

This could be a start…

Suggested change
Expressions in functions not having annotation \lstinline!GenerateEvents = true! (\Cref{modelica:GenerateEvents}), behave as though they were discrete-time expressions.
The variability of expressions inside functions depends upon the \lstinline!GenerateEvents! annotation (\Cref{modelica:GenerateEvents}).
With \lstinline!GenerateEvents = true!, expression variability is determined according to the same rules as outside of functions.
Otherwise, all expressions have at most discrete-time variability (some expressions, such as function inputs and literals have lower variability).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That was the intent of the text I wrote (ignoring the misplaced trailing quotes).

The overall structure of that secition is that it specifies when expressions have lower variability. Stating that functions having GenerateEvents=true use the same rule as non-function is thus not needed, and similarly there is no need to say "at most discrete-time" as the less variable cases should already be handled.

Copy link
Collaborator

Choose a reason for hiding this comment

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

OK, makes sense. The formulation is a bit unusual, though, shouldn't we simply say:

Suggested change
Expressions in functions not having annotation \lstinline!GenerateEvents = true! (\Cref{modelica:GenerateEvents}), behave as though they were discrete-time expressions.
Expressions in functions not having annotation \lstinline!GenerateEvents = true! (\Cref{modelica:GenerateEvents}).

This item would then look better before or after Expressions in a clocked discrete-time partition.

I also think there is a missing \cref{discrete-time-expressions} link to this section from this item in functions.tex, and the item would need to be updated according to whatever semantics we come up with here:

Components of a function will inside the function behave as though they had discrete-time variability.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The "behave as though they were discrete-time expressions." have been present for quite some time on some of the entries. I don't want to change them as part of this PR.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

And added the other reference.

\end{itemize}

Inside an \lstinline!if!-expression, \lstinline!if!-clause, \lstinline!while!-statement or \lstinline!for!-clause, that is controlled by a non-discrete-time (that is continuous-time, but not discrete-time) switching expression and not in the body of a \lstinline!when!-clause, it is not legal to have assignments to discrete-time variables, equations between discrete-time expressions, or real elementary relations/functions that should generate events.
Expand Down