> ## 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.

# Grover

Functions:

| Name                 | Description                       |
| -------------------- | --------------------------------- |
| `phase_oracle`       | \[Qmod Classiq-library function]. |
| `reflect_about_zero` | \[Qmod Classiq-library function]. |
| `grover_diffuser`    | \[Qmod Classiq-library function]. |
| `grover_operator`    | \[Qmod Classiq-library function]. |
| `grover_search`      | \[Qmod Classiq-library function]. |

### phase\_oracle

<pre><code>phase\_oracle(
predicate: QPerm\[Const\[QArray\[QBit]], QBit],
target: Const\[QArray\[QBit]]
) -> None</code></pre>

\[Qmod Classiq-library function]

Creates a phase oracle operator based on a predicate function.

Applies a predicate function and marks "good" and "bad" states with a phase flip.
If the predicate is marked as $\chi$, and the oracle is marked as $S_\{\chi\}$, then:

$$
S_{\chi}\lvert x \rangle =
\begin{cases}
-\lvert x \rangle & \text{if } \chi(x) = 1 \\
\phantom{-} \lvert x \rangle & \text{if } \chi(x) = 0
\end{cases}
$$

**Parameters:**

| Name        | Type                               | Description                                                                                                                        | Default    |
| ----------- | ---------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- | ---------- |
| `predicate` | `QPerm[Const[QArray[QBit]], QBit]` | A predicate function that takes a QArray of QBits and sets a single QBit \`\|1>` if the predicate is true, and \`\|0>\` otherwise. | *required* |
| `target`    | `Const[QArray[QBit]]`              | The target QArray of QBits to apply the phase oracle to.                                                                           | *required* |

### reflect\_about\_zero

<pre><code>reflect\_about\_zero(
qvar: Const\[QArray\[QBit]]
) -> None</code></pre>

\[Qmod Classiq-library function]

Reflects the state about the `|0>` state (i.e. applies a (-1) phase to all states
besides the `|0>` state). Implements the operator $S_0$:

$$
\begin{equation}
S_0|{x}\rangle = (-1)^{(x\ne0)}|{x}\rangle= (2|{0}\rangle\langle{0}|-I)|{x}\rangle
\end{equation}
$$

**Parameters:**

| Name   | Type                  | Description                   | Default    |
| ------ | --------------------- | ----------------------------- | ---------- |
| `qvar` | `Const[QArray[QBit]]` | The quantum state to reflect. | *required* |

### grover\_diffuser

<pre><code>grover\_diffuser(
space\_transform: QCallable\[QArray\[QBit]],
packed\_vars: QArray\[QBit]
) -> None</code></pre>

\[Qmod Classiq-library function]

Reflects the given state about the A`|0>` state, where A
is the `space_transform` parameter. It is defined as:

$$
\begin{equation}
D = A S_0 A^{\dagger}
\end{equation}
$$

where $S_0$ is the reflection about the `|0>` state (see `reflect_about_zero`).

**Parameters:**

| Name              | Type                      | Description                                        | Default    |
| ----------------- | ------------------------- | -------------------------------------------------- | ---------- |
| `space_transform` | `QCallable[QArray[QBit]]` | The operator which encodes the axis of reflection. | *required* |
| `packed_vars`     | `QArray[QBit]`            | The state to which to apply the diffuser.          | *required* |

### grover\_operator

<pre><code>grover\_operator(
oracle: QCallable\[QArray\[QBit]],
space\_transform: QCallable\[QArray\[QBit]],
packed\_vars: QArray\[QBit]
) -> None</code></pre>

\[Qmod Classiq-library function]

Applies the grover operator, defined by:

$$
Q=S_{\psi_0}S_{\psi_1}
$$

where $S_\{\psi_1\}$ is a reflection about the non-marked states, and $S_\{\psi_0\}$ is a reflection
about a given state defined by $|\psi_0\rangle = A|0\rangle$.

**Parameters:**

| Name              | Type                      | Description                                                                                                | Default    |
| ----------------- | ------------------------- | ---------------------------------------------------------------------------------------------------------- | ---------- |
| `oracle`          | `QCallable[QArray[QBit]]` | A unitary operator which adds a phase of (-1) to marked states.                                            | *required* |
| `space_transform` | `QCallable[QArray[QBit]]` | The operator which creates $\|\psi_0\rangle$, the initial state, used by the diffuser to reflect about it. | *required* |
| `packed_vars`     | `QArray[QBit]`            | The state to which to apply the grover operator.                                                           | *required* |

### grover\_search

<pre><code>grover\_search(
reps: CInt,
oracle: QCallable\[QArray\[QBit]],
packed\_vars: QArray\[QBit]
) -> None</code></pre>

\[Qmod Classiq-library function]

Applies Grover search algorithm.

**Parameters:**

| Name          | Type                      | Description                                                  | Default    |
| ------------- | ------------------------- | ------------------------------------------------------------ | ---------- |
| `reps`        | `CInt`                    | Number of repetitions of the grover operator.                | *required* |
| `oracle`      | `QCallable[QArray[QBit]]` | An oracle that marks the solution.                           | *required* |
| `packed_vars` | `QArray[QBit]`            | Packed form of the variable to apply the grover operator on. | *required* |
