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 two types of operations

There are also Binary Operations, they take two inputs. Each input can be False or True 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 16 binary operations, and each operation returns True or False. The truth table shows the 16 operations covered in these chapters and what they return when they receive input.

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

requirements

truth table: Nullary and Unary Operations


Binary Operations


what is next?

are you ready to test Binary Operations?