Boolean Algebra
Boolean algebra is the algebraic structure that handles binary variables and logic operations. It is the mathematical foundation of digital circuit design.
Basic Operations
The primary operations are:
- AND ( or ): , else .
- OR ( or ): , else .
- NOT ( or ): .
python
1def boolean_table(func):
2 print("A | B | Result")
3 print("---------")
4 for a in [0, 1]:
5 for b in [0, 1]:
6 print(f"{a} | {b} | {func(a, b)}")
7
8# XOR Implementation
9xor_func = lambda a, b: (a or b) and not (a and b)
10boolean_table(xor_func)
Algebraic Laws
- Idempotence: .
- De Morgan’s Laws: and .
- Absorption: .
python
1def de_morgan_test(x, y):
2 lhs = not (x or y)
3 rhs = (not x) and (not y)
4 return lhs == rhs
5
6print(f"De Morgan (0, 0): {de_morgan_test(0, 0)}")
7print(f"De Morgan (1, 0): {de_morgan_test(1, 0)}")
8print(f"De Morgan (1, 1): {de_morgan_test(1, 1)}")
Sum of Products (SOP) and Simplification
Every boolean function can be represented as a Sum of Products (canonical form). Simplification is typically done using Karnaugh Maps or the Quine-McCluskey algorithm.