studyhubDiscrete Structures I

Notes / Unit 5 · Module 4 · Final

Boolean Algebra and Logic Gates

Boolean algebra is the arithmetic of 0 and 1 that digital circuits run on. The exam asks you to read a circuit into an expression, write a function as minterms or maxterms from its truth table, and simplify an expression step by step, naming the law each step uses.

5.1Boolean values and operations

A Boolean variable takes one of two values: 1 or 0 (true or false, on or off, high or low). A Boolean function combines variables with operators and always outputs 0 or 1.

OR (Boolean sum)
A + B is 1 when at least one input is 1: 0 + 0 = 0, every other sum is 1, and 1 + 1 = 1.
AND (Boolean product)
AB, also written A · B, is 1 only when every input is 1.
NOT (complement)
A′ flips the value: 0′ = 1, 1′ = 0. Some books draw an overbar or write ~A. The course uses the prime.
Literal
A variable or its complement: A, A′.
Product term
Literals ANDed together, e.g. AB′C. It is 1 only if every literal is 1.
Sum term
Literals ORed together, e.g. A + B′ + C. It is 0 only if every literal is 0.

Precedence: NOT first, then AND, then OR, just as multiplication comes before addition. A + BC′ means A + (B(C′)).

With n variables a truth table has 2ⁿ rows, listed in binary order with A as the leftmost (most significant) bit: 000, 001, … 111 for three variables.

5.2The laws of Boolean algebra

Most laws come in an AND form and an OR form. These are the names the course uses:

LawAND formOR form
Identity1A = A0 + A = A
Null0A = 01 + A = 1
IdempotentAA = AA + A = A
InverseAA′ = 0A + A′ = 1
CommutativeAB = BAA + B = B + A
Associative(AB)C = A(BC)(A + B) + C = A + (B + C)
DistributiveA + BC = (A + B)(A + C)A(B + C) = AB + AC
AbsorptionA(A + B) = AA + AB = A
De Morgan's(AB)′ = A′ + B′(A + B)′ = A′B′
Double Complement(A′)′ = A—

Two more rules come up constantly. Both follow from the laws above: A + A′B = A + B and (A + B)(A + C) = A + BC. The second is the distributive law read backwards.

Duality: swap every AND with OR and every 0 with 1, and leave the variables alone. A true identity gives a true identity. The AND and OR columns above are duals of each other.

5.3De Morgan's law and complements

De Morgan's law: the complement of a product is the sum of the complements, and the complement of a sum is the product of the complements. It works for any number of variables: (ABC)′ = A′ + B′ + C′.

To complement a whole function, complement every variable and swap every AND with OR (De Morgan applied all the way through). Keep the original grouping in parentheses.

Worked example

Complement F = x + y′z

  1. 1Swap the operators: the OR becomes AND, the product y′z becomes a sum.
  2. 2Complement each literal: x → x′, y′ → y, z → z′.
  3. 3F′ = x′(y + z′).

5.4Logic gates

Every circuit is built from gates. AND, OR and NOT are the three basic ones. The rest are combinations of them:

GateSymbolExpressionOutput is 1 when
NOT (inverter)Triangle with a bubbleX = A′the input is 0
ANDD shapeX = ABall inputs are 1
ORCurved shieldX = A + Bat least one input is 1
NANDAND with an output bubbleX = (AB)′not all inputs are 1
NOROR with an output bubbleX = (A + B)′every input is 0
XOROR with an extra curve at the inputX = A ⊕ B = A′B + AB′the inputs differ
XNORXOR with an output bubbleX = (A ⊕ B)′ = A′B′ + ABthe inputs are equal
  • AX
    NOT · X = A′
  • ABX
    AND · X = AB
  • ABX
    OR · X = A + B
  • ABX
    NAND · X = (AB)′
  • ABX
    NOR · X = (A + B)′
  • ABX
    XOR · X = A ⊕ B
  • ABX
    XNOR · X = (A ⊕ B)′

A bubble on a gate means inversion. By De Morgan's law a NAND is the same as an OR with both inputs inverted (a negative-OR), and a NOR is the same as a negative-AND.

NAND and NOR are universal: either one alone can build NOT (tie both inputs together: (AA)′ = A′), then AND and OR, so it can build any circuit.

5.5Reading and building circuits

  1. Start at the inputs on the left.
  2. Write the expression at the output of each gate, using the expressions feeding it as its inputs.
  3. Work rightward until you reach the final gate. Its expression is the circuit's output.
  4. For the truth table, evaluate that expression on every input row in binary order.

Worked example

The course's circuit: AND of C and D, ORed with B, ANDed with A

  1. 1First AND gate: CD.
  2. 2OR gate: B + CD.
  3. 3Final AND gate: A(B + CD).
  4. 4It is 1 when A = 1 and either B = 1 or C = D = 1, so 5 of its 16 rows are 1.
  • ABCDX
    X = A(B + CD): a dot joins a wire to an input line, and a crossing without a dot is not a join

