Skip to content

13.9 Probability problem set, part a: axioms, Bayes, random variables, Box-Muller

Every random number in an LLM system comes from one generator, PCG32, and it feeds weight initialization, dropout, data shuffling, and sampling. Random variables, expectation, variance, and normal draws by Box-Muller turns its uniforms into normals, and Variance propagation and initialization chooses initialization scales so that activations neither explode nor vanish through 20 layers, which is an argument about variances. The token sampler of Sampling and logit processors in AI Engineering walks a cumulative distribution with a strict comparison that must agree bit for bit with a Rust port, and a gateway’s usage-policy classifier (Usage policy enforcement in AI Engineering) reports a precision that can only be interpreted with Bayes’ rule.

Concepts from other sections (15)

This section uses these ideas. Each has a short definition and a link to the section that explains it in full. Tap a dotted term in the text to preview it.

This problem set builds the vocabulary for all of that: the axioms, conditional probability, Bayes, discrete and continuous random variables, their moments, and the normal distribution. It is a pen-and-paper set with 29 exact answers (counting lettered parts) and one proof. The section first reviews the ideas and works two examples by hand; then come the problems, each followed by a collapsed worked answer with the final result, the derivation, and the common wrong answers and why they are wrong. Try each problem before opening its answer. Work it before reading the random-variables and initialization sections of this chapter; the later parts of the set, B, C, and D, follow the categorical-sampling, limit-theorem, and hypothesis-test sections.

You need counting and sets from the Discrete math 1 problem set, the probability and random-variable material in the chapter opening, and the Gaussian integral from the Calculus 2 problem set.

Learning objectives

  • Derive inclusion-exclusion and conditional probability from the three axioms.
  • Use Bayes’ rule and the law of total probability to turn a classifier’s per-class rates into its precision.
  • Compute expectations and variances of discrete and continuous distributions, using linearity and the scaling rules.
  • Sample any invertible distribution from one uniform, with the strict inverse-CDF comparison.
  • Turn two uniforms into two standard normals by Box-Muller, in the order the generator spec fixes.

The set uses these symbols.

SymbolMeaningType / shape
Ω\Omegasample space: the set of possible outcomesset
A,B⊆ΩA, B \subseteq \Omegaeventssets
P(A)P(A)probability of AAreal in [0,1][0, 1]
P(A∣B)P(A \mid B)conditional probability, P(A∩B)/P(B)P(A \cap B)/P(B) for P(B)>0P(B) > 0real
X,YX, Yrandom variables: functions from Ω\Omega to R\mathbb{R}
pX(k)p_X(k)probability mass function, P(X=k)P(X = k)real
fX(x),FX(x)f_X(x), F_X(x)density and cumulative distribution function, FX(x)=P(X≤x)F_X(x) = P(X \le x)real
E[X]E[X]expectation, ∑kk pX(k)\sum_k k\, p_X(k) or ∫xfX(x) dx\int x f_X(x)\, dxreal
Var⁡(X)\operatorname{Var}(X)variance, E[(X−E[X])2]E[(X - E[X])^2]real
UUa uniform random variable on [0,1)[0, 1)real
ZZa standard normal, density φ(z)=e−z2/2/2π\varphi(z) = e^{-z^2/2}/\sqrt{2\pi}real
λ\lambda (lam)rate of a Poisson or exponential distributionpositive real

A probability assigns each event A⊆ΩA \subseteq \Omega a number P(A)P(A) such that P(A)≥0P(A) \ge 0, P(Ω)=1P(\Omega) = 1, and the probability of a countable union of pairwise disjoint events is the sum of their probabilities. Everything else is derived: P(∅)=0P(\emptyset) = 0, P(Ac)=1−P(A)P(A^c) = 1 - P(A), and inclusion-exclusion P(A∪B)=P(A)+P(B)−P(A∩B)P(A \cup B) = P(A) + P(B) - P(A \cap B) (Problem 6). On a finite Ω\Omega of equally likely outcomes, P(A)=∣A∣/∣Ω∣P(A) = \lvert A \rvert / \lvert \Omega \rvert, which makes probability a counting problem.

