Using Sub-Matrix and Sub-Vector Specifications with the Modular Package
Description
Examples
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, M1..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 Matrix,r, r1..r2,c, or c1..c2,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.
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.
with⁡LinearAlgebraModular:
M≔Mod⁡13,Matrix⁡3,4,i,j↦rand⁡,integer
M≔1008122601192117
Specification of second row as a row Vector.
Copy⁡13,M,2
26011
Specification of third column as a column Vector. Note that the row range must be provided.
Copy⁡13,M,1..−1,3
8011
Transpose of submatrix excluding first row and last column.
Copy⁡13,M,2..−1,1..−2,transpose
2962011
The basic specification for a column Vector is of the form Vectorcolumn,r or r1..r2,transpose. Where the row-row range, and transpose are optional.
The same comments apply as for the rows of a Matrix.
V≔Mod⁡13,Vectorcolumn⁡4,i,j↦rand⁡,integer
V≔4111211
Specification of part of the Vector, and part of the transpose.
Copy⁡13,V,2..−2,Copy⁡13,V,2..−2,transpose
1112,1112
Similarly the basic specification for a row Vector is of the form Vectorrow,c or c1..c2,transpose. Where the column-column range, and transpose are optional.
V≔Mod⁡13,Vectorrow⁡5,i,j↦rand⁡,integer
V≔8941110
9411,9411
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≔Mod⁡13,Matrix⁡4,3,i,j↦rand⁡,integer
M≔3551673083117
P≔Create⁡13,4,4,integer
P≔0000000000000000
forito4doMultiply⁡13,M,i,M,i,transpose,P,i,ienddo:P
70000800008000010
Where the whole product is specified by the following.
Multiply⁡13,M,M,transpose
7310838711078081010
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:
M1≔Mod⁡13,Matrix⁡3,4,i,j↦rand⁡,integer
M1≔6453541046959
M2≔Mod⁡13,Matrix⁡3,4,i,j↦rand⁡,integer
M2≔104612651164972
AddMultiple⁡13,1,M1,2..3,3..4,M2,1..2,2..3
110107
AddMultiple⁡13,1,M1,2..3,3..4,M2,1,2
where the endpoints of the ranges for the second mod m Matrix are implied by the first.
See Also
LinearAlgebra/Details
LinearAlgebra[Modular]
LinearAlgebra[Modular][AddMultiple]
LinearAlgebra[Modular][Copy]
LinearAlgebra[Modular][Create]
LinearAlgebra[Modular][Fill]
LinearAlgebra[Modular][Mod]
LinearAlgebra[Modular][Multiply]
Download Help Document