truth table: Binary Operations


Warning

Welcome to the wonderful world of Boolean Logic. If this is new to you, then prepare for headaches and moving closer to the edge of insanity.

This is part of the process as you stretch yourself and learn new things that help you solve problems and see the world in a new way.

Do you still want to continue?

The last chapter covered 2 types of operations

We know that there are two booleans: True and False. There are also Binary Operations, they take 2 inputs. Each input can be True or False which means there are 4 possible ways the inputs can be sent to a binary operation

first input

second input

True

True

True

False

False

True

False

False

These combinations give us 16 binary operations, and each operation returns True or False. Here are the 16 operations covered in these chapters and what they return

return

True, True

True, False

False, True

False, False

operation

False

False

False

False

False

contradiction

first and second

True

False

False

False

logical_conjunction

second

True

False

True

False

project_second

(not first) and second

False

False

True

False

converse_non_implication

not first

False

False

True

True

negate_first

not (first and second)

False

True

True

True

logical_nand

True

True

True

True

True

tautology

first or second

True

True

True

False

logical_disjunction

(not (first and second)) and (first or second)

False

True

True

False

exclusive_disjunction

first and (not second)

False

True

False

False

material_non_implication

first

True

True

False

False

project_first

first or (not second)

True

True

False

True

converse_implication

not second

False

True

False

True

negate_second

not (first or second)

False

False

False

True

logical_nor

(not first or second) and (first or not second)

True

False

False

True

logical_equality

(not first) or second

True

False

True

True

material_implication


preview

These are the tests I have at the end of the chapters

  1import src.truth_table
  2import unittest
  3
  4
  5class TestBinaryOperations(unittest.TestCase):
  6
  7    def test_contradiction(self):
  8        self.assertFalse(
  9            src.truth_table.contradiction(True, True)
 10        )
 11        self.assertFalse(
 12            src.truth_table.contradiction(True, False)
 13        )
 14        self.assertFalse(
 15            src.truth_table.contradiction(False, True)
 16        )
 17        self.assertFalse(
 18            src.truth_table.contradiction(False, False)
 19        )
 20
 21    def test_logical_conjunction(self):
 22        self.assertTrue(
 23            src.truth_table.logical_conjunction(True, True)
 24        )
 25        self.assertFalse(
 26            src.truth_table.logical_conjunction(True, False)
 27        )
 28        self.assertFalse(
 29            src.truth_table.logical_conjunction(False, True)
 30        )
 31        self.assertFalse(
 32            src.truth_table.logical_conjunction(False, False)
 33        )
 34
 35    def test_project_second(self):
 36        self.assertTrue(
 37            src.truth_table.project_second(True, True)
 38        )
 39        self.assertFalse(
 40            src.truth_table.project_second(True, False)
 41        )
 42        self.assertTrue(
 43            src.truth_table.project_second(False, True)
 44        )
 45        self.assertFalse(
 46            src.truth_table.project_second(False, False)
 47        )
 48
 49    def test_converse_non_implication(self):
 50        self.assertFalse(
 51            src.truth_table.converse_non_implication(True, True)
 52        )
 53        self.assertFalse(
 54            src.truth_table.converse_non_implication(True, False)
 55        )
 56        self.assertTrue(
 57            src.truth_table.converse_non_implication(False, True)
 58        )
 59        self.assertFalse(
 60            src.truth_table.converse_non_implication(False, False)
 61        )
 62
 63    def test_negate_first(self):
 64        self.assertFalse(src.truth_table.negate_first(True, True))
 65        self.assertFalse(src.truth_table.negate_first(True, False))
 66        self.assertTrue(src.truth_table.negate_first(False, True))
 67        self.assertTrue(src.truth_table.negate_first(False, False))
 68
 69    def test_logical_nand(self):
 70        self.assertFalse(src.truth_table.logical_nand(True, True))
 71        self.assertTrue(src.truth_table.logical_nand(True, False))
 72        self.assertTrue(src.truth_table.logical_nand(False, True))
 73        self.assertTrue(src.truth_table.logical_nand(False, False))
 74
 75    def test_tautology(self):
 76        self.assertTrue(src.truth_table.tautology(True, True))
 77        self.assertTrue(src.truth_table.tautology(True, False))
 78        self.assertTrue(src.truth_table.tautology(False, True))
 79        self.assertTrue(src.truth_table.tautology(False, False))
 80
 81    def test_logical_disjunction(self):
 82        self.assertTrue(
 83            src.truth_table.logical_disjunction(True, True)
 84        )
 85        self.assertTrue(
 86            src.truth_table.logical_disjunction(True, False)
 87        )
 88        self.assertTrue(
 89            src.truth_table.logical_disjunction(False, True)
 90        )
 91        self.assertFalse(
 92            src.truth_table.logical_disjunction(False, False)
 93        )
 94
 95    def test_exclusive_disjunction(self):
 96        self.assertFalse(src.truth_table.exclusive_disjunction(True, True))
 97        self.assertTrue(src.truth_table.exclusive_disjunction(True, False))
 98        self.assertTrue(src.truth_table.exclusive_disjunction(False, True))
 99        self.assertFalse(src.truth_table.exclusive_disjunction(False, False))
100
101    def test_material_non_implication(self):
102        self.assertFalse(
103            src.truth_table.material_non_implication(True, True)
104        )
105        self.assertTrue(
106            src.truth_table.material_non_implication(True, False)
107        )
108        self.assertFalse(
109            src.truth_table.material_non_implication(False, True)
110        )
111        self.assertFalse(
112            src.truth_table.material_non_implication(False, False)
113        )
114
115    def test_project_first(self):
116        self.assertTrue(src.truth_table.project_first(True, True))
117        self.assertTrue(src.truth_table.project_first(True, False))
118        self.assertFalse(src.truth_table.project_first(False, True))
119        self.assertFalse(src.truth_table.project_first(False, False))
120
121    def test_converse_implication(self):
122        self.assertTrue(src.truth_table.converse_implication(True, True))
123        self.assertTrue(src.truth_table.converse_implication(True, False))
124        self.assertFalse(src.truth_table.converse_implication(False, True))
125        self.assertTrue(src.truth_table.converse_implication(False, False))
126
127    def test_negate_second(self):
128        self.assertFalse(src.truth_table.negate_second(True, True))
129        self.assertTrue(src.truth_table.negate_second(True, False))
130        self.assertFalse(src.truth_table.negate_second(False, True))
131        self.assertTrue(src.truth_table.negate_second(False, False))
132
133    def test_logical_nor(self):
134        self.assertFalse(src.truth_table.logical_nor(True, True))
135        self.assertFalse(src.truth_table.logical_nor(True, False))
136        self.assertFalse(src.truth_table.logical_nor(False, True))
137        self.assertTrue(src.truth_table.logical_nor(False, False))
138
139    def test_logical_equality(self):
140        self.assertTrue(src.truth_table.logical_equality(True, True))
141        self.assertFalse(src.truth_table.logical_equality(True, False))
142        self.assertFalse(src.truth_table.logical_equality(False, True))
143        self.assertTrue(src.truth_table.logical_equality(False, False))
144
145    def test_material_implication(self):
146        self.assertTrue(src.truth_table.material_implication(True, True))
147        self.assertFalse(src.truth_table.material_implication(True, False))
148        self.assertTrue(src.truth_table.material_implication(False, True))
149        self.assertTrue(src.truth_table.material_implication(False, False))
150
151
152# Exceptions seen
153# AttributeError
154# TypeError
155# AssertionError
156# SyntaxError

requirements

truth table: Nullary and Unary Operations


Binary Operations


what is next?

are you ready to test Binary Operations?