Microsoft.Quantum.Primitive

Operations

Assert

Asserts that measuring the given qubits in the given Pauli basis will always have the given result.

AssertProb

Asserts that measuring the given qubits in the given Pauli basis will have the given result with the given probability, within some tolerance.

CCNOT

Applies the doubly controlled–NOT (CCNOT) gate to three qubits.

CNOT

Applies the controlled-NOT (CNOT) gate to a pair of qubits. \begin{align} \operatorname{CNOT} \mathrel{:=} \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0 \end{bmatrix}, \end{align} where rows and columns are ordered as in the quantum concepts guide.

Exp

Applies the exponential of a multi-qubit Pauli operator. \begin{align} e^{i \theta [P_0 \otimes P_1 \cdots P_N]}, \end{align} where $P_i$ is the $i$th element of paulis, and where $N = $Length(paulis).

ExpFrac

Applies the exponential of a multi-qubit Pauli operator with an argument given by a dyadic fraction. \begin{align} e^{i \theta \pi k [P_0 \otimes P_1 \cdots P_N] / 2^n}, \end{align} where $P_i$ is the $i$th element of paulis, and where $N = $Length(paulis).

H

Applies the Hadamard transformation to a single qubit. \begin{align} H \mathrel{:=} \frac{1}{\sqrt{2}} \begin{bmatrix} 1 & 1 \\ 1 & -1 \end{bmatrix}. \end{align}

I

Performs the identity operation (no-op) on a single qubit.

M

Performs a measurement of a single qubit in the Pauli $Z$ basis. The output result is given by the distribution \begin{align} \Pr(\texttt{Zero} | \ket{\psi}) = \braket{\psi | 0} \braket{0 | \psi}. \end{align}

Measure

Performs a joint measurement of one or more qubits in the specified Pauli bases. The output result is given by the distribution: \begin{align} \Pr(\texttt{Zero} | \ket{\psi}) = \frac12 \braket{ \psi \mid| \left( \boldone + P_0 \otimes P_1 \otimes \cdots \otimes P_{N-1} \right) \mid| \psi }, \end{align} where $P_i$ is the $i$th element of bases, and where $N = \texttt{Length}(\texttt{bases})$. That is, measurement returns a Result $d$ such that the eigenvalue of the observed measurement effect is $(-1)^d$.

MultiX

Applies the gate $X \otimes X \otimes \cdots \otimes X$ to a register of qubits.

R

Applies a rotation about the given Pauli axis. \begin{align} R_{\mu}(\theta) \mathrel{:=} e^{-i \theta \sigma_{\mu} / 2}, \end{align} where $\mu \in {I, X, Y, Z}$.

R1

Applies a rotation about the $\ket{1}$ state by a given angle. \begin{align} R_1(\theta) \mathrel{:=} \operatorname{diag}(1, e^{i\theta}). \end{align}

R1Frac

Applies a rotation about the $\ket{1}$ state by an angle specified as a dyadic fraction. \begin{align} R_1(n, k) \mathrel{:=} \operatorname{diag}(1, e^{i \pi k / 2^n}). \end{align}

Warning

This operation uses the opposite sign convention from > R, and does not include the > factor of $1/ 2$ included by R1.

Random

The random operation takes an array of doubles as input, and returns a randomly-selected index into the array as an Int. The probability of selecting a specific index is proportional to the value of the array element at that index. Array elements that are equal to zero are ignored and their indices are never returned. If any array element is less than zero, or if no array element is greater than zero, then the operation fails.

Reset

Given a single qubit, measures it and ensures it is in the |0⟩ state such that it can be safely released.

ResetAll

Given an array of qubits, measure them and ensure they are in the |0⟩ state such that they can be safely released.

RFrac

Applies a rotation about the given Pauli axis by an angle specified as a dyadic fraction. \begin{align} R_{\mu}(n, k) \mathrel{:=} e^{i \pi n \sigma_{\mu} / 2^k}, \end{align} where $\mu \in {I, X, Y, Z}$.

Warning

This operation uses the opposite sign convention from > R.

Rx

Applies a rotation about the $x$-axis by a given angle. \begin{align} R_x(\theta) \mathrel{:=} e^{-i \theta \sigma_x / 2}. \end{align}

Ry

Applies a rotation about the $y$-axis by a given angle. \begin{align} R_y(\theta) \mathrel{:=} e^{-i \theta \sigma_y / 2}. \end{align}

Rz

Applies a rotation about the $z$-axis by a given angle. \begin{align} R_z(\theta) \mathrel{:=} e^{-i \theta \sigma_z / 2}. \end{align}

S

Applies the π/4 phase gate to a single qubit. \begin{align} S \mathrel{:=} \begin{bmatrix} 1 & 0 \\ 0 & i \end{bmatrix}. \end{align}

SWAP

Applies the SWAP gate to a pair of qubits. \begin{align} \operatorname{SWAP} \mathrel{:=} \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix}, \end{align} where rows and columns are ordered as in the quantum concepts guide.

T

Applies the π/8 gate to a single qubit. \begin{align} T \mathrel{:=} \begin{bmatrix} 1 & 0 \\ 0 & e^{i \pi / 4} \end{bmatrix}. \end{align}

X

Applies the Pauli $X$ gate. \begin{align} \sigma_x \mathrel{:=} \begin{bmatrix} 0 & 1 \\ 1 & 0 \end{bmatrix}. \end{align}

Y

Applies the Pauli $Y$ gate. \begin{align} \sigma_y \mathrel{:=} \begin{bmatrix} 0 & -i \\ i & 0 \end{bmatrix}. \end{align}

Z

Applies the Pauli $Z$ gate. \begin{align} \sigma_z \mathrel{:=} \begin{bmatrix} 1 & 0 \\ 0 & -1 \end{bmatrix}. \end{align}

Functions

Message

Logs a message.