Logic: logic gates and truth tables

← Back to specs
High school 24 Rooms Logic

Teaching objectives

A 24-room lab in which the student learns the logical operators by building them. Almost every room uses the same board: switches, bulbs and logic gates that can be dragged, placed without overlapping and connected by tapping two ends of different pieces (tapping again disconnects). Each operator is presented in three ways at once: the circuit (no current is 0, current is 1), true or false statements (1 is truth and 0 is a lie) and, for conjunction and disjunction, sets. The formal name and the symbol of each operator (∧, ∨, ¬, →, ↔, ⊕) are stressed throughout.

There are few explanation screens: the student tries combinations until the truth table is complete, builds circuits that reproduce a given table and answers comprehension challenges (choosing an option, tapping cells of a table of sets, deciding whether an argument is valid). The building challenges give a hint after several failed attempts and, later, show the solution built. Each challenge has to be solved to move on within a room.

What you'll learn

The lab takes the student from “0 is a lie and 1 is truth” to building a binary adder out of gates.

  • Reading a circuit as a logical statement and a truth table as a function of its inputs (rooms 1-3).
  • Seeing conjunction as intersection and disjunction as union in a table of sets (rooms 4 and 6).
  • Building a circuit that reproduces a given table, and discovering through De Morgan's laws that AND, OR and NOT can be expressed in terms of one another (rooms 7-8).
  • Understanding that implication is false in only one case and that A → B means that A is a subset of B (rooms 9-10).
  • Telling valid arguments (modus ponens, modus tollens, transitivity, disjunctive syllogism) from invalid ones (denying the antecedent or affirming the consequent) (rooms 11-12).
  • Checking whether two formulas are equivalent and why the converse of an implication is not; meeting equivalence and exclusion (rooms 13-15).
  • Memorising the names and symbols of the operators, and moving to three variables (rooms 16-17).
  • Going from logic to calculation: the binary system, addition with a carry and the half adder as an XOR and an AND (rooms 18-19).
  • Recognising that NAND and NOR are universal, building NOT, AND, → and XOR with NAND alone, and linking this to real processors (rooms 20-23).
  • Applying everything in a free workshop: full adder, majority function, parity and reproducing a truth table (room 24).

Key mathematical ideas

  • Truth and lies as 0 and 1. Everything is built from two values; a formula with n variables has a table of 2ⁿ rows (4 with two, 8 with three).
  • Conjunction (∧) and disjunction (∨). A ∧ B is 1 only if both are 1; A ∨ B is 0 only if both are 0 (inclusive). In sets, ∧ is the intersection and ∨ the union.
  • Negation (¬) and De Morgan's laws. ¬(¬A ∨ ¬B) = A ∧ B; negation turns OR into AND and vice versa. If “I am tall and I am Spanish” is a lie, all we know is that he is not tall or he is not Spanish.
  • Implication (→). A → B is false only if A is true and B false, and it equals ¬A ∨ B. A false premise implies anything. In terms of sets, A → B means A ⊆ B (every square is a rectangle, not the other way round).
  • Arguments. Modus ponens, modus tollens, transitivity and the disjunctive syllogism are valid. Denying the antecedent (“I am not in a hurry, so I do not run”) and affirming the consequent (“I passed, so I studied”) are not: they confuse A → B with its converse B → A.
  • Equivalence (↔). A ↔ B is 1 when A and B agree, and it is (A → B) ∧ (B → A). A → B and its contrapositive ¬B → ¬A are equivalent; A → B and B → A are not.
  • Exclusion (⊕). A ⊕ B is 1 when A and B are different; it is the “or” of everyday speech (“dessert or coffee”).
  • Binary and addition. Positions are worth powers of two (1, 2, 4, 8…) and 1 + 1 = 10, with a carry. In the sum of two digits, the units digit is an XOR and the carry is an AND: that is the half adder.
  • Universality of NAND and NOR. A single one of these gates is enough to build any circuit: NOT = NAND(A, A), AND with two NANDs, → with two and XOR with four. This is why chips are made with a single type of gate.
  • Full adder. It adds A + B + an incoming carry and gives a result and an outgoing carry (two XORs, two ANDs and one OR). The outgoing carry is the majority function, and the odd parity of three inputs is an XOR of all three.

