Probability theory: Repetitive experiments

This is part of the course “Probability Theory and Statistics for Programmers”.

Probability Theory For Programmers

In the practical application of probability theory, one often has to meet with problems in which the same or similar experiments are repeated many times. As a result of each experiment, some event may or may not occur, and we are not interested in the result of each individual experiment, but in the total number of occurrences of the event as a result of a series of experiments. Depend on the type of events you will use different approaches to find the probability.

Probability of repetitive experiments (independent events)

We have n experiments. In every experiment, the event can occur or not with probabilities p and q = 1-p. We should find probability Pm,n —the probability of event A occurring m times in n experiments. We can represent this event as a sum of all possible combinations of products of events. A number of such combinations can be calculated using combinatorics formula:


The probability of each such combination, by the multiplication theorem for independent events, is:

probability of combination

Now we can construct the formula:

probability of repetitive experiments(repetitive events)

Probability of repetitive (dependent experiments)

When we have dependent experiments different approach needed. The event that event A will appear m times during n experiments still will be represented as a sum of products of events. A Number of combinations also will be the same, but combinations will not have the same probability. Since independent events have a number of different probabilities. In order to find such a probability, we use a magic function. The probability that an event A in n independent experiments will appear exactly m times is equal to the coefficient

in the expression for the generating function:

It seems like magic, but it actually works, if you look at the example below you will find that coefficients represent a sum of products of events:

Now we can write code for this. At first, we create the list of list of products of events for each coefficient. In each iteration number of total products will be increased in two times, since we need to multiply existing products on corresponding q and p.

Next part ->

Reach the next level of focus and productivity with





Indie hacker behind More at

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Technological trends and Asymptotic notations

Closest pair of points

Bayes’ theorem

Understanding CSS Grids Fractional Units (FR) the easy way

On Average, You’re Using the Wrong Average — Part II

Time Complexity Analysis

Binomial distribution and normal approximation part II

Infinity: Exploring This Endless Enigma

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Radzion Chachura

Radzion Chachura

Indie hacker behind More at

More from Medium

Batch Gradient Descent and Simple Linear Regression

Pearson’s Correlation

Univariate Statistics in python

Meaning of P-Value in Hypothesis Testing.