# expression % exp¶

Restricting an expression to the words not accepted by the second. In other words:

$$(\mathsf{E} \% \mathsf{F})(u) = \begin{cases} \mathsf{E}(u) & \text{if \mathsf{F}(u) \ne 0} \\ 0 & \text{otherwise} \end{cases}$$

Preconditions:

• None

Caveat:

• The name difference is wrong, and will certainly be changed in the future.
• If the second argument is not Boolean, because we determinize it, the process might loop for ever.

## Examples¶

In the following example, we map every non empty word on $\{a, b\}$ to $2$ with the exception of words that are repetitions of $ab$ or of $ba$.

In :
import vcsn
ctx = vcsn.context('lal_char, q')
exp = lambda e: ctx.expression(e)
e = exp('<2>[ab]{+}') % exp('(ab+ba)*')
e

Out:
$\left\langle 2 \right\rangle \,\left(\left(a + b\right) \, \left(a + b\right)^{*}\right) \& {\left(a \, b + b \, a\right)^{*}}^{c}$
In :
e.shortest(len = 4)

Out:
$\left\langle 2\right\rangle \mathit{a} \oplus \left\langle 2\right\rangle \mathit{b} \oplus \left\langle 2\right\rangle \mathit{aa} \oplus \left\langle 2\right\rangle \mathit{bb} \oplus \left\langle 2\right\rangle \mathit{aaa} \oplus \left\langle 2\right\rangle \mathit{aab} \oplus \left\langle 2\right\rangle \mathit{aba} \oplus \left\langle 2\right\rangle \mathit{abb} \oplus \left\langle 2\right\rangle \mathit{baa} \oplus \left\langle 2\right\rangle \mathit{bab} \oplus \left\langle 2\right\rangle \mathit{bba} \oplus \left\langle 2\right\rangle \mathit{bbb} \oplus \left\langle 2\right\rangle \mathit{aaaa} \oplus \left\langle 2\right\rangle \mathit{aaab} \oplus \left\langle 2\right\rangle \mathit{aaba} \oplus \left\langle 2\right\rangle \mathit{aabb} \oplus \left\langle 2\right\rangle \mathit{abaa} \oplus \left\langle 2\right\rangle \mathit{abbb} \oplus \left\langle 2\right\rangle \mathit{baaa} \oplus \left\langle 2\right\rangle \mathit{babb} \oplus \left\langle 2\right\rangle \mathit{bbaa} \oplus \left\langle 2\right\rangle \mathit{bbab} \oplus \left\langle 2\right\rangle \mathit{bbba} \oplus \left\langle 2\right\rangle \mathit{bbbb}$

The operator % is also supported in the syntax of rational expressions:

In :
exp('<2>[ab]{+}%(ab+ba)*')

Out:
$\left\langle 2 \right\rangle \,\left(\left(a + b\right) \, \left(a + b\right)^{*}\right) \& {\left(a \, b + b \, a\right)^{*}}^{c}$