Construct a logic expression

Published by Patrick Mutisya · 8 days ago

Cambridge A-Level Computer Science 9618 – Logic Gates and Logic Circuits

3.2 Logic Gates and Logic Circuits

Objective

By the end of this lesson you will be able to construct a logic expression from a given description or circuit diagram, using the standard Boolean operators AND, OR, NOT, NAND, NOR, XOR and XNOR.

1. Review of Basic Logic Gates

  • AND – output is true only if all inputs are true. Symbol: \$\cdot\$.
  • OR – output is true if at least one input is true. Symbol: \$+\$.
  • NOT – inverts the input. Symbol: \$\lnot\$.
  • NAND – NOT‑AND. Output is false only when all inputs are true.
  • NOR – NOT‑OR. Output is true only when all inputs are false.
  • XOR – exclusive OR. Output is true when an odd number of inputs are true.
  • XNOR – exclusive NOR. Output is true when an even number of inputs are true.

2. Truth Tables and Boolean Algebra

Truth tables provide a systematic way to verify the behaviour of a gate or a combination of gates. Boolean algebra allows us to simplify expressions.

GateSymbolTruth Table
AND\$A \cdot B\$

ABOutput
000
010
100
111

OR\$A + B\$

ABOutput
000
011
101
111

NOT\$\overline{A}\$

AOutput
01
10

3. Steps to Construct a Logic Expression

  1. Identify all input variables (e.g., \$A\$, \$B\$, \$C\$).
  2. Read the problem statement carefully and translate each condition into a Boolean clause.
  3. Combine the clauses using the appropriate operators, respecting the order of operations (NOT, AND, OR).
  4. Use parentheses to make the intended grouping explicit.
  5. Validate the expression by constructing a truth table or by testing a few input combinations.

4. Example Construction

Problem: “The alarm sounds if the door is open AND the system is armed, OR if a fire is detected while the system is not armed.”

Let:

  • \$D\$ = “Door is open”
  • \$A\$ = “System is armed”
  • \$F\$ = “Fire is detected”
  • \$S\$ = “Alarm sounds” (output)

Translate the description:

  1. “Door is open AND the system is armed” → \$D \cdot A\$
  2. “Fire is detected while the system is not armed” → \$F \cdot \overline{A}\$
  3. Combine with OR → \$(D \cdot A) + (F \cdot \overline{A})\$

Thus the required logic expression is:

\$S = (D \cdot A) + (F \cdot \overline{A})\$

Suggested diagram: A circuit using two AND gates, one NOT gate, and an OR gate to implement the expression above.

5. Common Pitfalls

  • Forgetting to apply NOT to the correct variable (e.g., writing \$F \cdot A\$ instead of \$F \cdot \overline{A}\$).
  • Misinterpreting “either … or … but not both” – this requires XOR, not simple OR.
  • Omitting parentheses, leading to ambiguous precedence.

6. Summary Checklist

  • Identify variables.
  • Convert each English condition to a Boolean clause.
  • Choose the correct operator (AND, OR, NOT, XOR, etc.).
  • Use parentheses to enforce intended grouping.
  • Verify with a truth table.

7. Practice Questions

  1. Write a logic expression for: “A light turns on if either the motion sensor is triggered and it is dark, or the manual switch is on while the timer is not active.”
  2. Given the expression \$Y = \overline{(A + B)} \cdot (C \oplus D)\$, simplify it using De Morgan’s laws and the definition of XOR.
  3. Construct a truth table for the expression \$Z = (P \cdot \overline{Q}) + (\overline{P} \cdot Q)\$ and identify the gate that implements it.