Beispiel #1
0
 def test_minimum(self):
     self.assertTrue(
         pcabuilder.InitProp('A or false').minimum() == pcaprop.Variable(
             'A'))
     self.assertTrue(
         pcabuilder.InitProp('false or (A iff B)').minimum() == pcaprop.
         EquivalenceOp(pcaprop.Variable('A'), pcaprop.Variable('B')))
     self.assertTrue(
         pcabuilder.InitProp('A and false').minimum() ==
         pcaprop.FalseProp())
     self.assertTrue(
         pcabuilder.InitProp('false and (A iff B)').minimum() ==
         pcaprop.FalseProp())
     self.assertTrue(
         pcabuilder.InitProp(
             'B iff (A and (false and (A iff B)))').minimum() ==
         pcaprop.EquivalenceOp(pcaprop.Variable('B'), pcaprop.FalseProp()))
     self.assertTrue(
         pcabuilder.InitProp('Z iff (A and (B and bot))').minimum() ==
         pcaprop.EquivalenceOp(pcaprop.Variable('Z'), pcaprop.FalseProp()))
     self.assertTrue(
         pcabuilder.InitProp('Z iff (not A or not(B or bot))').minimum() ==
         pcaprop.EquivalenceOp(
             pcaprop.Variable('Z'),
             pcaprop.DisjunctionOp(
                 pcaprop.NegationOp(pcaprop.Variable('A')),
                 pcaprop.NegationOp(pcaprop.Variable('B')))))
Beispiel #2
0
 def test_commutativity(self):
     self.assertTrue(
         pcabuilder.InitProp('A and B').commutativity() == pcaprop.
         ConjunctionOp(pcaprop.Variable('B'), pcaprop.Variable('A')))
     self.assertTrue(
         pcabuilder.InitProp('A and (C and B)').commutativity() ==
         pcaprop.ConjunctionOp(
             pcaprop.ConjunctionOp(pcaprop.Variable(
                 'B'), pcaprop.Variable('C')), pcaprop.Variable('A')))
     self.assertTrue(
         pcabuilder.InitProp('A or (C and ( D or B))').commutativity() ==
         pcaprop.DisjunctionOp(
             pcaprop.ConjunctionOp(
                 pcaprop.DisjunctionOp(pcaprop.Variable('B'),
                                       pcaprop.Variable('D')),
                 pcaprop.Variable('C')), pcaprop.Variable('A')))
     self.assertTrue(
         pcabuilder.InitProp('B implies (A and B)').commutativity() ==
         pcaprop.ImplicationOp(
             pcaprop.Variable('B'),
             pcaprop.ConjunctionOp(pcaprop.Variable('B'),
                                   pcaprop.Variable('A'))))
     self.assertTrue(
         pcabuilder.InitProp('not not (A and B)').commutativity() ==
         pcaprop.NegationOp(
             pcaprop.NegationOp(
                 pcaprop.ConjunctionOp(pcaprop.Variable('B'),
                                       pcaprop.Variable('A')))))
Beispiel #3
0
 def test_prop(self):
     a = pcaparser.PARSER.parse('P or B iff C and A implies (P and C)')
     to_assert = pcaprop.EquivalenceOp(pcaprop.DisjunctionOp(pcaprop.Variable('P'), pcaprop.Variable('B')),
                                       pcaprop.ImplicationOp(
                                           pcaprop.ConjunctionOp(pcaprop.Variable('C'), pcaprop.Variable('A')),
                                           pcaprop.ConjunctionOp(pcaprop.Variable('P'), pcaprop.Variable('C'))))
     self.assertEqual(a, to_assert)
     a = pcaparser.PARSER.parse('true or not A implies false and not not not B or A')
     to_assert = pcaprop.ImplicationOp(
         pcaprop.DisjunctionOp(pcaprop.TrueProp(), pcaprop.NegationOp(pcaprop.Variable('A'))),
         pcaprop.DisjunctionOp(
             pcaprop.ConjunctionOp(pcaprop.FalseProp(), pcaprop.NegationOp(
                 pcaprop.NegationOp(pcaprop.NegationOp(pcaprop.Variable('B'))))),
             pcaprop.Variable('A')))
     self.assertEqual(a, to_assert)
Beispiel #4
0
 def test_prop(self):
     a = pcaprop.TrueProp()
     b = pcaprop.NegationOp(a)
     self.assertTrue(a)
     self.assertFalse(b.eval())
     self.assertTrue(pcaprop.DisjunctionOp(a, b.eval()).eval())
     self.assertFalse(pcaprop.ConjunctionOp(b.eval(), a).eval())
Beispiel #5
0
 def test_implication(self):
     self.assertTrue(
         pcabuilder.InitProp('A implies (B implies C) ').implication() ==
         pcaprop.DisjunctionOp(
             pcaprop.NegationOp(pcaprop.Variable('A')),
             pcaprop.DisjunctionOp(
                 pcaprop.NegationOp(pcaprop.Variable('B')),
                 pcaprop.Variable('C'))))
     self.assertTrue(
         pcabuilder.InitProp('A or not (A implies B)').implication() ==
         pcaprop.DisjunctionOp(
             pcaprop.Variable('A'),
             pcaprop.NegationOp(
                 pcaprop.DisjunctionOp(
                     pcaprop.NegationOp(pcaprop.Variable('A')),
                     pcaprop.Variable('B')))))
