> ## Documentation Index
> Fetch the complete documentation index at: https://prod-mint.classiq.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Power

The *power* statement applies the unitary operation raised to some integer power,
where the unitary is specified as a nested statement block.

## Syntax

<Tabs>
  <Tab title="Python">
    [comment]: DO_NOT_TEST

    ```python theme={null}
    def power(exponent: CInt, stmt_block: QCallable) -> None:
        pass
    ```
  </Tab>

  <Tab title="Native">
    **power** **(** *exponent* **)** **\{** *statements* **}**
  </Tab>
</Tabs>

## Semantics

* If the statement block specifies the unitary operation $U$ on some quantum object,
  *power* applies $U^{exponent}$.
* In the general case, the statement block is iterated over *exponent* times, but in some important
  special cases the operation is implemented more efficiently.
* Quantum variables declared outside the *power* statement and used inside its nested
  block must be initialized prior to it and remain initialized subsequently.
* Quantum variables declared inside the *power* statement, including in
  nested function calls, must be uninitialized at the end of the statement.

## Examples

In the following example `power` is applied 3 times - to gate-level functions `H` and `RX`,
and to a user-defined function `foo`. It demonstrates both special and general treatment
of the *power* operation.

<Tabs>
  <Tab title="Python">
    ```python theme={null}
    from classiq import *
    from classiq.qmod.symbolic import pi


    @qfunc
    def foo(p: CInt, q: QBit):
        power(p, lambda: H(q))
        power(p, lambda: PHASE(pi / 8, q))


    @qfunc
    def main(q: Output[QBit]):
        allocate(q)
        power(2, lambda: foo(5, q))
    ```
  </Tab>

  <Tab title="Native">
    ```
    qfunc foo(p: int, q: qbit) {
      power (p) {
        H(q);
      }
      power (p) {
        PHASE(pi / 8, q);
      }
    }

    qfunc main() {
      q: qbit;
      allocate(q);
      power (2) {
        foo(5, q);
      }
    }
    ```
  </Tab>
</Tabs>

Synthesizing this model creates the quantum program shown below.
Because two consecutive applications of `H` cancel each other out, raising `H` to the power
of 5 is equivalent to applying `H` once. Raising `RX` with rotation angle $\pi / 8$ to the
power 5 is equivalent to applying `RX` with rotation angle $5 \times \pi / 8$. However, raising
`foo` to the power 2 requires 2 consecutive applications of `foo`.

<img src="https://mintcdn.com/classiq/sA-J-h8chQJV9OAG/qmod-reference/language-reference/statements/resources/power.png?fit=max&auto=format&n=sA-J-h8chQJV9OAG&q=85&s=75e11710990e796de8d88a7f4157eadd" alt="power.png" width="832" height="70" data-path="qmod-reference/language-reference/statements/resources/power.png" />
