introduce containement checks functions
* spot/twaalgos/contains.hh, spot/twaalgos/contains.cc: New files. * spot/twaalgos/Makefile.am, python/spot/impl.i: Add them. * python/spot/__init__.py: Also attach these functions as methods, and support string arguments. * tests/python/contains.ipynb: New file. * tests/Makefile.am, doc/org/tut.org: Add it. * bin/autfilt.cc, tests/python/streett_totgba.py, tests/python/sum.py, tests/python/toweak.py: Use the new function.
This commit is contained in:
parent
58d9a12495
commit
d6f9618172
13 changed files with 547 additions and 60 deletions
|
|
@ -332,6 +332,7 @@ TESTS_ipython = \
|
|||
python/atva16-fig2b.ipynb \
|
||||
python/automata-io.ipynb \
|
||||
python/automata.ipynb \
|
||||
python/contains.ipynb \
|
||||
python/decompose.ipynb \
|
||||
python/formulas.ipynb \
|
||||
python/gen.ipynb \
|
||||
|
|
|
|||
328
tests/python/contains.ipynb
Normal file
328
tests/python/contains.ipynb
Normal file
|
|
@ -0,0 +1,328 @@
|
|||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import spot\n",
|
||||
"spot.setup(show_default='.a')"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Containement checks\n",
|
||||
"\n",
|
||||
"The `spot.contains()` function checks whether the language of its left argument is included in the language of its right argument. The arguments may mix automata and formulas; the latter can be given as strings."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"f = spot.formula('GFa'); aut_f = f.translate()\n",
|
||||
"g = spot.formula('FGa'); aut_g = g.translate()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"(False, True)"
|
||||
]
|
||||
},
|
||||
"execution_count": 3,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"spot.contains(f, g), spot.contains(g, f)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"(False, True)"
|
||||
]
|
||||
},
|
||||
"execution_count": 4,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"spot.contains(aut_f, aut_g), spot.contains(aut_g, aut_f)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"(False, True)"
|
||||
]
|
||||
},
|
||||
"execution_count": 5,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"spot.contains(aut_f, g), spot.contains(aut_g, f)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 6,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"(False, True)"
|
||||
]
|
||||
},
|
||||
"execution_count": 6,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"spot.contains(f, aut_g), spot.contains(g, aut_f)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 7,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"(False, True)"
|
||||
]
|
||||
},
|
||||
"execution_count": 7,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"spot.contains(\"GFa\", aut_g), spot.contains(\"FGa\", aut_f)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Those functions are also usable as methods:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 8,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"(False, True)"
|
||||
]
|
||||
},
|
||||
"execution_count": 8,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"f.contains(aut_g), g.contains(aut_f)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 9,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"(False, True)"
|
||||
]
|
||||
},
|
||||
"execution_count": 9,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"aut_f.contains(\"FGa\"), aut_g.contains(\"GFa\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Equivalence checks\n",
|
||||
"\n",
|
||||
"The `spot.are_equivalent()` tests the equivalence of the languages of its two arguments. Note that the corresponding method is called `equivalent_to()`."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 10,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"(False, False)"
|
||||
]
|
||||
},
|
||||
"execution_count": 10,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"spot.are_equivalent(f, g), spot.are_equivalent(aut_f, aut_g)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 11,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"(False, False)"
|
||||
]
|
||||
},
|
||||
"execution_count": 11,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"f.equivalent_to(aut_g), aut_f.equivalent_to(g)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 12,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"True"
|
||||
]
|
||||
},
|
||||
"execution_count": 12,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"aut_f.equivalent_to('XXXGFa')"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Containement checks between formulas with cache\n",
|
||||
"\n",
|
||||
"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 prefered when performing several containement checks using the same formulas."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 13,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"lcc = spot.language_containment_checker()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 14,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"(False, True)"
|
||||
]
|
||||
},
|
||||
"execution_count": 14,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"lcc.contains(f, g), lcc.contains(g, f)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 15,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"False"
|
||||
]
|
||||
},
|
||||
"execution_count": 15,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"lcc.are_equivalent(f, g)"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.6.5"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/python3
|
||||
# -*- mode: python; coding: utf-8 -*-
|
||||
# Copyright (C) 2017 Laboratoire de Recherche et Développement de
|
||||
# Copyright (C) 2017, 2018 Laboratoire de Recherche et Développement de
|
||||
# l'EPITA.
|
||||
#
|
||||
# This file is part of Spot, a model checking library.
|
||||
|
|
@ -23,29 +23,6 @@ import os
|
|||
import shutil
|
||||
import sys
|
||||
|
||||
def parse_multiple_auts(hoa):
|
||||
l = hoa.split('--END--')
|
||||
a = []
|
||||
cpt = 0
|
||||
for x in l:
|
||||
if x.isspace() or x == '':
|
||||
continue
|
||||
x = x + "--END--"
|
||||
a.append(spot.automaton(x))
|
||||
|
||||
return a
|
||||
|
||||
def ensure_deterministic(a):
|
||||
if a.is_existential() and spot.is_deterministic(a):
|
||||
return a
|
||||
|
||||
return a.postprocess('Generic', 'deterministic', 'Low')
|
||||
|
||||
def equivalent(a1, a2):
|
||||
na1 = spot.dualize(ensure_deterministic(a1))
|
||||
na2 = spot.dualize(ensure_deterministic(a2))
|
||||
return (not a1.intersects(na2)) and (not a2.intersects(na1))
|
||||
|
||||
def tgba(a):
|
||||
if not a.is_existential():
|
||||
a = spot.remove_alternation(a)
|
||||
|
|
@ -54,11 +31,11 @@ def tgba(a):
|
|||
|
||||
def test_aut(aut):
|
||||
stgba = tgba(aut)
|
||||
assert equivalent(stgba, aut)
|
||||
assert stgba.equivalent_to(aut)
|
||||
os.environ["SPOT_STREETT_CONV_MIN"] = '1'
|
||||
sftgba = tgba(aut)
|
||||
del os.environ["SPOT_STREETT_CONV_MIN"]
|
||||
assert equivalent(stgba, sftgba)
|
||||
assert stgba.equivalent_to(sftgba)
|
||||
|
||||
slike = spot.simplify_acceptance(aut)
|
||||
|
||||
|
|
@ -66,7 +43,7 @@ def test_aut(aut):
|
|||
os.environ["SPOT_STREETT_CONV_MIN"] = "1"
|
||||
slftgba = tgba(slike)
|
||||
del os.environ["SPOT_STREETT_CONV_MIN"]
|
||||
assert equivalent(sltgba, slftgba)
|
||||
assert sltgba.equivalent_to(slftgba)
|
||||
|
||||
# Those automata are generated with ltl2dstar, which is NOT part of spot,
|
||||
# using the following command:
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
# -*- mode: python; coding: utf-8 -*-
|
||||
# Copyright (C) 2017 Laboratoire de Recherche et Développement
|
||||
# de l'Epita
|
||||
# Copyright (C) 2017, 2018 Laboratoire de Recherche et Développement de l'Epita
|
||||
#
|
||||
# This file is part of Spot, a model checking library.
|
||||
#
|
||||
|
|
@ -55,37 +54,29 @@ def produce_phi(rg, n):
|
|||
phi.append(f)
|
||||
return phi
|
||||
|
||||
def equivalent(a, phi):
|
||||
negphi = spot.formula.Not(phi)
|
||||
nega = spot.dualize(spot.tgba_determinize(a))
|
||||
a2 = spot.ltl_to_tgba_fm(phi, dict)
|
||||
nega2 = spot.ltl_to_tgba_fm(negphi, dict)
|
||||
return spot.product(a, nega2).is_empty()\
|
||||
and spot.product(nega, a2).is_empty()
|
||||
|
||||
phi1 = produce_phi(rg, 1000)
|
||||
phi2 = produce_phi(rg, 1000)
|
||||
inputres = []
|
||||
aut = []
|
||||
for p in zip(phi1, phi2):
|
||||
inputres.append(spot.formula.Or(p))
|
||||
a1 = spot.ltl_to_tgba_fm(p[0], dict)
|
||||
a2 = spot.ltl_to_tgba_fm(p[1], dict)
|
||||
a1 = spot.ltl_to_tgba_fm(p[0], dict)
|
||||
a2 = spot.ltl_to_tgba_fm(p[1], dict)
|
||||
aut.append(spot.to_generalized_buchi( \
|
||||
spot.remove_alternation(spot.sum(a1, a2), True)))
|
||||
|
||||
for p in zip(aut, inputres):
|
||||
assert equivalent(p[0], p[1])
|
||||
assert p[0].equivalent_to(p[1])
|
||||
|
||||
aut = []
|
||||
inputres = []
|
||||
|
||||
for p in zip(phi1, phi2):
|
||||
inputres.append(spot.formula.And(p))
|
||||
a1 = spot.ltl_to_tgba_fm(p[0], dict)
|
||||
a2 = spot.ltl_to_tgba_fm(p[1], dict)
|
||||
a1 = spot.ltl_to_tgba_fm(p[0], dict)
|
||||
a2 = spot.ltl_to_tgba_fm(p[1], dict)
|
||||
aut.append(spot.to_generalized_buchi( \
|
||||
spot.remove_alternation(spot.sum_and(a1, a2), True)))
|
||||
|
||||
for p in zip(aut, inputres):
|
||||
assert equivalent(p[0], p[1])
|
||||
assert p[0].equivalent_to(p[1])
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# -*- mode: python; coding: utf-8 -*-
|
||||
# Copyright (C) 2017 Laboratoire de Recherche et Développement
|
||||
# Copyright (C) 2017, 2018 Laboratoire de Recherche et Développement
|
||||
# de l'Epita
|
||||
#
|
||||
# This file is part of Spot, a model checking library.
|
||||
|
|
@ -29,16 +29,10 @@ GF!b
|
|||
(b & GF!b) | (!b & FGb)
|
||||
b | (a & XF(b R a)) | (!a & XG(!b U !a))"""
|
||||
|
||||
def equivalent(a, phi):
|
||||
negphi = spot.formula.Not(phi)
|
||||
nega = spot.dualize(a)
|
||||
return not (spot.translate(negphi).intersects(a)
|
||||
or spot.translate(phi).intersects(nega))
|
||||
|
||||
def test_phi(phi):
|
||||
a = spot.translate(phi, 'TGBA', 'SBAcc')
|
||||
res = spot.to_weak_alternating(spot.dualize(a))
|
||||
assert equivalent(res, spot.formula.Not(spot.formula(phi)))
|
||||
assert res.equivalent_to(spot.formula.Not(spot.formula(phi)))
|
||||
|
||||
for p in phi1.split('\n'):
|
||||
print(p)
|
||||
|
|
@ -87,4 +81,4 @@ State: 6
|
|||
--END--
|
||||
""")
|
||||
a2 = spot.to_weak_alternating(a2)
|
||||
assert equivalent(a2, phi2)
|
||||
assert a2.equivalent_to(phi2)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue