Skip to content

Try to clean up clause-meaning.#3896

Open
HansOlsson wants to merge 20 commits into
modelica:masterfrom
HansOlsson:Clauses
Open

Try to clean up clause-meaning.#3896
HansOlsson wants to merge 20 commits into
modelica:masterfrom
HansOlsson:Clauses

Conversation

@HansOlsson
Copy link
Copy Markdown
Collaborator

Closes #3840

Not sure if we should add this to 3.7; or delay it.

However, the current situation isn't good either as seen in #3840; and in particular "when-clause" sometimes previously meant "body of a when- or else-when-clause"; and is now written as "body of when-clause".

I believe it is correct, but will try to look again.

@HansOlsson HansOlsson added this to the ModelicaSpec3.7 milestone May 6, 2026
@HansOlsson HansOlsson requested a review from henrikt-ma May 6, 2026 13:41
@henrikt-ma
Copy link
Copy Markdown
Collaborator

That is a lot of body of… we better make sure we really like this new terminology.

@HansOlsson
Copy link
Copy Markdown
Collaborator Author

That is a lot of body of… we better make sure we really like this new terminology.

I agree that it is used a lot, but to me that is necessary to differentiate between when pre(x)>0 then... and when b then y=pre(x)..., as the rules for two pre-uses differ.

Using "in a when-clause" to refer to "in the body of when-clause" (i.e., excluding its condition) as previously done isn't very clear (apart from the terminology not being applied consistently).

Obviously something other than "body" could be used, but we used "body" a few times before.

@henrikt-ma
Copy link
Copy Markdown
Collaborator

Just changing body of when-clause into when-clause body (and variations thereof) would make it read a bit lighter.

@HansOlsson
Copy link
Copy Markdown
Collaborator Author

Just changing body of when-clause into when-clause body (and variations thereof) would make it read a bit lighter.

Done. For those clauses. Note that "body of" is used in some other places as well (not changed by this PR), we should clean up that later.

@HansOlsson HansOlsson marked this pull request as ready for review May 7, 2026 13:16
@HansOlsson
Copy link
Copy Markdown
Collaborator Author

Poll:
Favor of adding (if time): Hans, Markus, Johannes, Quentin, Henrik (based on if time), Dag
Against:
Abstain: Chen

Comment thread chapters/classes.tex
Comment thread chapters/equations.tex Outdated
Comment thread chapters/equations.tex Outdated
Comment thread chapters/equations.tex Outdated
Co-authored-by: Henrik Tidefelt <henrikt@wolfram.com>
Comment thread chapters/equations.tex Outdated
Comment thread chapters/equations.tex Outdated
Comment thread chapters/equations.tex Outdated
Comment thread chapters/equations.tex
After solving the initialization problem, both \lstinline!b! and \lstinline!pre(b)! are false.
During transient analysis, \lstinline!initial()! is false, so \lstinline!b! changes from falso to true during the first round of the initial event iteration.
This triggers the \lstinline!when!-clause, and \lstinline!x! gets reinitialized.
This triggers the \lstinline!when!-clause body, and \lstinline!x! gets reinitialized.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Isn't it better to speak of triggered branches than triggered bodies?

Suggested change
This triggers the \lstinline!when!-clause body, and \lstinline!x! gets reinitialized.
This triggers the \lstinline!when!-clause branch, and \lstinline!x! gets reinitialized.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

As above I think that only the body is active/triggered.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'd say it's especially when speaking of triggering that branch makes much better sense than body.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Thinking more I believe that a solution might be something subtly different (which indicates that more time is needed).

I still think that only the body is really triggered, whereas the condition is triggering it.

Both of these are part of the branch, so to me it seems that the branch should be more active (instead of passively getting triggered). Perhaps something like:

Suggested change
This triggers the \lstinline!when!-clause body, and \lstinline!x! gets reinitialized.
The \lstinline!when!-clause branch triggers, and \lstinline!x! gets reinitialized.

possibly replace "triggers" by "triggers based on the change in b".

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The difference is very subtle and I don't see why the active way to see it would make more sense than the passive, while at least the passive is more easy to concisely connect with the previous sentence.

