 Mod - Maple Help

LinearAlgebra[Modular]

 Mod
 apply 'mod' to input with optional evaluation list producing a mod m Matrix or Vector as output Calling Sequence Mod(m, A, eval, dtype, order) Mod(m, A, eval, B) Parameters

 m - modulus A - input object; can contain Matrices, Vectors, sets or lists, and a subspec eval - (optional) equation or set or list of equations for the evaluation dtype - (optional) datatype of output object order - (optional) ordering of output object (default is C_order) B - output object (copy to), including subspec Description

 • The Mod function applies 'mod' with respect to the input modulus m, and optional evaluation list eval, to the input object A. This produces a new mod m Matrix or Vector with the specified datatype dtype and order order, or places the result in an existing mod m Matrix or Vector B.
 • Allowable formats for A include Matrices or Vectors, sets or lists of Vectors, or sets or lists of sets or lists (though a set of sets format is not typically useful). Input Matrices or Vectors must be rectangular and can have datatype integer/integer, float, or anything.
 The data is interpreted in different ways based on the input, that is, what type of mod mobject is produced in each case by default.
 In the case where the input is a Matrix or Vector, the output is the same type, with the same number of rows and columns, but with the specified datatype and ordering.
 If the input is a set or list of Vectors, the output is a Matrix. All input Vectors must have the same number of elements and orientation. If they are column Vectors, they correspond to the columns in the output. If they are row Vectors, they correspond to the rows in the output.
 If the input is a nested set or list, each set or list in the outer set or list corresponds to a row of the output. In this case, it is not required that all elements of the outer set or list have the same number of elements, as the output Matrix is chosen to be large enough to contain the longest of these as a row, and any rows with additional elements are zero padded.
 If the input is a simple set or list, the output is a column Vector.
 • Now that the default format has been described, the resulting object can be modified by using a subspec, so that only certain rows or columns are used, and the default output can be transposed.
 • If no evaluation eval is provided, the input can contain integers or fractions only (or floats for input float datatype).
 Note: The float datatype is provided primarily for conversion from a float mod p Matrix or Vector to one of the other datatypes. It is assumed that the closest integer to each float in the input is what is required.
 • If an evaluation list, eval, is specified, the inputs must be rational polynomials in terms of the indeterminates in the evaluation list.
 Note: The left-hand sides of all elements in the evaluation list can be any nonconstant object, for example, ${x}^{7}$ or $\mathrm{Rootof}\left({Z}^{2}+1\right)$, but the right-hand sides must all be integer values in the range $0..m-1$.  In addition, the provided evaluation must be sufficient to fully evaluate all elements of the input to integers mod m.
 The input can also contain univariate modp1 polynomials, but the modulus must match the input modulus $m$, and the evaluation eval must contain an equation with the indeterminate of the modp1 polynomials on the left-hand side. Special evaluation rules, such as ${x}^{7}=2$, are not applied to modp1 polynomials.
 • The first calling sequence results in a new mod m Matrix or Vector, which is output by the call.  The second calling sequence computes the Mod into an existing object, which can also be a sub-Vector or sub-Matrix.
 • This command is part of the LinearAlgebra[Modular] package, so it can be used in the form Mod(..) only after executing the command with(LinearAlgebra[Modular]).  However, it can always be used in the form LinearAlgebra[Modular][Mod](..). Examples

Conversion of a integer Matrix to a mod m integer[] Matrix.

 > $\mathrm{with}\left({\mathrm{LinearAlgebra}}_{\mathrm{Modular}}\right):$
 > $A≔\mathrm{Matrix}\left(4,4,\left(i,j\right)→\mathrm{rand}\left(\right)\right)$
 ${A}{≔}\left[\begin{array}{cccc}{395718860534}& {193139816415}& {22424170465}& {800187484459}\\ {427552056869}& {842622684442}& {412286285840}& {996417214180}\\ {386408307450}& {694607189265}& {773012980023}& {730616292946}\\ {106507053657}& {396412723003}& {944913350029}& {210936428922}\end{array}\right]$ (1)
 > $\mathrm{Am}≔\mathrm{Mod}\left(13,A,{\mathrm{integer}}_{[]}\right)$
 ${\mathrm{Am}}{≔}\left[\begin{array}{cccc}{10}& {0}& {8}& {12}\\ {2}& {6}& {0}& {11}\\ {9}& {2}& {11}& {7}\\ {4}& {11}& {12}& {11}\end{array}\right]$ (2)

