def truth(self, i: FiniteTrace, pos: int = 0): f1 = self.formulas[0] f2 = LTLfUntil( self.formulas[1:]) if len(self.formulas) > 2 else self.formulas[1] a = any(f2.truth(i, j) for j in range(pos, i.last() + 1)) b = all( f1.truth(i, k) for j in range(pos, i.last() + 1) for k in range(pos, j)) return any( f2.truth(i, j) and all(f1.truth(i, k) for k in range(pos, j)) for j in range(pos, i.last() + 1))
def test_ltlf_example_readme(): from flloat.parser.ltlf import LTLfParser from flloat.semantics.traces import FiniteTrace parser = LTLfParser() formula = "F (A & !B)" parsed_formula = parser(formula) t1 = FiniteTrace.from_symbol_sets([{}, {"A"}, {"A"}, {"A", "B"}]) assert parsed_formula.truth(t1, 0) t2 = FiniteTrace.from_symbol_sets([{}, {"A", "B"}, {"B"}]) assert not parsed_formula.truth(t2, 0) dfa = parsed_formula.to_automaton() assert dfa.accepts(t1.trace) assert not dfa.accepts(t2.trace)
def setup_class(cls): cls.parser = LTLfParser() cls.trace = FiniteTrace.from_symbol_sets([ {"A"}, {"A"}, {"B"}, {"B"}, {"C"}, {"C"}, ])
def test_truth(): sa, sb = "a", "b" a, b = PLAtomic(sa), PLAtomic(sb) i_ = PLFalseInterpretation() i_a = PLInterpretation({sa}) i_b = PLInterpretation({sb}) i_ab = PLInterpretation({sa, sb}) tr_false_a_b_ab = FiniteTrace([i_, i_a, i_b, i_ab, i_]) tt = LDLfLogicalTrue() ff = LDLfLogicalFalse() assert tt.truth(tr_false_a_b_ab, 0) assert not ff.truth(tr_false_a_b_ab, 0) assert not LDLfNot(tt).truth(tr_false_a_b_ab, 0) assert LDLfNot(ff).truth(tr_false_a_b_ab, 0) assert LDLfAnd([LDLfPropositional(a), LDLfPropositional(b)]).truth(tr_false_a_b_ab, 3) assert not LDLfDiamond(RegExpPropositional(PLAnd([a, b])), tt).truth( tr_false_a_b_ab, 0) parser = LDLfParser() trace = FiniteTrace.from_symbol_sets([{}, {"A"}, {"A"}, {"A", "B"}, {}]) formula = "<true*;A&B>tt" parsed_formula = parser(formula) assert parsed_formula.truth(trace, 0) formula = "[(A+!B)*]<C>tt" parsed_formula = parser(formula) assert not parsed_formula.truth(trace, 1) formula = "<(<!C>tt)?><A>tt" parsed_formula = parser(formula) assert parsed_formula.truth(trace, 1) formula = "<!C+A>tt" parsed_formula = parser(formula) assert parsed_formula.truth(trace, 1)
def test_ldlf_example_readme(): from flloat.parser.ldlf import LDLfParser parser = LDLfParser() formula = "<true*; A & B>tt" parsed_formula = parser(formula) assert str(parsed_formula) == "<((true)* ; (B & A))>(tt)" or str( parsed_formula) == "<((true)* ; (A & B))>(tt)" assert parsed_formula.find_labels() == {c for c in "AB"} from flloat.semantics.traces import FiniteTrace t1 = FiniteTrace.from_symbol_sets([{}, {"A"}, {"A"}, {"A", "B"}, {}]) assert parsed_formula.truth(t1, 0) t2 = FiniteTrace.from_symbol_sets([{}, {"A"}, {"B"}]) assert not parsed_formula.truth(t2, 0) dfa = parsed_formula.to_automaton() assert dfa.accepts(t1.trace) assert not dfa.accepts(t2.trace)
def truth(self, i: FiniteTrace, pos: int = 0): return PLAtomic(self.s).truth(i.get(pos))
def truth(self, i: FiniteTrace, pos: int = 0): return pos < i.last() and self.f.truth(i, pos + 1)
def truth(self, tr: FiniteTrace, start: int = 0, end: int = 0): return end == start + 1 \ and end <= tr.last() \ and self.pl_formula.truth(tr.get(start))
def truth(self, i: FiniteTrace, pos: int = 0): # last + 1 in order to include the last step return any( self.r.truth(i, pos, j) and self.f.truth(i, j) for j in range(pos, i.last() + 1))