CS181 Lecture 4 -- Fall 2026, UCLA
Overview
In CS181 Lecture 4, Eli Jaffe encodes an n-input, m-output NAND circuit with s gates as a sequence of integers: n, m, s, the output-node labels, and two input labels per gate. Prefix-free binary encoding bounds the representation length by about 12(n+s) log₂(n+s), enabling a counting proof of Shannon's theorem: there are 2^(2^n) Boolean functions but fewer circuits below the stated size threshold, so some functions require exponentially many gates. Jaffe emphasizes that the proof establishes the existence of hard functions without identifying an explicit example, then previews universal circuits as the next application of encoding circuits as data.
Key takeaways
- A NAND circuit with n inputs, m outputs, and s gates can be described by n, m, s, m output-node indices, and 2s gate-input indices.
- Prefix-free encoding of the circuit's integer description gives a bit-length bound of 12(n+s) log₂(n+s), using m ≤ n+s.
- There are 2^(2ⁿ) Boolean functions on n input bits because each of the 2ⁿ truth-table rows independently receives one of two output values.
- An injective circuit encoding lets the number of circuits be bounded by the number of bit strings of length at most L, at most 2^(L+1).
- Comparing the number of functions with the number of circuits establishes that some functions need exponentially many gates, even though counting does not reveal an explicit hard function.
- The lecture's broader technique is to convert structural objects, here circuits, into finite data strings so their size and abundance can be analyzed combinatorially.
Chapters
- The lecture resumes a proof that some Boolean functions require a minimum number of gates.
- The goal is to encode NAND circuits as short Boolean strings by first describing them as integer sequences.
- A complete description must specify the input count, output count, gate count, output nodes, and gate connections.
- Each circuit node receives an integer label so a listener can reconstruct connections without seeing the diagram.
- Input nodes use labels 0 through n−1, with their order fixed to preserve which input bit is which.
- The s NAND gates receive the remaining labels, giving n+s possible node labels.
- The description begins with n, m, and s, which tell the decoder how many values to expect in later sections.
- It lists m labels identifying the nodes that supply the ordered output bits; an output can come from an input or a gate.
- For each of the s NAND gates, it records a pair of labels for that gate's two incoming wires.
- Jaffe labels two inputs and two NAND gates, with the second gate receiving the first gate's output and one input.
- The circuit has one output, taken from the second NAND gate, whose label is included in the description.
- The example's integer sequence is 2, 1, 2, 3, 0, 1, 2, 1: counts, output label, then two input-label pairs.
- A sample sequence begins with three inputs, two outputs, and three NAND gates, which fixes how to parse the following integers.
- The next two integers identify the output nodes, and the remaining six values form three pairs of gate inputs.
- Different gate placements or consistent gate labels can yield the same input-output behavior; unused gates are still valid circuit components.
- Input labels must follow input-bit order because swapping x₀ and x₁ can change the function being computed.
- NAND gates are interchangeable when their connections and any output labels are updated consistently.
- The output-label list identifies which nodes provide each output bit, including intermediate values or even input nodes.
- A circuit's integer sequence becomes a binary string by applying a prefix-free natural-number encoding to every integer.
- The illustrated scheme duplicates each binary digit and appends the tag 01, allowing a decoder to separate consecutive integers.
- For example, the binary representation of 2, 10, becomes 1100 followed by 01 under the described encoding.
- Encoding n, m, and s costs roughly 2 log₂ of each value plus 2 tag bits per integer.
- Each output label and each of the 2s gate-input labels is at most n+s−1, so each takes at most about 2 log₂(n+s)+2 bits.
- The m output labels and 2s connection labels dominate the total length.
- Using m ≤ n+s, Jaffe bounds the full encoding by 12(n+s) log₂(n+s) bits.
- The constant 12 comes from the prefix-free encoding and the arithmetic over counts and node indices.
- This bound makes it possible to count small circuits by counting bit strings rather than circuit diagrams.
- The discussion revisits why the output-node indices are listed after the counts: m determines exactly how many labels follow.
- A decoder can choose its own visual arrangement and gate names, provided it interprets each index consistently.
- Changing the order assigned to gates changes the description, but not necessarily the represented function.
- Jaffe frames Shannon's theorem as showing that the set of small-circuit functions is strictly smaller than the set of all n-bit Boolean functions.
- The proof compares set sizes instead of constructing a particular hard function.
- The encoding supplies the key bridge: circuits become bit strings whose total number can be bounded.
- Allₙ denotes every function from n input bits to one output bit.
- Circuitₙ,ₛ denotes the functions computable by NAND circuits with at most s gates.
- The theorem seeks a strict subset relationship for s = 2ⁿ/(24n), proving that at least one n-bit function lies outside Circuitₙ,ₛ.
- There are 2ⁿ possible inputs to an n-bit Boolean function.
- Each input can independently map to 0 or 1, giving 2 choices for each of 2ⁿ truth-table rows.
- Therefore, the number of functions is 2^(2ⁿ); for n=2, the truth table has four rows and there are 16 functions.
- The number of functions represented by circuits is no greater than the number of circuits, since distinct circuits can compute the same function.
- An encoding is one-to-one, so the number of circuits cannot exceed the number of encoded strings.
- For encodings of length at most L = 12(n+s) log₂(n+s), the count is at most the number of binary strings of length at most L.
- There are 2ᵏ binary strings of length k, so strings of length at most L total 1+2+4+…+2ᴸ.
- The geometric sum is 2^(L+1)−1, which is at most 2^(L+1).
- This gives an upper bound on the number of functions computable by circuits with at most s gates.
- For s = 2ⁿ/(24n), the lecture states that the circuit-count upper bound is strictly below 2^(2ⁿ), the number of all Boolean functions.
- Thus at least one function requires at least the stated exponentially large number of NAND gates, although the counting proof does not identify it.
- Jaffe notes that most functions are hard by this argument, while proving that a specific function is hard remains a major open challenge.
- The result is presented as one application of representing circuits as data.
- The lecture closes by previewing universal circuits as the next topic.
- The encoding method links circuit structure to ordinary binary strings, supporting further theoretical constructions.
Transcript excerpt
0:02 Okay, for those of us joining us virtually for the recording, I'm sorry we missed the first 20 minutes. We did a little recap of last class. We introduced this awesome theorem we're trying to prove about the fact that there's some functions which require a minimum number of gates. And we rephrase that in terms of how uh we are going to represent nan circuits as boolean strings. And now we're in the process of proving that we can uh create an encoding that converts nan circuits to boolean strings of at most this length. So hopefully not the end of the world but sorry. Uh and we're in the process of thinking about how we would describe a nin circuit that only we can see to somebody else who can't see it in order
0:50 to inform our encoding. So we said we need to describe how many input variables it has, how many output variables, how many NAND gates and now finally how the vertices are connected. Okay, so I actually want you to talk to each other. So turn to the people next to you and think what could be a possible scheme or strategy by which you could describe how the vertices in an arbitrary circuit are connected to each other. Go. predict.
1:57 Yeah. Let's say very soon to my house. All right, let's come back together. Any
2:58 ideas? How could we go about describing to our partner in the dark room who can't see the circuit which gates or variables are connected to each other? What could we do? Yeah, Constantine. >> Explain this more visually >> visually or or you know really verbally, right? Imagine you are the person in the other room. What would you say to this person to let them know like they're
This is the start of the transcript. Save this video free for the whole transcript, searchable and time-coded.
In this course
Related notes
Summary, takeaways, and chapters were generated by AI from the video's transcript and may contain errors. The video belongs to its creator, Eli Jaffe.