Documentation

# `divide`

Divide polynomials

MuPAD® notebooks will be removed in a future release. Use MATLAB® live scripts instead.

MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.

## Syntax

```divide(`p`, `q`, <`[x]`>, <`order`>, `options`)
divide(`p`, `q`, <`[x1, x2, …]`>, <`order`>, `options`)
divide(`p`, `q1, q2, …`, <`order`>, `options`)
```

## Description

`divide(p, q)` divides polynomials or polynomial expressions `p` and `q`. By default, the function returns the quotient s and the remainder r, such that p = sq + r. Here degree(r) < degree(q).

`divide`(p, q1, q2, q3, …, qn) divides a polynomial or a polynomial expression `p` by polynomials or polynomial expressions q1, q2, q3, …, qn. The function returns the quotients s1, s2, s3, …, sn and the remainder `r`, such that p = s1q1 + s2q2 + s3q3 + … + s4q4 + r. Here the leading coefficient of the remainder `r` cannot be divided by the leading coefficients of any of divisors q1, q2, q3, …, qn.

`divide(p, q)` divides the polynomial or polynomial expression `p` by the polynomial or polynomial expression `q`. Use the `Quo` option to return the quotient only. Use the `Rem` option to return the remainder only.

The `divide` function operates on polynomials or polynomial expressions.

Polynomials must be of the same type: their variables and coefficient rings must be identical.

When you call `divide` for polynomial expressions, MuPAD® internally converts these expressions to polynomials. See the `poly` function. If you do not specify the list of indeterminates, `divide` treats all symbolic variables in the expressions as indeterminates. If the expressions cannot be converted to polynomials, the `divide` function returns `FAIL`. See Example 1.

If you call `divide` for polynomials, it returns polynomials. If you call `divide` for polynomial expressions, the function returns polynomial expressions. See Example 2.

If you divide polynomial expressions that contain more than one variable, you can specify particular variables to be treated as variables. The `divide` function treats all other variables as symbolic parameters. By default, `divide` assumes that all variables in polynomial expressions are variables, and none of them is a symbolic parameter. See Example 3.

`divide`(p, q1, q2, q3, …, qn) divides a polynomial or a polynomial expression `p` by polynomials or polynomial expressions q1, q2, q3, …, qn. The function returns quotients s1, s2, s3, …, sn and remainder `r`, such that p = s1q1 + s2q2 + s3q3 + … + s4q4 + r. Here the leading coefficient of the remainder `r` cannot be divided by the leading coefficients of any of the divisors q1, q2, q3, …, qn. See Example 6.

When dividing a polynomial by one or more polynomials, you can select the term ordering. The ordering accepts the following values:

• `LexOrder` sets the lexicographical ordering.

• `DegreeOrder` sets the total degree ordering. When using this ordering, MuPAD sorts the terms of a polynomial according to the total degree of each term (the sum of the exponents of the variables).

• `DegInvLexOrder` sets the total degree inverse lexicographic ordering. When using this ordering, MuPAD sorts the terms of a polynomial according to the total degree of each term (the sum of the exponents of the variables). If the several terms have equal total degrees, MuPAD sorts them using the inverse lexicographic ordering.

• your custom term ordering of type `Dom::MonomOrdering`.

The coefficient ring of the polynomials must implement the `"_divide"` method. MuPAD uses this method internally to divide coefficients. If the coefficients cannot be divided, this method must return `FAIL`.

## Examples

### Example 1

For polynomial expressions, `divide` internally calls the `poly` function, which converts an expression to a polynomial. If you do not specify the indeterminate of an expression, MuPAD assumes that all variables are indeterminates. For example, The `divide` function cannot divide the following polynomial expressions because it assumes that both `x` and `y` are indeterminates:

`divide(x/y, x)`
` `

If you specify that only `x` is an indeterminate, the result is:

`divide(x/y, x, [x])`
` `

### Example 2

