Example #1
0
    def test_eventually(self):
        parser = self.parser
        i_, i_a, i_b, i_ab = self.i_, self.i_a, self.i_b, self.i_ab
        true = self.true
        false = self.false

        assert parser("F a").delta(i_a) == PLOr([
            true,
            PLAnd([
                true,
                PLAnd([
                    PLAtomic(LTLfUntil([LTLfTrue(),
                                        LTLfAtomic("a")])),
                    PLAtomic(LTLfUntil([LTLfTrue(), LTLfTrue()])),
                ]),
            ]),
        ])
        assert parser("F a").delta(i_) == PLOr([
            false,
            PLAnd([
                true,
                PLAnd([
                    PLAtomic(LTLfUntil([LTLfTrue(),
                                        LTLfAtomic("a")])),
                    PLAtomic(LTLfUntil([LTLfTrue(), LTLfTrue()])),
                ]),
            ]),
        ])
        assert parser("F a").delta(i_a, epsilon=True) == false
        assert parser("F a").delta(i_, epsilon=True) == false
Example #2
0
    def test_always(self):
        parser = self.parser
        i_, i_a, i_b, i_ab = self.i_, self.i_a, self.i_b, self.i_ab
        true = self.true
        false = self.false

        assert parser("G a").delta(i_a) == PLAnd([
            true,
            PLOr([
                false,
                PLOr([
                    PLAtomic(LTLfRelease([LTLfFalse(),
                                          LTLfAtomic("a")])),
                    PLAtomic(LTLfRelease([LTLfFalse(),
                                          LTLfFalse()])),
                ]),
            ]),
        ])
        assert parser("G a").delta(i_a) == PLAnd([
            true,
            PLOr([
                false,
                PLOr([
                    PLAtomic(LTLfRelease([LTLfFalse(),
                                          LTLfAtomic("a")])),
                    PLAtomic(LTLfRelease([LTLfFalse(),
                                          LTLfFalse()])),
                ]),
            ]),
        ])
        assert parser("G a").delta(i_a, epsilon=True) == true
        assert parser("G a").delta(i_, epsilon=True) == true
Example #3
0
    def test_or(self):
        parser = self.parser
        i_, i_a, i_b, i_ab = self.i_, self.i_a, self.i_b, self.i_ab
        true = self.true
        false = self.false

        assert parser("a | b").delta(i_) == PLOr([false, false])
        assert parser("a | b").delta(i_a) == PLOr([true, false])
        assert parser("a | b").delta(i_b) == PLOr([false, true])
        assert parser("a | b").delta(i_ab) == PLOr([true, true])
        assert parser("a | b").delta(i_, epsilon=True) == false
Example #4
0
def _is_true(Q: FrozenSet[FrozenSet]):
    if frozenset() in Q:
        return True
    conj = [
        PLAnd([subf.s.delta(None, epsilon=True)
               for subf in q]) if len(q) >= 2 else next(iter(q)).s.delta(
                   None, epsilon=True) if len(q) == 1 else PLFalse() for q in Q
    ]
    if len(conj) == 0:
        return False
    else:
        pl_conj = PLOr(conj) if len(conj) >= 2 else conj[0]
        result = pl_conj.truth({})
        return result
Example #5
0
 def delta_diamond(self,
                   f: LDLfFormula,
                   i: PropositionalInterpretation,
                   epsilon=False):
     """Apply delta function for regular expressions in the diamond operator."""
     return PLOr(
         [LDLfDiamond(r, f)._delta(i, epsilon) for r in self.formulas])