Conversion of a list of lists of rationals to a mod m float Matrix.

 > $B≔\left[\left[\frac{153933017312}{211754691347}\right],\left[\frac{235538926099}{196277296419},\frac{836404711117}{474259255346}\right],\left[\frac{224085044619}{78606118334},\frac{102954832799}{79957903184},\frac{54261521239}{30724083518}\right],\left[\frac{867557918169}{866818474138},\frac{966905297479}{497201520366},\frac{69519730633}{45453427109},\frac{988383200003}{735342248716}\right]\right]$
 ${B}{≔}\left[\left[\frac{{153933017312}}{{211754691347}}\right]{,}\left[\frac{{235538926099}}{{196277296419}}{,}\frac{{836404711117}}{{474259255346}}\right]{,}\left[\frac{{224085044619}}{{78606118334}}{,}\frac{{102954832799}}{{79957903184}}{,}\frac{{54261521239}}{{30724083518}}\right]{,}\left[\frac{{867557918169}}{{866818474138}}{,}\frac{{966905297479}}{{497201520366}}{,}\frac{{69519730633}}{{45453427109}}{,}\frac{{988383200003}}{{735342248716}}\right]\right]$ (3)
 > $\mathrm{Mod}\left(13,B,{\mathrm{float}}_{8}\right)$
 $\left[\begin{array}{cccc}{12.}& {0.}& {0.}& {0.}\\ {1.}& {11.}& {0.}& {0.}\\ {11.}& {0.}& {5.}& {0.}\\ {12.}& {6.}& {11.}& {3.}\end{array}\right]$ (4)

Evaluation of a list of polynomials to a row vector.

 > $C≔\left[\mathrm{seq}\left(\mathrm{randpoly}\left(x\right),i=1..4\right)\right]$
 ${C}{≔}\left[{75}{}{{x}}^{{5}}{-}{92}{}{{x}}^{{4}}{+}{6}{}{{x}}^{{3}}{+}{74}{}{{x}}^{{2}}{+}{72}{}{x}{+}{37}{,}{-}{23}{}{{x}}^{{5}}{+}{87}{}{{x}}^{{4}}{+}{44}{}{{x}}^{{3}}{+}{29}{}{{x}}^{{2}}{+}{98}{}{x}{-}{23}{,}{10}{}{{x}}^{{5}}{-}{61}{}{{x}}^{{4}}{-}{8}{}{{x}}^{{3}}{-}{29}{}{{x}}^{{2}}{+}{95}{}{x}{+}{11}{,}{-}{49}{}{{x}}^{{5}}{-}{47}{}{{x}}^{{4}}{+}{40}{}{{x}}^{{3}}{-}{81}{}{{x}}^{{2}}{+}{91}{}{x}{+}{68}\right]$ (5)
 > $\mathrm{Mod}\left(13,C,'\mathrm{transpose}',x=2,\mathrm{integer}\right)$
 $\left[\begin{array}{cccc}{10}& {10}& {2}& {6}\end{array}\right]$ (6)

