qml.math.decomposition.decomp_int_to_powers_of_two

decomp_int_to_powers_of_two(k, n)[source]

Decompose an integer \(k<=2^{n-1}\) into additions and subtractions of the smallest-possible number of powers of two.

Parameters:
  • k (int) – Integer to be decomposed

  • n (int) – Number of bits to consider

Returns:

A list with length n, with entry \(c_i\) at position \(i\).

Return type:

list[int]

This function is documented in pennylane/ops/qubit/pcphase_decomposition.md.

As an example, consider the number \(k=121_{10}=01111001_2\), which can be (trivially) decomposed into a sum of five powers of two by reading off the bits: \(k = 2^6 + 2^5 + 2^4 + 2^3 + 2^0 = 64 + 32 + 16 + 8 + 1\). The decomposition here, however, allows for minus signs and achieves the decomposition \(k = 2^7 - 2^3 + 2^0 = 128 - 8 + 1\), which only requires three powers of two.