^ -- raise an expression to a
power
Introductionx^y computes the y-th power of
x.
Call(s)
x^y
_power(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, *, /, +, -, numlib::ispower, powermod
Detailsx^y is equivalent to the function call _power(x,
y).^ is left associative:
x^y^z is parsed as (x^y)^z. Cf.
example 2.x is a polynomial of type DOM_POLY, then y must
be a nonnegative integer._power is overloaded for matrix domains (matrix). In particular,
x^(-1) returns the inverse of the matrix
x.powermod to
compute modular powers. Cf. example 3.sqrt(x) is equivalent to
x^(1/2). Note, however, that sqrt tries to simplify the result. Cf.
example 4.x or y is an element of a domain with
a slot "_power", then this method
is used to compute x^y. Many library domains overload the
^ operator by an appropriate "_power" slot.
Powers 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 "_power", it is called in the
form d::_power(x, y). The result returned by
d::_power is the result of x^y.
X, Y, the power
X^Y is the set {x^y; x in X; y in Y}._power is a function of the system kernel.
Example
1Some powers are computed:
>> 2^10, I^(-5), 0.3^(1/3), x^(1/2) + y^(-1/2), (x^(-10) + 1)^2
1/2 1 / 1 \2
1024, - I, 0.66943295, x + ----, | --- + 1 |
1/2 | 10 |
y \ x /
Use expand to ``expand'' powers of
sums:
>> (x + y)^2 = expand((x + y)^2)
2 2 2
(x + y) = 2 x y + x + y
Note that identities such as (x*y)^z =
x^z * y^z only hold in certain areas of the complex
plane:
>> ((-1)*(-1))^(1/2) <> (-1)^(1/2) * (-1)^(1/2)
1 <> -1
Consequently, the following expand command does not expand its
argument:
>> expand((x*y)^(1/2))
1/2
(x y)
Example
2The power operator ^ is left
associative:
>> 2^3^4 = (2^3)^4, x^y^z
y z
4096 = 4096, (x )
Example
3Modular powers can be computed directly using
^ and mod.
However, powermod is
more efficient:
>> 123^12345 mod 17 = powermod(123, 12345, 17)
4 = 4
Example
4The function sqrt produces simpler results than
_power:
>> sqrt(4*x*y), (4*x*y)^(1/2)
1/2 1/2
2 (x y) , (4 x y)
Example
5For finite sets, X^Y is the set {x^y;
x in X; y in Y}:
>> {a, b, c}^2, {a, b, c}^{q, r, s}
2 2 2 q r q s r q s r s
{a , b , c }, {a , a , b , a , b , c , b , c , c }
Example
6Various library domains such as matrix domains or residue class domains overload
_power:
>> x := Dom::Matrix(Dom::IntegerMod(7))([[2, 3], [3, 4]]): x^2, x^(-1), x^3 * x^(-3)
+- -+ +- -+
| 6 mod 7, 4 mod 7 | | 3 mod 7, 3 mod 7 |
| |, | |,
| 4 mod 7, 4 mod 7 | | 3 mod 7, 5 mod 7 |
+- -+ +- -+
+- -+
| 1 mod 7, 0 mod 7 |
| |
| 0 mod 7, 1 mod 7 |
+- -+
>> delete x:
Example
7This example demonstrates the behavior of
_power on user-defined domains. Without a
"power" slot, powers of domain
elements are handled like any other symbolic powers:
>> myDomain := newDomain("myDomain"): x := new(myDomain, 1): x^2
2
(new(myDomain, 1))
>> type(x^2), op(x^2, 0), op(x^2, 1), op(x^2, 2)
"_power", _power, new(myDomain, 1), 2
After the "_power" slot is defined, this
method is used to compute powers of myDomain objects:
>> myDomain::_power := proc() begin "The result" end: x^2
"The result"
>> delete myDomain, x: