Skip to content
Merged

Clarify #3786

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions chapters/functions.tex
Original file line number Diff line number Diff line change
Expand Up @@ -1474,16 +1474,21 @@ \subsection{Using the Derivative Annotation}\label{using-the-derivative-annotati

\subsection{Partial Derivatives of Functions}\label{partial-derivatives-of-functions}\index{partial derivative}\index{der@\robustinline{der}!partial derivative}

A class defined as:
A function class defined as follows is a partial derivative of another function:
\begin{lstlisting}[language=grammar]
IDENT "=" der "(" name "," IDENT { "," IDENT } ")" comment
\end{lstlisting}
is the partial derivative of a function, and may only be used as declarations of functions.

The semantics is that a function (and only a function) can be specified in this form, defining that it is the partial derivative of the function to the right of the equal sign (looked up in the same way as a short class definition, and the looked up name must be a function), and partially differentiated with respect to each {\lstinline!IDENT!} in order (starting from the first one).
Each {\lstinline!IDENT!} must be a scalar {\lstinline!Real!} input to the function.
In \lstinline!$f$ = der($g$, $u_{1}, \ldots$)!, the function being defined is named $f$, and the function being differentiated is $g$.
The name $g$ is looked up in the same way as a in short class definition, and the referenced class must be a function.
Each $u_{i}$ must be a scalar {\lstinline!Real!} input to the function, and corresponds mathematically to prepending $\frac{\partial}{\partial u_{i}}$ to the function call.
The $u_{i}$ are applied in increasing order of $i$ (although the partial derivatives commute for a broad class of functions).

The comment allows a user to comment the function (in the info-layer and as one-line description, and as icon).
\begin{nonnormative}
In mathematical notation, the order of partial differentiation is reversed compared to the function definition; \lstinline!der($g$, $x$, $y$)! means $\frac{\partial}{\partial y}\frac{\partial}{\partial x}g$.
\end{nonnormative}

The \lstinline[language=grammar]!comment! has the same semantics as in a short class definition, for instance allowing the function to be given a description string, as well as \lstinline!Documentation! and \lstinline!Icon! annotations.

\begin{example}
The specific enthalpy can be computed from a Gibbs-function as follows:
Expand All @@ -1502,9 +1507,9 @@ \subsection{Partial Derivatives of Functions}\label{partial-derivatives-of-funct
h := Gibbs(p, T) - T * Gibbs_T(p, T);
end specificEnthalpy;
\end{lstlisting}
Thus \lstinline!der(Gibbs, T)! corresponds to $\frac{\partial \text{\lstinline!Gibbs(p, T)!}}{\partial \text{\lstinline!T!}} = \frac{\partial}{\partial \text{\lstinline!T!}}\text{\lstinline!Gibbs!}$.
\end{example}


\subsection{Using the Inverse Annotation}\label{using-the-inverse-annotation}

If a function $f_1$ with one output formal parameter $y$ can be restricted to an informally defined domain and codomain, such that the mapping of the input formal parameter $u_{k}$ to $y$ is bijective for any fixed assignment to the other input formal parameters in the domain (see examples below), then it can be given an \fmtannotationindex{inverse} annotation to provide an explicit inverse $f_2$ to this mapping, provided that the function is only applied on this domain:
Expand Down