Probability problem solver: dice, urns, Bayes' theorem, Bernoulli trials
Classical probability by counting outcomes, drawing from an urn, total probability and Bayes’ theorem with a tree and “natural frequencies”, Bernoulli trials with an exact answer and the De Moivre–Laplace approximation, expectation and variance from a table.
two dice, sum greater than 8
an urn has 7 white and 3 black, draw 4, exactly 1 black
prevalence 1%, sensitivity 99%, false positive rate 5%
P(H) = 0.5; 0.3; 0.2, P(A|H) = 0.01; 0.02; 0.03
n = 10, p = 0.3, k = 3
n = 100, p = 0.8, from 75 to 90
3 coins, at least one head
x: 0; 1; 2, p: 0.2; 0.5; 0.3
Loading the solver…
What problems it solves
School and first-year probability problems almost always belong to one of a few types, and each type has its own scheme of solution. Choose the type above the input field or write the problem briefly, as in the examples. The solver answers with an exact fraction, a decimal and a percentage, explains every step and checks the answer another way: by listing outcomes, by recounting in “natural frequencies”, or by adding up all the probabilities.
Classical probability: counting outcomes
If an experiment can end in $n$ equally likely ways and $m$ of them favour an event, its probability is simply the proportion: $P = \frac{m}{n}$. The whole difficulty is counting the outcomes correctly, and the main trap is counting them so that they stop being equally likely. Two dice have 36 outcomes, not 11 possible sums: a sum of 7 comes up in six ways (1 + 6, 2 + 5, …, 6 + 1), a sum of 12 in only one. Imagine the dice painted different colours: then 1 + 6 and 6 + 1 are different outcomes.
When drawing from an urn, the outcomes are the sets of balls drawn, and combinatorics counts them. If an urn has $N$ balls, $K$ of them black, and we draw $n$ at random, then
If the question asks for “at least one”, it’s almost always simpler to count the complementary event “none” and subtract it from one. That’s what the solver does when the complement is shorter.
Total probability and Bayes’ theorem
These problems come in two stages: first one of several hypotheses happens (a part was made at the first, second or third factory; a person is ill or healthy), then an event whose probability depends on the hypothesis. Draw a tree: from the root, branches for the hypotheses; from each, a branch for the event. The probability of a path is the product of the numbers on its branches, and the probability of the event is the sum of the paths that lead to it. That’s the law of total probability: $P(A) = \sum P(H_i)\,P(A \mid H_i)$.
Bayes’ theorem answers the reverse question: the event has happened, so what’s the probability of the hypothesis now? The answer is the share of its path among all the paths that lead to the event.
The result surprises almost everyone: the test is accurate, yet after a positive result the person is ill with a probability of only about $17\,\%$. The easiest way to see it is in “natural frequencies”. Out of 10,000 people, 100 are ill, and the test finds 99 of them. There are 9900 healthy people, and the test is wrong for 495 of them. There are 594 positive results, and 99 of them are ill: exactly one in six. The solver shows these numbers on a tree and on an area square; more about medical tests is in the chapter on probability.
Bernoulli trials
An experiment is repeated $n$ times independently, and each time a “success” happens with the same probability $p$: shots at a target, coin tosses, seeds germinating. The number of successes $X$ can be anything from 0 to $n$.
For questions like “at least”, “at most”, “from … to”, the probabilities of the relevant $k$ are added: the events “exactly 3 successes” and “exactly 4” can’t happen together. For large $n$ there are many terms, and by hand they’re replaced by the De Moivre–Laplace approximation: $X$ behaves almost like a normal variable with mean $np$ and standard deviation $\sqrt{npq}$. The solver computes both exactly and approximately, and says honestly how far off the approximation was. If $npq$ is less than 9, the error can be noticeable. For small $p$ and large $n$ the Poisson approximation is more accurate.
Expectation and variance from a table
If a random variable is given by a table of values $x_i$ and probabilities $p_i$, its expectation is the weighted average, $\mathbb{E}X = \sum x_i p_i$, and its variance is the mean square deviation from it. It’s easier to compute as $\operatorname{Var} X = \mathbb{E}X^2 - (\mathbb{E}X)^2$. The standard deviation $\sigma = \sqrt{\operatorname{Var} X}$ measures the spread in the same units as the variable itself. The first thing the solver does is check that the probabilities in the table add up to 1, and if one is unknown (you can put “?” in its place), it finds it from that condition.
Worked examples
Example 1. Two dice, a sum greater than 8
There are $6 \cdot 6 = 36$ outcomes, all equally likely. A sum of 9 comes up in 4 ways (3 + 6, 4 + 5, 5 + 4, 6 + 3), 10 in three, 11 in two, 12 in one. There are $4 + 3 + 2 + 1 = 10$ favourable outcomes, and $P = \frac{10}{36} = \frac{5}{18} \approx 0.278$.
Example 2. A faulty part
Three factories make $50\,\%$, $30\,\%$ and $20\,\%$ of the parts, and their fault rates are $1\,\%$, $2\,\%$ and $3\,\%$. The probability of a fault: $0.5 \cdot 0.01 + 0.3 \cdot 0.02 + 0.2 \cdot 0.03 = 0.005 + 0.006 + 0.006 = 0.017$. A faulty part turns up: what’s the probability it came from the first factory? $\frac{0.005}{0.017} = \frac{5}{17} \approx 0.29$. The first factory makes half the parts but less than a third of the faulty ones: it’s the most careful.
Example 3. Five shots
A marksman hits the target with probability 0.8. What is the probability of at least 4 hits out of 5? $P(X = 4) = \binom{5}{4} \cdot 0.8^4 \cdot 0.2 = 5 \cdot 0.4096 \cdot 0.2 = 0.4096$, $P(X = 5) = 0.8^5 = 0.32768$. Add them: $0.73728$. Here $npq = 0.8$, and the integral De Moivre–Laplace formula gives about 0.37, half the exact answer. For five trials it mustn’t be used.
Example 4. A distribution table
$X$ takes the values 0, 1, 2 with probabilities 0.2, 0.5, 0.3. The probabilities add up to 1, so the table is valid. $\mathbb{E}X = 0 \cdot 0.2 + 1 \cdot 0.5 + 2 \cdot 0.3 = 1.1$, $\mathbb{E}X^2 = 0.5 + 4 \cdot 0.3 = 1.7$, $\operatorname{Var} X = 1.7 - 1.1^2 = 0.49$, $\sigma = 0.7$.
Common mistakes
- Outcomes that aren’t equally likely. The sums of two dice, or “two heads / a head and a tail / two tails”, aren’t equally likely. Count ordered outcomes.
- Confusing $P(A \mid B)$ with $P(B \mid A)$. “The test detects $99\,\%$ of the ill” is $P(+ \mid \text{ill})$, while the question is usually about $P(\text{ill} \mid +)$. These are different numbers, and Bayes’ theorem links them.
- Adding the probabilities of events that can happen together. $P(A \text{ or } B) = P(A) + P(B)$ only if $A$ and $B$ can’t both happen. Otherwise subtract $P(A \text{ and } B)$.
- Forgetting the complementary event. “At least once in ten tries” is $1 - q^{10}$, not $10p$: with $p = 0.2$ the latter gives the impossible probability 2.
- Multiplying the probabilities of dependent events. A white ball was drawn and not put back, so the urn has changed, and the probability of a second white ball is different.
- Hypotheses whose probabilities don’t add up to 1. If the hypotheses overlap or one is missing, the law of total probability gives nonsense.
See also
How probability fools intuition (the Monty Hall door, the shared birthday, the gambler’s fallacy and the prosecutor’s fallacy) is told in the chapter on probability: the medical test in the section “Case three: a positive result”, birthdays in “Case four: a shared birthday”. Random variables and the binomial and normal distributions are in the chapter on random variables. The combinatorics solver will help count the outcomes of complicated draws, and where the binomial coefficients in the Bernoulli formula come from is explained in the chapter on combinatorics.
Where this is explained
Other solvers
- Quadratic equation
- Linear equation
- System of linear equations
- Higher-degree equations and factoring
- Inequalities by the interval method
- Derivative
- Integral
- Limit
- Curve sketching
- Fraction arithmetic
- GCD, LCM and Euclid's algorithm
- Prime factorisation
- Solving a triangle
- Matrices: determinant, inverse, rank, eigenvalues
- Trigonometric equation
- Exponential and logarithmic equations
- Percentages, compound interest, loans
- Permutations and combinations
- Number bases
- Complex numbers
- Congruences
- Progressions
- Differential equation