Shuffle product
The shuffle product of two words, w1 and w2, written
w1 w2,
is the set of all words formed by the letters in w1 and w2, preserving the order of each word's letters. The name comes from the analogy with doing a riffle shuffle of two decks of cards.
For example, bcd ae, the shuffle product of bcd and ae, would be all permutations of abcde in which the consonants appear in alphabetical order and the vowels are also in alphabetical order. So abecd and baecd would be included, but badec would not be because the d and c are in the wrong order.
Side note onIncidentally, the symbol for shuffle product is the Cyrillic letter sha (, U+0428), the only Cyrillic letter commonly used in mathematics, at least internationally. Presumably Russian mathematicians use other Cyrillic letters, but the only Cyrillic letter an American mathematician, for example, is likely to use is .
The uses of that I'm aware of are the Dirac comb distribution, the Tate-Shafarevich group, and the shuffle product.
Duplicate lettersWhat is the shuffle product of words containing duplicate letters? For example, what about the shuffle product of bread and crumb? Each word contains an r. The shuffle product, defined above as a set, doesn't distinguish between the two rs. But another way to define the shuffle product is as a formal sum, with coefficients that count duplicates.
Imagine coloring the letters in abc blue and the letters in cde red. Then abccde and abccde would count as two different possibilities, one with blue c followed by red c, and one the other way around. This term in the formal sum would be 2abccde, the two capturing that there are two ways to arrive at this word.
You could also have duplicate letters within a single word. So in banana, for example, you could imagine coloring each a a different color and coloring the two ns different colors.
Mathematica codeThis page gives an implementation of the shuffle product in Mathematica.
shuffleW[s1_, s2_] := Module[{p, tp, ord}, p = Permutations@Join[1 & /@ s1, 0 & /@ s2]\[Transpose]; tp = BitXor[p, 1]; ord = Accumulate[p] p + (Accumulate[tp] + Length[s1]) tp; Outer[Part, {Join[s1, s2]}, ord, 1][[1]]\[Transpose]]
This code takes two lists of characters and returns a list of lists of characters. You can use this to compute both senses of the shuffle product. For example, let's compute abc ac.
The Mathematica command
shuffleW[{a, b, c}, {a, c}]
returns a list of 10 lists:
{{a, b, c, a, c}, {a, b, a, c, c}, {a, b, a, c, c}, {a, a, b, c, c}, {a, a, b, c, c}, {a, a, c, b, c}, {a, a, b, c, c}, {a, a, b, c, c}, {a, a, c, b, c}, {a, c, a, b, c}}
If we ask for the union of the set above with Union[%] we get
{{a, a, b, c, c}, {a, a, c, b, c}, {a, b, a, c, c}, {a, b, c, a, c}, {a, c, a, b, c}}
So using the set definition, we could say
abc ac = {aabcc, aacbc, abacc, abcac, acabc}.
Using the formal sum definition we could say
abc ac = 4aabcc + 2aacbc + 2abacc + abcac + acabc.
Related postsPhoto by Amol Tyagi on Unsplash
The post Shuffle product first appeared on John D. Cook.