flattened
flattened(const Operator input) -> Operator
Flattens any operator by expanding all expressions into a sum of products (out-of-place).
This function distributes multiplication over addition, expanding nested sums and products into a flat sum of products. For example, expressions like A*(B + C) become A*B + A*C. We recommend using OperatorSum as input, which is safe. While any operator type is allowed, flattening does not make sense for other operator types.
Parameters
- input: The input Operator to be flattened (recommended: OperatorSum).
Returns
A fully flattened Operator where each OpProd contains only products (no nested sum) with scalar coefficient .
Example
var my_ops = (2+3i)*X(0) * (Y(1) + ID());
var my_flat = flattened(my_ops);
// Returns ((2+3i) * X(0) * Y(1) + (2+3i) * X(0) * ID())