In [1]:
from IPython.display import display
import spot
spot.setup()
Use to_str()
to output a string representing the automaton in different formats.
In [2]:
a = spot.translate('a U b')
for fmt in ('hoa', 'spin', 'dot', 'lbtt'):
print(a.to_str(fmt))
Use save()
to save the automaton into a file.
In [3]:
a.save('example.aut').save('example.aut', format='lbtt', append=True)
Out[3]:
In [4]:
!cat example.aut
Use spot.automata()
to read multiple automata from a file, and spot.automaton()
to read only one.
In [5]:
for a in spot.automata('example.aut'):
display(a)
The --ABORT--
feature of the HOA format allows discarding the automaton being read and starting over.
In [6]:
%%file example.aut
HOA: v1
States: 2
Start: 1
AP: 2 "a" "b"
acc-name: Buchi
Acceptance: 1 Inf(0)
--BODY--
State: 0 {0}
[t] 0
--ABORT-- /* the previous automaton should be ignored */
HOA: v1
States: 2
Start: 1
AP: 2 "a" "b"
Acceptance: 1 Inf(0)
--BODY--
State: 0 {0}
[t] 0
State: 1
[1] 0
[0&!1] 1
--END--
In [7]:
for a in spot.automata('example.aut'):
display(a)
Instead of passing a filename, you can also pass the contents of a file. spot.automata()
and spot.automaton()
look for the absence of newline to decide if this is a filename or a string containing some actual automaton text.
In [8]:
for a in spot.automata("""
HOA: v1
States: 2
Start: 1
name: "Hello world"
AP: 2 "a" "b"
Acceptance: 1 Inf(0)
--BODY--
State: 0 {0}
[t] 0
State: 1
[1] 0
[0&!1] 1
--END--
HOA: v1
States: 1
Start: 0
name: "Hello world 2"
AP: 2 "a" "b"
Acceptance: 2 Inf(0)&Inf(1)
--BODY--
State: 0 {0}
[t] 0 {1}
[0&!1] 0
--END--
"""):
display(a)
In [9]:
for a in spot.automata('ltl2tgba -s "a U b"; ltl2tgba --lbtt "b"|', 'ltl2tgba -H "GFa" "a & GFb"|'):
display(a)
A single automaton can be read using spot.automaton()
, with the same convention.
In [10]:
spot.automaton('ltl2tgba -s6 "a U b"|')
Out[10]:
In [ ]:
!rm example.aut