Anagram (source code)

= Anagram

An <anagram> of a finite <string> is another <string> with exactly the same number of occurrences of each symbol. Thus $aab$ and $aba$ are anagrams; $abb$ is not. Equivalently, the second string is obtained by a <permutation> of the positions.

If a length-$n$ string has symbol multiplicities $m_1,\ldots,m_r$, its number of distinct anagrams is the <multinomial coefficient> $n!/(m_1!\cdots m_r!)$. Dividing by the factorials removes position permutations that only exchange equal symbols. The count depends on multiplicities, not the original ordering.