Comment thread chapters/operatorsandexpressions.tex Outdated
Comment thread chapters/operatorsandexpressions.tex Outdated
Comment thread chapters/operatorsandexpressions.tex Outdated
Comment thread chapters/operatorsandexpressions.tex Outdated
Co-authored-by: Henrik Tidefelt <henrikt@wolfram.com>

For purposes of event iteration, each scalar expression in a \lstinline!when!-clause condition is treated as an implicit variable \lstinline!v!.
Since the \lstinline!when!-clause is triggered when \lstinline!v and not pre(v)!, the implicit variable is considered wrapped in \lstinline!pre($\ldots$)! and becomes part of the event iteration convergence criterion.
Since a \lstinline!when!-clause body is triggered when \lstinline!v and not pre(v)!, the implicit variable is considered wrapped in \lstinline!pre($\ldots$)! and becomes part of the event iteration convergence criterion.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Triggered branch:

Suggested change
Since a \lstinline!when!-clause body is triggered when \lstinline!v and not pre(v)!, the implicit variable is considered wrapped in \lstinline!pre($\ldots$)! and becomes part of the event iteration convergence criterion.
Since a \lstinline!when!-clause branch is triggered when \lstinline!v and not pre(v)!, the implicit variable is considered wrapped in \lstinline!pre($\ldots$)! and becomes part of the event iteration convergence criterion.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

As above I think that only the body is active/triggered, and the condition of the branch does the triggering.

Comment thread chapters/operatorsandexpressions.tex Outdated
Comment thread chapters/operatorsandexpressions.tex Outdated
Comment thread chapters/operatorsandexpressions.tex Outdated
Co-authored-by: Henrik Tidefelt <henrikt@wolfram.com>
Comment thread chapters/operatorsandexpressions.tex Outdated
Comment thread chapters/statements.tex Outdated
Comment thread chapters/statements.tex Outdated
Comment thread chapters/equations.tex Outdated
@henrikt-ma
Copy link
Copy Markdown
Collaborator

I have completed my initial sweep over this now, but need to take a break now and continue later today.

Co-authored-by: Henrik Tidefelt <henrikt@wolfram.com>
@HansOlsson HansOlsson added the clarification Specification of feature is unclear, but not incorrect label May 7, 2026
Co-authored-by: Henrik Tidefelt <henrikt@wolfram.com>
Comment thread chapters/equations.tex Outdated
HansOlsson and others added 2 commits May 7, 2026 23:46
Co-authored-by: Henrik Tidefelt <henrikt@wolfram.com>
Co-authored-by: Henrik Tidefelt <henrikt@wolfram.com>
Comment thread chapters/statements.tex Outdated
Co-authored-by: Henrik Tidefelt <henrikt@wolfram.com>
Comment thread chapters/statements.tex
Comment thread chapters/statements.tex Outdated
Comment thread chapters/equations.tex Outdated
Comment thread chapters/equations.tex
Comment thread chapters/equations.tex Outdated
@HansOlsson
Copy link
Copy Markdown
Collaborator Author

I think there are so many minor things that it is best to delay this PR (as it is just a clarification, not a new feature).

HansOlsson and others added 4 commits May 8, 2026 09:35
Co-authored-by: Henrik Tidefelt <henrikt@wolfram.com>
Co-authored-by: Henrik Tidefelt <henrikt@wolfram.com>
Moving and adjusting line.

Co-authored-by: Henrik Tidefelt <henrikt@wolfram.com>
Move modified line

Co-authored-by: Henrik Tidefelt <henrikt@wolfram.com>
Comment thread chapters/equations.tex
@@ -946,7 +947,7 @@ \section{Initialization, initial equation, and initial algorithm}\label{initiali
\end{lstlisting}
After solving the initialization problem, both \lstinline!b! and \lstinline!pre(b)! are false.
During transient analysis, \lstinline!initial()! is false, so \lstinline!b! changes from falso to true during the first round of the initial event iteration.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nearby typo:

Suggested change
During transient analysis, \lstinline!initial()! is false, so \lstinline!b! changes from falso to true during the first round of the initial event iteration.
During transient analysis, \lstinline!initial()! is false, so \lstinline!b! changes from false to true during the first round of the initial event iteration.

@HansOlsson HansOlsson removed this from the ModelicaSpec3.7 milestone May 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clarification Specification of feature is unclear, but not incorrect

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Clarify meaning of when-clause

2 participants