1 of 105

CS109: Probability for Computer Scientists

1

Chris Gregg

Summer 2026

2 of 105

We are in a paradigm-changing world…

2

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

3 of 105

CS109 is a stepping stone to understanding this new world

Probability is the core concept in machine learning and artificial intelligence algorithms!

This class is an applied mathematics course on probability

You will be seeing and writing code (in Python)

We will build on many concepts that lead to machine learning

Today:

We will discuss course logistics

We will start to talk about sample spaces, event spaces, and the meaning of a probability.

3

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

4 of 105

Who is Chris Gregg

  • Education:
    • BS Electrical Engineering, Johns Hopkins
    • MS Education, Harvard
    • Ph.D. Computer Engineering, University of Virginia
  • U.S. Naval Officer
    • Seven years Active Duty
    • 15+ years Reserves
    • Cryptologist / Information Warfare Officer
    • Lived in San Diego (2x WestPac deployments), Australia, Djibouti
  • Teaching
    • High School Phyiscs
      • Brookline High School, Brookline, MA
      • Pacific Collegiate School, Santa Cruz, CA
    • Computer Science
      • Tufts University
      • Stanford University

4

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

5 of 105

Who is Chris Gregg

  • I love teaching, and my current research focuses on computer science education
  • I have been teaching for 25 years, and cannot think of a better job
  • I love tinkering, and electronics. Check out some of my typewriter tinkering (1) and (2)
  • At Stanford, I have taught CS106A, CS106B, CS107, CS107E, CS181W, CS208E, CS298, and now (first time!), CS109
  • If you are interested in teaching, or in CS education, please ask me about it!

5

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

6 of 105

Chris and Probability

  • When I took probability in college, it was a very different course. When I took probability in graduate school, it was a very different course…
  • Today’s CS109 is geared towards teaching you the math you need to succeed in learning machine learning and AI concepts.
  • See all those names below? This course has a long history, with many instructors over the years.

6

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

7 of 105

Why is CS109 important?

We are seeing a huge surge in statistics, predictions, and probabilistic models shared through global news, governing bodies, and social media.

The technological and social innovation we develop during this time will strongly influence how we solve interesting problems impacting the lives of countless people across the globe.

7

National Weather

Service Alerts

https://www.weather.gov/

World Politics

https://abcnews.go.com/538

https://www.nytimes.com/

https://www.economist.com/

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

8 of 105

Course Logistics

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

9 of 105

Course Staff

TA: Justin Choo (oliver88@stanford.edu)

9

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

10 of 105

Course Mechanics (light version: see the syllabus for details)

  • Main website: https://cs109.stanford.edu
  • Ed Forum: https://edstem.org/us/courses/99736/discussion
  • Prerequisites
    • CS106B (important, coreq ok):
      • Recursion / Hash Tables / Binary Trees
      • Programming

    • CS103 (not necessary):
      • Proof techniques (induction) / Set Theory / Math maturity

    • Math 21 or equivalent (important, coreq ok)
      • Differentiation / Integration /Basic facility with linear algebra (vectors)

10

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

11 of 105

Course Components

Lecture: MTuWTh 10:30am-11:45am, CoDa B80

11

10%

7 Assignments (online, web app)

30%

2 Midterms (in class, on paper)�Monday July 13th

Monday August 3rd

35%

Final (in person, on paper)

3 hour exam, Saturday August 15th, 8:30am-11:30am

There will not be alternate exam times – do not take another course with an overlapping final exam!

25%

Participation / In-class work

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

12 of 105

Course Components

Written portion:

for typesetting, Tutorial on CS109 website

Coding portion in Python:

Review Session TBD

Late Policy:

All students given 2-hour grace period (but 2-hours and 1 second is actually late).

On the pset app, you can grant yourself up to two late days per assignment, up to five total. After that, you must contact the head CA

12

20%

7 Assignments (online, web app)

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

13 of 105

Course Components

We will have more information about both exams as they near.

If you have an OAE accommodation, please fill out the following form and upload your letter: https://forms.gle/49uNkj5c2EG8TjVi9

