Skip to content

Commit

Permalink
Clean up a couple of tables related to arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
henrikt-ma committed Sep 25, 2020
1 parent a135179 commit 9cf69af
Showing 1 changed file with 69 additions and 59 deletions.
128 changes: 69 additions & 59 deletions chapters/arrays.tex
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,24 @@ \section{Array Declarations}\label{array-declarations}
\end{itemize}

% IMPROVETOP
\begin{longtable}{|l|l|l|l|p{4cm}|}
\caption{General forms of declaration of arrays.}\\
\begin{table}[H]
\caption{General forms of declaration of arrays. The notation \lstinline!EB! stands for an enumeration type or \lstinline!Boolean!. The general array array can have zero or more dimensions ($k \geq 0$).}
\begin{center}
\begin{tabular}{l l c l l}
\hline
\tablehead{Modelica form 1} & \tablehead{Modelica form 2} & \tablehead{\# dims} & \tablehead{Designation} & \tablehead{Explanation}\\ \hline
\endhead
\lstinline!C x!; & \lstinline!C x!; & $0$ & Scalar & Scalar\\ \hline
\lstinline!C[$n$] x;! & \lstinline!C x[$n$];! & $1$ & Vector & $n$-Vector\\ \hline
\lstinline!C[EB] x;! & \lstinline!C x[EB]! & $1$ & Vector & Vector index by enumeration or \lstinline!Boolean! type \lstinline!EB!\\ \hline
\lstinline!C[$n$, $m$] x;! & \lstinline!C x[$n$, $m$];! & $2$ & Matrix & $n \times m$ Matrix\\ \hline
\tablehead{Modelica form 1} & \tablehead{Modelica form 2} & \tablehead{\# dims} & \tablehead{Designation} & \tablehead{Explanation}\\
\hline
\hline
\lstinline!C x!; & \lstinline!C x!; & $0$ & Scalar & Scalar\\
\lstinline!C[$n$] x;! & \lstinline!C x[$n$];! & $1$ & Vector & $n$-vector\\
\lstinline!C[EB] x;! & \lstinline!C x[EB]! & $1$ & Vector & Vector indexed by \lstinline!EB!\\
\lstinline!C[$n$, $m$] x;! & \lstinline!C x[$n$, $m$];! & $2$ & Matrix & $n \times m$ matrix\\
\lstinline!C[$n_1$, $n_{2}$, $\ldots$, $n_k$] x;! &
\lstinline!C x[$n_{1}$, $n_{2}$, $\ldots$, $n_{k}$];! & $k$ & Array & Array with $k$ dimensions ($k \geq 0$).\\ \hline
\end{longtable}
\lstinline!C x[$n_{1}$, $n_{2}$, $\ldots$, $n_{k}$];! & $k$ & Array & General array\\
\hline
\end{tabular}
\end{center}
\end{table}

\begin{example}
The number of dimensions and the dimensions sizes are part of
Expand Down Expand Up @@ -103,21 +109,24 @@ \section{Array Declarations}\label{array-declarations}
\end{lstlisting}
\end{example}

Zero-valued dimensions are allowed, so: \lstinline!C x[0];! declares an empty vector and: \lstinline!C x[0,3]!; an empty matrix.
Zero-valued dimensions are allowed, so: \lstinline!C x[0];! declares an empty vector, and: \lstinline!C x[0, 3];! an empty matrix. Some examples of array dimensions of size one are given in \cref{tab:size-1-dimensions}.

\begin{nonnormative}
Special cases:
\begin{longtable}{|l|l|l|l|p{3cm}|}
\caption{Declaration of arrays as 1-vectors, row-vectors, or column-vectors of arrays.}\\
\begin{table}[H]
\caption{Special cases of declaration of arrays as 1-vectors, row-vectors, or column-vectors of arrays.}\label{tab:size-1-dimensions}
\begin{center}
\begin{tabular}{l l c l l}
\hline
\tablehead{Modelica form 1} & \tablehead{Modelica form 2} & \tablehead{\# dims} & \tablehead{Designation} & \tablehead{Explanation}\\ \hline
\endhead
\lstinline!C[1] x;! & \lstinline!C x[1];! & $1$ & Vector & 1-Vector, representing a scalar\\ \hline
\lstinline!C[1, 1] x;! & \lstinline!C x[1, 1];! & $2$ & Matrix & $(1 \times 1)$-Matrix, representing a scalar\\ \hline
\lstinline!C[$n$, 1] x;! & \lstinline!C x[$n$, 1];! & $2$ & Matrix & $(n \times 1)$-Matrix, representing a column\\ \hline
\lstinline!C[1, $n$] x;! & \lstinline!C x[1, $n$];! & $2$ & Matrix & $(1 \times n)$-Matrix, representing a row\\ \hline
\end{longtable}
\end{nonnormative}
\tablehead{Modelica form 1} & \tablehead{Modelica form 2} & \tablehead{\# dims} & \tablehead{Designation} & \tablehead{Explanation}\\
\hline
\hline
\lstinline!C[1] x;! & \lstinline!C x[1];! & $1$ & Vector & 1-vector, representing a scalar\\
\lstinline!C[1, 1] x;! & \lstinline!C x[1, 1];! & $2$ & Matrix & $(1 \times 1)$-matrix, representing a scalar\\
\lstinline!C[$n$, 1] x;! & \lstinline!C x[$n$, 1];! & $2$ & Matrix & $(n \times 1)$-matrix, representing a column\\
\lstinline!C[1, $n$] x;! & \lstinline!C x[1, $n$];! & $2$ & Matrix & $(1 \times n)$-matrix, representing a row\\
\hline
\end{tabular}
\end{center}
\end{table}

The type of an array of array is the multidimensional array which is constructed by taking the first dimensions from the component declaration and subsequent dimensions
from the maximally expanded component type. A type is maximally expanded, if it is either one of the built-in types (\lstinline!Real!, \lstinline!Integer!, \lstinline!Boolean!,
Expand Down Expand Up @@ -431,24 +440,22 @@ \subsubsection{Reduction Expressions}\label{reduction-expressions}
deduction of ranges, see \cref{implicit-iteration-ranges}; and for using types as ranges
see \cref{types-as-iteration-ranges}.

\begin{longtable}{|p{3cm}|p{5cm}|p{6cm}|}
\caption{Reduction expressions with iterators.}\\
\begin{table}[H]
\caption{Reduction expressions with iterators. (The least and greatest values of \lstinline!Real! are available as \lstinline!-Modelica.Constants.inf! and \lstinline!Modelica.Constants.inf!, respectively.)}
\begin{center}
\begin{tabular}{l l l}
\hline
\tablehead{Function-name} & \tablehead{Restriction on expression1} & \tablehead{Result if expression2 is empty}\\ \hline
\endhead
\lstinline!sum! & \lstinline!Integer! or \lstinline!Real! & \lstinline!zeros($\ldots$)!\\ \hline
\lstinline!product! & Scalar \lstinline!Integer! or \lstinline!Real! & \lstinline!1!\\ \hline
\lstinline!min! & Scalar enumeration, \lstinline!Boolean!, \lstinline!Integer! or \lstinline!Real! &
\begin{tabular}{@{}p{6cm}@{}}
Greatest value of type\\
(\lstinline!Modelica.Constants.inf! for \lstinline!Real!)
\end{tabular}\\ \hline
\lstinline!max! & Scalar enumeration, \lstinline!Boolean!, \lstinline!Integer! or \lstinline!Real! &
\begin{tabular}{@{}p{6cm}@{}}
Least value of type\\
(\lstinline!-Modelica.Constants.inf! for \lstinline!Real!)
\end{tabular}\\ \hline
\end{longtable}
\tablehead{Reduction} & \tablehead{Restriction on \lstinline!expression1!} & \tablehead{Result for empty \lstinline!expression2!}\\
\hline
\hline
\lstinline!sum! & \lstinline!Integer! or \lstinline!Real! & \lstinline!zeros($\ldots$)!\\
\lstinline!product! & Scalar \lstinline!Integer! or \lstinline!Real! & 1\\
\lstinline!min! & Scalar enumeration, \lstinline!Boolean!, \lstinline!Integer! or \lstinline!Real! & Greatest value of type\\
\lstinline!max! & Scalar enumeration, \lstinline!Boolean!, \lstinline!Integer! or \lstinline!Real! & Least value of type\\
\hline
\end{tabular}
\end{center}
\end{table}

\begin{example}
% No frame since the math would break it.
Expand Down Expand Up @@ -791,26 +798,29 @@ \section{Array Indexing}\label{array-indexing}
(a vector-valued or colon index expression causes a vector to be returned).
\end{example}

\begin{example}
Array slicing given the declarations \lstinline!x[$n$, $m$]!, \lstinline!v[$k$]!, \lstinline!z[$i$, $j$, $p$]!.
\begin{longtable}[]{|l|l|l|}
\caption{Examples of scalars vs.\ array slices created with the colon index.}\\
\begin{table}[H]
\caption{Examples of scalars vs.\ array slices created with the colon index. The examples make use of the array variables \lstinline!x[$n$, $m$]!, \lstinline!v[$k$]!, and \lstinline!z[$i$, $j$, $p$]!.}
\begin{center}
\begin{tabular}{l c l}
\hline
\tablehead{Expression} & \tablehead{\# dims} & \tablehead{Type of value}\\ \hline
\endhead
\lstinline!x[1, 1]! & $0$ & Scalar\\ \hline
\lstinline!x[:, 1]! & $1$ & $n$-Vector\\ \hline
\lstinline!x[1, :]! or \lstinline!x[1]! & $1$ & $m$-Vector\\ \hline
\lstinline!v[1:$p$]! & $1$ & $p$-Vector\\ \hline
\lstinline!x[1:$p$, :]! & $2$ & $(p \times m)$-Matrix\\ \hline
\lstinline!x[1:1, :]! & $2$ & $1 \times m$ ``row'' matrix\\ \hline
\lstinline!x[{1, 3, 5}, :]! & $2$ & $(3 \times m)$-Matrix\\ \hline
\lstinline!x[:, v]! & $2$ & $(n \times k)$-Matrix\\ \hline
\lstinline!z[:, 3, :]! & $2$ & $(i \times p)$-Matrix\\ \hline
\lstinline!x[scalar([1]), :]! & $1$ & $m$-Vector\\ \hline
\lstinline!x[vector([1]), :]! & $2$ & $1 \times m$ ``row'' matrix\\ \hline
\end{longtable}
\end{example}
\tablehead{Expression} & \tablehead{\# dims} & \tablehead{Description}\\
\hline
\hline
\lstinline!x[1, 1]! & 0 & Scalar\\
\lstinline!x[:, 1]! & 1 & $n$-vector\\
\lstinline!x[1, :]! or \lstinline!x[1]! & 1 & $m$-vector\\
\lstinline!v[1:$p$]! & 1 & $p$-vector\\
\lstinline!x[1:$p$, :]! & 2 & $p \times m$ matrix\\
\lstinline!x[1:1, :]! & 2 & $1 \times m$ ``row'' matrix\\
\lstinline!x[{1, 3, 5}, :]! & 2 & $3 \times m$ matrix\\
\lstinline!x[:, v]! & 2 & $n \times k$ matrix\\
\lstinline!z[:, 3, :]! & 2 & $i \times p$ matrix\\
\lstinline!x[scalar([1]), :]! & 1 & $m$-vector\\
\lstinline!x[vector([1]), :]! & 2 & $1 \times m$ ``row'' matrix\\
\hline
\end{tabular}
\end{center}
\end{table}

\subsection{Indexing with Boolean or Enumeration Values}\label{indexing-with-boolean-or-enumeration-values}

Expand Down

0 comments on commit 9cf69af

Please sign in to comment.