Example #1
0
    def test_imply(self):
        impspec = imply(sptrue(), spfalse())
        self.assertEqual(impspec.type, parser.IMPLIES)
        self.assertIsNotNone(impspec.car)
        self.assertIsNotNone(impspec.cdr)

        with self.assertRaises(ValueError):
            impspec = imply(sptrue(), None)
Example #2
0
    def test_ctl(self):
        fsm = self.init_model()
        # EF admin = alice is True
        efaa = prop.ef(prop.atom("admin = alice"))
        self.assertTrue(fsm.init <= eval_ctl(fsm, efaa))

        # EG admin != alice is True
        egana = prop.eg(prop.atom("admin != alice"))
        self.assertTrue(fsm.init <= eval_ctl(fsm, egana))

        # AF admin != none is True
        afann = prop.af(prop.atom("admin != none"))
        self.assertTrue(fsm.init <= eval_ctl(fsm, afann))

        # AG admin in {alice, bob, none} is True
        aga = prop.ag(prop.atom("admin in {alice, bob, none}"))
        self.assertTrue(fsm.init <= eval_ctl(fsm, aga))

        # AG (admin != none -> AG admin != none) is True
        aganniann = prop.ag(
            prop.imply(prop.atom("admin != none"),
                       prop.ag(prop.atom("admin != none"))))
        self.assertTrue(fsm.init <= eval_ctl(fsm, aganniann))

        # AG (admin = alice -> AX admin = alice) is True
        agaaiaxaa = prop.ag(
            prop.imply(prop.atom("admin = alice"),
                       prop.ax(prop.atom("admin = alice"))))
        self.assertTrue(fsm.init <= eval_ctl(fsm, agaaiaxaa))

        # AX admin = alice is False
        axaa = prop.ax(prop.atom("admin = alice"))
        self.assertFalse(fsm.init <= eval_ctl(fsm, axaa))

        # EX admin != none is False
        exann = prop.ex(prop.atom("admin != none"))
        self.assertFalse(fsm.init <= eval_ctl(fsm, exann))

        # AG admin = none is False
        agan = prop.ag(prop.atom("admin = none"))
        self.assertFalse(fsm.init <= eval_ctl(fsm, agan))

        # EG admin = none is False
        egan = prop.eg(prop.atom("admin = none"))
        self.assertFalse(fsm.init <= eval_ctl(fsm, egan))
Example #3
0
 def test_ctl(self):
     fsm = self.init_model()
     # EF admin = alice is True
     efaa = prop.ef(prop.atom("admin = alice"))
     self.assertTrue(fsm.init <= eval_ctl(fsm, efaa))
     
     # EG admin != alice is True
     egana = prop.eg(prop.atom("admin != alice"))
     self.assertTrue(fsm.init <= eval_ctl(fsm, egana))
     
     # AF admin != none is True
     afann = prop.af(prop.atom("admin != none"))
     self.assertTrue(fsm.init <= eval_ctl(fsm, afann))
     
     # AG admin in {alice, bob, none} is True
     aga = prop.ag(prop.atom("admin in {alice, bob, none}"))
     self.assertTrue(fsm.init <= eval_ctl(fsm, aga))
     
     # AG (admin != none -> AG admin != none) is True
     aganniann = prop.ag(prop.imply(prop.atom("admin != none"),
                                    prop.ag(prop.atom("admin != none"))))
     self.assertTrue(fsm.init <= eval_ctl(fsm, aganniann))
     
     # AG (admin = alice -> AX admin = alice) is True
     agaaiaxaa = prop.ag(prop.imply(prop.atom("admin = alice"),
                                    prop.ax(prop.atom("admin = alice"))))
     self.assertTrue(fsm.init <= eval_ctl(fsm, agaaiaxaa))
     
     
     # AX admin = alice is False
     axaa = prop.ax(prop.atom("admin = alice"))
     self.assertFalse(fsm.init <= eval_ctl(fsm, axaa))
     
     # EX admin != none is False
     exann = prop.ex(prop.atom("admin != none"))
     self.assertFalse(fsm.init <= eval_ctl(fsm, exann))
     
     # AG admin = none is False
     agan = prop.ag(prop.atom("admin = none"))
     self.assertFalse(fsm.init <= eval_ctl(fsm, agan))
     
     # EG admin = none is False
     egan = prop.eg(prop.atom("admin = none"))
     self.assertFalse(fsm.init <= eval_ctl(fsm, egan))
Example #4
0
 def test_namecheR1(self):
     # activate bdd dynamic reordering
     nsopt.set_dynamic_reorder(nsopt.OptsHandler_get_instance())
     
     fsm = self.nameche_model()
     
     # AG (T_04BM.st = o & TRP_CM.krc = s -> AX (!R1.L_CS))
     to = prop.atom("T_04BM.st = o")
     trps = prop.atom("TRP_CM.krc = s")
     nr1lcs = prop.atom("!R1.L_CS")
     p = prop.imply(to & trps, prop.ax(nr1lcs))
     self.assertTrue(fsm.reachable_states <= eval_ctl(fsm, p))
     
     # AG (EF R1.L_CS)
     r1lcs = prop.atom("R1.L_CS")
     p = prop.ef(r1lcs)
     self.assertTrue(fsm.reachable_states <= eval_ctl(fsm, p))