Level: Bachillerato (upper secondary) and first university years. It works as an introduction to propositional logic and digital circuits; no programming is needed. In class it works well to project room 3, where the table of ¬(A ∧ B) is predicted by hand, room 8 with De Morgan's laws and room 13, which explains why “I passed, so I studied” is a fallacy. Room 24 is the longest and suits work in pairs.

Room-by-room contents

Room 1 · Learning: 0 and 1

A battery, a switch and a bulb in series, with the switch on and the bulb lit. When the switch is turned off the bulb goes out, and the room explains the convention: no current is 0 (a lie), current is 1 (truth). All the operations that follow are built from these two values.

Student tasks

  • Tap the switch to turn it off and see what happens to the bulb.
  • Answer: what does 0 represent in this system? (a lie).

Room 2 · Conjunction (AND)

Conjunction (∧) is true only if both parts are true; it is illustrated with «Madrid is the capital of Spain ∧ Vietnam is in America», which is false because of the second part. The circuit has two switches, an AND gate and a bulb, all off, and the truth table is filled in row by row by trying the four combinations (a counter shows how many lines are left).

Student tasks

  • Try the 4 combinations of the switches until the truth table is complete.
  • Decide whether «America is in Europe and New York is in America» is true.
  • Knowing that A is true and that A ∧ B = 1, say what B has to be (true, necessarily).

Room 3 · Negation (NOT)

Negation (¬) flips the value: where there was no current it appears, and the other way round. There are two switches, an AND gate, a NOT gate and a bulb, with no wires; wires are made by tapping two ends of different pieces, and tapping them again removes the wire. After building ¬(A ∧ B), the student fills in the truth table by hand, without touching the switches, and the room checks it row by row with an animation of the four states. This is the room where the building mechanics used in the rest of the lab are learned.

Student tasks

  • Build the circuit ¬(A ∧ B) by connecting A and B to the AND gate and its output to the NOT gate (if it takes long, a hint appears first with A ∧ B already built and, later, the solution).
  • Predict and fill in the truth table of ¬(A ∧ B) and press «Check table».

Room 4 · AND as intersection

The students of a school study English, French, both or neither. A 2×2 table («studies / does not study English» by «studies / does not study French») makes each cell a different group, and AND is the intersection of two conditions. Each correct cell reveals its expression in symbols (for example, ¬English ∧ French).

Student tasks

  • Tap the cell of the students who study English and French.
  • Tap the cell of the students who study French but not English.
  • Tap the cell of the students who study neither English nor French.

Room 5 · Disjunction (OR)

Disjunction (∨) is true if at least one of the parts is true: «Madrid is the capital of Spain ∨ Vietnam is in America» is true even though the second part is false. The circuit with an OR gate follows the same pattern as room 2: four combinations to complete the table, and a deduction challenge that mirrors the one for conjunction.

Student tasks

  • Try the 4 combinations and complete the truth table of OR.
  • Knowing that A is false and that A ∨ B = 1, say what B has to be (true).

Room 6 · OR as union

Back to the English and French table: «studies English ∨ French» gathers those who study at least one of the two, that is, three of the four cells (all except the one for neither). OR is the union, just as AND was the intersection.

Student tasks

  • Tap the 3 cells that make up «studies English ∨ French» and press «Check».

Room 7 · One NOT, one OR

First free-building challenge: with two switches, a NOT gate and an OR gate (each piece used once), the student has to make the bulb follow a given truth table (1, 0, 1, 1, which is A ∨ ¬B). If they get stuck, a hint appears («OR gives 0 only if both of its inputs are 0») and, later, the solution.

Student tasks

  • Build the circuit for the given table with one NOT and one OR, negating B and feeding it into one input of the OR together with A.

Room 8 · Three NOTs, one OR

With two switches, three NOT gates and one OR gate, the student has to reproduce the AND gate. The solution, ¬(¬A ∨ ¬B), is presented as one of De Morgan's laws: negation turns OR into AND and vice versa. Then a challenge in everyday language applies the same law: if Juan lied when he said «I am tall and I am Spanish», all we can be sure of is that he is not tall or he is not Spanish, without knowing which of the two fails.

Student tasks

  • Build a circuit with 3 NOTs and 1 OR that behaves like an AND.
  • Choose, among four statements about Juan, the one that is certainly true (Juan is not tall or Juan is not Spanish).