Conditional probability P(A∣B)=P(A∩B)/P(B)P(A \mid B) = P(A \cap B)/P(B) restricts the sample space to BB and renormalizes. Events are independent when P(A∩B)=P(A)P(B)P(A \cap B) = P(A)P(B), equivalently P(A∣B)=P(A)P(A \mid B) = P(A). The law of total probability splits on a partition B1,…,BkB_1, \dots, B_k of Ω\Omega: P(A)=∑iP(A∣Bi)P(Bi)P(A) = \sum_i P(A \mid B_i) P(B_i). Bayes’ rule inverts a conditional: P(B∣A)=P(A∣B) P(B)P(A).P(B \mid A) = \frac{P(A \mid B)\,P(B)}{P(A)}. For a classifier, P(flag∣bad)P(\text{flag} \mid \text{bad}) is its sensitivity (recall), P(flag∣ok)P(\text{flag} \mid \text{ok}) its false positive rate, and P(bad∣flag)P(\text{bad} \mid \text{flag}) its precision, which depends on the base rate P(bad)P(\text{bad}) as much as on the classifier.

A random variable XX is a numeric function of the outcome, and its distribution is described by the mass function pX(k)=P(X=k)p_X(k) = P(X = k). Expectation E[X]=∑kk pX(k)E[X] = \sum_k k\, p_X(k) is linear, E[aX+bY]=aE[X]+bE[Y]E[aX + bY] = aE[X] + bE[Y], for any XX and YY, independent or not. Variance is Var⁡(X)=E[(X−μ)2]=E[X2]−μ2\operatorname{Var}(X) = E[(X - \mu)^2] = E[X^2] - \mu^2 with μ=E[X]\mu = E[X]; it satisfies Var⁡(aX+b)=a2Var⁡(X)\operatorname{Var}(aX + b) = a^2 \operatorname{Var}(X), and for independent X,YX, Y, Var⁡(X+Y)=Var⁡(X)+Var⁡(Y)\operatorname{Var}(X + Y) = \operatorname{Var}(X) + \operatorname{Var}(Y). The distributions the set uses are these.

DistributionValuesP(X=k)P(X = k)E[X]E[X]
Bernoulli(pp){0,1}\{0, 1\}pp for 1, 1−p1 - p for 0pp
Binomial(n,pn, p){0,…,n}\{0, \dots, n\}(nk)pk(1−p)n−k\binom{n}{k} p^k (1-p)^{n-k}npnp (a sum of nn Bernoullis)
Geometric(pp){1,2,… }\{1, 2, \dots\}(1−p)k−1p(1-p)^{k-1} pderive it in Problem 9
Poisson(λ\lambda){0,1,… }\{0, 1, \dots\}e−λλk/k!e^{-\lambda} \lambda^k / k!λ\lambda
Categorical(qq){0,…,V−1}\{0, \dots, V-1\}qkq_k∑kk qk\sum_k k\, q_k

A language model’s next-token distribution is a categorical over the vocabulary. To sample it from one uniform uu, walk the ids in order with a running total cc and return the first id with u<cu < c (spec/sampling.md step 11). The id returned is kk exactly when q0+⋯+qk−1≤u<q0+⋯+qkq_0 + \dots + q_{k-1} \le u < q_0 + \dots + q_k, an interval of length qkq_k, so each id comes up with its probability.

Continuous random variables and the normal

Section titled “Continuous random variables and the normal”

A continuous XX has a density fX≥0f_X \ge 0 with ∫fX=1\int f_X = 1, and P(a≤X≤b)=∫abfX(x) dxP(a \le X \le b) = \int_a^b f_X(x)\,dx; its CDF is FX(x)=∫−∞xfXF_X(x) = \int_{-\infty}^x f_X. Expectation becomes an integral, E[g(X)]=∫g(x)fX(x) dxE[g(X)] = \int g(x) f_X(x)\,dx, with the same linearity and variance rules. The uniform on [0,1][0, 1] has f=1f = 1 there. The exponential with rate λ\lambda has F(x)=1−e−λxF(x) = 1 - e^{-\lambda x} for x≥0x \ge 0. Inverse-CDF sampling sets X=F−1(U)X = F^{-1}(U): then P(X≤x)=P(U≤F(x))=F(x)P(X \le x) = P(U \le F(x)) = F(x), so one uniform becomes a draw from any distribution whose CDF can be inverted.

The standard normal ZZ has density φ(z)=e−z2/2/2π\varphi(z) = e^{-z^2/2}/\sqrt{2\pi}, mean 0, and variance 1; the constant comes from the Gaussian integral (Problem 16). X=μ+σZX = \mu + \sigma Z is normal with mean μ\mu and variance σ2\sigma^2. Its CDF has no closed form, so inverse-CDF sampling is awkward, and Box-Muller sidesteps it. For two independent standard normals, the squared radius R2=Z02+Z12R^2 = Z_0^2 + Z_1^2 is exponential with rate 1/21/2, and the angle is uniform on [0,2π)[0, 2\pi), independent of it. Reversing that: draw u1,u2u_1, u_2, set r=−2ln⁡(1−u1)r = \sqrt{-2 \ln(1 - u_1)} (inverse-CDF sampling of the exponential, with 1−u1>01 - u_1 > 0 so the log is finite) and θ=2πu2\theta = 2\pi u_2, and return z0=rcos⁡θz_0 = r\cos\theta and z1=rsin⁡θz_1 = r \sin\theta. spec/pcg32.md fixes the order: z0z_0 is returned, and z1z_1 is kept as the spare for the next call.

