ApplyIfCA 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 unitary operation conditioned on a classical bit.

operation ApplyIfCA<'T> (bit : Bool, op : ('T => Unit is Ctl + Adj), target : 'T) : Unit is Adj + Ctl

Description

Given a bit value bit and an operation op, applies op to the target if bit is true. If false, nothing happens to the target. The suffix CA indicates that the operation to be applied is unitary (controllable and adjointable).

Input

bit : Bool

a boolean that controls whether op is applied or not.

op : 'T => Unit is Adj + Ctl

An operation to be conditionally applied.

target : 'T

The input to which the operation is applied.

Output : Unit

Type Parameters

'T

The input type of the operation to be conditionally applied.

Example

The following prepares a register of qubits into a computational basis state represented by a classical bit string given as an array of Bool values:

let bitstring = [true, false, true];
using (register = Qubit(3)) {
    ApplyToEach(ApplyIf(_, X, _), Zipped(bitstring, register));
    // register should now be in the state |101⟩.
    ...
}

See Also