/ -- divide expressions
Introductionx/y computes the quotient of x and
y.
Call(s)
x/y _divide(x, y)
Parametersx, y, ... |
- | arithmetical expressions,
polynomials of type DOM_POLY, or sets |
Returnsan arithmetical expression, a polynomial, or a set.
x, y
Related
Functions_invert, _negate, ^, *, +, -, div, divide, pdivide, poly
Detailsx/y is equivalent to the function call
_divide(x, y).Type::Numeric, the quotient is
returned as a number.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)).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.
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.X, Y, the quotient
X/Y is the set {x/y; x in X; y in Y}._divide is a function of the system kernel.
Example
1The quotient of numbers is simplified to a number:
>> 1234/234, 7.5/7, 6*I/2
617/117, 1.071428571, 3 I
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)
1
"_mult", _mult, x, -
y
>> op(op(x/y, 2), 0), op(op(x/y, 2), 1), op(op(x/y, 2), 2)
_power, y, -1
Example
2For finite sets X, Y, the
quotient X/Y is the set {x/y; x in X; y in
Y}:
>> {a, b, c} / {2, 3}
{ a a b b c c }
{ -, -, -, -, -, - }
{ 2 3 2 3 2 3 }
Example
3Polynomials 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 + 1, [x])
>> poly(x^2 - 1, [x]) / poly(x - 2, [x])
FAIL
The function divide provides division with a
remainder:
>> divide(poly(x^2 - 1, [x]), poly(x - 2, [x]))
poly(x + 2, [x]), poly(3, [x])
The polynomials must have the same indeterminates and the same coefficient ring:
>> poly(x^2 - 1, [x, y]) / poly(x - 1, [x])
Error: Illegal argument [divide]
Example
4Various 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
+- -+
| 11/2, -9/2 |
| |
| 9/2, -7/2 |
+- -+
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
FAIL
>> delete x, y:
Example
5This 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)
new(Do, 1)
----------
new(Do, 2)
1
_mult, new(Do, 1), ----------
new(Do, 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
"The Result"
>> delete Do, x, y: