A staircase light that is controlled from two switches works if either switch changes its state. The rule that describes this behaviour is a statement in Boolean algebra, the mathematics of logic. Boolean algebra lets an engineer describe a circuit with an expression and then make that expression shorter, which means a cheaper circuit.

Variables and Basic Operations

A Boolean variable has only two possible values, 0 and 1. Three basic operations combine variables. AND gives 1 only when all inputs are 1. OR gives 1 when at least one input is 1. NOT gives the opposite of its input. AND is written as A·B, OR as A + B and NOT as A'. Table 1.3 lists the results.

Table 1.3: Truth tables of the basic operations

A B A AND B A OR B NOT A
0 0 0 0 1
0 1 0 1 1
1 0 0 1 0
1 1 1 1 0

Definition: Boolean algebra. A system of algebra in which variables take only the values 0 and 1 and are combined using the operations AND, OR and NOT.

Laws of Boolean Algebra

The laws in Table 1.4 hold for every value of the variables. Each law has a dual form obtained by exchanging AND with OR and 0 with 1.

Table 1.4: Laws of Boolean algebra

Law AND form OR form
Identity A·1 = A A + 0 = A
Null A·0 = 0 A + 1 = 1
Idempotent A·A = A A + A = A
Complement A·A' = 0 A + A' = 1
Commutative A·B = B·A A + B = B + A
Associative (A·B)·C = A·(B·C) (A + B) + C = A + (B + C)
Distributive A·(B + C) = A·B + A·C A + B·C = (A + B)·(A + C)
Absorption A·(A + B) = A A + A·B = A

De Morgan's Theorems

De Morgan's theorems connect AND, OR and NOT. The first states that the complement of a product equals the sum of the complements: (A·B)' = A' + B'. The second states that the complement of a sum equals the product of the complements: (A + B)' = A'·B'. They are used to change an expression into a form that needs only NAND or only NOR gates.

Example 1.3: Simplifying an expression

Problem: Simplify F = A·B + A·B' + A'·B using Boolean laws.

Solution:

  1. Take A common from the first two terms: A·(B + B') + A'·B.
  2. By the complement law B + B' = 1, so the expression becomes A·1 + A'·B.
  3. By the identity law this is A + A'·B.
  4. By the distributive law A + A'·B = (A + A')·(A + B) = 1·(A + B).

Result: F = A + B.

for A in (0, 1):
    for B in (0, 1):
        f = (A & B) | (A & (1-B)) | ((1-A) & B)
        print(A, B, f, A | B)

Output

0 0 0 0
0 1 1 1
1 0 1 1
1 1 1 1

The program evaluates the original expression and A + B for every input pair. The last two columns of its output are identical, which confirms the result.

Common mistakes

  • Writing (A + B)' as A' + B'. The correct form is A'·B'.
  • Using A + A = 2A. In Boolean algebra A + A = A.
  • Forgetting that 1 + A = 1 for every A.

Key takeaways

  • Boolean variables take only the values 0 and 1.
  • Every law has a dual obtained by swapping AND with OR and 0 with 1.
  • De Morgan's theorems: (A·B)' = A' + B' and (A + B)' = A'·B'.
  • Simplifying an expression reduces the number of gates required.

Practice questions

  1. State De Morgan's two theorems.
  2. What is the value of A + A'?
  3. Simplify A + A·B.

Answers to the practice questions

  1. (A·B)' = A' + B' and (A + B)' = A'·B'.
  2. 1, by the complement law.
  3. A, by the absorption law.

Sources

  • Official BCA syllabus Computer Architecture, course code 25BCA401DS02, Unit I