These are siblings of Problems 3 and 15, not problems of the set.

Bayes. A spam filter catches 80% of spam and wrongly flags 2% of good mail, and 10% of mail is spam. What fraction of flagged mail is spam? Take 1000 messages: 100 spam, 900 good. Flagged spam: 0.8⋅100=800.8 \cdot 100 = 80. Flagged good: 0.02⋅900=180.02 \cdot 900 = 18. Flagged in total: 9898. So P(spam∣flag)=80/98=40/49≈0.816P(\text{spam} \mid \text{flag}) = 80/98 = 40/49 \approx 0.816. The same through the formula: P(flag)=0.8⋅0.1+0.02⋅0.9=0.098P(\text{flag}) = 0.8 \cdot 0.1 + 0.02 \cdot 0.9 = 0.098, and P(spam∣flag)=0.08/0.098=40/49P(\text{spam} \mid \text{flag}) = 0.08 / 0.098 = 40/49.

Box-Muller. Take 1−u1=e−1/21 - u_1 = e^{-1/2} and u2=1/4u_2 = 1/4. Then r=−2⋅(−1/2)=1r = \sqrt{-2 \cdot (-1/2)} = 1 and θ=2π/4=π/2\theta = 2\pi/4 = \pi/2, so z0=cos⁡(π/2)=0z_0 = \cos(\pi/2) = 0 and the spare is z1=sin⁡(π/2)=1z_1 = \sin(\pi/2) = 1. This is the bookkeeping the random-variables section relies on: two uniforms in, two normals out, z0z_0 first.

Probabilities are exact fractions (7/107/10, not 0.7), and lettered parts are answered separately. The tag after each problem says what kind of answer is expected: [number] an exact value, [expr in ...] a formula in the named variables, [bool] true or false, [proof] a written proof.

Axioms, conditional probability, and Bayes

Section titled “Axioms, conditional probability, and Bayes”

The first six problems exercise the axioms and conditioning, ending with a proof of inclusion-exclusion.

Problem 1. Events AA and BB have P(A)=1/2P(A) = 1/2, P(B)=2/5P(B) = 2/5, and P(A∩B)=1/5P(A \cap B) = 1/5. (a) P(A∪B)P(A \cup B). (b) P(A∣B)P(A \mid B). [number] (c) Are AA and BB independent? [bool]

Answer

(a) 7/107/10. (b) 1/21/2. (c) Yes. (a) Inclusion-exclusion (Problem 6): P(A∪B)=12+25−15=5+4−210=710P(A \cup B) = \frac12 + \frac25 - \frac15 = \frac{5 + 4 - 2}{10} = \frac{7}{10}. A common mistake is 9/109/10, which adds P(A)+P(B)P(A) + P(B) and counts the overlap twice. (b) P(A∣B)=P(A∩B)/P(B)=1/52/5=12P(A \mid B) = P(A \cap B)/P(B) = \frac{1/5}{2/5} = \frac12. A common mistake is 2/52/5, which is P(B∣A)=1/51/2P(B \mid A) = \frac{1/5}{1/2}: the conditioning event goes in the denominator. (c) P(A)P(B)=12⋅25=15=P(A∩B)P(A)P(B) = \frac12 \cdot \frac25 = \frac15 = P(A \cap B), so they are independent; equivalently P(A∣B)=12=P(A)P(A \mid B) = \frac12 = P(A).

Problem 2. Roll two fair six-sided dice. (a) P(the sum is 7)P(\text{the sum is } 7). (b) P(at least one die shows 6)P(\text{at least one die shows } 6). (c) P(the sum is 7∣at least one die shows 6)P(\text{the sum is } 7 \mid \text{at least one die shows } 6). [number]

Answer