Example #6
0
 def p_propositional(self, p):
     """propositional : propositional EQUIVALENCE propositional
                      | propositional IMPLIES propositional
                      | propositional OR propositional
                      | propositional AND propositional
                      | NOT propositional
                      | FALSE
                      | TRUE
                      | ATOM"""
     if len(p)==4:
         if p[2] == Symbols.EQUIVALENCE.value:
             p[0] = PLEquivalence([p[1], p[3]])
         elif p[2] == Symbols.IMPLIES.value:
             p[0] = PLImplies([p[1], p[3]])
         elif p[2] == Symbols.OR.value:
             p[0] = PLOr([p[1], p[3]])
         elif p[2] == Symbols.AND.value:
             p[0] = PLAnd([p[1], p[3]])
         else:
             raise ValueError
         # else:
         #     p[0] = p[2]
     elif len(p)==3:
         p[0] = PLNot(p[2])
     elif len(p)==2:
         if p[1]==Symbols.TRUE.value:
             p[0] = PLTrue()
         elif p[1]==Symbols.FALSE.value:
             p[0] = PLFalse()
         else:
             p[0] = PLAtomic(p[1])
     else:
         raise ValueError
Example #7
0
 def delta_box(self, f: LDLfFormula, i: PLInterpretation, epsilon=False):
     # ff = LDLfNot(self.f).to_nnf()
     # dff = ff._delta(i, epsilon)
     # fun = f._delta(i, epsilon)
     return PLOr([
         LDLfNot(self.f).to_nnf()._delta(i, epsilon),
         f._delta(i, epsilon)
     ])
Example #8
0
 def prop_or(self, args):
     if len(args) == 1:
         return args[0]
     elif (len(args) - 1) % 2 == 0:
         subformulas = args[::2]
         return PLOr(subformulas)
     else:
         raise ParsingError
Example #9
0
 def delta_diamond(self,
                   f: LDLfFormula,
                   i: PLInterpretation,
                   epsilon=False):
     return PLOr([
         f._delta(i, epsilon),
         LDLfDiamond(self.f, F(LDLfDiamond(self, f)))._delta(i, epsilon)
     ])
Example #10
0
 def delta_box(self,
               f: LDLfFormula,
               i: PropositionalInterpretation,
               epsilon=False) -> PLFormula:
     """Apply delta function for regular expressions in the box operator."""
     return PLOr([
         LDLfNot(self.f).to_nnf()._delta(i, epsilon),
         f._delta(i, epsilon)
     ])  # type: ignore
Example #11
0
 def delta_diamond(self,
                   f: LDLfFormula,
                   i: PropositionalInterpretation,
                   epsilon=False):
     """Apply delta function for regular expressions in the diamond operator."""
     return PLOr([
         f._delta(i, epsilon),
         LDLfDiamond(self.f,
                     _FreezedFalse(LDLfDiamond(self,
                                               f)))._delta(i, epsilon),
     ])
Example #12
0
 def _delta(self, i: PLInterpretation, epsilon: bool = False):
     if epsilon:
         return PLFalse()
     f1 = self.formulas[0]
     f2 = LTLfUntil(
         self.formulas[1:]) if len(self.formulas) > 2 else self.formulas[1]
     return PLOr([
         f2._delta(i, epsilon),
         PLAnd([f1._delta(i, epsilon),
                LTLfNext(self)._delta(i, epsilon)])
     ])
Example #13
0
 def _delta(self, i: PLInterpretation, epsilon=False):
     if epsilon:
         return PLTrue()
     f1 = self.formulas[0]
     f2 = LTLfRelease(
         self.formulas[1:]) if len(self.formulas) > 2 else self.formulas[1]
     return PLAnd([
         f2._delta(i, epsilon),
         PLOr(
             [f1._delta(i, epsilon),
              LTLfWeakNext(self)._delta(i, epsilon)])
     ])
Example #14
0
 def _delta(self, i: PropositionalInterpretation, epsilon: bool = False):
     """Apply the delta function."""
     if epsilon:
         return PLFalse()
     f1 = self.formulas[0]
     f2 = (LTLfUntil(self.formulas[1:])
           if len(self.formulas) > 2 else self.formulas[1])
     return PLOr([
         f2._delta(i, epsilon),
         PLAnd([f1._delta(i, epsilon),
                LTLfNext(self)._delta(i, epsilon)]),
     ])
