## Documentation |

Divide expressions

This functionality does not run in MATLAB.

x / y_divide(x,y)

`x/y` computes the quotient of `x` and `y`.

`x/y` is equivalent to the function call `_divide(x,
y)`.

For numbers of type `Type::Numeric`, the quotient is returned
as a number.

If neither `x` nor `y` are
elements of library
domains with `"_divide"` methods, `x/y` is
internally represented as `x * y^(-1)` = `_mult(x,
_power(y, -1))`.

If `x` or `y` is an element
of a domain with a slot`"_divide"`,
then this method is used to compute `x/y`. Many library domains overload
the `/` operator by an appropriate `"_divide"` slot.
Quotients are processed as follows:

`x/y` is searched for elements of library domains
from left to right. Let `z` (either `x` or `y`)
be the first term that is not of one of the basic types provided by
the kernel (numbers, expressions, etc.). If the domain `d` = `z::dom` = `domtype(z)` has
a slot`"_divide"`, it
is called in the form `d::_divide(x, y)`. The result
returned by `d::_divide` is the result of `x/y`.

Cf. examples Example 4 and Example 5.

Polynomials of type `DOM_POLY` can be divided by `/`,
if they have the same indeterminates and the same coefficient ring,
and if exact division is possible. The function `divide` can be used to compute the quotient
of polynomials with a remainder term.

For finite sets `X`, `Y`,
the quotient `X/Y` is the set
.

The quotient of numbers is simplified to a number:

1234/234, 7.5/7, 6*I/2

Internally, a symbolic quotient `x/y` is represented
as the product `x * y^(-1)`:

type(x/y), op(x/y, 0), op(x/y, 1), op(x/y, 2)

op(op(x/y, 2), 0), op(op(x/y, 2), 1), op(op(x/y, 2), 2)

For finite sets `X`, `Y`,
the quotient `X/Y` is the set
:

{a, b, c} / {2, 3}

Polynomials of type `DOM_POLY` can be divided by `/` if
they have the same indeterminates, the same coefficient ring, and
if exact division is possible:

poly(x^2 - 1, [x]) / poly(x - 1, [x])

poly(x^2 - 1, [x]) / poly(x - 2, [x])

The function `divide` provides
division with a remainder:

divide(poly(x^2 - 1, [x]), poly(x - 2, [x]))

The polynomials must have the same indeterminates and the same coefficient ring:

poly(x^2 - 1, [x, y]) / poly(x - 1, [x])

Error: The argument is invalid. [divide]

Various library domains such as matrix domains
overload `_divide`. The matrix domain defines `x/y` as `x
* (1/y)`, where `1/y` is the inverse of `y`:

x := Dom::Matrix(Dom::Integer)([[1, 2], [3, 4]]): y := Dom::Matrix(Dom::Rational)([[10, 11], [12, 13]]): x/y

The inverse of `x` has rational entries. Therefore, `1/x` returns `FAIL`, because
the component ring of `x` is `Dom::Integer`. Consequently,
also `y/x` returns `FAIL`:

y/x

delete x, y:

This example demonstrates the behavior of `_divide` on
user-defined domains. In the first case below, the user-defined domain
does not have a `"_divide"`slot.
Thus `x/y` is transformed to `x * (1/y)`:

Do := newDomain("Do"): x := new(Do, 1): y := new(Do, 2): x/y; op(x/y, 0..2)

After the slot`"_divide"` is
defined in the domain `Do`, this method is used to
divide elements:

Do::_divide := proc() begin "The Result" end: x/y

delete Do, x, y:

Was this topic helpful?