(a) 1/61/6. (b) 11/3611/36. (c) 2/112/11. The 36 ordered pairs are equally likely. (a) Six pairs sum to 7, (1,6),(2,5),…,(6,1)(1,6), (2,5), \ldots, (6,1): 6/36=1/66/36 = 1/6. A common mistake is 1/111/11, treating the 11 possible sums 2,…,122, \ldots, 12 as equally likely; they are not (one way to make 2, six ways to make 7). (b) The complement is “no 6 on either die”, (5/6)2=25/36(5/6)^2 = 25/36, so 1−25/36=11/361 - 25/36 = 11/36. Counting directly: 6 pairs with a 6 first, 6 with a 6 second, minus (6,6)(6, 6) counted twice. A common mistake is 1/6+1/6=1/31/6 + 1/6 = 1/3, which double-counts (6,6)(6, 6). (c) Conditioning shrinks the sample space to the 11 pairs with a 6; of those, (1,6)(1, 6) and (6,1)(6, 1) sum to 7: 2/112/11. Common mistakes: 1/61/6 ignores the condition, and 2/362/36 is the joint probability P(sum 7∩a 6)P(\text{sum } 7 \cap \text{a } 6), not the conditional.

Problem 3. The gateway’s usage-policy classifier flags 90% of violating requests and 5% of allowed ones, and 1% of requests violate the policy. (a) What fraction of all requests is flagged? (b) Given that a request is flagged, what is the probability that it violates the policy? [number]

Answer

(a) 117/2000117/2000. (b) 2/132/13. (a) Total probability over violate / allowed: P(flag)=0.9⋅0.01+0.05⋅0.99=0.009+0.0495=0.0585=117/2000P(\text{flag}) = 0.9 \cdot 0.01 + 0.05 \cdot 0.99 = 0.009 + 0.0495 = 0.0585 = 117/2000. A common mistake is 9/10009/1000, which counts only the true positives and forgets that 99% of traffic is allowed, so 5% of it is a much larger pool of flags. (b) Bayes: P(bad∣flag)=0.009/0.0585=90/585=2/13≈0.154P(\text{bad} \mid \text{flag}) = 0.009/0.0585 = 90/585 = 2/13 \approx 0.154. In 10 000 requests: 100 violate and 90 are flagged; 9900 are allowed and 495 are flagged; of 585 flags, 90 are right. The common mistake is 9/109/10, the sensitivity P(flag∣bad)P(\text{flag} \mid \text{bad}) quoted as if it were the precision; the safety report of Bias and safety evals in AI Engineering must quote precision, which the base rate drags down.

Problem 4. Draw 3 bytes independently and uniformly from the 256 byte values. What is the probability that all three are different? [number]

Answer

32385/3276832385/32768. The first byte is anything; the second avoids one value, the third two: 256256⋅255256⋅254256=255⋅25465536=6477065536=3238532768≈0.98831\frac{256}{256} \cdot \frac{255}{256} \cdot \frac{254}{256} = \frac{255 \cdot 254}{65536} = \frac{64770}{65536} = \frac{32385}{32768} \approx 0.98831. This is the birthday computation over the byte alphabet. A common mistake is 1−3/2561 - 3/256: the union bound says P(some pair equal)≤(32)/256=3/256P(\text{some pair equal}) \le \binom32/256 = 3/256, which is an inequality, not the exact answer (1−3/256=0.988281 - 3/256 = 0.98828 is slightly too small because the three pair-collision events overlap).

Problem 5. A bag holds a fair coin and a coin that lands heads with probability 3/43/4. Pick one of the two uniformly at random and flip it. (a) P(heads)P(\text{heads}). (b) P(the biased coin was picked∣heads)P(\text{the biased coin was picked} \mid \text{heads}). [number]

Answer

(a) 5/85/8. (b) 3/53/5. (a) Total probability: 12⋅12+12⋅34=14+38=58\frac12 \cdot \frac12 + \frac12 \cdot \frac34 = \frac14 + \frac38 = \frac58. A common mistake is 3/43/4, the biased coin’s rate, as if it were always picked. (b) Bayes: P(biased∩heads)P(heads)=3/85/8=35\frac{P(\text{biased} \cap \text{heads})}{P(\text{heads})} = \frac{3/8}{5/8} = \frac35. A common mistake is 3/83/8, the joint probability, without dividing by P(heads)P(\text{heads}). Heads is evidence for the biased coin, so the posterior 3/53/5 rises above the prior 1/21/2.

Problem 6. From the three axioms (P(E)≥0P(E) \ge 0; P(Ω)=1P(\Omega) = 1; PP of a countable union of pairwise disjoint events is the sum of their probabilities) prove P(A∪B)=P(A)+P(B)−P(A∩B)P(A \cup B) = P(A) + P(B) - P(A \cap B) for any events AA and BB. [proof]

Answer (model proof)

