REDUCE

9.6 Euclidean Division

The operators divide, poly_quotient and mod / remainder implement Euclidean division of polynomials (over the current number domain). The remainder operator is used with the syntax

     remainder(exprn1:polynomial,exprn2:polynomial):
          polynomial.

It returns the remainder when exprn1 is divided by exprn2. This is the true remainder based on the internal ordering of the variables, and not the pseudo-remainder.

Examples:

     remainder((x + y)*(x + 2*y), x + 3*y)  ->  2*y^2
     remainder(2*x + y, 2)                  ->  y

CAUTION: In the default case, remainders are calculated over the integers. If you need the remainder with respect to another domain, it must be declared explicitly.

Example:

     remainder(x^2 - 2, x + sqrt(2));  ->  x^2 - 2
     load_package arnum;
     defpoly sqrt2^2 - 2;
     remainder(x^2 - 2, x + sqrt2);    ->  0

(Note the use of sqrt2 in place of sqrt(2) in the second call of remainder.)

The infix operator mod is an alias for remainder when at least one operand is explicitly polynomial, e.g.

     (x^2 + y^2) mod (x - y);

        2
     2*y

However, when both operands are integers, mod implements the integer modulus operation, regardless of the current number domain, e.g.

     7 mod 4  ->  3

The Euclidean division operator divide is used with the syntax

     divide(exprn1:polynomial,exprn2:polynomial):
          list(polynomial,polynomial)

and returns both the quotient and the remainder together as the first and second elements of a list, e.g.

     divide(x^2 + y^2, x - y);

               2
     {x + y,2*y }

It can also be used as an infix operator:

     (x^2 + y^2) divide (x - y);

               2
     {x + y,2*y }

The infix operator poly_quotient returns only the quotient, i.e. the first element of the list returned by divide.

All Euclidean division operators (when used in prefix form) accept an optional third argument, which specifies the main variable to be used during the division. The default is the leading kernel in the current global ordering. Specifying the main variable does not change the ordering of any other variables involved, nor does it change the global environment. For example

     divide(x^2 + y^2, x - y, y);

                    2
     { - (x + y),2*x }

Specifying \(x\) as main variable gives the same behaviour as the default shown earlier, i.e.

     divide(x^2 + y^2, x - y, x);

               2
     {x + y,2*y }

All Euclidean division operators accept a (possibly nested) list as first argument/operand and map over that list, e.g.

     {x, x + 1, x^2 - 1} mod x - 1;

     {1,2,0}


Hosted by Download REDUCE Powered by MathJax