Example #5
0
    def test_namecheR1(self):
        # activate bdd dynamic reordering
        nsopt.set_dynamic_reorder(nsopt.OptsHandler_get_instance())

        fsm = self.nameche_model()

        # AG (T_04BM.st = o & TRP_CM.krc = s -> AX (!R1.L_CS))
        to = prop.atom("T_04BM.st = o")
        trps = prop.atom("TRP_CM.krc = s")
        nr1lcs = prop.atom("!R1.L_CS")
        p = prop.imply(to & trps, prop.ax(nr1lcs))
        self.assertTrue(fsm.reachable_states <= eval_ctl(fsm, p))

        # AG (EF R1.L_CS)
        r1lcs = prop.atom("R1.L_CS")
        p = prop.ef(r1lcs)
        self.assertTrue(fsm.reachable_states <= eval_ctl(fsm, p))
Example #6
0
 def test_imply(self):
     impspec = imply(sptrue(), spfalse())
     self.assertEqual(impspec.type, parser.IMPLIES)
     self.assertIsNotNone(impspec.car)
     self.assertIsNotNone(impspec.cdr)
Example #7
0
def ast_to_spec(ast):
    """
    Return a PyNuSMV specification representing `ast`.

    :param ast: an AST-based CTL formula
    :return: a PyNuSMV specification representing `ast`
    :rtype: :class:`pynusmv.prop.Spec`

    :raise: a :exc:`NotImplementedError` if an operator is not implemented
    """
    if isinstance(ast, TrueExp):
        return true()

    elif isinstance(ast, FalseExp):
        return false()

    elif isinstance(ast, Atom):
        return atom(ast.value)

    elif isinstance(ast, Not):
        return not_(ast_to_spec(ast.child))

    elif isinstance(ast, And):
        return and_(ast_to_spec(ast.left), ast_to_spec(ast.right))

    elif isinstance(ast, Or):
        return or_(ast_to_spec(ast.left), ast_to_spec(ast.right))

    elif isinstance(ast, Imply):
        return imply(ast_to_spec(ast.left), ast_to_spec(ast.right))

    elif isinstance(ast, Iff):
        return iff(ast_to_spec(ast.left), ast_to_spec(ast.right))

    elif isinstance(ast, AX):
        return ax(ast_to_spec(ast.child))

    elif isinstance(ast, AF):
        return af(ast_to_spec(ast.child))

    elif isinstance(ast, AG):
        return ag(ast_to_spec(ast.child))

    elif isinstance(ast, AU):
        return au(ast_to_spec(ast.left), ast_to_spec(ast.right))

    elif isinstance(ast, AW):
        return aw(ast_to_spec(ast.left), ast_to_spec(ast.right))

    elif isinstance(ast, EX):
        return ex(ast_to_spec(ast.child))

    elif isinstance(ast, EF):
        return ef(ast_to_spec(ast.child))

    elif isinstance(ast, EG):
        return eg(ast_to_spec(ast.child))

    elif isinstance(ast, EU):
        return eu(ast_to_spec(ast.left), ast_to_spec(ast.right))

    elif isinstance(ast, EW):
        return ew(ast_to_spec(ast.left), ast_to_spec(ast.right))

    # A(phi oU psi) <=> A(phi U (phi & psi))
    elif isinstance(ast, AoU):
        return au(ast_to_spec(ast.left),
                  and_(ast_to_spec(ast.left), ast_to_spec(ast.right)))

    # A(phi oW psi) <=> A(phi W (phi & psi))
    elif isinstance(ast, AoW):
        return aw(ast_to_spec(ast.left),
                  and_(ast_to_spec(ast.left), ast_to_spec(ast.right)))

    # A(phi dU psi) <=> A(phi U (!phi & psi))
    elif isinstance(ast, AdU):
        return au(ast_to_spec(ast.left),
                  and_(not_(ast_to_spec(ast.left)), ast_to_spec(ast.right)))

    # A(phi dW psi) <=> A(phi W (!phi & psi))
    elif isinstance(ast, AdW):
        return aw(ast_to_spec(ast.left),
                  and_(not_(ast_to_spec(ast.left)), ast_to_spec(ast.right)))

    # E(phi oU psi) <=> E(phi U (phi & psi))
    elif isinstance(ast, EoU):
        return eu(ast_to_spec(ast.left),
                  and_(ast_to_spec(ast.left), ast_to_spec(ast.right)))

    # E(phi oW psi) <=> E(phi W (phi & psi))
    elif isinstance(ast, EoW):
        return ew(ast_to_spec(ast.left),
                  and_(ast_to_spec(ast.left), ast_to_spec(ast.right)))

    # E(phi dU psi) <=> E(phi U (!phi & psi))
    elif isinstance(ast, EdU):
        return eu(ast_to_spec(ast.left),
                  and_(not_(ast_to_spec(ast.left)), ast_to_spec(ast.right)))

    # E(phi dW psi) <=> E(phi W (!phi & psi))
    elif isinstance(ast, EdW):
        return ew(ast_to_spec(ast.left),
                  and_(not_(ast_to_spec(ast.left)), ast_to_spec(ast.right)))

    else:
        raise NotImplementedError(NOT_IMPLEMENTED_MSG.format(op=type(ast)))