Example #15
0
    def test_misc(self):
        a, b = self.a, self.b
        i_, i_a, i_b, i_ab = self.i_, self.i_a, self.i_b, self.i_ab

        material_implication = PLEquivalence(
            [PLOr([PLNot(a), b]), PLNot(PLAnd([a, PLNot(b)])), PLImplies([a, b])]
        )

        # the equivalence is valid (i.e. satisfied for every interpretation)
        assert material_implication.truth(i_)
        assert material_implication.truth(i_a)
        assert material_implication.truth(i_b)
        assert material_implication.truth(i_ab)

        a_and_false_and_true = PLAnd([a, PLFalse(), PLTrue()])
        assert not a_and_false_and_true.truth(i_)
        assert not a_and_false_and_true.truth(i_a)
        assert not a_and_false_and_true.truth(i_b)
        assert not a_and_false_and_true.truth(i_ab)

        a_or_false_or_true = PLOr([a, PLFalse(), PLTrue()])
        assert a_or_false_or_true.truth(i_)
        assert a_or_false_or_true.truth(i_a)
        assert a_or_false_or_true.truth(i_b)
        assert a_or_false_or_true.truth(i_ab)
Example #16
0
    def test_until(self):
        parser = self.parser
        i_, i_a, i_b, i_ab = self.i_, self.i_a, self.i_b, self.i_ab
        true = self.true
        false = self.false

        assert parser("A U B").delta(i_a) == PLOr([
            false,
            PLAnd([
                true,
                PLAtomic(LTLfUntil([LTLfAtomic("A"), LTLfAtomic("B")])),
                PLAtomic(LTLfEventually(LTLfTrue()).to_nnf())
            ])
        ])
        assert parser("A U B").delta(i_ab, epsilon=True) == false
Example #17
0
    def test_release(self):
        parser = self.parser
        i_, i_a, i_b, i_ab = self.i_, self.i_a, self.i_b, self.i_ab
        true = self.true
        false = self.false

        assert parser("A R B").delta(i_a) == PLAnd([
            false,
            PLOr([
                true,
                PLAtomic(LTLfRelease([LTLfAtomic("A"), LTLfAtomic("B")])),
                PLAtomic(LTLfAlways(LTLfFalse()).to_nnf())
            ])
        ])
        assert parser("A R B").delta(i_ab, epsilon=True) == true
Example #18
0
def test_parser():
    parser = PLParser()
    sa, sb = "A", "B"
    a, b = PLAtomic(sa), PLAtomic(sb)

    a_and_b = parser("A & B")
    true_a_and_b = PLAnd([a, b])
    assert a_and_b == true_a_and_b

    material_implication = parser("!A | B <-> !(A & !B) <-> A->B")
    true_material_implication = PLEquivalence(
        [PLOr([PLNot(a), b]), PLNot(PLAnd([a, PLNot(b)])), PLImplies([a, b])]
    )

    assert material_implication == true_material_implication

    true_a_and_false_and_true = PLAnd([a, PLFalse(), PLTrue()])
    a_and_false_and_true = parser("A & false & true")

    assert a_and_false_and_true == true_a_and_false_and_true
Example #19
0
 def _delta(self, i: PLInterpretation, epsilon=False):
     if epsilon:
         return PLTrue()
     else:
         return PLOr([PLAtomic(self.f), PLAtomic(LTLfEnd().to_nnf())])
Example #20
0
 def _delta(self, i: PLInterpretation, epsilon=False):
     return PLOr([f._delta(i, epsilon) for f in self.formulas])
Example #21
0
 def p_formula_or(self, p):
     'formula : formula OR formula'
     p[0] = PLOr([p[1], p[3]])
Example #22
0
 def _delta(self, i: PropositionalInterpretation, epsilon=False):
     """Apply the delta function."""
     if epsilon:
         return PLTrue()
     else:
         return PLOr([PLAtomic(self.f), PLAtomic(LTLfEnd().to_nnf())])
Example #23
0
 def _delta(self, i: PropositionalInterpretation, epsilon=False):
     """Apply the delta function."""
     return PLOr([f._delta(i, epsilon) for f in self.formulas])
Example #24
0
 def delta_diamond(self,
                   f: LDLfFormula,
                   i: PLInterpretation,
                   epsilon=False):
     return PLOr(
         [LDLfDiamond(r, f)._delta(i, epsilon) for r in self.formulas_set])