Skip to main content
Once you have one or more BlockEncoding instances (see Constructing Block Encodings), combine them with arithmetic operators or classmethods to block-encode sums, products, and scaled matrices, or transform a single encoding into its inverse or its qubitized walk operator. This page covers a selection of the available combinators and transformations — more are added over time, so check the SDK reference for the full, current list. Every combinator returns a new BlockEncoding with alpha, block_size, and hermitian_be computed from its inputs. All examples on this page import:

Sum: +

be_a + be_b block-encodes A+BA + B via LCU, using one extra block qubit to select between the two branches.
be_sum.alpha prints 13.0, and be_sum.to_matrix() is the diagonal matrix diag(6,8,7,8)\text{diag}(6, 8, 7, 8).

Weighted sum: weighted_sum

For more than two terms, or complex coefficients, use BlockEncoding.weighted_sum directly instead of chaining +: it’s more efficient.
be_ws.alpha prints 32.0, and be_ws.to_matrix() is the diagonal matrix diag(16,17,20,19)\text{diag}(16, 17, 20, 19).

Scalar multiplication: * / rmul

scalar * be (or be * scalar) block-encodes c⋅Ac \cdot A for a complex scalar cc. block_size is unchanged; alpha is rescaled by ∣c∣\vert c \vert.
be_scaled.alpha prints 14.0, and be_scaled.to_matrix() is the diagonal matrix diag(6,14,4,10)\text{diag}(6, 14, 4, 10).

Product: @ / product

be_a @ be_b block-encodes the product A⋅BA \cdot B, applying be_b’s unitary followed by be_a’s. BlockEncoding.product([be_1, ..., be_n]) generalizes this to more than two factors efficiently.
be_product.alpha prints 33.0, and be_product.to_matrix() is the diagonal matrix diag(4.2,11)\text{diag}(4.2, 11).

Inverse

be.inverse(kappa) block-encodes A−1A^{-1} using QSVT polynomial inversion, given an estimate kappa of AA‘s condition number. Pass either the QSVT polynomial degree, or eps (a target relative error, from which the degree is derived).
See Verifying with to_matrix for more on this global-phase caveat.

Qubitize

be.qubitize() builds the Low–Chuang qubitization walk operator W=RUW = R U, where RR reflects about the block variable’s ∣0⟩\vert 0 \rangle state and UU is be’s own unitary. Powers of WW give Chebyshev polynomials of the encoded matrix: ⟨0∣Wk∣0⟩=Tk(A/α)\langle 0 \vert W^k \vert 0 \rangle = T_k(A / \alpha). These are the basis of quantum signal processing and QSVT algorithms. qubitize requires be.hermitian_be=True and be.block_size > 0. The walk operator is built from two reflections, so UU itself must also be Hermitian. It also needs a block variable to reflect about.
hermitian_be is computed automatically by every constructor and combinator on this page and in Constructing Block Encodings. If you’re confident your block encoding’s unitary is Hermitian but the computed value is False (or vice versa), you can build a corrected copy with dataclasses.replace(be, hermitian_be=True). Only do this when you’re sure it’s genuinely true — qubitize’s walk operator is only correct when hermitian_be reflects reality.

Verifying with to_matrix

be.to_matrix() reconstructs the encoded matrix AA by state-vector simulation: it prepares an equal superposition over data, applies be.unitary, post-selects the block variable on |0>, and rescales by alpha. It’s meant for testing and small examples, not as part of a production algorithm.
The reconstruction is exact only up to a single, unknown global phase. For the moment, to_matrix() does not resolve this phase, so when comparing against a known matrix, compare dot products or magnitudes rather than raw entries, as the inverse example does.