Room 9 · Implication

Implication (→, «if A then B») promises a consequence from a condition. The student completes its table by trying a circuit with a → gate and finds that it is false in only one case (A true and B false), so a false premise does not make it false. Then they have to build A → B with just one NOT and one OR.

Student tasks

  • Try the 4 combinations and complete the truth table of A → B.
  • Build A → B with one NOT and one OR (¬A ∨ B).

Room 10 · Implication as a subset

If A → B is a law, everything that satisfies A also satisfies B: the set of the A is contained in the set of the B (A ⊆ B). It is illustrated with «square implies rectangle»: squares are a subset of rectangles and not the other way round. The room thus guards against reading the inclusion the wrong way.

Student tasks

  • Knowing that «being a multiple of 6» implies «being a multiple of 3», choose the correct set inclusion ({multiples of 6} ⊆ {multiples of 3}).

Room 11 · Syllogisms I

A syllogism is two premises and a conclusion. Three arguments, one per challenge, to decide whether the conclusion really follows: one invalid (denying the premise of an implication), a modus ponens and a modus tollens. After answering, each challenge explains why.

Student tasks

  • Decide whether «when I am in a hurry I run; today I am not in a hurry; so today I will not run» is valid (it is not).
  • Decide whether «if it rains, the ground gets wet; it is raining; so the ground is wet» is valid (yes: modus ponens).
  • Decide whether «if a number is a multiple of 4, it is even; this number is not even; so it is not a multiple of 4» is valid (yes: modus tollens).

Room 12 · Syllogisms II

Three more arguments in the same format: an error of affirming the consequent, the transitivity of implication (and of set inclusion) and the disjunctive syllogism, which holds with a non-exclusive OR.

Student tasks

  • Decide whether «if you study, you pass; you passed; so you studied» is valid (it is not).
  • Decide whether «if I eat a lot, I put on weight; if I put on weight, I get more tired when running; so if I eat a lot, I get more tired» is valid (yes: transitivity).
  • Decide whether «I will go to the party on Saturday or Sunday; I did not go on Saturday; so I went on Sunday» is valid (yes: disjunctive syllogism).

Room 13 · Equivalent formulas

Two formulas are equivalent if they give the same result for every combination of values. There are two circuits, each with its own bulb, and the student tries the four combinations of A and B in each, comparing whether the bulbs always light up together. First A → B against its contrapositive ¬B → ¬A (equivalent) and then against its converse B → A (they are not, which explains the fallacy in room 12).

Student tasks

  • Try the 4 combinations and decide whether A → B and ¬B → ¬A are equivalent (yes).
  • Do the same with A → B and B → A (they are not equivalent).

Room 14 · Equivalence (↔)

Equivalence (↔) is true exactly when A and B have the same value, which formalises the hand comparison of the previous room. The student completes its table with a one-gate ↔ circuit and chooses, among three formulas, the one that defines it; the wrong answers explain with a concrete case why they fail.

Student tasks

  • Try the 4 combinations and complete the truth table of A ↔ B.
  • Choose the formula that defines A ↔ B: (A → B) ∧ (B → A).

Room 15 · Exclusion (XOR)

XOR (⊕) is true when A and B are different, which is the usual meaning of «or» in everyday speech («the menu comes with dessert or coffee»). The circuit already has an XOR gate built, and the student completes its table and reasons through a deduction case.

Student tasks

  • Try the 4 combinations and complete the truth table of XOR.
  • Knowing that A is true and that A ⊕ B = 0, say what B has to be (true).

Room 16 · Quick test: name and symbol

A timed test to review the six operators: the name of each one is given and the student has to choose its symbol among four. Correct answers add points and the time per question adjusts depending on whether the answer was right or wrong; if the test is not passed, it is repeated.

Student tasks

  • Choose the symbol of conjunction, disjunction, negation, implication, equivalence and exclusion (∧, ∨, ¬, →, ↔, ⊕) in the timed rounds.

Room 17 · Three variables

With three switches the truth table has 8 rows instead of 4. The room starts from an already built circuit, A ∧ (B ∨ ¬C), to see how its table fills in as the switches are moved. Then come two building challenges; the second is almost a mirror of the first, differing only in whether A is negated.