13

30%

2 Midterms (in class, on paper)�Monday July 13th

Monday August 3rd

35%

Final (in person, on paper)

3 hour exam, Saturday August 15th, 8:30am-11:30am

There will not be alternate exam times – do not take another course with an overlapping final exam!

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

14 of 105

Course Components

We will not have regular sections for in-person students. We will have a section for CGOE students.

Class time will be spent on a short recap of the lecture slides, and then we will spend the bulk of the time working on practice problems covering the material.

14

25%

Participation / In-class work

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

15 of 105

CS109 Contest

  • Announced mid-quarter, genuinely optional
    • Boost final course grades after letter grade buckets have been determined
  • Your baseline is CS109, and the sky is the limit.
  • Some recent winners:
    • The Probability of Curing Cancer: Will My Clinical Trial Succeed?
    • Modeling Indexical Fields as Bayesian Networks
    • StatTuring: Distinguishing between LLM and Human text
    • Parka: A Mobile App for Early Parkinson’s Disease Detection

15

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

16 of 105

If you have questions:

16

Q&A forum

All announcements

“Working” office hours

start on Wednesday

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

17 of 105

17

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

18 of 105

How this class will work:

  • Because the summer quarter has a relatively low enrollment, we are going to be running the class in a modified “flipped” format:
    • Prior to each lecture, lecture slides will be provided, which students are expected to go through.
    • We will also provide a series of “LLM Prompt” instructions, which will allow students to dig into the material using an LLM. Students should follow those prompts, and then explore the material in as much detail as they would like. This will allow you to ask targeted questions to enhance your own learning. Have fun with it!
    • During class time, we will spend about 20 minutes going over the material in a lecture-like format, and then we will spend the rest of the time working on a combination of practice problems, old midterm and final exam problems, and homework problems.
    • For most of the classes, both Chris and Justin will be available to help with the problems. We will also spend time reviewing the solution to many of the problems.
  • We will do our best to highlight when we are solving problems on the board so CGOE students can jump to those sections of the video. We can also go over those problems during the CGOE section.

18

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

19 of 105

The Story of Modern AI

19

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

20 of 105

Modern AI

or, How we learned to combine

probability and programming

20

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

21 of 105

Brief History

21

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

22 of 105

Early Optimism in the 1950s

22

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

23 of 105

Early Optimism in the 1950s

23

“Machines will be capable, within twenty years, of doing any work a man can do.”

–Herbert Simon, 1952

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

24 of 105

Underwhelming Results 1950s to 1980s

24

The world is too complex

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

25 of 105

25

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

26 of 105

The (Second!) AI Winter Started to Thaw in the late 1990s

26

1997: Deep Blue

2005: Stanley

2011: Watson

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

27 of 105

Progression was Incredible!

Speech Recognition is Almost Perfect Today!

27

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

28 of 105

The last remaining board game

Humans conquered by AlphaGo in 2015

28

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

29 of 105

Translation is AI-driven (and amazing)

29

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

30 of 105

Self-Driving Cars (right outside in Palo Alto!)

30

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

31 of 105

In 2022, everything changed, again:

AI that seems to understand language

31

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

32 of 105

We Now Live in a World of AI

32

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

33 of 105

There are problems that seemed virtually impossible for a computer a short time ago

33

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

34 of 105

The Chihuahua or Muffin Challenge

34

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

35 of 105

The Chihuahua or Muffin Challenge

35

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

36 of 105

The Chihuahua or Muffin Challenge

36

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

37 of 105

This is what a human sees: This is what a computer sees:

37

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

38 of 105

Why is it easy for humans?

38

About 30% of your cortex is used from vision

3% is used to process hearing

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

39 of 105

Let’s start a bit easier…digit recognition:

39

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

40 of 105

Classification: Make a Harry Potter Sorting Hat

40

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

41 of 105

Classification: Make a Harry Potter Sorting Hat

41

That is an image of a one

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

42 of 105

