AI / ML Theory
Chapter 1 · 18 min

1.6 — The XOR problem and why we need depth

Goal: Prove no linear classifier solves XOR, then build a 2-hidden-unit network that does — the simplest case where depth strictly increases expressivity.

1. Why this session exists

Minsky and Papert's 1969[1] book Perceptrons observed that the simplest non-trivial logical function — exclusive OR — cannot be computed by a single-layer perceptron. The observation effectively killed neural-network research for a decade. The fix (a hidden layer) is mathematically trivial once you know it, but conceptually it is the entire reason the rest of this course exists: adding depth strictly increases what a linear-threshold network can represent.

This session does the proof of impossibility and constructs the explicit 2-hidden-unit solution.


2. XOR

The XOR function on {0,1}2\{0, 1\}^2 takes the four input combinations to the values

XOR(0,0)=0,XOR(0,1)=1,XOR(1,0)=1,XOR(1,1)=0.\text{XOR}(0, 0) = 0,\quad \text{XOR}(0, 1) = 1,\quad \text{XOR}(1, 0) = 1,\quad \text{XOR}(1, 1) = 0.

Geometrically: the two diagonally opposite corners of the unit square share a label; the two off-diagonal corners share the other label.


3. Impossibility for a single linear unit

Claim. No affine function f(x)=w1x1+w2x2+bf(x) = w_1 x_1 + w_2 x_2 + b classifies all four points correctly under the encoding {0↦−1, 1↦+1}\{0 \mapsto -1,\ 1 \mapsto +1\} via sign⁡(f(x))\operatorname{sign}(f(x)).

Proof. Suppose for contradiction such (w1,w2,b)(w_1, w_2, b) exist. The four required sign conditions read

XOR(0,0)=0  ⟹   b<0,XOR(1,0)=1  ⟹   w1+b>0,XOR(0,1)=1  ⟹   w2+b>0,XOR(1,1)=0  ⟹   w1+w2+b<0.\begin{aligned} \text{XOR}(0, 0) = 0 \implies\ & b < 0, \\ \text{XOR}(1, 0) = 1 \implies\ & w_1 + b > 0, \\ \text{XOR}(0, 1) = 1 \implies\ & w_2 + b > 0, \\ \text{XOR}(1, 1) = 0 \implies\ & w_1 + w_2 + b < 0. \end{aligned}

Add the middle two:

(w1+b)+(w2+b)=w1+w2+2b  >  0.(w_1 + b) + (w_2 + b) = w_1 + w_2 + 2 b \;>\; 0.

Add the first and the last:

b+(w1+w2+b)=w1+w2+2b  <  0.b + (w_1 + w_2 + b) = w_1 + w_2 + 2 b \;<\; 0.

The two sums are the same number but are required to be both positive and negative. Contradiction. ■\blacksquare


4. The solution: one hidden layer

XOR is not a half-space. But it is the symmetric difference of two half-spaces. We compute it as a small linear combination of thresholded sums.

Let

h1(x)=1[ x1+x2−0.5>0 ],h2(x)=1[ x1+x2−1.5>0 ].h_1(x) = \mathbb{1}\bigl[\,x_1 + x_2 - 0.5 > 0\,\bigr], \qquad h_2(x) = \mathbb{1}\bigl[\,x_1 + x_2 - 1.5 > 0\,\bigr].

Read off:

  • h1(x)=1h_1(x) = 1 iff at least one input is on. (Logical OR.)
  • h2(x)=1h_2(x) = 1 iff both inputs are on. (Logical AND.)

Then

XOR(x1,x2)=h1(x) ∧ ¬h2(x)=h1(x)−h2(x),\text{XOR}(x_1, x_2) = h_1(x) \,\wedge\, \neg h_2(x) = h_1(x) - h_2(x),

where the subtraction works because h1≥h2h_1 \ge h_2 pointwise on {0,1}2\{0, 1\}^2.

