Exercises — Module 21 (Boolean Functions and Optimal Evaluation)
Self-contained problems on this module's material — counting special functions, normal forms, monotonicity, Boolean chains, and the combinational complexity . You can work every one without the books: each states the problem in full, gives a hint to peek at when stuck, and a worked answer sketch to check against after you try. Numeric answers here are reproduced by the code you write in the lab (or a few lines at a REPL).
Ratings follow Knuth's scale (00–50; M = needs mathematics, ▶ = especially
instructive). Where a problem mirrors a TAOCP exercise, its number in §7.1.1–7.1.2
is noted for readers who own Volume 4A.
Tracking
| # | Topic | Rating | Status |
|---|---|---|---|
| 1 | Count the self-dual functions of variables | 10 | ⬜ |
| 2 | ▶ Symmetric functions weight bits | 20 | ⬜ |
| 3 | Monotone positive-literal DNF | 22 | ⬜ |
| 4 | ▶ Optimum 4-gate median-of-3; no 3-gate chain | 15 | ⬜ |
| 5 | of the full adder's two outputs; can they share? | 20 | ⬜ |
| 6 | ▶ A random needs gates (Shannon/Lupanov) | 30 | ⬜ |
| 7 | Compute the Dedekind number ; the story | 40 | ⬜ |
Problems
1. Count the self-dual functions of variables (rating 10 · cf. 7.1.1–2)
Problem. A function is self-dual if for every input (complementing all inputs complements the output). How many self-dual Boolean functions of variables are there?
Hint. The inputs pair up under complementation: with . How many such pairs are there, and how much freedom does self-duality leave you on each pair?
Answer sketch. The map has no fixed points (an -bit string never equals its own complement for ), so the inputs split into exactly complementary pairs. Self-duality forces , so fixing on one member of a pair fixes it on the other. You may choose freely (0 or 1) on one representative of each of the pairs, and nothing else. Hence there are
self-dual functions. Check: (the two projections ); ; — all confirmed by brute-force enumeration. Compare the grand total of all functions: self-dual ones are the square root of that count, a vanishing fraction, yet they include the important median/majority function the lesson singles out.
2. ▶ Symmetric functions weight bits (rating M20 · cf. 7.1.1–5)
Problem. A function is symmetric if its value depends only on how many inputs are 1, not which. Prove that every symmetric function of variables is determined by the bits (where is the value when exactly inputs are 1), and count how many symmetric functions there are.
Hint. Group the inputs by popcount. What does symmetry say about all inputs in one group? Then count the free choices.
Answer sketch. Partition the inputs by their number of 1s: group
holds the inputs with popcount , for .
Symmetry means is constant on each group (any two inputs with the same
popcount give the same value), so is completely described by its value
on group — exactly the bits , giving
(the module's symmetric_function).
Conversely any choice of the yields a symmetric function. So the symmetric
functions are in bijection with -bit strings, and there are exactly
of them. Check: , — confirmed by enumeration. This is a spectacular compression: bits instead of , and it is why majority, threshold, and parity — all symmetric — are among the cheap functions the counting bound (Problem 6) says must be rare.
3. Monotone positive-literal DNF (rating 22 · cf. 7.1.1–16)
Problem. Call monotone (nondecreasing) if under the bitwise-subset order (flipping any input never flips the output ). Prove that is monotone iff it can be written as a DNF (an OR of product terms) using only positive literals — no complemented variables.
Hint. One direction: show a positive term is monotone and that OR preserves monotonicity. Other direction: for a monotone , build a DNF from its minimal 1-inputs, using for each the product of the variables that are 1 there.
Answer sketch. () A positive product term is monotone: raising an input from 0 to 1 can only turn the AND from 0 to 1, never the reverse. The OR of monotone functions is monotone (raising an input cannot turn any disjunct off, so it cannot turn the OR off). Hence any positive-literal DNF is monotone. () Let be monotone. Call an input minimal if but for every . For each minimal form the positive term , and let . Then : if , walk down from by clearing 1-bits while the value stays 1 until you reach a minimal ; then is satisfied by (all its variables are 1 in ), so . Conversely if is satisfied by then , so by monotonicity . Thus and agree on every input, and uses only positive literals. (The minimal 1-inputs are exactly the prime implicants of a monotone function; this is a proof by exhaustive agreement — the two formulas match on all rows.)
4. ▶ Optimum 4-gate median-of-3; no 3-gate chain (rating 15 · cf. 7.1.2–1)
Problem. Exhibit a 4-gate Boolean chain computing the median (majority) of three inputs, and argue that no chain of 3 gates can compute it — so over the full 16-operation basis.
Hint. For the witness, combine an AND, an OR, and one more AND/OR. For the lower bound, recall why the "reachable functions" shortcut that reports 3 is wrong — it assumes both operands of a gate are free, ignoring that sharing is what a real chain provides.
Answer sketch. Upper bound (witness). The chain
computes in 4 gates. Check the cases: if , ; if exactly one of is 1 then and , so the output is 1 iff supplies the second vote; if everything is 0. So the output is 1 iff at least two inputs are 1 — the majority. Lower bound. The state-BFS of §6 — which carries the whole set of computed values forward so any later gate can reuse an earlier one — finds no 3-gate chain for majority; its first appearance is at depth 4. The tempting "reachable set" shortcut () reports 3, but it double-counts by pretending both operands are available for free when each may itself cost gates; it computes only a lower bound on cost, not the cost. Since the shortcut's 3 is not achievable and the witness achieves 4, .
5. of the full adder's two outputs; can they share? (rating 20 · cf. 7.1.2–2)
Problem. A full adder has inputs and two outputs: the sum and the carry . Individually, and over the full basis. If we build one chain producing both outputs, can it cost fewer than gates by sharing an intermediate value? Find the smallest such chain.
Hint. Is there a subexpression common to a cheap chain for and a cheap chain for ? Rewrite the carry using instead of where they agree.
Answer sketch. Yes — the two outputs share the half-sum , so both fit in 5 gates, not 6. When (the region that matters for the second disjunct) equals , giving the identity . Now:
Gate feeds both the sum (via ) and the carry (via ) — that is the sharing. Evaluating all inputs confirms and on every row. So the joint (multi-output) complexity is 5, strictly below the sum of the separate complexities — a concrete instance of why circuit cost is about sharing, the theme behind the module's state-BFS.
6. ▶ A random needs gates (Shannon/Lupanov) (rating M30 · cf. 7.1.2–23)
Problem. Explain why almost every Boolean function of variables has combinational complexity : most functions require exponentially many gates. Give the counting argument for the lower bound and state the matching Lupanov upper bound.
Hint. Count how many distinct functions a chain of gates can possibly compute, and compare with the total number of functions . If there are too few small chains, most functions cannot have one.
Answer sketch. Lower bound (counting chains). A chain of gates over the 16-operation basis is specified by choosing, per gate, an operation (16 ways) and two earlier operands (at most ways). So at most
distinct functions have an -gate chain. To realize even a constant fraction of all functions we need , i.e. , which forces . Because the count of realizable functions is so much smaller than the count of functions whenever , the fraction of functions with a small chain tends to 0: almost every function needs gates. Upper bound (Lupanov). Lupanov proved gates always suffice — every function has a chain of that order — so the bound is tight and the typical complexity is . Moral. This is the double exponential of §1 biting back: there are functions but only small circuits, so small circuits are precious. The functions we actually build hardware for (adders, comparators, symmetric functions) are the rare cheap exceptions.
7. Compute the Dedekind number ; the story (rating 40 · cf. §7.1.1)
Problem. The Dedekind number counts the monotone Boolean functions of variables. Compute by brute force — enumerate the relevant space and count the monotone functions — and describe why and needed heroic computation rather than a simple loop.
Hint. For a direct count you would sweep all functions and test monotonicity (single-bit raises), as the lab does for . At the space is already large; think about what makes astronomically worse.
Answer sketch. By definition (README §4) , and the next value is
A brute-force enumeration of all functions, testing each for monotonicity via single-bit raises, reproduces — feasible but no longer instant, which is why the lab caps its live computation at ( functions). The wall past is the double exponential : the search space is at , at , at — far beyond any exhaustive sweep, and there is no known closed form for . So was found only in 1991 on a supercomputer, and was computed only in 2023 — independently by Christian Jäkel and by Van Hirtum et al. — using months of FPGA and GPU time on cleverly structured counts (not naïve enumeration), giving . Dedekind posed the problem in 1897; each new value has been a milestone, and the count remains open past .
Your solutions
Use this space to log your own work — a restated problem, your approach, and how it compared with the sketch above.
Exercise N (rating RR)
Approach. Answer / proof. Compared with the sketch: what you did differently, what you missed.