 SubMatrix subVector specifications - Maple Help

Using Sub-Matrix and Sub-Vector Specifications with the Modular Package Description

 • Low-level functions in the Modular package allow for working with or on part of a Matrix or Vector, or with the transpose of a Matrix or Vector. This is most useful in utilization of the package for algorithms that use some form of blocking, or when only a part of a calculation is needed.
 • Using standard Maple syntax to define sub-Matrices and sub-Vectors, for example, ${M}_{1..5,2..3}$) produces a copy of the data, which is inefficient when the copy is not required for some other purpose. This functionality is provided to avoid data duplication.
 • Examples of the available functionality include interpreting a row of a Matrix as a row Vector, interpreting a row Vector as a column Vector, interpreting some part of a Matrix as a smaller Matrix, etcetera.
 • The basic specification for a Matrix is of the form $\mathrm{Matrix},r$, $\mathrm{r1}..\mathrm{r2},c$, or $\mathrm{c1}..\mathrm{c2},'\mathrm{transpose}'$. Each of the three trailing entries is optional, but in order to provide a column-column range for a Matrix, the row-row range must be provided.
 If the row is specified as a fixed value, for example, 2, but the column is not provided or specified as a range, the Matrix is interpreted as a row Vector with values corresponding to the specified row of the Matrix.
 If the row is provided as a range and the column is a fixed value, the Matrix is interpreted as a column Vector with values corresponding to the specified column of the Matrix.
 If both the row and column are fixed values, the selected entry of the Matrix is interpreted as a scalar (only valid for output).
 If both the row and column are specified as ranges, the Matrix is interpreted as a sub-Matrix with the specified rows and columns.
 Note: For all functions, it is invalid for a range to be empty. Ranges can include negative values, which are interpreted as offsets from the highest available value, similar to lists. For example, $1..-1$ refers to the entire range.
 The 'transpose' keyword is only available for input objects (not for output), and indicates that the specified sub-Matrix is transposed prior to performing the requested operation. Examples

To illustrate these ideas, use the Copy function.  Note that usage of a subspec does not produce a copy unless the Copy function is used.

 > $\mathrm{with}\left(\mathrm{LinearAlgebra}\left[\mathrm{Modular}\right]\right):$
 > $M≔\mathrm{Mod}\left(13,\mathrm{Matrix}\left(3,4,\left(i,j\right)↦\mathrm{rand}\left(\right)\right),\mathrm{integer}\left[\right]\right)$
 ${M}{≔}\left[\begin{array}{cccc}{10}& {0}& {8}& {12}\\ {2}& {6}& {0}& {11}\\ {9}& {2}& {11}& {7}\end{array}\right]$ (1)

Specification of second row as a row Vector.

 > $\mathrm{Copy}\left(13,M,2\right)$
 $\left[\begin{array}{cccc}{2}& {6}& {0}& {11}\end{array}\right]$ (2)

Specification of third column as a column Vector. Note that the row range must be provided.

 > $\mathrm{Copy}\left(13,M,1..-1,3\right)$
 $\left[\begin{array}{c}{8}\\ {0}\\ {11}\end{array}\right]$ (3)

Transpose of submatrix excluding first row and last column.

 > $\mathrm{Copy}\left(13,M,2..-1,1..-2,'\mathrm{transpose}'\right)$
 $\left[\begin{array}{cc}{2}& {9}\\ {6}& {2}\\ {0}& {11}\end{array}\right]$ (4)

The basic specification for a column Vector is of the form ${\mathrm{Vector}}_{\mathrm{column}},r$ or $\mathrm{r1}..\mathrm{r2},'\mathrm{transpose}'$. Where the row-row range, and transpose are optional.

The same comments apply as for the rows of a Matrix.

 > $V≔\mathrm{Mod}\left(13,\mathrm{Vector}\left[\mathrm{column}\right]\left(4,\left(i,j\right)↦\mathrm{rand}\left(\right)\right),\mathrm{integer}\left[\right]\right)$
 ${V}{≔}\left[\begin{array}{c}{4}\\ {11}\\ {12}\\ {11}\end{array}\right]$ (5)

Specification of part of the Vector, and part of the transpose.

 > $\mathrm{Copy}\left(13,V,2..-2\right),\mathrm{Copy}\left(13,V,2..-2,'\mathrm{transpose}'\right)$
 $\left[\begin{array}{c}{11}\\ {12}\end{array}\right]{,}\left[\begin{array}{cc}{11}& {12}\end{array}\right]$ (6)