So XOR is computed by the two-layer network

h1=1[ 1⋅x1+1⋅x2−0.5>0 ]h2=1[ 1⋅x1+1⋅x2−1.5>0 ]o=h1−h2.\begin{aligned} h_1 &= \mathbb{1}\bigl[\,1 \cdot x_1 + 1 \cdot x_2 - 0.5 > 0\,\bigr] \\ h_2 &= \mathbb{1}\bigl[\,1 \cdot x_1 + 1 \cdot x_2 - 1.5 > 0\,\bigr] \\ o &= h_1 - h_2. \end{aligned}

Two hidden units with hard-threshold activations, one output unit with linear activation. Walk the four inputs:

  • (x1,x2)=(0,0)(x_1, x_2) = (0, 0): h1=0, h2=0, o=0h_1 = 0,\ h_2 = 0,\ o = 0. ✅
  • (x1,x2)=(0,1)(x_1, x_2) = (0, 1): h1=1, h2=0, o=1h_1 = 1,\ h_2 = 0,\ o = 1. ✅
  • (x1,x2)=(1,0)(x_1, x_2) = (1, 0): h1=1, h2=0, o=1h_1 = 1,\ h_2 = 0,\ o = 1. ✅
  • (x1,x2)=(1,1)(x_1, x_2) = (1, 1): h1=1, h2=1, o=0h_1 = 1,\ h_2 = 1,\ o = 0. ✅

Exactly XOR.


5. What this teaches us about depth

The XOR result is the simplest piece of evidence for two structural truths in deep learning.

  1. Depth ≠ width. A wide single-layer perceptron — no matter how many parameters — can only carve Rn\mathbb{R}^n into two half-spaces. It cannot compute the intersection of two half-spaces, which is what XOR requires.
  2. Composition is the source of expressivity. Composing two threshold functions yields a non-convex decision region. Iterating composition (the MLP of Chapter 2) yields arbitrarily complex piecewise-affine regions; in the limit, MLPs can approximate any continuous function on a compact set — the universal approximation theorem (Cybenko 1989; Hornik 1991), which we'll prove in Chapter 3.

The hidden layer is the new primitive. It is the difference between fitting a half-space and fitting a polyhedron, and it is the difference between linear regression and "deep learning". Everything else in this course is engineering on top of that insight.


6. Takeaways

  • A single linear classifier cannot solve XOR (the contradiction in §3).
  • Two hidden units plus one output unit do solve XOR (the construction in §4).
  • Cause: XOR is not a half-space; it is the symmetric difference of two half-spaces.
  • This is the prototype demonstration that depth strictly enlarges the function class.

Self-test

(a) Walk through the §3 contradiction explicitly with w1,w2,bw_1, w_2, b replaced by symbolic numbers, observing which two pairs of inequalities clash.

(b) Build a two-hidden-unit network that computes the parity function on three inputs, x1⊕x2⊕x3x_1 \oplus x_2 \oplus x_3. (Hint: parity on nn bits needs more hidden units than on 2; try n=3n = 3 first and find the minimum count.)

(c) Replace the hard-threshold activations in §4 with sigmoids hj=σ(α(wj⊤x−bj))h_j = \sigma\bigl(\alpha (w_j^\top x - b_j)\bigr) with steepness parameter α\alpha. Show that as α→∞\alpha \to \infty, the sigmoid network recovers the hard-threshold one. What goes wrong with backprop when α\alpha is very large? (A foreshadow of vanishing-gradient: Chapter 5.)

(d) Argue that the family of functions computable by a single linear-threshold unit is closed under negation but not under XOR. Use this closure property to give a 3-line non-existence proof of XOR for a perceptron.


References

  1. [1]

    Minsky, M., & Papert, S. (1969). Perceptrons: An Introduction to Computational Geometry. MIT Press. — The XOR impossibility result (1.6).

    ↩