Claim. For any events A,BA, B, P(A∪B)=P(A)+P(B)−P(A∩B)P(A \cup B) = P(A) + P(B) - P(A \cap B).

Method. Split each set into disjoint pieces and apply the third axiom. A finite union is a countable one padded with empty sets, and P(∅)=0P(\emptyset) = 0 follows from additivity applied to ∅=∅∪∅∪⋯\emptyset = \emptyset \cup \emptyset \cup \cdots together with P≥0P \ge 0. Write B∖A=B∩AcB \setminus A = B \cap A^c.

  1. A∪B=A∪(B∖A)A \cup B = A \cup (B \setminus A), and AA and B∖AB \setminus A are disjoint (an element of B∖AB \setminus A is not in AA). By additivity, P(A∪B)=P(A)+P(B∖A)P(A \cup B) = P(A) + P(B \setminus A).
  2. B=(A∩B)∪(B∖A)B = (A \cap B) \cup (B \setminus A), and these two are disjoint (one lies inside AA, the other outside it). By additivity, P(B)=P(A∩B)+P(B∖A)P(B) = P(A \cap B) + P(B \setminus A), so P(B∖A)=P(B)−P(A∩B)P(B \setminus A) = P(B) - P(A \cap B).
  3. Substituting step 2 into step 1: P(A∪B)=P(A)+P(B)−P(A∩B)P(A \cup B) = P(A) + P(B) - P(A \cap B). ■\blacksquare

Every step used only set identities and the additivity axiom. A complete proof must (i) write both A∪BA \cup B and BB as disjoint unions, (ii) apply additivity to each, (iii) eliminate P(B∖A)P(B \setminus A), and (iv) name each step. A common gap is to “subtract the overlap because it was counted twice”, which is the intuition, not a proof from the axioms. The model proof is also in course/solutions/solve/S-M07a/q6.md.

The next five problems compute means and variances of the standard discrete distributions and walk the inverse CDF of a categorical.

Problem 7. XX is a fair die roll, uniform on {1,…,6}\{1, \dots, 6\}. (a) E[X]E[X]. (b) E[X2]E[X^2]. (c) Var⁡(X)\operatorname{Var}(X). [number]

Answer

(a) 7/27/2. (b) 91/691/6. (c) 35/1235/12. (a) (1+⋯+6)/6=21/6=7/2(1 + \cdots + 6)/6 = 21/6 = 7/2; a common slip is 3, which is not the midpoint of 1..61..6. (b) (1+4+9+16+25+36)/6=91/6(1 + 4 + 9 + 16 + 25 + 36)/6 = 91/6. A common mistake is 49/4=(E[X])249/4 = (E[X])^2: the mean of the squares is not the square of the mean. (c) E[X2]−E[X]2=916−494=182−14712=3512E[X^2] - E[X]^2 = \frac{91}{6} - \frac{49}{4} = \frac{182 - 147}{12} = \frac{35}{12}, matching the two-pass computation in Random variables, expectation, variance, and normal draws by Box-Muller. Common mistakes: 35/235/2, the sum of squared deviations 2(6.25+2.25+0.25)=17.52(6.25 + 2.25 + 0.25) = 17.5 not divided by 6; and 7/27/2, that sum divided by n−1=5n - 1 = 5, which is the sample variance formula, not the variance of a known distribution.

Problem 8. (a) Give Var⁡(X)\operatorname{Var}(X) for X∼Bernoulli(p)X \sim \mathrm{Bernoulli}(p). [expr in p] (b) Give Var⁡(Y)\operatorname{Var}(Y) for Y∼Binomial(n,p)Y \sim \mathrm{Binomial}(n, p), the number of successes in nn independent Bernoulli(pp) trials. [expr in n, p]

Answer

(a) p(1−p)p(1 - p). (b) np(1−p)np(1 - p). (a) X2=XX^2 = X for a 0/1 variable, so E[X2]=pE[X^2] = p and Var⁡(X)=p−p2=p(1−p)\operatorname{Var}(X) = p - p^2 = p(1-p). Common mistakes: pp (the mean) and p2p^2 (the squared mean). (b) Y=X1+⋯+XnY = X_1 + \cdots + X_n with independent XiX_i, and variances of independent sums add: np(1−p)n p(1-p). A common mistake is n2p(1−p)n^2 p(1 - p), which is Var⁡(nX1)\operatorname{Var}(nX_1): one trial scaled by nn, perfectly correlated, not nn independent trials. The difference is why the standard error of an accuracy shrinks like 1/n1/\sqrt n (LLN, CLT, confidence intervals, bootstrap, and the evaluation harness of The evaluation harness and the model zoo).

