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

automaton.filter(states)

Return a subautomaton such that their states are in the input states set.

Postcondition:

  • The result automaton is subautomaton of input automaton.

  • The states of automaton are in the input states set.

See also:

Examples

import vcsn
%%automaton -s aut context = "lal_char(a), b" 0 -> 1 a 1 -> 0 a 1 -> $ 1 -> 2 a 3 -> 0 a 4 -> 3 a 0 -> 3 a $ -> 0 3 -> 5 a
Image in a Jupyter notebook

To keep only states 0,1,2,30, 1, 2 , 3:

aut.filter([0, 1, 2, 3])
Image in a Jupyter notebook

"Keeping" a non-existing state is not an error:

aut.filter([0, 1, 7])
Image in a Jupyter notebook

Calls to filter can be filtered:

a1 = aut.filter([0, 1, 2, 3, 4]).filter([0, 1, 3, 5]) a1
Image in a Jupyter notebook

but it is less efficient than filtering on the intersection. This is on purpose: the outter automaton has a view on the filtered automaton.

a2 = aut.filter(list(set([0, 1, 2, 3, 4]) & set([0, 1, 3, 5]))) print(a1.info()['type']) print(a2.info()['type']) print(a1.is_isomorphic(a2))
filter_automaton<filter_automaton<mutable_automaton<letterset<char_letters(a)>, b>>> filter_automaton<mutable_automaton<letterset<char_letters(a)>, b>> True

We can filter a transposed automaton:

trans = aut.transpose() trans
Image in a Jupyter notebook
trans.filter([0, 1, 2, 3])
Image in a Jupyter notebook