automaton.trim

Create a new automaton from the useful part of the input, i.e., the subautomaton whose states both accessible (can be reached from a initial state) and coaccessible (can reach a final state).

Preconditions:

  • None

Postconditions:

  • Result.is_accessible
  • Result.is_coaccessible
  • Result.is_trim

See also:

Examples

In [1]:
import vcsn
:0: FutureWarning: IPython widgets are experimental and may change in the future.

The following automaton has states that cannot be reach any final(s) states:

In [2]:
a = vcsn.automaton('''
digraph
{
  vcsn_context = "lal_char(abc), b"
  I -> 0
  0 -> 1 [label = "a"]
  1 -> F
  i -> 0 [label = "a"]
  1 -> f [label = "a"]
}
''')
a
Out[2]:
%3 I0 0 0 I0->0 F1 1 1 0->1 a 1->F1 3 3 1->3 a 2 2 2->0 a
In [3]:
a.is_trim()
Out[3]:
False

Calling trim returns the same automaton, but without any useless states:

In [4]:
a.trim()
Out[4]:
%3 I0 0 0 I0->0 F1 1 1 0->1 a 1->F1
In [5]:
a.trim().is_trim()
Out[5]:
True