Evaluation of a list of Vectors of modp1 polynomials to a new Matrix, and to an existing Matrix with sub-specification.

 > $\mathrm{Vl}≔\left[\mathrm{seq}\left({\mathrm{Vector}}_{\mathrm{column}}\left(3,i→\mathrm{randpoly}\left(x\right)mod13\right),i=1..4\right)\right]$
 ${\mathrm{Vl}}{≔}\left[\left[\begin{array}{c}\left({3}{}{{x}}^{{5}}{+}{5}{}{{x}}^{{4}}{+}{{x}}^{{3}}{+}{12}{}{{x}}^{{2}}{+}{4}{}{x}{+}{1}\right)\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}{\mathbf{mod}}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}{13}\\ \left({{x}}^{{5}}{+}{3}{}{{x}}^{{4}}{+}{11}{}{{x}}^{{3}}{+}{3}{}{{x}}^{{2}}{+}{4}{}{x}{+}{12}\right)\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}{\mathbf{mod}}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}{13}\\ \left({11}{}{{x}}^{{5}}{+}{6}{}{{x}}^{{4}}{+}{8}{}{{x}}^{{3}}{+}{7}{}{{x}}^{{2}}{+}{4}{}{x}{+}{8}\right)\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}{\mathbf{mod}}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}{13}\end{array}\right]{,}\left[\begin{array}{c}\left({{x}}^{{5}}{+}{4}{}{{x}}^{{4}}{+}{{x}}^{{3}}{+}{3}{}{x}{+}{4}\right)\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}{\mathbf{mod}}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}{13}\\ \left({{x}}^{{5}}{+}{11}{}{{x}}^{{4}}{+}{5}{}{{x}}^{{3}}{+}{3}{}{x}{+}{9}\right)\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}{\mathbf{mod}}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}{13}\\ \left({6}{}{{x}}^{{5}}{+}{3}{}{{x}}^{{4}}{+}{5}{}{{x}}^{{3}}{+}{9}{}{{x}}^{{2}}{+}{5}{}{x}{+}{8}\right)\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}{\mathbf{mod}}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}{13}\end{array}\right]{,}\left[\begin{array}{c}\left({7}{}{{x}}^{{5}}{+}{4}{}{{x}}^{{4}}{+}{7}{}{{x}}^{{3}}{+}{10}{}{{x}}^{{2}}{+}{11}{}{x}{+}{5}\right)\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}{\mathbf{mod}}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}{13}\\ \left({5}{}{{x}}^{{5}}{+}{9}{}{{x}}^{{4}}{+}{12}{}{{x}}^{{3}}{+}{7}\right)\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}{\mathbf{mod}}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}{13}\\ \left({{x}}^{{5}}{+}{12}{}{{x}}^{{4}}{+}{{x}}^{{3}}{+}{5}{}{{x}}^{{2}}{+}{5}{}{x}\right)\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}{\mathbf{mod}}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}{13}\end{array}\right]{,}\left[\begin{array}{c}\left({5}{}{{x}}^{{5}}{+}{11}{}{{x}}^{{4}}{+}{6}{}{{x}}^{{3}}{+}{5}{}{{x}}^{{2}}{+}{12}\right)\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}{\mathbf{mod}}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}{13}\\ \left({6}{}{{x}}^{{5}}{+}{7}{}{{x}}^{{4}}{+}{7}{}{{x}}^{{3}}{+}{10}{}{{x}}^{{2}}{+}{7}{}{x}{+}{2}\right)\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}{\mathbf{mod}}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}{13}\\ \left({12}{}{{x}}^{{4}}{+}{{x}}^{{3}}{+}{8}{}{{x}}^{{2}}{+}{11}{}{x}{+}{5}\right)\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}{\mathbf{mod}}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}{13}\end{array}\right]\right]$ (7)
 > $\mathrm{M1}≔\mathrm{Mod}\left(13,\mathrm{Vl},x=2,{\mathrm{integer}}_{[]}\right)$
 ${\mathrm{M1}}{≔}\left[\begin{array}{cccc}{7}& {10}& {8}& {0}\\ {5}& {3}& {4}& {0}\\ {10}& {9}& {2}& {12}\end{array}\right]$ (8)
 > $\mathrm{M2}≔\mathrm{Create}\left(13,3,3,{\mathrm{integer}}_{[]}\right):$
 > $\mathrm{Mod}\left(13,\mathrm{Vl},1..3,2..4,x=2,\mathrm{M2}\right):$
 > $\mathrm{M2}$
 $\left[\begin{array}{ccc}{10}& {8}& {0}\\ {3}& {4}& {0}\\ {9}& {2}& {12}\end{array}\right]$ (9)

Extended evaluation syntax.

 > $L≔\left[ⅇ,{x}^{7},x,\mathrm{RootOf}\left({Z}^{2}+1\right),\frac{x}{y},233\right]$
 ${L}{≔}\left[{ⅇ}{,}{{x}}^{{7}}{,}{x}{,}{\mathrm{RootOf}}{}\left({{\mathrm{_Z}}}^{{2}}{+}{1}\right){,}\frac{{x}}{{y}}{,}{233}\right]$ (10)
 > $V≔\mathrm{Mod}\left(13,L,\left\{ⅇ=3,{x}^{7}=2,x=1,\frac{x}{y}=2,y=0,\mathrm{RootOf}\left({Z}^{2}+1\right)=10\right\},{\mathrm{float}}_{8}\right)$
 ${V}{≔}\left[\begin{array}{c}{3.}\\ {2.}\\ {1.}\\ {10.}\\ {2.}\\ {12.}\end{array}\right]$ (11)

Floating-point input. This is not a good choice, notice the rounding.

 > $V≔{\mathrm{Vector}}_{\mathrm{row}}\left(5,i→\frac{\mathrm{irem}\left(\mathrm{rand}\left(\right),130\right)}{10.0},\mathrm{datatype}={\mathrm{float}}_{8}\right)$
 ${V}{≔}\left[\begin{array}{ccccc}{4.}& {1.80000000000000}& {10.5000000000000}& {12.9000000000000}& {3.70000000000000}\end{array}\right]$ (12)
 > $\mathrm{Mod}\left(13,V,{\mathrm{integer}}_{[]}\right)$
 $\left[\begin{array}{ccccc}{4}& {1}& {10}& {12}& {3}\end{array}\right]$ (13)