Similarly the basic specification for a row Vector is of the form ${\mathrm{Vector}}_{\mathrm{row}},c$ or $\mathrm{c1}..\mathrm{c2},'\mathrm{transpose}'$. Where the column-column range, and transpose are optional.

 > $V≔\mathrm{Mod}\left(13,\mathrm{Vector}\left[\mathrm{row}\right]\left(5,\left(i,j\right)↦\mathrm{rand}\left(\right)\right),\mathrm{integer}\left[\right]\right)$
 ${V}{≔}\left[\begin{array}{ccccc}{8}& {9}& {4}& {11}& {10}\end{array}\right]$ (7)

Specification of part of the Vector, and part of the transpose.

 > $\mathrm{Copy}\left(13,V,2..-2\right),\mathrm{Copy}\left(13,V,2..-2,'\mathrm{transpose}'\right)$
 $\left[\begin{array}{ccc}{9}& {4}& {11}\end{array}\right]{,}\left[\begin{array}{c}{9}\\ {4}\\ {11}\end{array}\right]$ (8)

Now as a more involved example, consider the product of a Matrix and its transpose, but only obtain the diagonal elements of the product, placing them in the diagonal of a Matrix of the product form. The following example accomplishes this.

 > $M≔\mathrm{Mod}\left(13,\mathrm{Matrix}\left(4,3,\left(i,j\right)↦\mathrm{rand}\left(\right)\right),\mathrm{integer}\left[\right]\right)$
 ${M}{≔}\left[\begin{array}{ccc}{3}& {5}& {5}\\ {1}& {6}& {7}\\ {3}& {0}& {8}\\ {3}& {11}& {7}\end{array}\right]$ (9)
 > $P≔\mathrm{Create}\left(13,4,4,\mathrm{integer}\left[\right]\right)$
 ${P}{≔}\left[\begin{array}{cccc}{0}& {0}& {0}& {0}\\ {0}& {0}& {0}& {0}\\ {0}& {0}& {0}& {0}\\ {0}& {0}& {0}& {0}\end{array}\right]$ (10)
 > $\mathbf{for}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}i\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{to}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}4\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{do}\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}\phantom{\rule[-0.0ex]{2.0em}{0.0ex}}\mathrm{Multiply}\left(13,M,i,M,i,'\mathrm{transpose}',P,i,i\right)\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}\mathbf{end}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{do}:$$P$
 $\left[\begin{array}{cccc}{7}& {0}& {0}& {0}\\ {0}& {8}& {0}& {0}\\ {0}& {0}& {8}& {0}\\ {0}& {0}& {0}& {10}\end{array}\right]$ (11)

Where the whole product is specified by the following.

 > $\mathrm{Multiply}\left(13,M,M,'\mathrm{transpose}'\right)$
 $\left[\begin{array}{cccc}{7}& {3}& {10}& {8}\\ {3}& {8}& {7}& {1}\\ {10}& {7}& {8}& {0}\\ {8}& {1}& {0}& {10}\end{array}\right]$ (12)

The final item involves shortcut specifications. If the function being called accepts mod m Matrix or Vector arguments, any dimensions where the range is implied by prior arguments can only be specified by the start of the range.

For example, the following two AddMultiple commands are equivalent:

 > $\mathrm{M1}≔\mathrm{Mod}\left(13,\mathrm{Matrix}\left(3,4,\left(i,j\right)↦\mathrm{rand}\left(\right)\right),\mathrm{integer}\left[\right]\right)$
 ${\mathrm{M1}}{≔}\left[\begin{array}{cccc}{6}& {4}& {5}& {3}\\ {5}& {4}& {10}& {4}\\ {6}& {9}& {5}& {9}\end{array}\right]$ (13)
 > $\mathrm{M2}≔\mathrm{Mod}\left(13,\mathrm{Matrix}\left(3,4,\left(i,j\right)↦\mathrm{rand}\left(\right)\right),\mathrm{integer}\left[\right]\right)$
 ${\mathrm{M2}}{≔}\left[\begin{array}{cccc}{10}& {4}& {6}& {12}\\ {6}& {5}& {11}& {6}\\ {4}& {9}& {7}& {2}\end{array}\right]$ (14)
 > $\mathrm{AddMultiple}\left(13,1,\mathrm{M1},2..3,3..4,\mathrm{M2},1..2,2..3\right)$
 $\left[\begin{array}{cc}{1}& {10}\\ {10}& {7}\end{array}\right]$ (15)
 > $\mathrm{AddMultiple}\left(13,1,\mathrm{M1},2..3,3..4,\mathrm{M2},1,2\right)$
 $\left[\begin{array}{cc}{1}& {10}\\ {10}& {7}\end{array}\right]$ (16)

where the endpoints of the ranges for the second mod m Matrix are implied by the first.