def ltlf_and(self, args): """Parse LTLf And.""" if len(args) == 1: return args[0] elif (len(args) - 1) % 2 == 0: subformulas = args[::2] return LTLfAnd(subformulas) else: raise ParsingError
def ltlf_main(self): """ Obtains the equivalent LTLf formula using the classes from whitemensh """ # This is outdated return NotImplementedError eqs = [] rep2lit = {} ltl = self.ltlf(eqs, rep2lit) for eq in eqs[::-1]: ltl = LTLfAnd([ltl, LTLfAlways(LTLfEquivalence([eq[0], eq[1]]))]) return ltl
def test_parser(): parser = LTLfParser() a, b, c = [LTLfAtomic(c) for c in "abc"] assert parser("!a | b <-> !(a & !b) <-> a->b") == LTLfEquivalence([ LTLfOr([LTLfNot(a), b]), LTLfNot(LTLfAnd([a, LTLfNot(b)])), LTLfImplies([a, b]), ]) assert parser("(X a) & (WX !b)") == LTLfAnd( [LTLfNext(a), LTLfWeakNext(LTLfNot(b))]) assert parser("(F (a&b)) <-> !(G (!a | !b) )") == LTLfEquivalence([ LTLfEventually(LTLfAnd([a, b])), LTLfNot(LTLfAlways(LTLfOr([LTLfNot(a), LTLfNot(b)]))), ]) assert parser("(a U b U c) <-> !(!a R !b R !c)") == LTLfEquivalence([ LTLfUntil([a, b, c]), LTLfNot(LTLfRelease([LTLfNot(a), LTLfNot(b), LTLfNot(c)])), ])
def test_nnf(): parser = LTLfParser() a, b, c = [LTLfAtomic(c) for c in "abc"] f = parser("!(a & !b)") assert f.to_nnf() == LTLfOr([LTLfNot(a), b]) f = parser("!(!a | b)") assert f.to_nnf() == LTLfAnd([a, LTLfNot(b)]) f = parser("!(a <-> b)") assert f.to_nnf() == LTLfAnd( [LTLfOr([LTLfNot(a), LTLfNot(b)]), LTLfOr([a, b])]) # Next and Weak Next f = parser("!(X (a & b))") assert f.to_nnf() == LTLfWeakNext(LTLfOr([LTLfNot(a), LTLfNot(b)])) f = parser("!(WX (a & b))") assert f.to_nnf() == LTLfNext(LTLfOr([LTLfNot(a), LTLfNot(b)])) # Eventually and Always f = parser("!(F (a | b))") assert f.to_nnf() == LTLfAlways(LTLfAnd([LTLfNot(a), LTLfNot(b)])).to_nnf() # Until and Release f = parser("!(a U b)") assert f.to_nnf() == LTLfRelease([LTLfNot(a), LTLfNot(b)]) f = parser("!(a R b)") assert f.to_nnf() == LTLfUntil([LTLfNot(a), LTLfNot(b)]) f = parser("!(F (a | b))") assert f.to_nnf() == LTLfAlways(LTLfAnd([LTLfNot(a), LTLfNot(b)])).to_nnf() f = parser("!(G (a | b))") assert f.to_nnf() == LTLfEventually(LTLfAnd([LTLfNot(a), LTLfNot(b)])).to_nnf()
def test_QuotedFormula(): from ltlf2dfa.base import QuotedFormula from ltlf2dfa.ltlf import LTLfAnd, LTLfAtomic from ltlf2dfa.parser.ltlf import LTLfParser f = LTLfParser()("!(G a)") qf = QuotedFormula(f) atomf = LTLfAnd([LTLfAtomic(f), LTLfAtomic(f)]) assert qf.wrapped is f dir_qf = dir(qf) for member in dir(f): assert member in dir_qf assert hasattr(qf, member)