Skip to content

Commit

Permalink
Cleanup related to 'function'
Browse files Browse the repository at this point in the history
  • Loading branch information
henrikt-ma committed Oct 13, 2020
1 parent 99f8fb8 commit 6705aee
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 34 deletions.
2 changes: 1 addition & 1 deletion chapters/classes.tex
Expand Up @@ -801,7 +801,7 @@ \section{Specialized Classes}\label{specialized-classes}
See \cref{function-as-a-specialized-class} for restrictions and enhancements of functions. Enhanced to allow the function to contain an external function interface.

\begin{nonnormative}
Non-function specialized classes do not have this property.
Non-\lstinline!function! specialized classes do not have this property.
\end{nonnormative}

\item \lstinline!connector! --
Expand Down
3 changes: 1 addition & 2 deletions chapters/equations.tex
Expand Up @@ -630,8 +630,7 @@ \section{Events and Synchronization}\label{events-and-synchronization}
used to guard against \emph{outside domain} errors, e.g.\ \lstinline!y = if noEvent(x>= 0) then sqrt(x) else 0.!
\end{example}

All equations and assignment statements within when-clauses and all assignment statements within function classes are implicitly treated with \lstinline!noEvent!, i.e., relations within the scope of
these operators never induce state or time events.
All equations and assignment statements within when-clauses and all assignment statements within \lstinline!function! classes are implicitly treated with \lstinline!noEvent!, i.e., relations within the scope of these operators never induce state or time events.

\begin{nonnormative}
Using state events in when-clauses is unnecessary because the body of a when-clause is not evaluated during continuous integration.
Expand Down
36 changes: 11 additions & 25 deletions chapters/functions.tex
Expand Up @@ -113,7 +113,7 @@ \subsection{Inheritance of Functions}\label{inheritance-of-functions}
following the usual rules for inheritance of classes (\cref{inheritance-modification-and-redeclaration}).

\begin{nonnormative}
For example, it is possible to modify and extend a function class to add default values for input variables.
For example, it is possible to modify and extend a \lstinline!function! class to add default values for input variables.
\end{nonnormative}

