Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 45894
Kernel: Python 3

expression.difference(exp)

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.

See also:

Examples

In the following example, we map every non empty word on {a,b}\{a, b\} to 22 with the exception of words that are repetitions of abab or of baba.

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

2((a+b)(a+b))&(ab+ba)c \left\langle 2 \right\rangle \,\left(\left(a + b\right) \, \left(a + b\right)^{*}\right) \& {\left(a \, b + b \, a\right)^{*}}^{c}

e.shortest(len = 4)

2a2b2aa2bb2aaa2aab2aba2abb2baa2bab2bba2bbb2aaaa2aaab2aaba2aabb2abaa2abbb2baaa2babb2bbaa2bbab2bbba2bbbb\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:

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

2((a+b)(a+b))&(ab+ba)c \left\langle 2 \right\rangle \,\left(\left(a + b\right) \, \left(a + b\right)^{*}\right) \& {\left(a \, b + b \, a\right)^{*}}^{c}