def test_strengthen2(self): """ Forall(i) GFa_i and G(b_i) -> Forall(j) GF(c_j) and G(d_j) replaced by 'liveness': Forall(i) GFa_i and G(b_i) -> Forall(j) GF(c_j) and 'safety': Forall(i) G(b_i) -> Forall(j) G(d_j) """ a_i, b_i = QuantifiedSignal("a", "i"), QuantifiedSignal("b", "i") c_j, d_j = QuantifiedSignal("c", "j"), QuantifiedSignal("d", "j") ass = ForallExpr(["i"], BinOp("*", UnaryOp("G", UnaryOp("F", a_i)), UnaryOp("G", b_i))) gua = ForallExpr(["j"], BinOp("*", UnaryOp("G", UnaryOp("F", c_j)), UnaryOp("G", d_j))) property = SpecProperty([ass], [gua]) safety_properties, liveness_properties = strengthen(property, self._get_converter()) assert len(liveness_properties) == 1, str(liveness_properties) assert len(safety_properties) == 1, str(safety_properties) expected_liveness_gua = ForallExpr(["j"], UnaryOp("G", UnaryOp("F", c_j))) #: :type: SpecProperty liveness_prop = liveness_properties[0] assert str(liveness_prop.assumptions) == str([ass]), str(liveness_prop) assert str(liveness_prop.guarantees) == str([expected_liveness_gua]) safety_prop = safety_properties[0] expected_safety_ass = ForallExpr(["i"], UnaryOp("G", b_i)) expected_safety_gua = ForallExpr(["j"], UnaryOp("G", d_j)) expected_safety_prop = SpecProperty([expected_safety_ass], [expected_safety_gua]) assert str(expected_safety_prop) == str(safety_prop), str(safety_prop)
def test_strengthen3(self): """ Forall(i,j) GFa_i * GFb_i_j * Gc_i_j -> Forall(k,m) GF(d_k_m) * G(e_k) replaced by 'safety': Forall(i) Gc_i_j -> Forall(k) G(e_k) 'liveness': Forall(i,j) GFa_i * GFb_i_j * Gc_i -> Forall(k,m) GF(d_k_m) """ a_i, b_i_j, c_i_j = _get_is_true("a", "i"), _get_is_true("b", "i", "j"), _get_is_true("c", "i", "j") ass = ForallExpr( ["i", "j"], BinOp( "*", UnaryOp("G", UnaryOp("F", a_i)), BinOp("*", UnaryOp("G", UnaryOp("F", b_i_j)), UnaryOp("G", c_i_j)) ), ) d_k_m = _get_is_true("d", "k", "m") e_k = _get_is_true("e", "k") gua = ForallExpr(["k", "m"], BinOp("*", UnaryOp("G", UnaryOp("F", d_k_m)), UnaryOp("G", e_k))) property = SpecProperty([ass], [gua]) safety_properties, liveness_properties = strengthen(property, self._get_converter()) # lazy.. print("safety_properties", safety_properties) assert len(safety_properties) == 1, str(safety_properties) assert len(list(chain(*[sp.assumptions for sp in safety_properties]))) == 1 assert len(list(chain(*[sp.guarantees for sp in safety_properties]))) == 1 print("liveness_properties", liveness_properties)
def test_strengthen3(self): """ Forall(i,j) GFa_i * GFb_i_j * Gc_i_j -> Forall(k,m) GF(d_k_m) * G(e_k) replaced by 'safety': Forall(i) Gc_i_j -> Forall(k) G(e_k) 'liveness': Forall(i,j) GFa_i * GFb_i_j * Gc_i -> Forall(k,m) GF(d_k_m) """ a_i, b_i_j, c_i_j = _get_is_true('a', 'i'), _get_is_true( 'b', 'i', 'j'), _get_is_true('c', 'i', 'j') ass = ForallExpr(['i', 'j'], BinOp( '*', UnaryOp('G', UnaryOp('F', a_i)), BinOp('*', UnaryOp('G', UnaryOp('F', b_i_j)), UnaryOp('G', c_i_j)))) d_k_m = _get_is_true('d', 'k', 'm') e_k = _get_is_true('e', 'k') gua = ForallExpr(['k', 'm'], BinOp('*', UnaryOp('G', UnaryOp('F', d_k_m)), UnaryOp('G', e_k))) property = SpecProperty([ass], [gua]) safety_properties, liveness_properties = strengthen( property, self._get_converter()) #lazy.. print('safety_properties', safety_properties) assert len(safety_properties) == 1, str(safety_properties) assert len(list(chain(*[sp.assumptions for sp in safety_properties]))) == 1 assert len(list(chain(*[sp.guarantees for sp in safety_properties]))) == 1 print('liveness_properties', liveness_properties)
def test_strengthen2(self): """ Forall(i) GFa_i -> Forall(j) GF(b_j) is left as it is """ a_i, b_j = QuantifiedSignal("a", "i"), QuantifiedSignal("b", "j") liveness_ass = ForallExpr(["i"], UnaryOp("G", UnaryOp("F", a_i))) liveness_gua = ForallExpr(["j"], UnaryOp("G", UnaryOp("F", b_j))) property = SpecProperty([liveness_ass], [liveness_gua]) safety_properties, liveness_properties = strengthen(property, self._get_converter()) assert len(liveness_properties) == 1, str(liveness_properties) assert len(safety_properties) == 0, str(safety_properties) actual = liveness_properties[0] expected = property assert str(actual) == str(expected), str(actual) + " vs " + str(expected)
def test_strengthen2(self): """ Forall(i) GFa_i and G(b_i) -> Forall(j) GF(c_j) and G(d_j) replaced by 'liveness': Forall(i) GFa_i and G(b_i) -> Forall(j) GF(c_j) and 'safety': Forall(i) G(b_i) -> Forall(j) G(d_j) """ a_i, b_i = QuantifiedSignal('a', 'i'), QuantifiedSignal('b', 'i') c_j, d_j = QuantifiedSignal('c', 'j'), QuantifiedSignal('d', 'j') ass = ForallExpr(['i'], BinOp('*', UnaryOp('G', UnaryOp('F', a_i)), UnaryOp('G', b_i))) gua = ForallExpr(['j'], BinOp('*', UnaryOp('G', UnaryOp('F', c_j)), UnaryOp('G', d_j))) property = SpecProperty([ass], [gua]) safety_properties, liveness_properties = strengthen( property, self._get_converter()) assert len(liveness_properties) == 1, str(liveness_properties) assert len(safety_properties) == 1, str(safety_properties) expected_liveness_gua = ForallExpr(['j'], UnaryOp('G', UnaryOp('F', c_j))) #: :type: SpecProperty liveness_prop = liveness_properties[0] assert str(liveness_prop.assumptions) == str([ass]), str(liveness_prop) assert str(liveness_prop.guarantees) == str([expected_liveness_gua]) safety_prop = safety_properties[0] expected_safety_ass = ForallExpr(['i'], UnaryOp('G', b_i)) expected_safety_gua = ForallExpr(['j'], UnaryOp('G', d_j)) expected_safety_prop = SpecProperty([expected_safety_ass], [expected_safety_gua]) assert str(expected_safety_prop) == str(safety_prop), str(safety_prop)
def test_strengthen1(self): """ Forall(i) GFa_i -> Forall(j) G(b_j) replaced by 'safety': Forall(j) G(b_j) 'liveness': [] """ a_i, b_j = QuantifiedSignal("a", "i"), QuantifiedSignal("b", "j") liveness_ass = ForallExpr(["i"], UnaryOp("G", UnaryOp("F", a_i))) safety_gua = ForallExpr(["j"], UnaryOp("G", b_j)) property = SpecProperty([liveness_ass], [safety_gua]) safety_properties, liveness_properties = strengthen(property, self._get_converter()) assert len(liveness_properties) == 0, str(liveness_properties) assert len(safety_properties) == 1, str(safety_properties) actual_guarantees = safety_properties[0].guarantees assert str(actual_guarantees) == str([safety_gua]), "\n" + str(actual_guarantees) + "\nvs\n" + str([safety_gua])
def test_strengthen2(self): """ Forall(i) GFa_i -> Forall(j) GF(b_j) is left as it is """ a_i, b_j = QuantifiedSignal('a', 'i'), QuantifiedSignal('b', 'j') liveness_ass = ForallExpr(['i'], UnaryOp('G', UnaryOp('F', a_i))) liveness_gua = ForallExpr(['j'], UnaryOp('G', UnaryOp('F', b_j))) property = SpecProperty([liveness_ass], [liveness_gua]) safety_properties, liveness_properties = strengthen( property, self._get_converter()) assert len(liveness_properties) == 1, str(liveness_properties) assert len(safety_properties) == 0, str(safety_properties) actual = liveness_properties[0] expected = property assert str(actual) == str( expected), str(actual) + ' vs ' + str(expected)
def test_strengthen1(self): """ Forall(i) GFa_i -> Forall(j) G(b_j) replaced by 'safety': Forall(j) G(b_j) 'liveness': [] """ a_i, b_j = QuantifiedSignal('a', 'i'), QuantifiedSignal('b', 'j') liveness_ass = ForallExpr(['i'], UnaryOp('G', UnaryOp('F', a_i))) safety_gua = ForallExpr(['j'], UnaryOp('G', b_j)) property = SpecProperty([liveness_ass], [safety_gua]) safety_properties, liveness_properties = strengthen( property, self._get_converter()) assert len(liveness_properties) == 0, str(liveness_properties) assert len(safety_properties) == 1, str(safety_properties) actual_guarantees = safety_properties[0].guarantees assert str(actual_guarantees) == str([safety_gua]), \ '\n' + str(actual_guarantees) + '\nvs\n' + str([safety_gua])