Skip to main content

reorder_by_site

reorder_by_site(const Operator input) -> Operator

Reorders operators within a product by their site indices while preserving quantum commutation rules.

This function takes an operator and reorders its constituent operators in ascending order of their site indices. The reordering only occurs between operators with disjoint support sets to preserve quantum mechanical commutation relationships. Operators with overlapping support are treated as equivalent and maintain their original relative ordering through stable sorting.

Parameters

  • input: The input operator to be reordered. Can be a single operator or OperatorProduct.

Returns

A new operator with constituent operators reordered by site indices. Returns a clone of the input if it's not an OperatorProduct or contains only a single operator.

Example

var op = X(2) * Y(0) * Z(1);
var reordered = reorder_by_site(op); // Returns Y(0) * Z(1) * X(2)