Template Function sequant::canonical_children(TreeNode const&)

Function Documentation

template<typename TreeNode>
std::pair<TreeNode const&, TreeNode const&> sequant::canonical_children(TreeNode const &n)

A node’s two children in canonical order &#8212; the order-independent view that every derivation of node identity reads them through.

Returns the children swapped iff canonical_operand_cmp says the right one belongs first. The node is left alone and nothing is cached on it: the decision is one comparison of two already-computed hashes, and leaving the tree untouched is the whole point &#8212; evaluation, slicing positions, operand reads, dry-run op costs and the peak sweep all keep the left/right the DP emitted.

Meaningful for a commutative (Product) node; callers use the emitted order for everything else (a Sum’s left child is the in-place accumulator, an Adjoint’s right child is a sentinel), so this is not applied there.

Note

The returned pair holds references into n, so n must outlive it; binding a temporary is rejected by the deleted overload below.

Parameters:

n – a non-leaf node

Pre:

n is not a leaf

Returns:

n's children, the canonically first one first