ControlledOnBitString function
Namespace: Microsoft.Quantum.Canon
Package: Microsoft.Quantum.Standard
Returns a unitary operation that applies an oracle on the target register if the control register state corresponds to a specified bit mask.
function ControlledOnBitString<'T> (bits : Bool[], oracle : ('T => Unit is Adj + Ctl)) : ((Qubit[], 'T) => Unit is Adj + Ctl)
Description
The output of this function is an operation that can be represented by a
unitary transformation $U$ such that
\begin{align}
U \ket{b_0 b_1 \cdots b_{n - 1}} \ket{\psi} = \ket{b_0 b_1 \cdots b_{n-1}} \otimes
\begin{cases}
V \ket{\psi} & \textrm{if} (b_0 b_1 \cdots b_{n - 1}) = \texttt{bits} \\
\ket{\psi} & \textrm{otherwise}
\end{cases},
\end{align}
where $V$ is a unitary transformation that represents the action of the
oracle operation.
Input
bits : Bool[]
The bit string to control the given unitary operation on.
oracle : 'T => Unit is Adj + Ctl
The unitary operation to be applied on the target register.
Output : (Qubit[],'T) => Unit is Adj + Ctl
A unitary operation that applies oracle on the target register if the control register state corresponds to the bit mask bits.
Type Parameters
'T
Example
The following code snippets are equivalent:
(ControlledOnBitString(bits, oracle))(controlRegister, targetRegister);
and
within {
ApplyPauliFromBitString(PauliX, false, bits, controlRegister);
} apply {
Controlled oracle(controlRegister, targetRegister);
}
The following code prepares a state $\frac{1}{2}(\ket{00} - \ket{01} + \ket{10} + \ket{11})$:
using (register = Qubit[2]) {
ApplyToEach(H, register);
(ControlledOnBitString([false], Z))(register[0..0], register[1]);
}
Remarks
The pattern given by bits may be shorter than controlRegister,
in which case additional control qubits are ignored (that is, neither
controlled on $\ket{0}$ nor $\ket{1}$).
If bits is longer than controlRegister, an error is raised.
Given a Boolean array bits and a unitary operation oracle, the output of this function
is an operation that performs the following steps:
- apply an
Xoperation to each qubit of the control register that corresponds tofalseelement of thebits; - apply
Controlled oracleto the control and target registers; - apply an
Xoperation to each qubit of the control register that corresponds tofalseelement of thebitsagain to return the control register to the original state.
The output of the Controlled functor is a special case of ControlledOnBitString where bits is equal to [true, ..., true].
反馈
提交和查看相关反馈