Classification: Make a Harry Potter Sorting Hat

42

That is an image of a zero

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

43 of 105

Classification: Make a Harry Potter Sorting Hat

43

That is an image of a zero

* Sometimes it will be wrong!

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

44 of 105

Classification is Hard to Program

44

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

45 of 105

In this class, we will learn the math that underpins classification

45

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

46 of 105

So all of probability is to inform machine learning?

46

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

47 of 105

So all of probability is to inform machine learning?

No.

47

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

48 of 105

Probability is more than just machine learning!

48

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

49 of 105

Algorithms and Probability

E.g., Raytracing E.g., HashMaps

49

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

50 of 105

Understanding the world and building tools

E.g., CT Scanner: uses probability to determine if body material is bone, muscle, or fat.

50

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

51 of 105

Philosophy and Ethics

51

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

52 of 105

Most Desired Skill by PhD Students

Most CS PhD students list their highest desiderata upon

graduation as:

“Better understanding of probability”

52

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

53 of 105

Learning Real Skills in CS109

53

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

54 of 105

Learning Real Skills in CS109

Learning Real Skills in CS109

Recent exam question:

Patient sees a series of letters of different font size, and for each, answers correct or incorrect

54

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

55 of 105

Learning Real Skills in CS109

Recent exam question (part 2):

A patient has answered 20 “letter sizes” and got a few

correct. What is your belief in how well they can see?

55

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

56 of 105

Learning Real Skills in CS109

Now state of the art for eye exam theory!

56

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

57 of 105

Learning Real Skills in CS109

57

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

58 of 105

CS109 Provides a Foundation for Your Future

58

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

59 of 105

CS109 Provides a Foundation for Your Future

But, it is not always intuitive

59

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

60 of 105

Unintuitive Probability

60

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

61 of 105

Unintuitive Probability

61

  • 0.8% of people have zika
  • Test has 90% positive rate for people with zika
  • Test has 7% positive rate for people without zika

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

62 of 105

Unintuitive Probability

62

  • 0.8% of people have zika
  • Test has 90% positive rate for people with zika
  • Test has 7% positive rate for people without zika

The right answer is 9%

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

63 of 105

CS109 View of Probability:

Teach you how to write programs to numerically solve probability problems

63

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

64 of 105

CS109 View of Probability:

Teach you the theory you need to do the math

64

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

65 of 105

CS109 Major Topics

65

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

66 of 105

Let’s Dive in to Some Probability!

66

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

67 of 105

Events and the Sample Space

67

  • Event, E, is some subset of S {E ⊆ S}

  • Coin flip is heads: E = {Head}
  • ≥ 1 head on 2 coin flips: E = {[H, H], [H, T], [T, H]}
  • Roll of die is 3 or less: E = {1, 2, 3}
  • # emails in a day ≤ 20: E = {x | x ∈ ℤ, 0 ≤ x ≤ 20}
  • Wasted day {≥ 5 YT hrs.}: E = {x | x ∈ ℝ, 5 ≤ x ≤ 24}

Note: When Ross uses: ⊂, he really means: ⊆

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

68 of 105

Events and the Sample Space

68

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

69 of 105

What is a probability?

69

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

70 of 105

A probability is a number between 0 and 1

70

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

71 of 105

Our belief that an event E might occur

71

P(E)

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

72 of 105

What is a probability?

72

The event we care about

How many times does it occur?

Out of (close to) infinite trials

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

73 of 105

What is a probability?

73

n is the number of trials

The “event” E is that you hit the target

Hit: 0

Thrown: 0

P(E)≈

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

74 of 105

What is a probability?

74

n is the number of trials

The “event” E is that you hit the target

Hit: 0

Thrown: 1

P(E)≈ 0.00

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

75 of 105

What is a probability?

75

n is the number of trials

The “event” E is that you hit the target

Hit: 1

Thrown: 2

P(E)≈ 0.50

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

76 of 105

What is a probability?

76

n is the number of trials

The “event” E is that you hit the target

Hit: 11

Thrown: 24

