XOR, Boolean Functions and the Power of a Network of Perceptrons
On this page 8 headings
Build XOR from two hidden decisions
Let one hidden neuron compute OR and the other compute AND. The output is 1 when OR − 2·AND − 0.5 is at least zero.
For inputs (1, 0), OR is 1 and AND is 0.
For inputs (1, 1), both hidden outputs are 1.
The same rule handles the other two inputs.
What changed? The hidden layer creates two useful features. Their combination separates the XOR cases.
Quick check: What is the final output for (0, 1)?
1: OR is 1, AND is 0, and the output score is 0.5.
Swipe long formulas, tables or code sideways to see the rest.
Start here One perceptron draws one straight line. Some problems — even a tiny one called XOR — cannot be solved with one line. The fix is surprisingly simple: use many perceptrons in layers. This page proves that such a network can represent any Boolean function.
XOR (“exclusive OR”) is 1 when the two inputs are different.
| XOR | Condition for a perceptron | Simplifies to | ||
|---|---|---|---|---|
| 0 | 0 | 0 | ||
| 0 | 1 | 1 | ||
| 1 | 0 | 1 | ||
| 1 | 1 | 0 |
The contradiction, step by step:
- From rows 2 and .
- From , so , so .
- .e. .
- Row 4 needs . Impossible.
Real data is like this too. Most real-world data is not linearly separable. It has outliers, and sometimes even without outliers no line can separate it. We need models that can handle this. A single perceptron cannot — but a network of perceptrons can.
Each function is one way of filling the output column for the 4 input rows. Each row can be 0 or 1, so there are functions.
| f1 | f2 | f3 | f4 | f5 | f6 | f7 | f8 | f9 | f10 | f11 | f12 | f13 | f14 | f15 | f16 | ||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
| 1 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 |
| 0 | 1 | 0 | 0 | 1 | 1 | 0 | 0 | 1 | 1 | 0 | 0 | 1 | 1 | 0 | 0 | 1 | 1 |
| 1 | 1 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 1 |
Of these 16, 14 are linearly separable. Only and are not.
For n inputs: there are input rows, and each can output 0 or 1, so there are Boolean functions. (.) Some of these are not linearly separable. (The exact count is not needed for this course.)
For this part, use True and False .
The network:
- Input layer:
- Hidden layer: 4 perceptrons . Each gets both inputs with weights +1 (blue edge) or −1 (red edge). Each has bias −2 — it fires only if its weighted sum is .
- Output layer: one perceptron y, with weights from the hidden units (these are what we choose/learn).
Terminology: input layer, hidden layer (the middle one), output layer. Red/blue edges layer 1 weightslayer 2 weights. Outputs of the hidden perceptrons .
Key trick: each hidden perceptron fires for exactly one input.
| Hidden unit | Weights | Fires only for | Check: sum for that input |
|---|---|---|---|
| (−1, −1) | (−1, −1) | ||
| (−1, +1) | (−1, +1) | ||
| (+1, −1) | (+1, −1) | 2 ✔ | |
| (+1, +1) | (+1, +1) | 2 ✔ |
For any other input, the sum is 0 or −2, which is , so the unit stays off.
Lecture example — XOR with this network Let the output fire if (output threshold). For each input only one , so the sum is just that :
XOR 0 (−1) 0 (−1) 0 1 0 0 0 0 (−1) 1 (+1) 1 0 1 0 0 1 (+1) 0 (−1) 1 0 0 1 0 1 (+1) 1 (+1) 0 0 0 0 1 Conditions: No contradiction now! One answer: .
Why it works: each controls one row alone, so we can set every row’s answer freely. The same network can do all 16 functions — just change . Each function gives its own set of non-contradicting inequalities.
- 3 inputs: 8 input combinations → 8 hidden perceptrons (bias −3, each fires for one combination) → 8 output weights.
- n inputs: combinations hidden perceptrons.
Theorem. Any Boolean function of n inputs can be represented exactly by a network of perceptrons with 1 hidden layer of perceptrons and 1 output perceptron. Proof (informal): we just built it.
Note: perceptrons is sufficient, not necessary. AND needs just 1 perceptron.
The catch: the hidden layer grows exponentially.
We have past data: for each movie, features and the label y (like / dislike ). Points with are ; points with are . The data may or may not be linearly separable.
The theorem says: there exists a network of perceptrons whose weights can be learned so that its output matches y for every and . So a network can separate positive and negative points even when one line cannot.
Networks with an input layer, one or more hidden layers, and an output layer are called Multilayer Perceptrons (MLPs). (A more accurate name would be “multilayered network of perceptrons”, but MLP is the common name.)
Representation power of an MLP with one hidden layer: it can represent any Boolean function exactly.
In one line: One perceptron fails on XOR, but one hidden layer of perceptrons can represent any Boolean function — at the cost of exponentially many units.
Exam words: XOR, XNOR, not linearly separable, Boolean functions, hidden layer, input layer, output layer, layer 1/layer 2 weights, multilayer perceptron (MLP), representation power, hidden perceptrons, sufficient vs necessary.
