ApplyPauliFromBitString operation

Warning

This documentation refers to the Classic QDK, which has been replaced by the Modern QDK.

Please see https://aka.ms/qdk.api for the API documentation for the Modern QDK.

Namespace: Microsoft.Quantum.Canon

Package: Microsoft.Quantum.Standard

Applies a Pauli operator on each qubit in an array if the corresponding bit of a Boolean array matches a given input.

operation ApplyPauliFromBitString (pauli : Pauli, bitApply : Bool, bits : Bool[], qubits : Qubit[]) : Unit is Adj + Ctl

Input

pauli : Pauli

Pauli operator to apply to qubits[idx] where bitsApply == bits[idx]

bitApply : Bool

apply Pauli if bit is this value

bits : Bool[]

Boolean register specifying which corresponding qubit in qubits should be operated on

qubits : Qubit[]

Quantum register on which to selectively apply the specified Pauli operator

Output : Unit

Example

The following applies an X operation on qubits 0 and 2, and a Z operation on qubits 1 and 3.

use qubits = Qubit[4];
let bits = [true, false, true, false];
// Apply when index in `bits` is `true`.
ApplyPauliFromBitString(PauliX, true, bits, qubits);
// Apply when index in `bits` is `false`.
ApplyPauliFromBitString(PauliZ, false, bits, qubits);

Remarks

The Boolean array and the quantum register must be of equal length.