automaton.difference(aut)

automaton % aut

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

$$ (\mathcal{A} \% \mathcal{B})(u) = \begin{cases} \mathcal{A}(u) & \text{if $\mathcal{B}(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\}$ to $2$ with the exception of words that are repetitions of $ab$ or of $ba$.

In [1]:
import vcsn
ctx = vcsn.context('lal, q')
aut = lambda e: ctx.expression(e).automaton()
a = aut('<2>[ab]{+}')
b = aut('(ab+ba)*')
vcsn.ipython.table([["a", "b"], [a, b]])
Out[1]:
a b
%3 I0 0 0 I0->0 F1 1 1 0->1 ⟨2⟩a, ⟨2⟩b 1->F1 1->1 a, b %3 I0 0 0 I0->0 F0 0->F0 1 1 0->1 a 2 2 0->2 b 1->0 b 2->0 a
In [2]:
a % b
Out[2]:
%3 I0 0 0 I0->0 F1 F2 F3 1 1 0->1 ⟨2⟩a 2 2 0->2 ⟨2⟩b 1->F1 3 3 1->3 a 4 4 1->4 b 2->F2 2->3 b 2->4 a 3->F3 3->3 a, b 4->1 a 4->2 b
In [3]:
(a%b).shortest(len = 4)
Out[3]:
$\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}$