# expression.shuffle(exp)¶

$\newcommand{\Ed}{\mathsf{E}}% \newcommand{\Fd}{\mathsf{F}}% \newcommand{\Gd}{\mathsf{G}}% \newcommand{\infiltrate}{\mathbin{\uparrow}}% \newcommand{\shuffle}{\mathbin{\between}}$ The shuffle product of expressions.

## Examples¶

In [1]:
import vcsn


### Boolean Automata¶

The shuffle product computes the shuffling of languages: all the possible interleavings.

In [2]:
a = vcsn.B.expression('abc')
a

Out[2]:
$a \, b \, c$
In [3]:
b = vcsn.B.expression('xyz')
b

Out[3]:
$x \, y \, z$
In [4]:
shuff = a.shuffle(b)
shuff

Out[4]:
$a \, b \, c \between x \, y \, z$
In [5]:
shuff.automaton()

Out[5]:

### Weighted expressions¶

In the case of weighted expressions, weights are "kept" with the letters.

In [6]:
exp = vcsn.Z.expression
a = exp('<2>a<3>b', 'trivial')
b = exp('<4>x<-2>y', 'trivial')
a.shuffle(b).automaton()

Out[6]:

### Associativity¶

The operator is associative: $(\Ed \shuffle \Fd) \shuffle \Gd \equiv \Ed \shuffle (\Fd \shuffle \Gd)$, i.e., both expressions denote the same series.

In [7]:
x = exp('<2>a', 'trivial')
y = exp('<3>a', 'trivial')
z = exp('<4>a', 'trivial')
(x.shuffle(y)).shuffle(z).automaton()

Out[7]:
In [8]:
x.shuffle(y.shuffle(z)).automaton()

Out[8]: