Ejemplo n.º 1
0
 def test_truth_sequence(self):
     ref = self.ref
     a = self.a
     b = self.b
     c = self.c
     self.assertTrue(
         ref.truth(PathExpressionSequence(And(a, b), And(a, c)),
                   self.trace_1, 0, 2))
     self.assertTrue(
         ref.truth(
             PathExpressionSequence(
                 And(a, b), PathExpressionSequence(And(a, c), And(b, c))),
             self.trace_1, 2, 5))
Ejemplo n.º 2
0
    def test_to_nnf(self):
        f1 = Not(
            PathExpressionEventually(
                PathExpressionSequence(PathExpressionTest(Not(self.a_and_b)),
                                       PathExpressionStar(TrueFormula())),
                self.abc))
        nnf_f1 = PathExpressionAlways(
            PathExpressionSequence(
                PathExpressionTest(Or(Not(self.a), Not(self.b))),
                # PathExpressionStar(Or(DUMMY_ATOMIC, Not(DUMMY_ATOMIC)))
                PathExpressionStar(TrueFormula())),
            Or(Not(self.a), Or(Not(self.b), Not(self.c))))

        self.assertEqual(self.ldlf.to_nnf(f1), nnf_f1)
Ejemplo n.º 3
0
    def _build_automata(self):
        rows = self.row_symbols
        atoms = [AtomicFormula(r) for r in rows]
        alphabet = Alphabet(set(rows))
        ldlf = LDLf_EmptyTraces(alphabet)
        f = PathExpressionEventually(
            PathExpressionSequence.chain([
                PathExpressionStar(
                    And.chain([Not(atoms[0]),
                               Not(atoms[1]),
                               Not(atoms[2])])),
                PathExpressionStar(
                    And.chain([atoms[0],
                               Not(atoms[1]),
                               Not(atoms[2])])),
                # Not(atoms[3]), Not(atoms[4]), Not(atoms[5])]),
                PathExpressionStar(
                    And.chain([atoms[0], atoms[1],
                               Not(atoms[2])])),
                # Not(atoms[3]), Not(atoms[4]), Not(atoms[5])]),
                # And.chain([atoms[0],      atoms[1],      atoms[2]]),  # Not(atoms[3]), Not(atoms[4]), Not(atoms[5])]),
                # And.chain([atoms[0],     atoms[1],      atoms[2],      atoms[3],  Not(atoms[4]), Not(atoms[5])]),
                # And.chain([atoms[0],     atoms[1],      atoms[2],      atoms[3],      atoms[4],  Not(atoms[5])]),
                # And.chain([atoms[0],     atoms[1],      atoms[2],      atoms[3],      atoms[4],      atoms[5] ])
            ]),
            And.chain([atoms[0], atoms[1], atoms[2]]))
        nfa = ldlf.to_nfa(f)
        dfa = _to_pythomata_dfa(nfa)

        return dfa
Ejemplo n.º 4
0
 def to_nnf(self, f: Formula):
     if isinstance(f, PathExpressionUnion):
         return PathExpressionUnion(self.to_nnf(f.p1), self.to_nnf(f.p2))
     elif isinstance(f, PathExpressionSequence):
         return PathExpressionSequence(self.to_nnf(f.p1), self.to_nnf(f.p2))
     elif isinstance(f, PathExpressionStar):
         return PathExpressionStar(self.to_nnf(f.p))
     elif isinstance(f, Formula):
         pl = PL(self.alphabet)
         assert pl.is_formula(f)
         return f
     else:
         raise ValueError
Ejemplo n.º 5
0
 def to_nnf_path(self, path: PathExpression):
     if isinstance(path, PathExpressionTest):
         return PathExpressionTest(self.to_nnf(path.f))
     elif isinstance(path, PathExpressionUnion):
         return PathExpressionUnion(self.to_nnf_path(path.p1), self.to_nnf_path(path.p2))
     elif isinstance(path, PathExpressionSequence):
         return PathExpressionSequence(self.to_nnf_path(path.p1), self.to_nnf_path(path.p2))
     elif isinstance(path, PathExpressionStar):
         return PathExpressionStar(self.to_nnf_path(path.p))
     elif isinstance(path, Formula):
         pl = PL(self.alphabet)
         assert pl.is_formula(path)
         return pl.to_nnf(path)
     else:
         raise ValueError
