Multiply - Maple Help

LinearAlgebra[Modular]

 Multiply
 scalar, Vector, and Matrix multiplication

 Calling Sequence Multiply(m, A, B, order, 'sparse') Multiply(m, A, B, C, 'sparse')

Parameters

 m - modulus A - scalar, Matrix, or Vector including subspec B - Matrix or Vector, including subspec order - (optional) ordering of output object; C_order or Fortran_order sparse - (optional) controls behavior of operation C - output Matrix or Vector, including subspec

Description

 • The Multiply function performs the operation A*B placing the output in a new object, or in C, depending on calling sequence. All Matrices or Vectors must have the same datatype. Multiply can perform Matrix-Matrix, Matrix-Vector, Vector-Matrix, scalar-Matrix, Vector-Vector, or scalar-Vector multiplication with output as a scalar,Vector or Matrix. The output depends on the input specification.
 The first calling sequence returns a scalar or new mod m Matrix or Vector for the result with the specified ordering order, or the ordering of the input objects A and B.
 Note: If A and B are both Matrices or Vectors and have a different ordering, order must be specified.
 The remaining calling sequence places the output of the computation into C, returning NULL.
 • Scalar multiplication can be performed by setting A to a scalar value in the range $1..m-1$, and specifying B as a mod m Matrix or Vector. In this case, C can be specified as the same Matrix or Vector as B as long as the operation is performed with direct overlap. For example, if B and C are the same Matrix, the operation involving the entry ${B}_{i,j}$ must have the result going to ${C}_{i,j}$.
 If the optional keyword, 'sparse', is specified, it only applies to scalar multiplication if the multiplier is not $1$ or $m-1$ and the datatype is a hardware datatype. It indicates that the algorithm checks for zero entries before performing multiplications. This typically provides an efficiency gain when matrices have 10% or more entries in B equal to zero. This is not implemented for the integer datatype, as it typically provides very little gain for that case.
 Note: If sparse does not apply but it has been specified, the option is ignored.
 • For multiplication of two mod m Matrices or Vectors, the number of columns in A must be equal to the number of rows in B, and the result has dimensions equal to $\mathrm{rows}\left(A\right)x\mathrm{cols}\left(B\right)$.
 For example, if A is a row Vector, and B is a column Vector, the result is a zero dimensional value representing the dot product of A and B. In this case, the output of the first calling sequence is a scalar value. For the second calling sequence, the entry in C into which this value is placed is determined by the sub-Matrix or sub-Vector specification for C.
 Alternatively, if A is a column Vector, and B is a row Vector, the result is a Matrix which represents the outer product of A and B.
 • The Multiply function allows the use of sub-Matrix and sub-Vector specifications for both input and output Vectors/Matrices. For example, the function can be used to multiply a row of a Matrix to the transpose of a row in another Matrix, placing the result in a specified entry of a third Matrix.
 • Note: For scalar multiplication, B and C are allowed direct overlap. If both A and B are mod m Matrices or Vectors and if either overlap with C, the behavior of Multiply is undefined.
 • This command is part of the LinearAlgebra[Modular] package, so it can be used in the form Multiply(..) only after executing the command with(LinearAlgebra[Modular]).  However, it can always be used in the form LinearAlgebra[Modular][Multiply](..).

Examples

 > $\mathrm{with}\left({\mathrm{LinearAlgebra}}_{\mathrm{Modular}}\right):$
 > $A≔\mathrm{Mod}\left(13,{\mathrm{Vector}}_{\mathrm{row}}\left(4,i→\mathrm{rand}\left(\right)\right),{\mathrm{integer}}_{[]}\right)$
 ${A}{≔}\left[\begin{array}{cccc}{10}& {0}& {8}& {12}\end{array}\right]$ (1)
 > $B≔\mathrm{Mod}\left(13,{\mathrm{Vector}}_{\mathrm{column}}\left(4,i→\mathrm{rand}\left(\right)\right),{\mathrm{integer}}_{[]}\right)$
 ${B}{≔}\left[\begin{array}{c}{2}\\ {6}\\ {0}\\ {11}\end{array}\right]$ (2)

The inner product.

 > $\mathrm{Multiply}\left(13,A,B\right)$
 ${9}$ (3)

The outer product.

 > $\mathrm{Multiply}\left(13,B,A\right)$
 $\left[\begin{array}{cccc}{7}& {0}& {3}& {11}\\ {8}& {0}& {9}& {7}\\ {0}& {0}& {0}& {0}\\ {6}& {0}& {10}& {2}\end{array}\right]$ (4)

The inner product into existing Matrix.

 > $C≔\mathrm{Create}\left(13,2,2,{\mathrm{integer}}_{[]}\right)$
 ${C}{≔}\left[\begin{array}{cc}{0}& {0}\\ {0}& {0}\end{array}\right]$ (5)
 > $\mathrm{Multiply}\left(13,A,B,C,1,2\right):$
 > $C$
 $\left[\begin{array}{cc}{0}& {9}\\ {0}& {0}\end{array}\right]$ (6)

Matrix-Vector multiplication.

 > $A≔\mathrm{Mod}\left(13,\mathrm{Matrix}\left(3,4,\left(i,j\right)→\mathrm{rand}\left(\right)\right),{\mathrm{integer}}_{[]}\right)$
 ${A}{≔}\left[\begin{array}{cccc}{9}& {2}& {11}& {7}\\ {4}& {11}& {12}& {11}\\ {8}& {9}& {4}& {11}\end{array}\right]$ (7)
 > $\mathrm{Multiply}\left(13,A,B\right)$
 $\left[\begin{array}{c}{3}\\ {0}\\ {9}\end{array}\right]$ (8)

Vector-Matrix multiplication.

 > $B≔\mathrm{Mod}\left(13,{\mathrm{Vector}}_{\mathrm{row}}\left(3,i→\mathrm{rand}\left(\right)\right),{\mathrm{integer}}_{[]}\right)$
 ${B}{≔}\left[\begin{array}{ccc}{10}& {3}& {5}\end{array}\right]$ (9)
 > $\mathrm{Multiply}\left(13,B,A\right)$
 $\left[\begin{array}{cccc}{12}& {7}& {10}& {2}\end{array}\right]$ (10)

Scalar multiplication of A into A.

 > $\mathrm{Multiply}\left(13,2,A,A\right):$
 > $A$
 $\left[\begin{array}{cccc}{5}& {4}& {9}& {1}\\ {8}& {9}& {11}& {9}\\ {3}& {5}& {8}& {9}\end{array}\right]$ (11)

Multiplication of the third row of A to the transpose of A, with result being placed in a specified location of a new Matrix.

 > $C≔\mathrm{Create}\left(13,2,6,{\mathrm{integer}}_{[]}\right)$
 ${C}{≔}\left[\begin{array}{cccccc}{0}& {0}& {0}& {0}& {0}& {0}\\ {0}& {0}& {0}& {0}& {0}& {0}\end{array}\right]$ (12)
 > $\mathrm{Multiply}\left(13,A,3,A,'\mathrm{transpose}',C,2,2..4\right):$
 > $C$
 $\left[\begin{array}{cccccc}{0}& {0}& {0}& {0}& {0}& {0}\\ {0}& {12}& {4}& {10}& {0}& {0}\end{array}\right]$ (13)