Documentation

# `^`, `_power`

Raise an expression to a power

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.

For the `power` function in MATLAB®, see `power`.

## Syntax

```x ^ y
_power(`x`, `y`)
```

## Description

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

`x^y` is equivalent to the function call ```_power(x, y)```.

The power operator `^` is left associative: `x^y^z` is parsed as `(x^y)^z`. Cf. Example 2.

If `x` is a polynomial of type `DOM_POLY`, then `y` must be a nonnegative integer smaller than 231.

`_power` is overloaded for matrix domains (`matrix`). In particular, `x^(-1)` returns the inverse of the matrix `x`.

Use `powermod` to compute modular powers. Cf. Example 3.

Mathematically, the call `sqrt(x)` is equivalent to `x^(1/2)`. Note, however, that `sqrt` tries to simplify the result. Cf. Example 4.

If `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`.

See Example 6 and Example 7.

For finite sets `X`, `Y`, the power `X^Y` is the set .

## Examples

### Example 1

Some powers are computed:

`2^10, I^(-5), 0.3^(1/3), x^(1/2) + y^(-1/2), (x^(-10) + 1)^2`
` `

Use `expand` to “expand” powers of sums:

`(x + y)^2 = expand((x + y)^2)`
` `

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)`
` `

Consequently, the following `expand` command does not expand its argument:

`expand((x*y)^(1/2))`
` `

### Example 2

The power operator `^` is left associative:

`2^3^4 = (2^3)^4, x^y^z`
` `

### Example 3

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

`123^12345 mod 17 = powermod(123, 12345, 17)`
` `

### Example 4

The function `sqrt` produces simpler results than `_power`:

`sqrt(4*x*y), (4*x*y)^(1/2)`
` `

### Example 5

For finite sets, `X^Y` is the set :

`{a, b, c}^2, {a, b, c}^{q, r, s}`
` `

### 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)```
` `
`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`
` `
`type(x^2), op(x^2, 0), op(x^2, 1), op(x^2, 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`
` `
`delete myDomain, x:`

## Parameters

 `x`, `y`

## Return Values

Arithmetical expression, a polynomial, a floating-point interval, or a set.

`x`, ` y`