MODULE 16

Discrete Probability Calculator: Bayes' Theorem & Expectation

Event Probability

Conditional Probability P(A|B)

Independence Check

Bayes' Theorem

P(A) = prior, P(B|A) and P(B|A') = likelihoods.

Expected Value & Variance

What is Probability?

Probability quantifies uncertainty, assigning a number between 0 and 1 to how likely an outcome is. Discrete probability connects directly to counting, since most probabilities reduce to favorable outcomes over total outcomes.

How Does This Calculator Work?

Enter your sample space, event, or conditional setup depending on which calculation you need, and the tool shows the favorable-over-total reasoning or Bayes' theorem substitution step by step.

Common Formulas & Rules

  • Sample space: the set of all possible outcomes of an experiment.
  • Event: any subset of the sample space.
  • P(A) = favorable outcomes / total outcomes, for equally likely outcomes.
  • Independence: events A and B are independent if P(A ∩ B) = P(A)·P(B).
  • Conditional probability P(A|B): the probability of A given that B has already occurred, = P(A ∩ B) / P(B).
  • Bayes' theorem: relates P(A|B) to P(B|A), letting you "flip" conditional probabilities.

Worked Example

Rolling two fair dice, what's the probability the sum is 7? There are 36 equally likely outcomes total, and exactly 6 of them sum to 7: (1,6),(2,5),(3,4),(4,3),(5,2),(6,1). So P(sum=7) = 6/36 = 1/6 — the most likely single sum when rolling two dice.

Study guide: Probability

Written for students learning this topic for the first time. Last updated October 2026.

Overview

Discrete probability deals with a finite or countable set of outcomes. When outcomes are equally likely, the probability of an event is the number of favorable outcomes divided by the total, so counting is the main tool.

Conditional probability, independence, Bayes' theorem and expectation extend this to reasoning when you have partial information.

Key ideas explained

Sample spaces and the basic rules

The sample space S is the set of all outcomes and an event is a subset. Probabilities satisfy 0 ≤ P(E) ≤ 1, P(S) = 1, P(E′) = 1 − P(E) and P(A ∪ B) = P(A) + P(B) − P(A ∩ B).

Conditional probability and independence

P(A | B) = P(A ∩ B) / P(B). Events are independent when P(A ∩ B) = P(A)·P(B), equivalently P(A | B) = P(A). Independent is not the same as mutually exclusive: two mutually exclusive events with positive probability are always dependent.

Bayes' theorem

P(A | B) = P(B | A)·P(A) / P(B), where P(B) = P(B | A)·P(A) + P(B | A′)·P(A′). It reverses the direction of conditioning, and it shows why the base rate of A matters.

Expectation and variance

E[X] = Σ x·P(x). Expectation is linear: E[X + Y] = E[X] + E[Y] even when X and Y are dependent. Var(X) = E[X²] − (E[X])². A fair die has E = 3.5 and Var = 35/12.

Worked examples

Counting outcomes with two dice

Problem. Find P(sum = 8) for two fair dice, and P(sum = 8 | first die is 3).

  1. There are 36 equally likely outcomes.
  2. Sum 8 occurs for (2,6), (3,5), (4,4), (5,3), (6,2): five outcomes.
  3. If the first die is 3, the second must be 5, which is one of the six equally likely values.

Answer. P(sum = 8) = 5/36 and P(sum = 8 | first = 3) = 1/6.

Bayes' theorem and the base rate

Problem. A condition affects 1% of people. A test is positive for 95% of those who have it and for 5% of those who do not. What is P(condition | positive)?

  1. Numerator: 0.95 × 0.01 = 0.0095.
  2. P(positive) = 0.95 × 0.01 + 0.05 × 0.99 = 0.0095 + 0.0495 = 0.059.
  3. Divide: 0.0095 / 0.059 ≈ 0.161.

Answer. About 16.1%. Most positive results are false alarms because the condition is rare.

Enter these same values in the calculator above and compare each step with the working shown here.

Common mistakes to avoid

  • Base-rate neglect: treating P(positive | condition) as if it were P(condition | positive).
  • Multiplying probabilities of events that are not independent.
  • The gambler's fallacy: past independent outcomes do not change the next one.
  • Equating “mutually exclusive” with “independent”.
  • Adding probabilities of overlapping events without subtracting the intersection.

Where this shows up in computer science

  • Naive Bayes classifiers, used in spam filtering, apply Bayes' theorem to word frequencies.
  • Randomized algorithms and hashing are analysed with expected values, for example the expected number of collisions.
  • Reliability engineering and A/B testing depend on independence and conditional probability.

Test yourself

Try each question before opening the answer.

What is the probability of at least one head in 3 fair coin flips?

1 − (1/2)³ = 7/8.

What is the expected value of a fair six-sided die?

3.5.

If P(A) = 0.4, P(B) = 0.5 and A, B are independent, what is P(A ∪ B)?

0.4 + 0.5 − 0.4·0.5 = 0.7.

Frequently asked questions

What's the difference between independent and mutually exclusive events?

Independent events don't affect each other's probability (P(A∩B) = P(A)·P(B)). Mutually exclusive events can never both happen (P(A∩B) = 0). Two events with non-zero probability can't be both independent and mutually exclusive at once.

What does Bayes' theorem actually do?

Bayes' theorem lets you "flip" a conditional probability: given P(B|A), it computes P(A|B). It's the mathematical basis for updating beliefs as new evidence arrives, used heavily in spam filters and medical testing.

How do you calculate expected value?

Multiply each possible outcome by its probability, then sum the results. It represents the long-run average value you'd expect if you repeated the experiment many times.