LinearAlgebra[Modular]
Multiply
scalar, Vector, and Matrix multiplication
Calling Sequence
Parameters
Description
Examples
Multiply(m, A, B, order, 'sparse')
Multiply(m, A, B, C, 'sparse')
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
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 Bi,j must have the result going to Ci,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 rows⁡A⁢x⁢cols⁡B.
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](..).
with⁡LinearAlgebraModular:
A≔Mod⁡13,Vectorrow⁡4,i↦rand⁡,integer
A≔100812
B≔Mod⁡13,Vectorcolumn⁡4,i↦rand⁡,integer
B≔26011
The inner product.
Multiply⁡13,A,B
9
The outer product.
Multiply⁡13,B,A
703118097000060102
The inner product into existing Matrix.
C≔Create⁡13,2,2,integer
C≔0000
Multiply⁡13,A,B,C,1,2:
0900
Matrix-Vector multiplication.
A≔Mod⁡13,Matrix⁡3,4,i,j↦rand⁡,integer
A≔92117411121189411
309
Vector-Matrix multiplication.
B≔Mod⁡13,Vectorrow⁡3,i↦rand⁡,integer
B≔1035
127102
Scalar multiplication of A into A.
Multiply⁡13,2,A,A:
5491891193589
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≔Create⁡13,2,6,integer
C≔000000000000
Multiply⁡13,A,3,A,transpose,C,2,2..4:
00000001241000
See Also
LinearAlgebra/Details
LinearAlgebra[Modular][Create]
LinearAlgebra[Modular][Mod]
LinearAlgebra[Modular][subspec]
Vector
Download Help Document