Student tasks

  • Move the 3 switches and complete the 8-row table of A ∧ (B ∨ ¬C).
  • Build ¬A ∨ (B ∧ C).
  • Build a circuit with the table 00011111 (A, B, C from 000 to 111), which is A ∨ (B ∧ C).

Room 18 · The binary system

Computers count with 0 and 1, so instead of units, tens and hundreds they use units, «twos», «fours» and «eights» (powers of two). The first ten natural numbers are shown in binary and addition with a carry is explained, with a worked example (101 + 011 = 1000).

Student tasks

  • Convert 1100 from binary to decimal (12).
  • Add 1111 + 1010 in binary (11001); if it goes wrong, the sum is shown in columns with the carries marked.

Room 19 · The half adder

A circuit that adds two binary digits needs two bulbs, because 1 + 1 = 10: one for the units and one for the «twos» (the carry). The student identifies which function matches each bulb from the sum, and wrong answers are refuted with a specific row of the table. Then they build the circuit with the switches and the two gates.

Student tasks

  • Choose the function for the units digit (XOR).
  • Choose the function for the carry, which is 1 only when adding 1 + 1 (AND).
  • Build the half adder: the switches to an XOR gate and an AND gate, each to its own bulb.

Room 20 · NAND and NOR

NAND is «not (A and B)» and NOR is «not (A or B)». Each one, on its own, is universal: with only NAND gates (or only NOR gates) any circuit can be built. A demonstration circuit has a NOR with both inputs wired to the same switch, and it can be seen to invert the signal, that is, to be a NOT.

Student tasks

  • Flip the switch of the NOR with its two inputs joined and see that it inverts the signal.
  • Answer whether any logic circuit could be built using only NOR gates (yes).

Room 21 · Logic gates in real processors

A short room for reflection: the ALU of a processor is made of millions of gates built at the transistor level, and they are almost always of the same type (NAND or NOR), taking advantage of the universality just seen.

Student tasks

  • Choose why it suits a chip manufacturer to make a single type of gate: because mass-producing and testing a single piece is cheaper and simpler.

Room 22 · Building with NAND (I)

First constructions that check the universality of NAND: NOT with a single gate (joining A to both inputs) and AND with exactly two gates, where the second only needs the output of the first wired to both of its inputs.

Student tasks

  • Build ¬A with a single NAND gate.
  • Build A ∧ B with exactly 2 NAND gates.

Room 23 · Building with NAND (II)

Two longer constructions using only NAND: implication, with two gates (the first gives ¬B and the second combines it with A), and XOR, with four gates, which is the longest construction in the lab.

Student tasks

  • Build A → B with exactly 2 NAND gates.
  • Build A ⊕ B with exactly 4 NAND gates.

Room 24 · Free workshop

A closing room with loose pieces (switches, bulbs and several types of gate) to place and connect freely. Each challenge is preceded by an explanation with a worked example: the full adder (the half adder of room 19 plus an incoming carry), the majority function, odd parity and reproducing a given truth table. After the four challenges, the student can keep playing with the pieces.

Student tasks

  • Build a full adder with 3 inputs (A, B, incoming carry) and 2 outputs (result and outgoing carry).
  • Build the 3-input majority function, which turns on if at least 2 inputs are on (it is the same signal as the adder's outgoing carry).
  • Build a circuit that turns on only when the number of switches that are on, out of 3, is odd.
  • Build a circuit with the table 0, 1, 1, 0, 1, 0, 0, 1 (A, B, C from 000 to 111) using the pieces the student chooses.

Rooms to project

The most striking ones to show and discuss in class.

★
Room 3 · Negation (NOT) — It is the first building room and sets the wiring mechanics used throughout the lab; predicting the table of ¬(A ∧ B) before seeing it checked is a good moment for the class to discuss each row.
★
Room 8 · Three NOTs, one OR — De Morgan appears both as a circuit and as reasoning about Juan: finding the solution with three NOTs and one OR and understanding why only one of the four sentences is certain leads to a discussion of how a conjunction is negated.
★
Room 13 · Equivalent formulas — Comparing two circuits by hand shows that the contrapositive is equivalent to the implication and the converse is not, which explains why «I passed, so I studied» is a fallacy.