Swap - Maple Help

LinearAlgebra[Modular]

 Swap
 swap data between two mod m Matrices or Vectors of the same datatype

 Calling Sequence Swap(m, ctype, A, B)

Parameters

 m - modulus A - mod m Matrix or Vector, including subspec B - mod m Matrix or Vector, including subspec ctype - (optional) swap type

Description

 • The Swap function exchanges data between two mod m Matrices or Vectors.
 Note that the dimensions of the object specified by A must match those specified for B.
 In all cases, the datatype of the output object must match the datatype of the input object.
 • The ctype parameter is used to specify the type of swap to be performed. Valid options are upper for the upper triangular part of a Matrix, lower for the lower triangular part of a Matrix, and $\mathrm{uppernodiag}$ and $\mathrm{lowernodiag}$ for the corresponding copy operation without the diagonal.
 Note: These swap types are only valid for square Matrices.
 • The Swap function allows the use of sub-Matrix and sub-Vector specifications for both input and output. For example, the function can be used to exchange a row of a Matrix with a row of another Matrix (or the same Matrix), or exchange data between a column in a Matrix and a row Vector.
 Note: If A and B overlap, the behavior of Swap is undefined.
 • This command is part of the LinearAlgebra[Modular] package, so it can be used in the form Swap(..) only after executing the command with(LinearAlgebra[Modular]).  However, it can always be used in the form LinearAlgebra[Modular][Swap](..).

Examples

 > $\mathrm{with}\left(\mathrm{LinearAlgebra}\left[\mathrm{Modular}\right]\right):$
 > $A≔\mathrm{Create}\left(13,4,4,\mathrm{random},\mathrm{integer}\left[\right]\right):$
 > $B≔\mathrm{Create}\left(13,4,4,\mathrm{random},\mathrm{integer}\left[\right]\right):$
 > $A,B$
 $\left[\begin{array}{cccc}{6}& {7}& {7}& {3}\\ {10}& {3}& {6}& {6}\\ {10}& {12}& {7}& {6}\\ {1}& {2}& {0}& {11}\end{array}\right]{,}\left[\begin{array}{cccc}{12}& {10}& {12}& {0}\\ {5}& {9}& {12}& {3}\\ {5}& {2}& {5}& {10}\\ {6}& {7}& {5}& {10}\end{array}\right]$ (1)

Swap entire Matrices.

 > $\mathrm{Swap}\left(13,A,B\right):$
 > $A,B$
 $\left[\begin{array}{cccc}{12}& {10}& {12}& {0}\\ {5}& {9}& {12}& {3}\\ {5}& {2}& {5}& {10}\\ {6}& {7}& {5}& {10}\end{array}\right]{,}\left[\begin{array}{cccc}{6}& {7}& {7}& {3}\\ {10}& {3}& {6}& {6}\\ {10}& {12}& {7}& {6}\\ {1}& {2}& {0}& {11}\end{array}\right]$ (2)

Exchange rows 1 and 4 in A.

 > $A$
 $\left[\begin{array}{cccc}{12}& {10}& {12}& {0}\\ {5}& {9}& {12}& {3}\\ {5}& {2}& {5}& {10}\\ {6}& {7}& {5}& {10}\end{array}\right]$ (3)
 > $\mathrm{Swap}\left(13,A,1,A,4\right):$
 > $A$
 $\left[\begin{array}{cccc}{6}& {7}& {5}& {10}\\ {5}& {9}& {12}& {3}\\ {5}& {2}& {5}& {10}\\ {12}& {10}& {12}& {0}\end{array}\right]$ (4)

Swap row vector and third column of A.

 > $V≔\mathrm{Create}\left(13,0,4,\mathrm{random},\mathrm{integer}\left[\right]\right)$
 ${V}{≔}\left[\begin{array}{cccc}{2}& {5}& {5}& {10}\end{array}\right]$ (5)
 > $A$
 $\left[\begin{array}{cccc}{6}& {7}& {5}& {10}\\ {5}& {9}& {12}& {3}\\ {5}& {2}& {5}& {10}\\ {12}& {10}& {12}& {0}\end{array}\right]$ (6)
 > $\mathrm{Swap}\left(13,V,\mathrm{transpose},A,1..-1,3\right):$
 > $A$
 $\left[\begin{array}{cccc}{6}& {7}& {2}& {10}\\ {5}& {9}& {5}& {3}\\ {5}& {2}& {5}& {10}\\ {12}& {10}& {10}& {0}\end{array}\right]$ (7)

Swap transposed upper triangular part of A with self (in-place transpose).

 > $A$
 $\left[\begin{array}{cccc}{6}& {7}& {2}& {10}\\ {5}& {9}& {5}& {3}\\ {5}& {2}& {5}& {10}\\ {12}& {10}& {10}& {0}\end{array}\right]$ (8)
 > $\mathrm{Swap}\left(13,\mathrm{upper},A,\mathrm{transpose},A\right):$
 > $A$
 $\left[\begin{array}{cccc}{6}& {5}& {5}& {12}\\ {7}& {9}& {2}& {10}\\ {2}& {5}& {5}& {10}\\ {10}& {3}& {10}& {0}\end{array}\right]$ (9)