Ejemplo n.º 6
0
 def to_equivalent_formula(self, derived_formula: Formula):
     # make lines shorter
     ef = self.to_equivalent_formula
     if isinstance(derived_formula, AtomicFormula):
         return PathExpressionEventually(derived_formula, LogicalTrue())
     elif isinstance(derived_formula, LogicalFalse):
         return Not(LogicalTrue())
     elif isinstance(derived_formula, Or):
         return Not(And(Not(derived_formula.f1), Not(derived_formula.f2)))
     elif isinstance(derived_formula, PathExpressionAlways):
         return Not(
             PathExpressionEventually(derived_formula.p,
                                      Not(derived_formula.f)))
     elif isinstance(derived_formula, Next):
         return PathExpressionEventually(
             TrueFormula(), And(derived_formula.f, Not(ef(End()))))
     elif isinstance(derived_formula, End):
         return ef(PathExpressionAlways(TrueFormula(), ef(LogicalFalse())))
     elif isinstance(derived_formula, Until):
         return PathExpressionEventually(
             PathExpressionStar(
                 PathExpressionSequence(
                     PathExpressionTest(derived_formula.f1),
                     ef(TrueFormula()))),
             And(derived_formula.f2, Not(ef(End()))))
     elif isinstance(derived_formula, FalseFormula):
         return FalseFormula()
     elif isinstance(derived_formula, TrueFormula):
         return TrueFormula()
     elif isinstance(derived_formula, LDLfLast):
         return PathExpressionEventually(ef(TrueFormula()), ef(End()))
     # propositional
     elif isinstance(derived_formula, Formula):
         pl = PL(self.alphabet)
         assert pl.is_formula(derived_formula)
         f = pl.to_nnf(derived_formula)
         return PathExpressionEventually(f, LogicalTrue())
     else:
         raise ValueError("Derived formula not recognized")
Ejemplo n.º 7
0
    def setUp(self):
        """Set up test fixtures, if any."""
        # Symbols
        self.a_sym = Symbol("a")
        self.b_sym = Symbol("b")
        self.c_sym = Symbol("c")

        # Propositions
        self.a = AtomicFormula(self.a_sym)
        self.b = AtomicFormula(self.b_sym)
        self.c = AtomicFormula(self.c_sym)

        # Propositionals
        self.not_a = Not(self.a)
        self.not_b = Not(self.b)
        self.not_c = Not(self.c)
        self.a_and_b = And(self.a, self.b)
        self.a_and_c = And(self.a, self.c)
        self.b_and_c = And(self.b, self.c)
        self.abc = And(self.a, And(self.b, self.c))
        self.b_or_c = Or(self.b, self.c)
        self.a_or_b = Or(self.a, self.b)
        self.not_abc = Not(And(self.a, And(self.b, self.c)))

        ### Path expression
        # Tests
        self.test_a = PathExpressionTest(self.a)
        self.test_b = PathExpressionTest(self.b)
        self.test_not_a = PathExpressionTest(self.not_a)
        self.test_not_b = PathExpressionTest(self.not_b)
        # Union
        self.path_a_or_b = PathExpressionUnion(self.a, self.b)
        self.path_b_or_c = PathExpressionUnion(self.b, self.c)
        # Sequence
        self.path_seq_a_and_b__a_and_c = PathExpressionSequence(
            self.a_and_b, self.a_and_c)
        self.path_a_or_b__b_or_c = PathExpressionSequence(
            self.path_a_or_b, self.path_b_or_c)
        # Stars
        self.path_b_or_c_star = PathExpressionStar(self.path_b_or_c)
        self.path_not_abc = PathExpressionStar(self.not_abc)

        # Modal connective
        self.eventually_propositional_a_and_b__a_and_c = PathExpressionEventually(
            self.a_and_b, self.a_and_c)
        self.eventually_test_a__c = PathExpressionEventually(
            self.test_a, self.c)
        self.eventually_test_a__b = PathExpressionEventually(
            self.test_a, self.b)
        self.eventually_seq_a_and_b__a_and_c__not_c = PathExpressionEventually(
            self.path_seq_a_and_b__a_and_c, self.not_c)
        self.eventually_seq_a_and_b__a_and_c__c = PathExpressionEventually(
            self.path_seq_a_and_b__a_and_c, self.c)
        self.eventually_b_or_c_star__b_and_c = PathExpressionEventually(
            self.path_b_or_c_star, self.b_and_c)

        self.next_a_and_c = PathExpressionEventually(TrueFormula(),
                                                     self.a_and_c)
        self.liveness_b_and_c = PathExpressionEventually(
            PathExpressionStar(TrueFormula()), self.b_and_c)
        self.liveness_abc = PathExpressionEventually(
            PathExpressionStar(TrueFormula()), self.abc)

        self.always_true__a = PathExpressionAlways(
            PathExpressionStar(TrueFormula()), self.a)
        self.always_true__b_or_c = PathExpressionAlways(
            PathExpressionStar(TrueFormula()), self.b_or_c)

        self.alphabet = Alphabet({self.a_sym, self.b_sym, self.c_sym})
        # Traces
        self.ldlf = LDLf(self.alphabet)
        self.trace_1_list = [
            {self.a_sym, self.b_sym},
            {self.a_sym, self.c_sym},
            {self.a_sym, self.b_sym},
            {self.a_sym, self.c_sym},
            {self.b_sym, self.c_sym},
        ]
        self.trace_1 = FiniteTrace(self.trace_1_list, self.alphabet)
Ejemplo n.º 8
0
 def test_sequence(self):
     alphabet = Alphabet.fromStrings({"a", "b"})
     a = AtomicFormula.fromName("a")
     b = AtomicFormula.fromName("b")
     ref = REf(alphabet)
     self.assertTrue(ref.is_formula(PathExpressionSequence(a, b)))