
powermod - power modulo of a number or polynomial

Calling sequence:
powermod(expr_1, integer, expr_2)

Parameter:
expr_1, expr_2  --   expressions
integer         --   non-negative integer

Summary:

powermod(b,e,m) calculates the power b^e mod m for a non-negative integer
exponent e.  It is much more efficient as the direct calculation of such an
expression.

 o  If the modulus m is a positive integer then the base b must be a rational
    number or an expression which may be converted to an IntMod-polynomial.

    If b is a rational number then the modular inverse of the denominator
    is calulated and then multiplied with the numerator.

 o  In any other case the modulus m must be a univariate polynomial or
    polynomial expression.  The base b must be an expression which may
    be converted to a polynomial of the same type as m. The polynomials
    are then divided by divide.

If the modulus m is an integer and the base b a rational then dependent
on the current definition of the system function _mod, either the positive or
symmetrical integer modulus is calculated. However, when using powermod,
_mod may not be a user-defined procedure or function environment. Only the

system functions modp and mods are permitted as values of _mod. If the the
base b is a polynomial then always the symmetrical modulus is calculated.

powermod returns FAIL if one of the expressions can not be converted to
polynomials.

>>  powermod(3,3,7);

      6

>>  powermod(x^2 + 7*x - 3, 2, 7);

      x^2 + x^4 + 2

>>  powermod(x^2 + 7*x - 3, 2, x^2 + 1);

      -56*x - 33

See also:  divide , modp, mods, poly

