Sub topic 1
Boolean Values and Operators
Prerequisites
This chapter assumes you can convert between binary and decimal, know the gates AND, OR, NOT, NAND, NOR, XOR, and XNOR, and read basic set and propositional logic notation.
Boolean values and operators
A Boolean variable takes one of two values, 0 or 1. Three basic operators combine them:
- AND (written A·B or AB) outputs 1 only when both inputs are 1.
- OR (A + B) outputs 1 when at least one input is 1.
- NOT (A' or ¬A) outputs the opposite of its input.
Truth tables and checking equivalence
A truth table lists every input combination and the matching output. With n variables, it has 2^n rows. Two expressions are equivalent when their outputs match on every row. The code below checks De Morgan's law across all rows.
from itertools import product
def equivalent(f, g, n):
return all(f(*v) == g(*v) for v in product([0, 1], repeat=n))
# De Morgan: NOT(A AND B) == (NOT A) OR (NOT B)
print(equivalent(lambda a, b: int(not (a and b)),
lambda a, b: int((not a) or (not b)), 2))Output: True
Boolean identities and laws
- Identity: A + 0 = A and A·1 = A.
- Complement: A + A' = 1 and A·A' = 0.
- Distributive: A(B + C) = AB + AC.
- Absorption: A + AB = A.
- Consensus: AB + A'C + BC = AB + A'C.
Duality and De Morgan's laws
The dual of an expression swaps AND with OR and 0 with 1, and leaves the variables unchanged. The dual of A(B + 0) is A + BC? No: it is A + (B·1), which simplifies to A + B.
De Morgan's laws give the rules for complementing a grouped expression:
- (AB)' = A' + B'
- (A + B)' = A'B'
Canonical forms: minterms and maxterms
A minterm is a product term containing every variable once, and it equals 1 on exactly one row. A maxterm is a sum term containing every variable once, and it equals 0 on exactly one row.
Take F(A, B) = A XOR B. It equals 1 on rows (0,1) and (1,0), so F = A'B + AB' = Σm(1,2). It equals 0 on rows (0,0) and (1,1), so F = (A + B)(A' + B') = ΠM(0,3).
| Row | A | B | Minterm | Maxterm |
|---|---|---|---|---|
| 0 | 0 | 0 | A'B' | A + B |
| 1 | 0 | 1 | A'B | A + B' |
| 2 | 1 | 0 | AB' | A' + B |
| 3 | 1 | 1 | AB | A' + B' |
Exercise
Write the sum-of-minterms form of F = A XNOR B.
Show answer
F equals 1 on rows (0,0) and (1,1), so F = A'B' + AB = Σm(0,3).