Going the other way, from an expression to a circuit, start from the innermost parentheses. Each sum or product becomes a gate, a prime over a group becomes a NAND/NOR or an inverter after the gate, and the last operator to be applied is the output gate.

5.6Sum of products and product of sums

SOP (sum of products)
Product terms ORed together, e.g. AB + B′CD + AC′. Built as AND gates feeding one OR gate.
POS (product of sums)
Sum terms ANDed together, e.g. (A + B)(B′ + C + D). Built as OR gates feeding one AND gate.
Standard (canonical) form
Every term contains every variable of the domain, primed or not.
Minterm mᵢ
A product of all the variables that is 1 on row i only. Prime a variable where the row has a 0.
Maxterm Mᵢ
A sum of all the variables that is 0 on row i only. Prime a variable where the row has a 1.
RowA B CMintermMaxterm
00 0 0m0 = A′B′C′M0 = A + B + C
10 0 1m1 = A′B′CM1 = A + B + C′
20 1 0m2 = A′BC′M2 = A + B′ + C
30 1 1m3 = A′BCM3 = A + B′ + C′
41 0 0m4 = AB′C′M4 = A′ + B + C
51 0 1m5 = AB′CM5 = A′ + B + C′
61 1 0m6 = ABC′M6 = A′ + B′ + C
71 1 1m7 = ABCM7 = A′ + B′ + C′
  1. Number the rows of the truth table 0 to 2ⁿ − 1 by reading the inputs as a binary number.
  2. SOP: take the rows where F = 1, write each one's minterm and OR them: F = ∑(those rows).
  3. POS: take the rows where F = 0, write each one's maxterm and AND them: F = ∏(those rows).
  4. To convert between them, swap ∑ and ∏ and list the row numbers that are missing.

Worked example

F is 1 on rows 001, 100 and 111

  1. 1SOP: F = A′B′C + AB′C′ + ABC = m1 + m4 + m7, so F(A, B, C) = ∑(1, 4, 7).
  2. 2The 0 rows are 0, 2, 3, 5, 6, so F = M0M2M3M5M6 = ∏(0, 2, 3, 5, 6).
  3. 3The complement swaps them: F′ = ∑(0, 2, 3, 5, 6).

To expand a non-standard term, AND it with (X + X′) for each missing variable X. Each missing variable doubles the number of terms: in F(A, B, C) the term A becomes AB′C′ + AB′C + ABC′ + ABC. For POS, OR in XX′ and distribute.

5.7Simplifying expressions

Every truth table has exactly one canonical form but many equivalent expressions. A simpler expression needs fewer gates, so the circuit is cheaper, uses less power and runs faster. Simplify by applying the laws one step at a time and naming each law.

Worked example

AB + A(B + C) + B(B + C)

  1. 1= AB + AB + AC + BB + BC: Distributive.
  2. 2= AB + AB + AC + B + BC: Idempotent (BB = B).
  3. 3= AB + AC + B + BC: Idempotent (AB + AB = AB).
  4. 4= AB + AC + B: Absorption (B + BC = B).
  5. 5= B + AC: Absorption (B + AB = B). Five gates are down to two.

Worked example

ABC + ABC′ + A′C

  1. 1= AB(C + C′) + A′C: Distributive (factor out AB).
  2. 2= AB · 1 + A′C: Inverse.
  3. 3= AB + A′C: Identity.

Worked example

x(x + y) = x

  1. 1= xx + xy: Distributive.
  2. 2= x + xy: Idempotent.
  3. 3= x(1 + y): Distributive (factor out x).
  4. 4= x · 1: Null.
  5. 5= x: Identity.

Worked example

(A′B)′A

  1. 1= ((A′)′ + B′)A: De Morgan's.
  2. 2= (A + B′)A: Double Complement.
  3. 3= AA + AB′: Distributive.
  4. 4= A + AB′: Idempotent.
  5. 5= A: Absorption.

Patterns worth spotting on sight: XY + XY′ = X (combine terms that differ in one variable), X + XY = X (absorption), X + X′Y = X + Y, and XY + X′Z + YZ = XY + X′Z (the YZ term is redundant). A Karnaugh map does the same combining visually, grouping adjacent 1s in blocks of 1, 2, 4 or 8.

Check yourself

Answer these out loud, without scrolling up. Any you can't, reread that section — then let the drill mark you.

  1. 1.Write both forms of De Morgan's law, and complement F = AB′ + C.
  2. 2.Name the law behind each of these: A + AB = A, A + A′ = 1, A · 0 = 0, (A′)′ = A.
  3. 3.A circuit has G1 = NAND(A, B), G2 = NOT(C) and X = OR(G1, G2). Write X as an expression and give its value when A = B = C = 1.
  4. 4.For F(A, B, C) = ∑(1, 3, 6), write the minterm for row 6, the maxterm for row 0, and F as a product of maxterms.
  5. 5.Simplify AB + A(B + C) + B(B + C), naming the law at each step.
  6. 6.How do you make a NOT gate from a NAND gate, and why does that make NAND universal?