Problem 9. XX counts independent Bernoulli(pp) trials up to and including the first success, so X∈{1,2,3,… }X \in \{1, 2, 3, \dots\}. Give E[X]E[X]. [expr in p]

Answer

1/p1/p. First-step analysis: one trial is always made; with probability 1−p1 - p it fails and the process starts afresh, so E[X]=1+(1−p)E[X]E[X] = 1 + (1 - p)E[X], giving pE[X]=1pE[X] = 1. Directly: E[X]=∑k≥1k(1−p)k−1p=p⋅1(1−(1−p))2=1pE[X] = \sum_{k \ge 1} k (1-p)^{k-1} p = p \cdot \frac{1}{(1 - (1-p))^2} = \frac1p, using ∑k≥1krk−1=1/(1−r)2\sum_{k \ge 1} k r^{k-1} = 1/(1-r)^2. A common mistake is (1−p)/p(1 - p)/p, the expected number of failures before the first success; it differs by the success trial itself.

Problem 10. A sampler draws a token id from the categorical distribution q=(1/10,2/10,3/10,4/10)q = (1/10, 2/10, 3/10, 4/10) over ids 0,1,2,30, 1, 2, 3. (a) Give E[id]E[\text{id}]. The sampler then uses the inverse CDF of spec/sampling.md: walk the ids in ascending order adding qiq_i to a running total cc, and return the first id with u<cu < c. Which id does it return for (b) u=0.35u = 0.35 and (c) u=0.3u = 0.3 (exactly)? [number]

Answer

(a) 22. (b) 22. (c) 22. (a) 0⋅0.1+1⋅0.2+2⋅0.3+3⋅0.4=0.2+0.6+1.2=20 \cdot 0.1 + 1 \cdot 0.2 + 2 \cdot 0.3 + 3 \cdot 0.4 = 0.2 + 0.6 + 1.2 = 2. A common mistake is 3/23/2, the plain mean of the ids, which ignores qq. (b) The running totals are 0.1,0.3,0.6,1.00.1, 0.3, 0.6, 1.0; 0.35<0.10.35 < 0.1 and 0.35<0.30.35 < 0.3 fail, 0.35<0.60.35 < 0.6 holds: id 2. (c) 0.3<0.10.3 < 0.1 fails and 0.3<0.30.3 < 0.3 fails (strict), 0.3<0.60.3 < 0.6 holds: id 2. Id 1 owns [0.1,0.3)[0.1, 0.3), half open, so its right end belongs to id 2. The common mistake is id 1, from u≤cu \le c; then a Python and a Rust sampler that disagree on the comparison return different tokens at boundaries. (In float64 the running total 0.1+0.20.1 + 0.2 is 0.300000000000000040.30000000000000004, slightly above the double 0.30.3, so a float sampler returns id 1 here; the question asks for the exact-arithmetic rule, and the spec fixes the float operations so every port rounds the same way.)

Problem 11. X∼Poisson(λ)X \sim \mathrm{Poisson}(\lambda) has P(X=k)=e−λλk/k!P(X = k) = e^{-\lambda} \lambda^k / k!. Give P(X=0)P(X = 0). [expr in lam]

Answer

e−λe^{-\lambda}. Set k=0k = 0: λ0/0!=1\lambda^0/0! = 1. This is also the probability that an exponential waiting time with rate λ\lambda exceeds 1, which is how Poisson arrivals (in Categorical sampling) and the exponential connect. A common mistake is 1−e−λ1 - e^{-\lambda}, which is P(X≥1)P(X \ge 1).

Continuous random variables, the normal, and Box-Muller

Section titled “Continuous random variables, the normal, and Box-Muller”

The last five problems move to densities: the uniform and exponential, scaling a normal, Box-Muller, and the Gaussian integral that normalizes it all.

Problem 12. UU is uniform on [0,1][0, 1]. (a) E[U]E[U]. (b) Var⁡(U)\operatorname{Var}(U). [number]

Answer

(a) 1/21/2. (b) 1/121/12. (a) ∫01u du=1/2\int_0^1 u\,du = 1/2. (b) E[U2]=∫01u2 du=1/3E[U^2] = \int_0^1 u^2\,du = 1/3, so Var⁡(U)=1/3−1/4=1/12\operatorname{Var}(U) = 1/3 - 1/4 = 1/12. A common mistake is 1/31/3, which is E[U2]E[U^2] without subtracting the squared mean. Scaling gives Var⁡ U(−a,a)=(2a)2/12=a2/3\operatorname{Var}\,\mathcal{U}(-a, a) = (2a)^2/12 = a^2/3, the fact behind Xavier-uniform’s bound in Variance propagation and initialization.

