Skip to content

Commit

Permalink
Clean up so-called "formal" definition of array concatenation
Browse files Browse the repository at this point in the history
  • Loading branch information
henrikt-ma committed Jun 16, 2020
1 parent a1c6a50 commit bf340da
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions chapters/arrays.tex
Original file line number Diff line number Diff line change
Expand Up @@ -673,48 +673,48 @@ \subsection{Array Concatenation}\doublelabel{array-concatenation}
\end{lstlisting}
\end{example}

Concatenation is formally defined according to:
\begin{lstlisting}[language=modelica, escapechar=!]
!Let! R = cat(k,A,B,C,...)!, and let! n = ndims(A) = ndims(B) = ndims(C) =
....!, then!
size(R,k) = size(A,k) + size(B,k) + size(C,k) + ...
size(R,j) = size(A,j) = size(B,j) = size(C,j) = ...., for 1 <=j <= n and j <> k.

R[i_1, ..., i_k, ..., i_n] = A[i_1, ..., i_k, ..., i_n], for i_k <= size(A,k),
R[i_1, ..., i_k, ..., i_n] = B[i_1, ..., i_k - size(A,i), ..., i_n], for i_k <= size(A,k) + size(B,k),
....
where 1 <= i_j <= size(R,j) for 1 <= j <= n.
Formally, the concatenation \lstinline[mathescape=true]!R = cat($k$, A, B, C, $\ldots$)! is defined as follows. Let $n$ = \lstinline!ndims(A)! = \lstinline!ndims(B)! = \lstinline!ndims(C)! = \ldots Then the size of \lstinline!R! is given by
\begin{lstlisting}[language=modelica,escapechar=!,mathescape=true,frame=none,xleftmargin=1em]
size(R,$k$) = size(A,$k$) + size(B,$k$) + size(C,$k$) + $\ldots$
size(R,$j$) = size(A,$j$) = size(B,$j$) = size(C,$j$) = $\ldots$ !for! $1 \leq j \leq n$ and $j \neq k$
\end{lstlisting}
and the array elements of \lstinline!R! are given by
\begin{lstlisting}[language=modelica,escapechar=!,mathescape=true,frame=none,xleftmargin=1em]
R[$i_{1}$, $\ldots$, $i_{k}$, $\ldots$, $i_{n}$] = A[$i_{1}$, $\ldots$, $i_{k}$, $\ldots$, $i_{n}$]
!for! $0 < i_{k} \leq$ size(A,$k$)
R[$i_{1}$, $\ldots$, $i_{k}$, $\ldots$, $i_{n}$] = B[$i_{1}$, $\ldots$, $i_{k}$ - size(A,$k$), $\ldots$, $i_{n}$]
!for! size(A,$k$) $< i_{k} \leq$ size(A,$k$) + size(B,$k$)
R[$i_{1}$, $\ldots$, $i_{k}$, $\ldots$, $i_{n}$] = C[$i_{1}$, $\ldots$, $i_{k}$ - size(A,$k$) - size(B,$k$), $\ldots$, $i_{n}$]
!for! size(A,$k$) + size(B,$k$) $< i_{k} \leq$ size(A,$k$) + size(B,$k$) + size(C,$k$)
$\ldots$
\end{lstlisting}
where $1 \leq i_{j} \leq$ \lstinline[mathescape=true]!size(R,$j$)! for $1 \leq j \leq n$.


\subsubsection{Array Concatenation along First and Second Dimensions}\doublelabel{array-concatenation-along-first-and-second-dimensions}

For convenience, a special syntax is supported for the concatenation
along the first and second dimensions.

For convenience, a special syntax is supported for the concatenation along the first and second dimensions:
\begin{itemize}
\item
\emph{Concatenation along first dimension}:\\
\lstinline![A; B; C; ...] = cat(1, promote(A,n), promote(B,n), promote(C,n), ...)!
where \lstinline!n = max(2, ndims(A), ndims(B), ndims(C), ....)!. If necessary, 1-sized
dimensions are added to the right of A, B, C before the operation is
carried out, in order that the operands have the same number of
dimensions which will be at least two.
\lstinline[mathescape=true]![A; B; C; $\ldots$] = cat(1, promote(A, n), promote(B, n), promote(C, n), $\ldots$)!
where \lstinline[mathescape=true]!n = max(2, ndims(A), ndims(B), ndims(C), $\ldots$)!. If necessary, 1-sized
dimensions are added to the right of \lstinline!A!, \lstinline!B!, \lstinline!C! before the operation is
carried out, in order that the operands have the same number of dimensions which will be at least two.
\item
\emph{Concatenation along second dimension}:\\
\lstinline![A, B, C, ...] = cat(2, promote(A,n), promote(B,n), promote(C,n), ...)!
where \lstinline!n = max(2, ndims(A), ndims(B), ndims(C), ....)!. If necessary, 1-sized
dimensions are added to the right of A, B, C before the operation is
\lstinline[mathescape=true]![A, B, C, $\ldots$] = cat(2, promote(A, n), promote(B, n), promote(C, n), $\ldots$)!
where \lstinline[mathescape=true]!n = max(2, ndims(A), ndims(B), ndims(C), $\ldots$)!. If necessary, 1-sized
dimensions are added to the right of \lstinline!A!, \lstinline!B!, \lstinline!C! before the operation is
carried out, especially that each operand has at least two dimensions.
\item
The two forms can be mixed. \lstinline![...,...]! has higher precedence than
\lstinline![...;...]!, e.g., \lstinline![a, b; c, d]! is parsed as \lstinline![[a,b];[c,d]]!.
The two forms can be mixed. \lstinline[mathescape=true]![$\ldots$, $\ldots$]! has higher precedence than
\lstinline[mathescape=true]![$\ldots$; $\ldots$]!, e.g., \lstinline![a, b; c, d]! is parsed as \lstinline![[a, b]; [c, d]]!.
\item
\lstinline![A] = promote(A,max(2,ndims(A)))!, i.e., \lstinline![A] = A!, if A has 2 or
more dimensions, and it is a matrix with the elements of A, if A is a
scalar or a vector.
\lstinline![A] = promote(A, max(2, ndims(A)))!, i.e., \lstinline![A] = A!, if \lstinline!A! has 2 or more dimensions, and it is a matrix
with the elements of \lstinline!A!, if \lstinline!A! is a scalar or a vector.
\item
There must be at least one argument (i.e.\ \lstinline![]! is not defined)
There must be at least one argument (i.e.\ \lstinline![]! is not defined).
\end{itemize}

\begin{example}
Expand Down

0 comments on commit bf340da

Please sign in to comment.