divide and mod / remainder Operators
Date: 2020-10-07 18:10:00

Up | Next | Prev | PrevTail | Tail

### 9.6 divide and mod / remainder Operators

The operators divide and mod / remainder implement Euclidean division of polynomials. 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

The inﬁx operator is an alias for remainder, e.g.

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

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 ﬁrst 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 inﬁx operator:

(x^2 + y^2) divide (x - y);
2
{x + y,2*y }

All Euclidean division operators (when used in preﬁx form, and including the standard remainder operator) accept an optional third argument, which speciﬁes 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

remainder(x^2 + y^2, x - y, y);
2
2*x
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 }
remainder(x^2 + y^2, x - y, x);
2
2*y

Up | Next | Prev | PrevTail | Front