In [1]:
import spot
spot.setup()
Let's build a small automaton to use as example.
In [2]:
aut = spot.translate('G(Fa <-> Xb)'); aut
Out[2]:
Build an accepting run:
In [3]:
run = aut.accepting_run(); run
Out[3]:
Accessing the contents of the run can be done via the prefix and cycle lists.
In [4]:
print(spot.bdd_format_formula(aut.get_dict(), run.prefix[0].label))
print(run.cycle[0].acc)
To convert the run into a word, using spot.twa_word(). Note that our runs are labeled by Boolean formulas that are not necessarily a conjunction of all involved litterals. The word is just the projection of the run on its labels.
In [5]:
word = spot.twa_word(run); word
Out[5]:
Accessing the different formulas (stored as BDDs) can be done again via the prefix and cycle lists.
In [6]:
print(spot.bdd_format_formula(aut.get_dict(), word.prefix[0]))
print(spot.bdd_format_formula(aut.get_dict(), word.cycle[0]))
print(spot.bdd_format_formula(aut.get_dict(), word.cycle[1]))
Calling simplifify() will produce a shorter word that is compatible with the original word. For instance in the above word, the initial !a is compatible with both a & b and !a & b. The word obtained by restricting !a to !a & b is therefore still accepted, but it allows removing the prefix by rotating the cycle:
In [7]:
word.simplify()
word
Out[7]:
Such a simplified word can be created directly from the automaton:
In [8]:
aut.accepting_word()
Out[8]:
Words can be created using the parse_word function:
In [9]:
print(spot.parse_word('a; b; cycle{a&b}'))
print(spot.parse_word('cycle{a&bb|bac&(aaa|bbb)}'))
print(spot.parse_word('a; b;b; qiwuei;"a;b&c;a" ;cycle{a}'))
In [10]:
# make sure that we can parse a word back after it has been printed
spot.parse_word(str(spot.parse_word('a;b&a;cycle{!a&!b}')))
Out[10]:
Words can be easily converted as automata
In [11]:
w1 = spot.parse_word('a; !a; cycle{a; !a; a}')
In [12]:
w1.as_automaton()
Out[12]:
The rest of this pages tests some syntax errors, you (humans) may skip it, but the test suite will not.
In [13]:
print(spot.parse_word('a; b&!a; b'))
In [14]:
print(spot.parse_word('a; b; c}'))
In [15]:
print(spot.parse_word('a; cycle{}'))
In [16]:
print(spot.parse_word('a; cycle{!a}; a'))
In [17]:
# Creating an empty word is OK...
w = spot.twa_word(spot._bdd_dict)
In [18]:
# ... as long as this word is not printed.
print(w)