Problem 13. X∼Exponential(λ)X \sim \mathrm{Exponential}(\lambda) has CDF F(x)=1−e−λxF(x) = 1 - e^{-\lambda x} for x≥0x \ge 0. (a) Give the inverse-CDF sampler: the xx with F(x)=uF(x) = u. [expr in u, lam] (b) Give E[X]E[X]. [expr in lam]

Answer

(a) −ln⁡(1−u)/λ-\ln(1 - u)/\lambda. (b) 1/λ1/\lambda. (a) 1−e−λx=u⇒e−λx=1−u⇒x=−ln⁡(1−u)/λ1 - e^{-\lambda x} = u \Rightarrow e^{-\lambda x} = 1 - u \Rightarrow x = -\ln(1-u)/\lambda. This is exponential_icdf from Categorical sampling. Common mistakes: −λln⁡(1−u)-\lambda\ln(1-u), multiplying by the rate (a higher rate must mean shorter waits), and e−λue^{-\lambda u}, the survival function evaluated at uu, not its inverse. (b) E[X]=∫0∞P(X>x) dx=∫0∞e−λx dx=1/λE[X] = \int_0^\infty P(X > x)\,dx = \int_0^\infty e^{-\lambda x}\,dx = 1/\lambda. A common mistake is λ\lambda: the rate is events per unit time, and the mean wait is its reciprocal.

Problem 14. ZZ is a standard normal and a,ba, b are constants. Give Var⁡(aZ+b)\operatorname{Var}(aZ + b). [expr in a, b]

Answer

a2a^2. Var⁡(aZ+b)=E[(aZ+b−b)2]=a2E[Z2]=a2\operatorname{Var}(aZ + b) = E[(aZ + b - b)^2] = a^2 E[Z^2] = a^2, since E[aZ+b]=bE[aZ + b] = b and Var⁡(Z)=1\operatorname{Var}(Z) = 1. normal_init(std) in Variance propagation and initialization is std⋅Z\text{std} \cdot Z, with variance std2\text{std}^2. Common mistakes: a2+ba^2 + b (a shift does not spread the distribution) and aa, which confuses the variance with the standard deviation ∣a∣\lvert a \rvert.

Problem 15. spec/pcg32.md turns two uniforms into two normals by Box-Muller: r=−2ln⁡(1−u1)r = \sqrt{-2 \ln(1 - u_1)}, then z0=rcos⁡(2πu2)z_0 = r \cos(2\pi u_2) is returned and z1=rsin⁡(2πu2)z_1 = r \sin(2\pi u_2) is kept as the spare. For u1u_1 with 1−u1=e−21 - u_1 = e^{-2} and u2=1/12u_2 = 1/12, give (a) z0z_0 and (b) z1z_1. [number]

Answer

(a) 3\sqrt3. (b) 11. r=−2ln⁡e−2=4=2r = \sqrt{-2 \ln e^{-2}} = \sqrt4 = 2 and θ=2π/12=π/6\theta = 2\pi/12 = \pi/6. (a) z0=2cos⁡(π/6)=2⋅32=3z_0 = 2\cos(\pi/6) = 2 \cdot \frac{\sqrt3}{2} = \sqrt3. (b) z1=2sin⁡(π/6)=2⋅12=1z_1 = 2\sin(\pi/6) = 2 \cdot \frac12 = 1. Common mistakes for (a): 11, from swapping sine and cosine (the spec emits the cosine first, and every port must agree); and 3/2\sqrt3/2, from forgetting the radius. For (b), 3\sqrt3 is the same swap.

Problem 16. Give ∫−∞∞e−x2/2 dx\int_{-\infty}^{\infty} e^{-x^2/2}\, dx, the constant that normalizes the standard normal density. [number]

Answer

2π\sqrt{2\pi}. Square the integral and switch to polar coordinates: I2=∬e−(x2+y2)/2 dx dy=∫02π ⁣ ⁣∫0∞e−r2/2 r dr dθ=2π⋅[−e−r2/2]0∞=2πI^2 = \iint e^{-(x^2 + y^2)/2}\,dx\,dy = \int_0^{2\pi}\!\!\int_0^\infty e^{-r^2/2}\, r\,dr\,d\theta = 2\pi \cdot \bigl[-e^{-r^2/2}\bigr]_0^\infty = 2\pi, so I=2πI = \sqrt{2\pi}. The same polar picture, run backwards, is Box-Muller (see “Continuous random variables and the normal” above). Common mistakes: π\sqrt\pi, which is ∫e−x2 dx\int e^{-x^2}\,dx (no factor 12\tfrac12 in the exponent), and 11, which is the integral of the already normalized density.

