import spot
from spot.jupyter import display_inline
spot.setup(show_default='.a')
The spot.contains()
function checks whether the language of its right argument is included in the language of its left argument. The arguments may mix automata and formulas; the latter can be given as strings.
f = spot.formula('GFa'); aut_f = f.translate()
g = spot.formula('FGa'); aut_g = g.translate()
spot.contains(f, g), spot.contains(g, f)
spot.contains(aut_f, aut_g), spot.contains(aut_g, aut_f)
spot.contains(aut_f, g), spot.contains(aut_g, f)
spot.contains(f, aut_g), spot.contains(g, aut_f)
spot.contains("GFa", aut_g), spot.contains("FGa", aut_f)
Those functions are also usable as methods:
f.contains(aut_g), g.contains(aut_f)
aut_f.contains("FGa"), aut_g.contains("GFa")
The spot.are_equivalent()
tests the equivalence of the languages of its two arguments. Note that the corresponding method is called equivalent_to()
.
spot.are_equivalent(f, g), spot.are_equivalent(aut_f, aut_g)
f.equivalent_to(aut_g), aut_f.equivalent_to(g)
aut_f.equivalent_to('XXXGFa')
In the case of containement checks between formulas, language_containement_checker
instances provide similar services, but they cache automata representing the formulas checked. This should be preferred when performing several containement checks using the same formulas.
lcc = spot.language_containment_checker()
lcc.contains(f, g), lcc.contains(g, f)
lcc.are_equivalent(f, g)
Assume you have computed two automata, that are_equivalent(a1, a2)
returns False
, and you want to know why. (This often occur when debugging some algorithm that produce an automaton that is not equivalent to which it should.) The automaton class has a method called a1.exclusive_run(a2)
that can help with this task: it returns a run that recognizes a word is is accepted by one of the two automata but not by both. The method a1.exclusive_word(a2)
will return just a word.
For instance let's find a word that is exclusive between aut_f
and aut_g
. (The adjective exclusive is a reference to the exclusive or operator: the word belongs to L(aut_f) "xor" it belongs to L(aut_g).)
aut_f.exclusive_word(aut_g)
We can even write a small function that highlights one difference between two automata. Note that the run
returned will belong to either left
or right
, so calling the highlight()
method will colorize one of those two automata.
def show_one_difference(left, right):
run = left.exclusive_run(right)
if not run:
print("The two automata are equivalent.")
else:
print("The following word is only accepted by one automaton:", spot.make_twa_word(run))
run.highlight(5)
display_inline(left, right)
show_one_difference(aut_f, aut_g)