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.

It is part of the process as you stretch yourself, 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 False or True. 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

name of 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

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

requirements

truth table: Nullary and Unary Operations


Binary Operations


what is next?

are you ready to test Binary Operations?