The `divide` divides polynomials or polynomial expressions. When you divide polynomials, the function returns polynomials:

`divide(poly(x^3 + x + 1, [x]), poly(x^2 + x + 1, [x]))`
` `

When you divide polynomial expressions, MuPAD internally converts these expressions to polynomials, divides these polynomials, and then converts the result of division to polynomial expressions:

`divide(x^3 + x + 1, x^2 + x + 1)`
` `

### Example 3

When dividing multivariate polynomials, you can specify the list of variables. The `divide` function assumes all other variables are symbolic parameters. For example, divide the following two polynomial expressions specifying that both `x` and `y` are variables:

`divide(x^2 - 2*x - y, y*x - 1, [x, y])`
` `

Divide the same polynomial expressions specifying that only `x` is a variable. MuPAD assumes that `y` is a symbolic parameter:

`divide(x^2 - 2*x - y, y*x - 1, [x])`
` `

Now, divide these expressions specifying that only `y` is a variable. MuPAD assumes that `x` is a symbolic parameter:

`divide(x^2 - 2*x - y, y*x - 1, [y])`
` `

By default, the `divide` function treats polynomial expressions with more than one variable as multivariate polynomial expressions. The function does not assume that any of the variables are symbolic parameters:

`divide(x^2 - 2*x - y, y*x - 1)`
` `

### Example 4

By default, `divide` returns the quotient and the remainder of the division of polynomials:

`divide(x^3 + x + 1, x^2 + x + 1)`
` `

To return the quotient only, use the `Quo` option:

`divide(x^3 + x + 1, x^2 + x + 1, Quo)`
` `

To return the remainder only, use the `Rem` option:

`divide(x^3 + x + 1, x^2 + x + 1, Rem)`
` `

### Example 5

Suppose, you want to get the result of the division only when the exact division is possible. To return the quotient `s` of the exact division of polynomials or polynomial expressions, use the `Exact` option:

`divide(x^4 + 12*x^3 + 28*x^2 + 204*x + 187, x + 11, Exact)`
` `

When exact division without remainder is impossible, the `divide` function with the `Exact` option returns `FAIL`:

`divide(x^4 + 12*x^3 + 28*x^2 + 204*x + 187, x + 12, Exact)`
` `

### Example 6

The `divide` function allows you to divide a polynomial (or polynomial expression) by multiple polynomials (or polynomial expressions):

`divide(4*x^4 + 2*x^2 + 1, x^3 - x + 1, x - 1)`
` `

When dividing a polynomial by multiple polynomials, you can select the term ordering:

`divide(x^2+y^3+1, x-y^2, y, LexOrder)`
` `
`divide(x^2+y^3+1, x-y^2, y, DegreeOrder)`
` `

## Parameters

 `p`, `q` Univariate or multivariate polynomials or polynomial expressions. `p`, `q1, q2, …` Univariate or multivariate polynomials or polynomial expressions. `x` The indeterminate of the polynomial: typically, an identifier or an indexed identifier. `divide` treats the expressions as univariate polynomials in the indeterminate `x`. `x1, x2, …` The indeterminates of the polynomial: typically, identifiers or indexed identifiers. `divide` treats multivariate expressions as multivariate polynomials in these indeterminates. `order` The term ordering when dividing one multivariate polynomial by one or more multivariate polynomials: `LexOrder`, `DegreeOrder`, `DegInvLexOrder`, or a custom term ordering of type `Dom::MonomOrdering`. The default is the lexicographical ordering `LexOrder`.

## Options

 `Exact` Return the quotient `s` of the exact division of multivariate polynomials. If no exact division without remainder is possible, return `FAIL`. `Quo`, `Rem` Return the quotient `s` or the remainder `r`. By default, the `divide` function returns both the quotient and the remainder.

## Return Values

Polynomial, a polynomial expression, a sequence of polynomials or polynomial expressions, or the value `FAIL`.

`p`, `q`