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()
def test_assert(a, d=None): t = test_aut(a, d) if not t[0]: print (t[1]) print (a.to_str('hoa')) print (spot.dualize(a).to_str('hoa')) assert False
def test_assert(a, d=None): t = test_aut(a, d) if not t[0]: print(t[1]) print(a.to_str('hoa')) print(spot.dualize(a).to_str('hoa')) assert False
def test_aut(aut, d=None): if d is None: d = spot.dualize(aut) aa = aut.acc() da = d.acc() complete = spot.is_complete(aut) univ = aut.is_univ_dest(aut.get_init_state_number()) an = aut.num_states() dn = d.num_states() if not dualtype(aut, d): return (False, 'Incorrect transition mode resulting of dual') for p in match_strings: if ((getattr(aa, p[0])() and getattr(da, p[1])())\ or (getattr(aa, p[1])() and getattr(da, p[0])())): return (True, '') return (False, 'Incorrect acceptance type dual')
def test_aut(aut, d = None): if d is None: d = spot.dualize(aut) aa = aut.acc() da = d.acc() complete = spot.is_complete(aut) univ = aut.is_univ_dest(aut.get_init_state_number()) an = aut.num_states() dn = d.num_states() if not dualtype(aut, d): return (False, 'Incorrect transition mode resulting of dual') for p in match_strings: if ((getattr(aa, p[0])() and getattr(da, p[1])())\ or (getattr(aa, p[1])() and getattr(da, p[0])())): return (True, '') return (False, 'Incorrect acceptance type dual')
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_assert(a, d=None): t = test_aut(a, d) if not t[0]: print(t[1]) print(a.to_str('hoa')) print(spot.dualize(a).to_str('hoa')) assert False aut = spot.translate('a') test_assert(aut) dual = spot.dualize(aut) h = dual.to_str('hoa') assert h == """HOA: v1 States: 3 Start: 1 AP: 1 "a" acc-name: co-Buchi Acceptance: 1 Fin(0) properties: trans-labels explicit-labels state-acc complete properties: deterministic stutter-invariant weak --BODY-- State: 0 {0} [t] 0 State: 1 [0] 0
[!0&!1&2] 1 State: 2 [0&!1&2] 7 State: 3 [!0&!1&2] 1 State: 4 [0&1&!2] 2 State: 5 [0&1&!2] 3 State: 6 {0} [!0&1&!2] 6 State: 7 {0} [0&!1&2] 7 --END-- """) # In Reuben's report this first block built an incorrect deterministic # automaton, which ultimately led to an non-empty product. The second # was fine. print("use_simulation=True") b1 = spot.tgba_determinize(b, False, True, True, True) assert b1.num_states() == 5 b1 = spot.remove_fin(spot.dualize(b1)) assert not a.intersects(b1) print("\nuse_simulation=False") b2 = spot.tgba_determinize(b, False, True, False, True) assert b2.num_states() == 5 b2 = spot.remove_fin(spot.dualize(b2)) assert not a.intersects(b2)
States: 3 Start: 1 AP: 1 "a" Acceptance: 1 Inf(0) --BODY-- State: 0 {0} [t] 0 State: 1 [!0] 0 [0] 2 State: 2 [t] 2 --END-- """) aut.prop_inherently_weak(True) aut = spot.dualize(aut) aut1 = spot.scc_filter_states(aut) assert (aut1.to_str('hoa') == """HOA: v1 States: 2 Start: 0 AP: 1 "a" acc-name: co-Buchi Acceptance: 1 Fin(0) properties: trans-labels explicit-labels state-acc deterministic properties: inherently-weak --BODY-- State: 0 [0] 1 State: 1 [t] 1 --END--""")
def incl(a, b): return not b.intersects(spot.dualize(spot.tgba_determinize(a)))
# You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # Test some function that must return exceptions on error. Doing # so is mostly a way to improve the coverage report. import spot try: spot.iar(spot.translate('GFa & GFb & GFc')) except RuntimeError as e: assert 'iar() expects Rabin-like input' in str(e) alt = spot.dualize(spot.translate('FGa | FGb')) try: spot.tgba_determinize(alt) except RuntimeError as e: assert 'tgba_determinize() does not support alternation' in str(e) aut = spot.translate('a U b U c') aps = aut.ap() rem = spot.remove_ap() rem.add_ap('"a"=0,b') aut = rem.strip(aut) assert aut.ap() == aps[2:] try: rem.add_ap('"a=0,b')
[!0&2] 3 State: 3 [!0&!2] 1 [!0&2] 3 [0&2] 4 [0&1&2] 5 State: 4 [2] 4 [0&1&2] 5 [!0&!2] 6 State: 5 {4} [1&2] 5 [!0&1&!2] 7 State: 6 [0&2] 4 [0&1&2] 5 State: 7 {1 3 4} [0&1&2] 5 --END-- """) tgba = spot.streett_to_generalized_buchi(a) assert tgba.acc().is_generalized_buchi() ba = spot.simplify_acceptance(a) assert ba.acc().is_buchi() nba = spot.dualize(ba.postprocess('generic', 'deterministic')) ntgba = spot.dualize(tgba.postprocess('generic', 'deterministic')) assert not ba.intersects(ntgba) assert not tgba.intersects(nba)
def test_phi(phi): a = spot.translate(phi, 'TGBA', 'SBAcc') res = spot.to_weak_alternating(spot.dualize(a)) assert res.equivalent_to(spot.formula.Not(spot.formula(phi)))
States: 3 Start: 1 AP: 1 "a" Acceptance: 1 Inf(0) --BODY-- State: 0 {0} [t] 0 State: 1 [!0] 0 [0] 2 State: 2 [t] 2 --END-- """) aut.prop_inherently_weak(True) aut = spot.dualize(aut) aut1 = spot.scc_filter_states(aut) assert(aut1.to_str('hoa') == """HOA: v1 States: 2 Start: 0 AP: 1 "a" acc-name: co-Buchi Acceptance: 1 Fin(0) properties: trans-labels explicit-labels state-acc deterministic properties: inherently-weak --BODY-- State: 0 [0] 1 State: 1 [t] 1 --END--""")
[0] 1 --END--""" c = spot.automaton("randaut -A'(Fin(0)&Inf(1)&Inf(2))|Fin(2)' 1 |") assert spot.is_partially_degeneralizable(c) == [1, 2] dc = spot.partial_degeneralize(c, [1, 2]) assert dc.equivalent_to(c) assert str(dc.get_acceptance()) == '(Fin(0) & Inf(2)) | Fin(1)' assert spot.is_partially_degeneralizable(d) == [] dd = spot.partial_degeneralize(d, []) assert dd.equivalent_to(d) assert dd.num_states() == 1 assert str(dd.get_acceptance()) == 'Inf(1) & Fin(0)' e = spot.dualize(b) de = spot.partial_degeneralize(e, [0, 1]) assert de.equivalent_to(e) assert de.num_states() == 4 de.copy_state_names_from(e) dehoa = de.to_str('hoa') assert dehoa == """HOA: v1 States: 4 Start: 0 AP: 1 "p0" acc-name: parity max even 2 Acceptance: 2 Fin(1) & Inf(0) properties: trans-labels explicit-labels trans-acc complete properties: deterministic --BODY--
def test_complement(aut): assert aut.is_deterministic() d = spot.dualize(aut) s = spot.product_or(aut, d) assert spot.dualize(s).is_empty()
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))
s = spot.product_or(aut, d) assert spot.dualize(s).is_empty() def test_assert(a, d=None): t = test_aut(a, d) if not t[0]: print (t[1]) print (a.to_str('hoa')) print (spot.dualize(a).to_str('hoa')) assert False aut = spot.translate('a') test_assert(aut) dual = spot.dualize(aut) h = dual.to_str('hoa') assert h == """HOA: v1 States: 3 Start: 1 AP: 1 "a" acc-name: co-Buchi Acceptance: 1 Fin(0) properties: trans-labels explicit-labels state-acc complete properties: deterministic stutter-invariant weak --BODY-- State: 0 {0} [t] 0 State: 1 [0] 0
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)))
def complement(aut): return spot.dualize(aut.postprocess('det', 'gen'))
# You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # Test some function that must return exceptions on error. Doing # so is mostly a way to improve the coverage report. import spot try: spot.iar(spot.translate('GFa & GFb & GFc')) except RuntimeError as e: assert 'iar() expects Rabin-like or Streett-like input' in str(e) alt = spot.dualize(spot.translate('FGa | FGb')) try: spot.tgba_determinize(alt) except RuntimeError as e: assert 'tgba_determinize() does not support alternation' in str(e) aut = spot.translate('a U b U c') aps = aut.ap() rem = spot.remove_ap() rem.add_ap('"a"=0,b') aut = rem.strip(aut) assert aut.ap() == aps[2:] try: rem.add_ap('"a=0,b')