Example #8
0
def ast_to_spec(ast):
    """
    Return a PyNuSMV specification representing `ast`.

    :param ast: an AST-based CTL formula
    :return: a PyNuSMV specification representing `ast`
    :rtype: :class:`pynusmv.prop.Spec`

    :raise: a :exc:`NotImplementedError` if an operator is not implemented
    """
    if isinstance(ast, TrueExp):
        return true()

    elif isinstance(ast, FalseExp):
        return false()

    elif isinstance(ast, Atom):
        return atom(ast.value)

    elif isinstance(ast, Not):
        return not_(ast_to_spec(ast.child))

    elif isinstance(ast, And):
        return and_(ast_to_spec(ast.left), ast_to_spec(ast.right))

    elif isinstance(ast, Or):
        return or_(ast_to_spec(ast.left), ast_to_spec(ast.right))

    elif isinstance(ast, Imply):
        return imply(ast_to_spec(ast.left), ast_to_spec(ast.right))

    elif isinstance(ast, Iff):
        return iff(ast_to_spec(ast.left), ast_to_spec(ast.right))

    elif isinstance(ast, AX):
        return ax(ast_to_spec(ast.child))

    elif isinstance(ast, AF):
        return af(ast_to_spec(ast.child))

    elif isinstance(ast, AG):
        return ag(ast_to_spec(ast.child))

    elif isinstance(ast, AU):
        return au(ast_to_spec(ast.left), ast_to_spec(ast.right))

    elif isinstance(ast, AW):
        return aw(ast_to_spec(ast.left), ast_to_spec(ast.right))

    elif isinstance(ast, EX):
        return ex(ast_to_spec(ast.child))

    elif isinstance(ast, EF):
        return ef(ast_to_spec(ast.child))

    elif isinstance(ast, EG):
        return eg(ast_to_spec(ast.child))

    elif isinstance(ast, EU):
        return eu(ast_to_spec(ast.left), ast_to_spec(ast.right))

    elif isinstance(ast, EW):
        return ew(ast_to_spec(ast.left), ast_to_spec(ast.right))

    # A(phi oU psi) <=> A(phi U (phi & psi))
    elif isinstance(ast, AoU):
        return au(ast_to_spec(ast.left),
                  and_(ast_to_spec(ast.left), ast_to_spec(ast.right)))

    # A(phi oW psi) <=> A(phi W (phi & psi))
    elif isinstance(ast, AoW):
        return aw(ast_to_spec(ast.left),
                  and_(ast_to_spec(ast.left), ast_to_spec(ast.right)))

    # A(phi dU psi) <=> A(phi U (!phi & psi))
    elif isinstance(ast, AdU):
        return au(ast_to_spec(ast.left),
                  and_(not_(ast_to_spec(ast.left)), ast_to_spec(ast.right)))

    # A(phi dW psi) <=> A(phi W (!phi & psi))
    elif isinstance(ast, AdW):
        return aw(ast_to_spec(ast.left),
                  and_(not_(ast_to_spec(ast.left)), ast_to_spec(ast.right)))

    # E(phi oU psi) <=> E(phi U (phi & psi))
    elif isinstance(ast, EoU):
        return eu(ast_to_spec(ast.left),
                  and_(ast_to_spec(ast.left), ast_to_spec(ast.right)))

    # E(phi oW psi) <=> E(phi W (phi & psi))
    elif isinstance(ast, EoW):
        return ew(ast_to_spec(ast.left),
                  and_(ast_to_spec(ast.left), ast_to_spec(ast.right)))

    # E(phi dU psi) <=> E(phi U (!phi & psi))
    elif isinstance(ast, EdU):
        return eu(ast_to_spec(ast.left),
                  and_(not_(ast_to_spec(ast.left)), ast_to_spec(ast.right)))

    # E(phi dW psi) <=> E(phi W (!phi & psi))
    elif isinstance(ast, EdW):
        return ew(ast_to_spec(ast.left),
                  and_(not_(ast_to_spec(ast.left)), ast_to_spec(ast.right)))

    else:
        raise NotImplementedError(NOT_IMPLEMENTED_MSG.format(op=type(ast)))