Bender-Knuth involution (source code)

= Bender-Knuth involution
{c}

For adjacent letters $i,i+1$, pair entries in the same column and leave those pairs fixed. In each row, interchange the numbers of unpaired $i$ and $i+1$ entries, preserving their weak order. Strict columns are preserved: a letter that could obstruct a change from $i$ to $i+1$, or conversely, would already have been paired. Applying the operation twice restores the tableau. The paired letters contribute equal amounts to the two contents, so the involution swaps their total multiplicities.