BlockEncoding.__mul__#
- BlockEncoding.__mul__(other: ArrayLike) BlockEncoding[source]#
Returns a BlockEncoding of the scaled operator.
This method implements the scalar multiplication \(c \cdot A\), where \(A\) is the operator encoded by this instance and \(c\) is the provided scalar.
- Parameters:
- otherArrayLike
The scalar scaling factor (coefficient) to apply. Can be a Python float, a JAX/NumPy scalar, or a 0-dimensional array.
- Returns:
- BlockEncoding
A new BlockEncoding instance representing the scaled operator.
Notes
Multiplying by a scalar \(c\) results in a new BlockEncoding of \(cA\) by updating \(\alpha \rightarrow c\alpha\).
Examples
Define two block-encodings and implement their scaled sum as a new block encoding.
from qrisp import * from qrisp.block_encodings import BlockEncoding from qrisp.operators import X, Y, Z # Commuting operators H1 and H2 H1 = X(0)*X(1) + 0.2*Y(0)*Y(1) H2 = Z(0)*Z(1) + X(2) H3 = 2*H1 + H2 BE1 = BlockEncoding.from_operator(H1) BE2 = BlockEncoding.from_operator(H2) BE3 = BlockEncoding.from_operator(H3) BE_mul = 2*BE1 + BE2 BE_mul_r = BE1*2 + BE2 def operand_prep(): qv = QuantumFloat(3) return qv @terminal_sampling def main(BE): qv = BE.apply_rus(operand_prep)() return qv res_be3 = main(BE3) res_be_mul = main(BE_mul) res_be_mul_r = main(BE_mul_r) print("Result from BE of 2 * H1 + H2: ", res_be3) print("Result from 2 * BE1 + BE2: ", res_be_mul) print("Result from BE1 * 2 + BE2: ", res_be_mul_r) # Result from BE of 2 * H1 + H2: {3.0: 0.5614033770142979, 0.0: 0.21929831149285103, 4.0: 0.21929831149285103} # Result from 2 * BE1 + BE2: {3.0: 0.5614033770142979, 0.0: 0.21929831149285103, 4.0: 0.21929831149285103} # Result from BE1 * 2 + BE2: {3.0: 0.5614033770142979, 0.0: 0.21929831149285103, 4.0: 0.21929831149285103}