is_two_power#

Functionality#

There are two versions to identify whether an integer \(y\) is a power of \(2\).


is_two_power_phase.py#

Callaee: Is2PowerPhase

Given an \(n\)-qubit computational basis state \(\ket{y}_n\), this phase-version program computes a Boolean function:

\[ U_{\mathrm{Is2PowerPhase}}: \ket{y}_n \mapsto (-1)^{\mathrm{IS2POWER}(y)} \ket{y}_n = e^{i \pi \mathrm{IS2POWER}(y)} \ket{y}_n. \]

The Boolean function is defined as:

\[\begin{split} \mathrm{IS2POWER}(y) \equiv \begin{cases} 1, & \text{if }\exists k\in\mathbb{N}: y=2^k \\ 0, & \text{otherwise} \end{cases} \end{split}\]

The input state is defined as \(\ket{y}_n = |q_{n-1} \cdots q_1 q_0\rangle_n\), where \(y\) is the decimal value of the binary string \(q_{n-1} \cdots q_0\). We regard \(q_0\) as the least significant qubit and \(q_{n-1}\) as the most significant qubit.

Test expectations:

The result is encoded as a phase flip on the corresponding basis state of \(y\). It is a global phase, which can be directly inspected on a statevector-based backend, but not directly observable by measurement.

Doc references: [5]


is_two_power_qubit.py#

Callable: Is2PowerQubit

The qubit version stores the result into the most significant qubit involved in the entire quantum circuit:

\[ U_{\mathrm{Is2PowerQubit}}: |x\rangle_1 \ket{y}_n \mapsto |x \oplus \mathrm{IS2POWER}(y)\rangle_1 \ket{y}_n. \]

Test expectations:

The result is encoded in one auxiliary qubit via XOR. When \(\ket{x}_1\) is initialized as \(\ket{0}_1\), its final state turns out to be \(\ket{\mathrm{IS2POWER}(y)}_1\), which can be directly observed by measurement.

Doc references: [5]

API#

qolumbina.programs.is_two_power.is_two_power_phase#

class Is2PowerPhase(input_qubits, name=None)[source]#

Bases: QuantumCircuit

Implements Q# operation Is2Power_P: Checks if the input qubit register represents a 2-power. Uses MultiX (X on all qubits) and MCZ (emulated via H-MCX-H).

Parameters:
  • input_qubits (int) – Number of qubits in the input register (\(n\)).

  • name (str | None) – Optional name for the circuit.

qolumbina.programs.is_two_power.is_two_power_qubit#

class Is2PowerQubit(input_qubits, name=None)[source]#

Bases: QuantumCircuit

Qubit version of Is2Power_Q operation.

Acts on n input qubits and 1 target qubit. Flips the target qubit when the input qubits represent a power of 2, following the original Q# Is2Power_Q logic.

Parameters:
  • input_qubits (int) – Number of qubits in the input register (\(n\)).

  • name (str | None) – Optional name for the circuit.