Beispiel #6
0
 def _implication(op):
     if isinstance(op, (pcaprop.Variable, pcaprop.TrueProp, pcaprop.FalseProp)):
         return op
     if isinstance(op, pcaprop.UnaryOp):
         return op.__class__(_implication(op.prop))
     if isinstance(op, pcaprop.BinaryOp):
         prop_l = _implication(op.prop_l)
         prop_r = _implication(op.prop_r)
         if isinstance(op, pcaprop.ImplicationOp):
             return pcaprop.DisjunctionOp(pcaprop.NegationOp(prop_l), prop_r)
         return op.__class__(prop_l, prop_r)
Beispiel #7
0
 def _de_morgan(op):
     if isinstance(op, (pcaprop.Variable, pcaprop.TrueProp, pcaprop.FalseProp)):
         return op
     if isinstance(op, pcaprop.UnaryOp):
         return op.__class__(_de_morgan(op.prop))
     if isinstance(op, pcaprop.BinaryOp):
         prop_l = _de_morgan(op.prop_l)
         prop_r = _de_morgan(op.prop_r)
         if isinstance(op, pcaprop.DisjunctionOp):
             return pcaprop.NegationOp(pcaprop.ConjunctionOp(pcaprop.NegationOp(prop_l),
                                                             pcaprop.NegationOp(prop_r)))
         if isinstance(op, pcaprop.ConjunctionOp):
             return pcaprop.NegationOp(pcaprop.DisjunctionOp(pcaprop.NegationOp(prop_l),
                                                             pcaprop.NegationOp(prop_r)))
         return op.__class__(prop_l, prop_r)
Beispiel #8
0
 def test_idempotence(self):
     self.assertTrue(
         pcabuilder.InitProp('A and A').idempotence() == pcaprop.Variable(
             'A'))
     self.assertTrue(
         pcabuilder.InitProp('not not (A and A)').idempotence() ==
         pcaprop.NegationOp(pcaprop.NegationOp(pcaprop.Variable('A'))))
     self.assertTrue(
         pcabuilder.InitProp('B or not (A and A)').idempotence() ==
         pcaprop.DisjunctionOp(pcaprop.Variable('B'),
                               pcaprop.NegationOp(pcaprop.Variable('A'))))
     self.assertTrue(
         pcabuilder.InitProp('B or not (A and ( A or A))').idempotence() ==
         pcaprop.DisjunctionOp(pcaprop.Variable('B'),
                               pcaprop.NegationOp(pcaprop.Variable('A'))))
     self.assertFalse(
         pcabuilder.InitProp('not not (A and B)').idempotence() ==
         pcaprop.NegationOp(pcaprop.NegationOp(pcaprop.Variable('A'))))
Beispiel #9
0
 def exp_not(self, value):
     return pcaprop.NegationOp(value[1])
Beispiel #10
0
 def test_precedence(self):
     a = pcaprop.Variable("A")
     b = pcaprop.Variable("B")
     self.assertEqual((a + b >> ~a * b), pcaprop.ImplicationOp(
       pcaprop.DisjunctionOp(a, b), pcaprop.ConjunctionOp(pcaprop.NegationOp(a), b)))
Beispiel #11
0
 def test_creation(self):
     a = pcaprop.Variable("A")
     b = pcaprop.Variable("B")
     c = pcaprop.Variable("C")
     self.assertEqual(a >> (~(a * b) + c), pcaprop.ImplicationOp(
         a, pcaprop.DisjunctionOp(pcaprop.NegationOp(pcaprop.ConjunctionOp(a, b)), c)))
Beispiel #12
0
 def test_de_morgan(self):
     self.assertEqual(
         list(pcabuilder.InitProp('not(A or B)').interpretations()),
         list(pcabuilder.InitProp('(not A) and (not B)').interpretations()))
     self.assertTrue(
         pcabuilder.InitProp(
             '(not(A and B)) ⇔ ((not A) or (not B))').tautology())
     self.assertTrue(
         pcabuilder.InitProp(
             '(not(A or B)) ⇔ ((not A) and (not B))').tautology())
     self.assertEqual(
         pcabuilder.InitProp('¬(A or B)').de_morgan(),
         pcaprop.NegationOp(
             pcaprop.NegationOp(
                 pcaprop.ConjunctionOp(
                     pcaprop.NegationOp(pcaprop.Variable('A')),
                     pcaprop.NegationOp(pcaprop.Variable('B'))))))
     self.assertEqual(
         pcabuilder.InitProp('¬(A and B)').de_morgan(),
         pcaprop.NegationOp(
             pcaprop.NegationOp(
                 pcaprop.DisjunctionOp(
                     pcaprop.NegationOp(pcaprop.Variable('A')),
                     pcaprop.NegationOp(pcaprop.Variable('B'))))))
     to_test = pcaprop.NegationOp(
         pcaprop.ConjunctionOp(
             pcaprop.NegationOp(pcaprop.Variable('A')),
             pcaprop.NegationOp(
                 pcaprop.NegationOp(
                     pcaprop.NegationOp(
                         pcaprop.DisjunctionOp(
                             pcaprop.NegationOp(pcaprop.Variable('A')),
                             pcaprop.NegationOp(pcaprop.Variable('B'))))))))
     self.assertEqual(
         pcabuilder.InitProp('A or ¬(A and B)').de_morgan(), to_test)