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

# Swap Test

Functions:

| Name        | Description                       |
| ----------- | --------------------------------- |
| `swap_test` | \[Qmod Classiq-library function]. |

### swap\_test

<pre><code>swap\_test(
state1: QArray\[QBit],
state2: QArray\[QBit],
test: Output\[QBit]
) -> None</code></pre>

\[Qmod Classiq-library function]

Tests the overlap (in terms of fidelity) of two quantum states.
The fidelity of `state1` and `state2` is calculated from the probability of measuring `test` qubit in the state 0 as follows:

$$
    |\langle state1 | state2 \rangle |^2 = 2*Prob(test=0)-1
$$

**Parameters:**

| Name     | Type           | Description                                                                                           | Default    |
| -------- | -------------- | ----------------------------------------------------------------------------------------------------- | ---------- |
| `state1` | `QArray[QBit]` | A quantum state to check its overlap with state2.                                                     | *required* |
| `state2` | `QArray[QBit]` | A quantum state to check its overlap with state1.                                                     | *required* |
| `test`   | `Output[QBit]` | A qubit for which the probability of measuring 0 is $0.5*(\|\langle state1 \| state2 \rangle \|^2+1)$ | *required* |
