commands → mulmod

mulmod(A,B,P)
mulmod(A,B,C,X)
mulmod(A,B,C,X,P)

The mulmod command computes A*B modulo P efficiently. In the case of polynomials the fourth argument X specifies the variable and an optional fifth argument P specifies the modulus.

Examples

# integers
mulmod(2,2,4);
	0

# polynomials
mulmod(x-1,x+1,x^2+x+1,x);
	-x-2

# polynomials mod p
mulmod(x-1,x+1,x^2+x+1,x,11);
	10*x+9

References

Gullberg, Jan. Mathematics: From the Birth of Numbers. Norton, 1996.