The wrong answers in this set cluster around a handful of habits, and each has a downstream cost. Adding the probabilities of overlapping events can push P(A∪B)P(A \cup B) above 1 for large events; the fix is to subtract the overlap (Problems 1a and 2b). Confusing P(A∣B)P(A \mid B) with P(B∣A)P(B \mid A) quotes a classifier’s recall as its precision; Bayes with the base rate in the numerator and P(flag)P(\text{flag}) below gets it right (Problems 3b and 5b). Treating unequal outcomes as equally likely gives each of the 11 dice sums probability 1/11; counting the 36 equally likely ordered pairs does not (Problem 2a).

Warning: Computing variance as E[X2]E[X^2], or with n−1n - 1 in a population formula, puts initialization scales off by the squared mean. Use E[X2]−E[X]2E[X^2] - E[X]^2 over the known distribution (Problems 7c and 12b). Likewise, a shift never changes variance, Var⁡(aZ+b)=a2\operatorname{Var}(aZ + b) = a^2 (Problem 14), so a normal_init with a nonzero mean would break the variance argument of the initialization section.

The two sampling pitfalls matter for cross-language parity. Using u≤cu \le c instead of u<cu < c in the inverse CDF makes a Python and a Rust sampler disagree at boundaries; half-open intervals send u=0.3u = 0.3 to id 2 (Problem 10c). Swapping sine and cosine, or forgetting the radius, makes normals differ from spec/pcg32.md; the spec has z0=rcos⁡θz_0 = r\cos\theta, with r=2r = 2 in Problem 15.

The counting behind Problems 2 and 4 comes from the Discrete math 1 problem set. Next in this chapter, Random variables, expectation, variance, and normal draws by Box-Muller builds normal, expectation, and variance over PCG32, checked by sample moments and a chi-square test; Variance propagation and initialization uses variance propagation to pick the xavier_* and kaiming_normal scales; and Categorical sampling: inverse CDF, Gumbel-max, alias method samples categoricals three ways, followed by problem set B. Further on, the sampler of Sampling and logit processors in AI Engineering uses the inverse-CDF step with the strict comparison of Problem 10, and Usage policy enforcement in AI Engineering reports the policy head’s precision and recall, which you now read with Problem 3.

  • Blitzstein and Hwang, Introduction to Probability (free), ch. 1 to 5.
  • Box and Muller, “A Note on the Generation of Random Normal Deviates” (1958).
  • Probability axioms: non-negativity, P(Ω)=1P(\Omega) = 1, and countable additivity over disjoint events; every other rule is derived from them.
  • Conditional probability: P(A∣B)=P(A∩B)/P(B)P(A \mid B) = P(A \cap B)/P(B), probability restricted to BB and renormalized.
  • Bayes’ rule: P(B∣A)=P(A∣B)P(B)/P(A)P(B \mid A) = P(A \mid B) P(B) / P(A), which inverts a conditional using the base rate.
  • Precision: P(bad∣flag)P(\text{bad} \mid \text{flag}), the fraction of flags that are right; unlike sensitivity it depends on the base rate.
  • Variance: E[X2]−E[X]2E[X^2] - E[X]^2; it scales by a2a^2 and adds over independent sums.
  • Inverse-CDF sampling: X=F−1(U)X = F^{-1}(U), which turns one uniform into a draw from FF.
  • Box-Muller: the transform r=−2ln⁡(1−u1)r = \sqrt{-2\ln(1-u_1)}, θ=2πu2\theta = 2\pi u_2 that turns two uniforms into two independent standard normals.
  • Probability is a function on events with three axioms; inclusion-exclusion and conditioning follow from them (Problems 1 and 6).
  • Bayes’ rule turns a classifier’s per-class rates into the probability a flag is right, and with a 1% base rate a 90%-sensitive classifier is right only 2 times in 13 (Problem 3).
  • Expectation is linear and variance is E[X2]−E[X]2E[X^2] - E[X]^2; variances of independent sums add, and a scale aa multiplies variance by a2a^2 (Problems 7, 8, and 14).
  • An inverse CDF turns one uniform into any distribution, and its comparison is strict: u<cu < c, so a uu landing exactly on a boundary goes to the next id (Problems 10 and 13).
  • Box-Muller turns two uniforms into two independent standard normals, cosine first, sine as the spare (Problem 15).