P(E)≈ 0.46

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

77 of 105

Let’s look at the Course Reader:

https://probabilitycoders.stanford.edu/spr26/probability

77

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

78 of 105

What is a probability (in a Dataset)?

78

Trial

Value

1

Rainy

2

Sunny

3

Rainy

4

Cloudy

5

Rainy

6

Sunny

7

Sunny

8

Sunny

10000

Cloudy

Let E be the event that it is Sunny

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

79 of 105

What is a probability (in a Dataset)?

79

Trial

Value

1

Rainy

2

Sunny

3

Rainy

4

Cloudy

5

Rainy

6

Sunny

7

Sunny

8

Sunny

10000

Cloudy

Let E be the event that it is Sunny

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

80 of 105

Equally Likely Outcomes

80

Some sample spaces have equally likely outcomes.

  • Coin flip: S = {Head, Tails}
  • Flipping two coins: S = {[H, H], [H, T], [T, H], [T, T]}
  • Roll of 6-sided die: S = {1, 2, 3, 4, 5, 6}

If we have equally likely outcomes, then P(Each outcome)

Therefore

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

81 of 105

Not Everything is Equally Likely

81

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

82 of 105

Not Everything is Equally Likely

82

  • Play lottery.
    • What is P(Win)?

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

83 of 105

Not Everything is Equally Likely

83

  • Play lottery.
    • What is P(Win)?
  • S = {Lose, Win}
  • E = {Win}
  • P(Win) = |E|/|S| = 1/2 = 50%

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

84 of 105

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

85 of 105

Solve probabilities using math!

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

86 of 105

The Axioms of Probability

(Kolmogorov, 1933)

86

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

87 of 105

Axioms of Proability

87

Recall: S = all possible outcomes. E = the event.

  • Axiom 1: 0 ≤ P(E) ≤ 1

  • Axiom 2: P(S) = 1

  • Axiom 3: If events E and F are mutually exclusive:

P(E ∪ F) = P(E) + P(F)

Kolmogorov

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

88 of 105

Mutually Exclusive Events

88

If events are mutually exclusive, probability of OR is simple:

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

89 of 105

Mutually Exclusive Events

89

If events are mutually exclusive, probability of OR is simple:

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

90 of 105

If events are mutually exclusive, the probability of OR is easy!

90

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

91 of 105

91

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

92 of 105

Many times it is easier to calculate P(EC)

Provable Identity #1:

P(EC) = 1 - P(E)

92

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

93 of 105

Sources of Probability:

A dice story

93

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

94 of 105

Sum of Two Die = 7?

Roll two 6-sided dice. What is the probability that the sum = 7?

Let E be the event that the sum is 7

94

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

95 of 105

Sum of Two Die = 7?

Roll two 6-sided dice. What is the probability that the sum = 7?

Let E be the event that the sum is 7

95

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

96 of 105

Sum of Two Die = 7?

96

cgregg % python3 dice_soln.py

After 10000000 trials

P(E) = 0.1666913

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

97 of 105

Sum of Two Die = 2?

Roll two 6-sided dice. What is the probability that the sum = 2?

Let E be the event that the sum is 2

97

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

98 of 105

Sum of Two Die = 2?

Roll two 6-sided dice. What is the probability that the sum = 2?

Let E be the event that the sum is 2

98

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

99 of 105

Other ways to make a Sample Space?

99

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

100 of 105

Sum of Two Dice: Three options for the sample space

100

Value of a die

Value of a die

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

101 of 105

Sum of Two Dice: Bug: Die are Indistinct

101

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

102 of 105

Sum of Two Dice: Three options for the sample space

102

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

103 of 105

Sum of Two Dice: Bug: Just look at the sum

103

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

104 of 105

Sum of Two Dice: Three options for the sample space

104

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026

105 of 105

Next time:

Conditional Probability

and Bayes’ Theorem

105

Mehran Sahami, Chris Piech, Lisa Yan, Jerry Cain, Juliette Woodrow, and Chris Gregg, Spring 2026