Chapter 6 — Boolean Algebra & Digital Logic
This chapter covers Boolean algebra and digital logic, essential for representing logical relationships, rule-based AI systems, and digital circuit simulations in AI & ML.
6.1 Boolean Variables & Functions
Boolean variables take values True (1) or False (0). Boolean functions combine variables using logical operations.
AI/ML Context: Representing features, decision rules, and binary classifiers.
# Example in Python
A = True
B = False
def boolean_function(A, B):
return A and not B
print(boolean_function(A, B)) # Output: True
6.2 Boolean Operations
- AND (∧): True if both inputs are True
- OR (∨): True if at least one input is True
- NOT (¬): Inverts the input
- XOR (⊕): True if inputs are different
# Python examples
A = True
B = False
print(A and B) # AND -> False
print(A or B) # OR -> True
print(not A) # NOT -> False
print(A != B) # XOR -> True
6.3 Simplification Using Boolean Laws
Boolean expressions can be simplified using laws for efficient computation and circuit design.
- Identity Law: A ∧ 1 = A, A ∨ 0 = A
- Complement Law: A ∧ ¬A = 0, A ∨ ¬A = 1
- Distributive Law: A ∧ (B ∨ C) = (A ∧ B) ∨ (A ∧ C)
- De Morgan’s Law: ¬(A ∧ B) = ¬A ∨ ¬B, ¬(A ∨ B) = ¬A ∧ ¬B
# Python example of De Morgan's Law
A = True
B = False
print(not (A and B)) # True
print((not A) or (not B)) # True
6.4 Karnaugh Maps (K-Maps)
K-Maps provide a visual method to simplify Boolean expressions. AI/ML Context: Simplifying logical rules and feature interactions in decision systems.
# Example: 2-variable K-Map
# Variables: A, B
# Function: F(A,B) = Σ(1,3)
# K-Map simplifies F = B
6.5 ML Use Case: Logical Feature Interactions & Rule-based AI
- Binary classification using Boolean features
- Rule-based expert systems
- Logical preprocessing for feature engineering
- Simulation of digital circuits or logic gates in AI models
6.6 Practical Python Applications
# Example: Logical rule system
features = {"is_raining": True, "have_umbrella": False}
def should_go_out(features):
return features["have_umbrella"] or not features["is_raining"]
print(should_go_out(features)) # Output: False
6.7 Why Boolean Algebra & Digital Logic Matter in AI/ML
- Represent logical rules for decision-making systems.
- Simplify binary feature interactions.
- Simulate digital circuits and logic layers in AI models.
- Foundational knowledge for advanced topics like knowledge graphs and symbolic AI.
6.8 Exercises
- Simplify Boolean expressions using De Morgan’s laws.
- Implement a small rule-based AI system in Python.
- Create a K-map for a 3-variable Boolean function and simplify it.
Hints / Solutions
- Use logical equivalences to reduce expressions step by step.
- Python
and,or,notoperators can implement rules. - K-map groups of 1s help visualize simplification patterns.
6.9 Further Reading & Videos
- Boolean Algebra and Digital Logic by Morris Mano
- Python logical operations tutorials (Corey Schafer, YouTube)
- Karnaugh Map simplification guides on GeeksforGeeks
- Rule-based AI systems and expert system research papers
Next Chapter: Matrices & Linear Transformations — introducing matrix operations, vector spaces, and their applications in AI & ML.