modp1
univariate polynomial arithmetic modulo n
Calling Sequence
Parameters
Description
Examples
modp1(e, n)
e
-
algebraic expression
n
positive integer
The modp1 function provides very efficient arithmetic and other operations in the domain of univariate polynomials over the integers modulo n, written Zn[x]. The mod function, which supports operations in the domain of multivariate polynomials over the integers modulo n, uses modp1 for the univariate case. Hence, interactive calculations can be performed using mod.
To achieve a high level of efficiency, modp1 uses a special representation. Explicit conversions are provided for converting the Maple "sum of products" representation to and from this representation and also from a list of integers representing a polynomial to and from this representation. Knowledge of this representation is not required by the user to use modp1. If the modulus n is sufficiently small, arithmetic in Zn is performed directly by the hardware instead of using multi-precision integer arithmetic and the data representation is an array of machine integers. The modp1(Prime(1)) command returns the largest prime for which arithmetic is done in the hardware. On a 32-bit machine, this is the prime 46327. On a 64-bit machine, this is the prime 3037000453.
A typical use of modp1 is modp1(Eval(a, x), n), which evaluates the modp1 polynomial a at the value x (an integer) modulo n. The modp1 function accepts the following functions, whose names are also protected global names.
Add
Chrem
Coeff
Constant
ConvertIn
ConvertOut
Degree
Det
Diff
Divide
Embed
Eval
Factors
Gcd
Gcdex
Indeterminate
Interp
Irreduc
IsConstant
IsOne
IsZero
Lcm
Lcoeff
Ldegree
Modulus
Monomial
Multiply
One
Power
Powmod
Prem
Prime
Quo
Randpoly
Rem
Resultant
Roots
Smith
Shift
Sqrfree
Subtract
Tcoeff
Translate
UNormal
Zero
The Add function is n-ary. The Subtract function is unary or binary. The Zero and One nullary functions create the 0 and 1 modp1 polynomials. (The One and Zero functions require one argument, the indeterminate variable.) The Constant function creates a modp1 polynomial for the given integer constant. (The Constant function requires a second argument, the indeterminate variable.) The Multiply function is binary. Note that scalar multiplication requires explicit conversion using the Constant function.
The Degree function computes the degree. The Ldegree function computes the low degree. The Coeff function computes the coefficient. The Lcoeff function computes the leading coefficient. The Tcoeff function computes the trailing Coefficient. The Diff function computes the derivative. The UNormal function computes the monic part or unit normal part. Note that Degree returns 0 and Ldegree returns 1 for the zero modp1 polynomial. The Randpoly function takes a degree as an argument and generates a polynomial of the given degree with random coefficients modulo n.
The ConvertIn and ConvertOut functions convert to and from the modp1 representation. The modp1(ConvertIn(b, x), n) command converts from a univariate polynomial b in x over the integers to a modp1 polynomial modulo n. The modp1(ConvertIn([a0, a1, ..., ak], x), n) command converts from the given list of integers representing the polynomial a0+a1⁢x+...+ak⁢xk to a modp1 polynomial. The ConvertOut function does the reverse of ConvertIn.
Note that unlike the mod function, modp1 arithmetic operations do not take the variable as an argument. For example, the calling sequences of the Rem operation are Rem(a, b) and Rem(a, b, 'q'). Calling sequences are similar for Coeff, Degree, Diff, Discrim, Gcdex, Interp, Lcoeff, Ldegree, Powmod, Prem, Quo, Resultant, Smith, and Tcoeff.
The Constant, Interp, Monomial, One, Randpoly, and Zero functions all expect their last argument to be the indeterminate variable. The indeterminate of an existing modp1 polynomial can be queried using the Indeterminate function. The modulus can be queried using Modulus.
The IsZero, IsOne, and IsConstant boolean functions must be used to check against an integer constant value. The zero polynomial is not the same as the zero modp1 polynomial.
Separate help exists for most of the remaining functions.
p≔11
a≔modp1⁡ConvertIn⁡x4−x2+2,x,p
a≔x4+10⁢x2+2mod11
modp1⁡IsZero⁡a,p
false
modp1⁡Degree⁡a,p
4
modp1⁡Coeff⁡a,2,p
10
b≔modp1⁡ConvertIn⁡1,−2,3,4,x,p
b≔4⁢x3+3⁢x2+9⁢x+1mod11
modp1⁡Multiply⁡a,b,p
4⁢x7+3⁢x6+5⁢x5+9⁢x4+10⁢x3+5⁢x2+7⁢x+2mod11
modp1⁡Rem⁡a,b,p
9⁢x2+9⁢x+7mod11
Convert to a Maple polynomial.
modp1⁡ConvertOut⁡b,x,p
4⁢x3+3⁢x2+9⁢x+1
Convert to a list of coefficients.
modp1⁡ConvertOut⁡b,p
1,9,3,4
zero≔modp1⁡Zero⁡x,p
zero≔0mod11
evalb⁡zero=0
a≔modp1⁡Randpoly⁡10,x,p
a≔6⁢x10+9⁢x9+5⁢x8+x7+10⁢x6+3⁢x5+5⁢x4+4⁢x3+10⁢x2+7mod11
The next example results in an error because you cannot mix Maple operations with modp1 operations.
3⁢a
Error, invalid terms in product: modp1(ConvertIn(6*x^10+9*x^9+5*x^8+x^7+10*x^6+3*x^5+5*x^4+4*x^3+10*x^2+7,x),11)
Scalar multiplication
modp1⁡Multiply⁡Constant⁡3,x,b,p
x3+9⁢x2+5⁢x+3mod11
Roots and their multiplicities
modp1⁡Roots⁡a,p
6,1,8,1
Factors and their multiplicities
modp1⁡Factors⁡a,p
6,x3+10⁢x2+x+8mod11,1,x+3mod11,1,x5+2⁢x3+9⁢x2+5⁢x+8mod11,1,x+5mod11,1
b≔modp1⁡Randpoly⁡9,x,p
b≔9⁢x9+10⁢x8+x7+x6+3⁢x5+7⁢x4+10⁢x3+2⁢x2+8⁢x+9mod11
Extended Euclidean algorithm
g≔modp1⁡Gcdex⁡a,b,s,t,p
g≔x+5mod11
Check s⁢a+t⁢b=g
modp1⁡Add⁡Multiply⁡s,a,Multiply⁡t,b,p
x+5mod11
s is the inverse of amodb
modp1⁡Rem⁡Multiply⁡s,a,b,p
See Also
mod
modp2
type/zppoly
Download Help Document