Almost surely

In mathematics—specifically, in probability theory—the phrase almost surely is a subtle, precise way to say that something is certain except for cases that almost never happen, though still possible. The concept usually comes into play in questions that involve infinite time or infinitesimal space.
The locution almost surely is to probability theory as almost everywhere is to measure theory. Formally it is equivalent to "with probability 1". For example, imagine throwing a dart at the unit square; the probability that the dart lands in any subregion of the square is the area of that subregion. The area of the diagonal of the square is zero, so the probability that the dart lands exactly on the diagonal is zero. But the diagonal is not the empty set; a point on the diagonal is no less probable than is any point at which the dart could land. One says that the dart will almost surely not land on the diagonal. In other words an event is "almost sure" if the probability of its complement is zero, even though the complement may not be empty.
To put it more mathematically, the probability of an event being 0 means that as the number of trials tends to infinity, the limit superior of the ratio of successes to trials is zero. Thus, a dart can hit the diagonal many times and still the probability of hitting the diagonal is zero, provided that as the number of trials (throws of the dart) becomes larger and larger, the mean interval between hits becomes even larger yet, and in such a way that the ratio of hits to throws has limit superior of zero. Similarly, for an event to have probability 1, it is only necessary that the limit inferior of the ratio of successes to trials, as the number of trials tends to infinity, be 1. This means that occasional failures may happen, but as the number of trials increases, the intervals between failures must increase sufficiently fast that the limit inferior just mentioned is 1.
Instead of infinitesimal space, one may consider infinite time. Suppose that a coin is flipped again and again. A sequence heads, heads, heads, ..., ad infinitum, without ever coming up tails, is possible in some sense  it does not violate any laws of physics to suppose that tails never appears  but it is very, very improbable. In fact, such a sequence has probability zero. However, any real sequence must have a finite length, and any possible realization has probability greater than zero. The difficulty comes when the sequence is hypothetically extended to infinite length. It is common to talk about almost sure convergence or divergence of random variables.
An example of the fine distinction between 'sure' and 'almost sure' can be found in the difference between constant and almost surely constant random variables. In measure theoretic probability theory these two types of random variable are not identical, but for practical purposes they are equivalent, since if a constant random variable X and an almost surely constant random variable Y represent the same constant c, then they share the same cumulative distribution functions.he:כמעט כל (מתמטיקה)