LinearAlgebra[Modular]
Mod
apply 'mod' to input with optional evaluation list producing a mod m Matrix or Vector as output
Calling Sequence
Parameters
Description
Examples
Mod(m, A, eval, dtype, order)
Mod(m, A, eval, B)
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
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[4]/integer[8], float[8], 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[8] datatype).
Note: The float[8] datatype is provided primarily for conversion from a float[8] 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, x7 or Rootof⁡Z2+1, 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 x7=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](..).
Conversion of a integer Matrix to a mod m integer[] Matrix.
with⁡LinearAlgebraModular:
A≔Matrix⁡4,4,i,j↦rand⁡
A≔39571886053419313981641522424170465800187484459427552056869842622684442412286285840996417214180386408307450694607189265773012980023730616292946106507053657396412723003944913350029210936428922
Am≔Mod⁡13,A,integer
Am≔10081226011921174111211
Conversion of a list of lists of rationals to a mod m float[8] Matrix.
B≔153933017312211754691347,235538926099196277296419,836404711117474259255346,22408504461978606118334,10295483279979957903184,5426152123930724083518,867557918169866818474138,966905297479497201520366,6951973063345453427109,988383200003735342248716
Mod⁡13,B,float8
12.0.0.0.1.11.0.0.11.0.5.0.12.6.11.3.
Evaluation of a list of polynomials to a row vector.
C≔seq⁡randpoly⁡x,i=1..4
C≔75⁢x5−92⁢x4+6⁢x3+74⁢x2+72⁢x+37,−23⁢x5+87⁢x4+44⁢x3+29⁢x2+98⁢x−23,10⁢x5−61⁢x4−8⁢x3−29⁢x2+95⁢x+11,−49⁢x5−47⁢x4+40⁢x3−81⁢x2+91⁢x+68
Mod⁡13,C,transpose,x=2,integer
101026
Evaluation of a list of Vectors of modp1 polynomials to a new Matrix, and to an existing Matrix with sub-specification.
Vl≔seq⁡Vectorcolumn⁡3,i↦modp1⁡ConvertIn⁡randpoly⁡x,x,13,i=1..4
Vl≔3⁢x5+5⁢x4+x3+12⁢x2+4⁢x+1mod13x5+3⁢x4+11⁢x3+3⁢x2+4⁢x+12mod1311⁢x5+6⁢x4+8⁢x3+7⁢x2+4⁢x+8mod13,x5+4⁢x4+x3+3⁢x+4mod13x5+11⁢x4+5⁢x3+3⁢x+9mod136⁢x5+3⁢x4+5⁢x3+9⁢x2+5⁢x+8mod13,7⁢x5+4⁢x4+7⁢x3+10⁢x2+11⁢x+5mod135⁢x5+9⁢x4+12⁢x3+7mod13x5+12⁢x4+x3+5⁢x2+5⁢xmod13,5⁢x5+11⁢x4+6⁢x3+5⁢x2+12mod136⁢x5+7⁢x4+7⁢x3+10⁢x2+7⁢x+2mod1312⁢x4+x3+8⁢x2+11⁢x+5mod13
M1≔Mod⁡13,Vl,x=2,integer
M1≔710805340109212
M2≔Create⁡13,3,3,integer:
Mod⁡13,Vl,1..3,2..4,x=2,M2:
M2
10803409212
Extended evaluation syntax.
L≔exp⁡1,x7,x,RootOf⁡Z2+1,xy,233
L≔ⅇ,x7,x,RootOf⁡_Z2+1,xy,233
V≔Mod⁡13,L,x=1,y=0,xy=2,RootOf⁡Z2+1=10,x7=2,exp⁡1=3,float8
V≔3.2.1.10.2.12.
Floating-point input. This is not a good choice, notice the rounding.
V≔Vectorrow⁡5,i↦0.1000000000⋅irem⁡rand⁡,130,datatype=float8
V≔4.1.8000000000000010.500000000000012.90000000000003.70000000000000
Mod⁡13,V,integer
4110123
See Also
LinearAlgebra/Details
LinearAlgebra[Modular][Copy]
LinearAlgebra[Modular][Create]
LinearAlgebra[Modular][subspec]
randpoly
seq
Vector
Download Help Document