\section{Function as a Specialized Class}\label{function-as-a-specialized-class}
Expand Down Expand Up @@ -199,8 +199,7 @@ \section{Function as a Specialized Class}\label{function-as-a-specialized-class}
\item
Instances of functions have a special meaning, see \cref{functional-input-arguments-to-functions}.
\item
The lookup of the function class to be called is extended, see
\cref{composite-name-lookup}.
The lookup of the \lstinline!function! class to be called is extended, see \cref{composite-name-lookup}.
\end{itemize}
\item
A function can be \emph{recursive}.
Expand Down Expand Up @@ -828,29 +827,20 @@ \subsection{Flexible Array Sizes and Resizing of Arrays in Functions}\label{flex

\subsection{Scalar Functions Applied to Array Arguments}\label{scalar-functions-applied-to-array-arguments}

Functions with one scalar return value can be applied to arrays
element-wise, e.g.\ if \lstinline!A! is a vector of reals, then \lstinline!sin(A)! is a vector
where each element is the result of applying the function \lstinline!sin! to the
corresponding element in \lstinline!A!. Only function classes that are transitively
non-replaceable (\cref{transitively-non-replaceable} and \cref{restrictions-on-base-classes-and-constraining-types-to-be-transitively-non-replaceable}) may be called vectorized.
Functions with one scalar return value can be applied to arrays element-wise, e.g.\ if \lstinline!A! is a vector of reals, then \lstinline!sin(A)! is a vector where each element is the result of applying the function \lstinline!sin! to the corresponding element in \lstinline!A!. Only \lstinline!function! classes that are transitively non-replaceable (\cref{transitively-non-replaceable} and \cref{restrictions-on-base-classes-and-constraining-types-to-be-transitively-non-replaceable}) may be called vectorized.

Consider the expression \lstinline!f(arg1,...,argn)!, an application of the function
\lstinline!f! to the arguments \lstinline!arg1,..., argn! is defined.
Consider the expression \lstinline!f(arg1, $\ldots$, argn)!, an application of the function \lstinline!f! to the arguments \lstinline!arg1!, \ldots, \lstinline!argn! is defined.

For each passed argument, the type of the argument is checked against
the type of the corresponding formal parameter of the function.

\begin{enumerate}
\item
\item\label{argument-type-check-match}
If the types match, nothing is done.
\item
If the types do not match, and a type conversion can be applied, it is
applied. Continue with step 1.
applied. Continue with step~\ref{argument-type-check-match}.
\item
If the types do not match, and no type conversion is applicable, the
passed argument type is checked to see if it is an n-dimensional array
of the formal parameter type. If it is not, the function call is
invalid. If it is, we call this a foreach argument.
If the types do not match, and no type conversion is applicable, the passed argument type is checked to see if it is an $n$-dimensional array of the formal parameter type. If it is not, the function call is invalid. If it is, we call this a \emph{foreach argument}.
\item
For all foreach arguments, the number and sizes of dimensions must
match. If they do not match, the function call is invalid.
Expand All @@ -859,16 +849,12 @@ \subsection{Scalar Functions Applied to Array Arguments}\label{scalar-functions-
fashion, and the result has the type specified by the function
definition.
\item
The result of the function call expression is an n-dimensional array
with the same dimension sizes as the foreach arguments. Each element
ei,..,j is the result of applying f to arguments constructed from the
original arguments in the following way:
The result of the function call expression is an $n$-dimensional array with the same dimension sizes as the foreach arguments. Each element \lstinline!ei!, \ldots, \lstinline!j! is the result of applying \lstinline!f! to arguments constructed from the original arguments in the following way:
\begin{itemize}
\item
If the argument is not a foreach argument, it is used as-is.
\item
If the argument is a foreach argument, the element at index
\lstinline![i, $\ldots$, j]! is used.
If the argument is a foreach argument, the element at index \lstinline![i, $\ldots$, j]! is used.
\end{itemize}
\end{enumerate}

Expand All @@ -878,8 +864,8 @@ \subsection{Scalar Functions Applied to Array Arguments}\label{scalar-functions-
\begin{example}
\begin{lstlisting}[language=modelica]
sin({a, b, c}) = {sin(a), sin(b), sin(c)} // argument is a vector
sin([a,b,c]) = [sin(a),sin(b),sin(c)] // argument may be a matrix
atan({a,b,c},{d,e,f}) = {atan(a,d), atan(b,e), atan(c,f)}
sin([a, b, c]) = [sin(a), sin(b), sin(c)] // argument may be a matrix
atan({a, b, c}, {d, e, f}) = {atan(a, d), atan(b, e), atan(c, f)}
\end{lstlisting}
This works even if the function is declared to take an array as
one of its arguments. If \lstinline!pval! is defined as a function that takes
Expand Down
4 changes: 1 addition & 3 deletions chapters/interface.tex
Expand Up @@ -536,9 +536,7 @@ \section{Function-Compatibility or Function-Subtyping for Functions}\label{funct
\end{nonnormative}

\begin{definition}[Function-compatibility or function-subtyping for functions]
A function class \lstinline!A! is \emph{function-compatible with or a function
subtype of} function class \lstinline!B! iff (the terms \emph{function-compatible}
and \emph{function subtype} of are synonyms and used interchangeably):
A \lstinline!function! class \lstinline!A! is \emph{function-compatible with or a function subtype of} \lstinline!function! class \lstinline!B! iff (the terms \emph{function-compatible} and \emph{function subtype} of are synonyms and used interchangeably):
\begin{itemize}
\item
\lstinline!A! is compatible to (subtype of) \lstinline!B!.
Expand Down
6 changes: 3 additions & 3 deletions chapters/operatorsandexpressions.tex
Expand Up @@ -1298,7 +1298,7 @@ \subsection{Event-Related Operators with Function Syntax}\label{event-related-op
pre($y$)
\end{lstlisting}\end{synopsis}
\begin{semantics}
Returns the \emph{left limit} $y(t^{-})$ of variable $y(t)$ at a time instant $t$. At an event instant, $y(t^{-})$ is the value of $y$ after the last event iteration at time instant $t$ (see comment below). Any subscripts in the component expression $y$ must be parameter expressions. \lstinline!pre! can be applied if the following three conditions are fulfilled simultaneously: (a) variable $y$ is either a subtype of a simple type or is a record component, (b) $y$ is a discrete-time expression (c) the operator is \emph{not} applied in a function class.
Returns the \emph{left limit} $y(t^{-})$ of variable $y(t)$ at a time instant $t$. At an event instant, $y(t^{-})$ is the value of $y$ after the last event iteration at time instant $t$ (see comment below). Any subscripts in the component expression $y$ must be parameter expressions. \lstinline!pre! can be applied if the following three conditions are fulfilled simultaneously: (a) variable $y$ is either a subtype of a simple type or is a record component, (b) $y$ is a discrete-time expression (c) the operator is \emph{not} applied in a \lstinline!function! class.
\begin{nonnormative}
This can be applied to continuous-time variables in when-clauses, see \cref{discrete-time-expressions} for the definition of discrete-time expression.
\end{nonnormative}
Expand All @@ -1319,7 +1319,7 @@ \subsection{Event-Related Operators with Function Syntax}\label{event-related-op
edge($b$)
\end{lstlisting}\end{synopsis}
\begin{semantics}
Expands into \lstinline!($b$ and not pre($b$))! for \lstinline!Boolean! variable $b$. The same restrictions as for \lstinline!pre! apply (e.g.\ not to be used in function classes).
Expands into \lstinline!($b$ and not pre($b$))! for \lstinline!Boolean! variable $b$. The same restrictions as for \lstinline!pre! apply (e.g.\ not to be used in \lstinline!function! classes).
\end{semantics}
\end{operatordefinition}

Expand Down Expand Up @@ -1424,7 +1424,7 @@ \subsection{Parameter Expressions}\label{parameter-expressions}
\item
\lstinline!cardinality(c)!, see restrictions for use in \cref{cardinality-deprecated}.
\item
\lstinline!end! in \lstinline!A[$\ldots$ end $\ldots$]! if \lstinline!A! is variable declared in a non-function class.
\lstinline!end! in \lstinline!A[$\ldots$ end $\ldots$]! if \lstinline!A! is variable declared in a non-\lstinline!function! class.
\item
\lstinline!size(A)! (including \lstinline!size(A, j)! where \lstinline!j! is parameter expression) if \lstinline!A! is variable declared in a non-function class.
\item
Expand Down

0 comments on commit 6705aee

Please sign in to comment.