Previous Page Next Page Contents

^ -- raise an expression to a power

Introduction

x^y computes the y-th power of x.

Call(s)


x^y
_power(x, y)

Parameters

x, y - arithmetical expressions, polynomials of type DOM_POLY, or sets

Returns

an arithmetical expression, a polynomial, or a set.

Overloadable:

x, y

Related Functions

_invert, _negate, *, /, +, -, numlib::ispower, powermod

Details

Example 1

Some 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 2

The power operator ^ is left associative:

>> 2^3^4 = (2^3)^4, x^y^z 
                                           y z
                            4096 = 4096, (x )

Example 3

Modular powers can be computed directly using ^ and mod. However, powermod is more efficient:

>> 123^12345 mod 17 = powermod(123, 12345, 17)
                                   4 = 4

Example 4

The 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 5

For 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 6

Various 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 7

This 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:

Changes




Do you have questions or comments?


Copyright © SciFace Software GmbH & Co. KG 2000