In
combinatorics
Combinatorics is an area of mathematics primarily concerned with counting, both as a means and an end in obtaining results, and certain properties of finite structures. It is closely related to many other areas of mathematics and has many a ...
, a branch of
mathematics, the inclusion–exclusion principle is a counting technique which generalizes the familiar method of obtaining the number of elements in the
union of two
finite set
In mathematics, particularly set theory, a finite set is a set that has a finite number of elements. Informally, a finite set is a set which one could in principle count and finish counting. For example,
:\
is a finite set with five elements. ...
s; symbolically expressed as
:
where ''A'' and ''B'' are two finite sets and , ''S'', indicates the
cardinality
In mathematics, the cardinality of a set is a measure of the number of elements of the set. For example, the set A = \ contains 3 elements, and therefore A has a cardinality of 3. Beginning in the late 19th century, this concept was generalized ...
of a set ''S'' (which may be considered as the number of elements of the set, if the set is
finite
Finite is the opposite of infinite. It may refer to:
* Finite number (disambiguation)
* Finite set, a set whose cardinality (number of elements) is some natural number
* Finite verb
Traditionally, a finite verb (from la, fīnītus, past partici ...
). The formula expresses the fact that the sum of the sizes of the two sets may be too large since some elements may be counted twice. The double-counted elements are those in the
intersection
In mathematics, the intersection of two or more objects is another object consisting of everything that is contained in all of the objects simultaneously. For example, in Euclidean geometry, when two lines in a plane are not parallel, thei ...
of the two sets and the count is corrected by subtracting the size of the intersection.
The inclusion-exclusion principle, being a generalization of the two-set case, is perhaps more clearly seen in the case of three sets, which for the sets ''A'', ''B'' and ''C'' is given by
:
This formula can be verified by counting how many times each region in the
Venn diagram
A Venn diagram is a widely used diagram style that shows the logical relation between sets, popularized by John Venn (1834–1923) in the 1880s. The diagrams are used to teach elementary set theory, and to illustrate simple set relationships ...
figure is included in the right-hand side of the formula. In this case, when removing the contributions of over-counted elements, the number of elements in the mutual intersection of the three sets has been subtracted too often, so must be added back in to get the correct total.
Generalizing the results of these examples gives the principle of inclusion–exclusion. To find the cardinality of the union of sets:
# Include the cardinalities of the sets.
# Exclude the cardinalities of the pairwise intersections.
# Include the cardinalities of the triple-wise intersections.
# Exclude the cardinalities of the quadruple-wise intersections.
# Include the cardinalities of the quintuple-wise intersections.
# Continue, until the cardinality of the -tuple-wise intersection is included (if is odd) or excluded ( even).
The name comes from the idea that the principle is based on over-generous ''inclusion'', followed by compensating ''exclusion''.
This concept is attributed to
Abraham de Moivre
Abraham de Moivre FRS (; 26 May 166727 November 1754) was a French mathematician known for de Moivre's formula, a formula that links complex numbers and trigonometry, and for his work on the normal distribution and probability theory.
He mov ...
(1718),
although it first appears in a paper of
Daniel da Silva (1854) and later in a paper by
J. J. Sylvester (1883). Sometimes the principle is referred to as the formula of Da Silva or Sylvester, due to these publications. The principle can be viewed as an example of the
sieve method extensively used in
number theory
Number theory (or arithmetic or higher arithmetic in older usage) is a branch of pure mathematics devoted primarily to the study of the integers and integer-valued functions. German mathematician Carl Friedrich Gauss (1777–1855) said, "Math ...
and is sometimes referred to as the ''sieve formula''.
As finite probabilities are computed as counts relative to the cardinality of the
probability space
In probability theory, a probability space or a probability triple (\Omega, \mathcal, P) is a mathematical construct that provides a formal model of a random process or "experiment". For example, one can define a probability space which models t ...
, the formulas for the principle of inclusion–exclusion remain valid when the cardinalities of the sets are replaced by finite probabilities. More generally, both versions of the principle can be put under the common umbrella of
measure theory.
In a very abstract setting, the principle of inclusion–exclusion can be expressed as the calculation of the inverse of a certain matrix. This inverse has a special structure, making the principle an extremely valuable technique in combinatorics and related areas of mathematics. As
Gian-Carlo Rota put it:
"One of the most useful principles of enumeration in discrete probability and combinatorial theory is the celebrated principle of inclusion–exclusion. When skillfully applied, this principle has yielded the solution to many a combinatorial problem."
Formula
In its general formula, the principle of inclusion–exclusion states that for finite sets , one has the identity
This can be compactly written as
:
or
:
In words, to count the number of elements in a finite union of finite sets, first sum the cardinalities of the individual sets, then subtract the number of elements that appear in at least two sets, then add back the number of elements that appear in at least three sets, then subtract the number of elements that appear in at least four sets, and so on. This process always ends since there can be no elements that appear in more than the number of sets in the union. (For example, if
there can be no elements that appear in more than
sets; equivalently, there can be no elements that appear in at least
sets.)
In applications it is common to see the principle expressed in its complementary form. That is, letting be a finite
universal set containing all of the and letting
denote the complement of in , by
De Morgan's laws
In propositional logic and Boolean algebra, De Morgan's laws, also known as De Morgan's theorem, are a pair of transformation rules that are both valid rules of inference. They are named after Augustus De Morgan, a 19th-century British mathem ...
we have
:
As another variant of the statement, let be a list of properties that elements of a set may or may not have, then the principle of inclusion–exclusion provides a way to calculate the number of elements of which have none of the properties. Just let be the subset of elements of which have the property and use the principle in its complementary form. This variant is due to
J. J. Sylvester.
Notice that if you take into account only the first sums on the right (in the general form of the principle), then you will get an overestimate if is odd and an underestimate if is even.
Examples
Counting integers
As a simple example of the use of the principle of inclusion–exclusion, consider the question:
:How many integers in are not divisible by 2, 3 or 5?
Let ''S'' = and ''P''
1 the property that an integer is divisible by 2, ''P''
2 the property that an integer is divisible by 3 and ''P''
3 the property that an integer is divisible by 5. Letting ''A''
i be the subset of ''S'' whose elements have property ''P''
i we have by elementary counting: , ''A''
1, = 50, , ''A''
2, = 33, and , ''A''
3, = 20. There are 16 of these integers divisible by 6, 10 divisible by 10, and 6 divisible by 15. Finally, there are just 3 integers divisible by 30, so the number of integers not divisible by any of 2, 3 or 5 is given by:
:100 − (50 + 33 + 20) + (16 + 10 + 6) - 3 = 26.
Counting derangements
A more complex example is the following.
Suppose there is a deck of ''n'' cards numbered from 1 to ''n''. Suppose a card numbered ''m'' is in the correct position if it is the ''m''th card in the deck. How many ways, ''W'', can the cards be shuffled with at least 1 card being in the correct position?
Begin by defining set ''A''
''m'', which is all of the orderings of cards with the ''m''th card correct. Then the number of orders, ''W'', with ''at least'' one card being in the correct position, ''m'', is
:
Apply the principle of inclusion–exclusion,
:
Each value
represents the set of shuffles having at least ''p'' values ''m''
1, …, ''m
p'' in the correct position. Note that the number of shuffles with at least ''p'' values correct only depends on ''p'', not on the particular values of
. For example, the number of shuffles having the 1st, 3rd, and 17th cards in the correct position is the same as the number of shuffles having the 2nd, 5th, and 13th cards in the correct positions. It only matters that of the ''n'' cards, 3 were chosen to be in the correct position. Thus there are
equal terms in the ''p''th summation (see
combination).
:
is the number of orderings having ''p'' elements in the correct position, which is equal to the number of ways of ordering the remaining ''n'' − ''p'' elements, or (''n'' − ''p'')!. Thus we finally get:
:
A permutation where ''no'' card is in the correct position is called a
derangement. Taking ''n''! to be the total number of permutations, the probability ''Q'' that a random shuffle produces a derangement is given by
:
a truncation to ''n'' + 1 terms of the
Taylor expansion
In mathematics, the Taylor series or Taylor expansion of a function is an infinite sum of terms that are expressed in terms of the function's derivatives at a single point. For most common functions, the function and the sum of its Taylor se ...
of ''e''
−1. Thus the probability of guessing an order for a shuffled deck of cards and being incorrect about every card is approximately ''e''
−1 or 37%.
A special case
The situation that appears in the derangement example above occurs often enough to merit special attention. Namely, when the size of the intersection sets appearing in the formulas for the principle of inclusion–exclusion depend only on the number of sets in the intersections and not on which sets appear. More formally, if the intersection
:
has the same cardinality, say ''α
k'' = , ''A
J'', , for every ''k''-element subset ''J'' of , then
:
Or, in the complementary form, where the universal set ''S'' has cardinality ''α''
0,
:
Formula generalization
Given a
family (repeats allowed) of subsets ''A''
1, ''A''
2, ..., ''A''
n of a universal set ''S'', the principle of inclusion–exclusion calculates the number of elements of ''S'' in none of these subsets. A generalization of this concept would calculate the number of elements of ''S'' which appear in exactly some fixed ''m'' of these sets.
Let ''N'' =
''n''">/nowiki>''n''/nowiki> = . If we define , then the principle of inclusion–exclusion can be written as, using the notation of the previous section; the number of elements of ''S'' contained in none of the ''A''i is:
:
If ''I'' is a fixed subset of the index set ''N'', then the number of elements which belong to ''A''i for all ''i'' in ''I'' and for no other values is:
:
Define the sets
:
We seek the number of elements in none of the ''B''k which, by the principle of inclusion–exclusion (with ), is
:
The correspondence ''K'' ↔ ''J'' = ''I'' ∪ ''K'' between subsets of ''N'' \ ''I'' and subsets of ''N'' containing ''I'' is a bijection and if ''J'' and ''K'' correspond under this map then ''B''K = ''A''J, showing that the result is valid.
In probability
In probability
Probability is the branch of mathematics concerning numerical descriptions of how likely an Event (probability theory), event is to occur, or how likely it is that a proposition is true. The probability of an event is a number between 0 and ...
, for events ''A''1, ..., ''A''''n'' in a probability space
In probability theory, a probability space or a probability triple (\Omega, \mathcal, P) is a mathematical construct that provides a formal model of a random process or "experiment". For example, one can define a probability space which models t ...
, the inclusion–exclusion principle becomes for ''n'' = 2
:
for ''n'' = 3
:
and in general
:
which can be written in closed form as
:
where the last sum runs over all subsets ''I'' of the indices 1, …, ''n'' which contain exactly ''k'' elements, and
:
denotes the intersection of all those ''Ai'' with index in ''I''.
According to the Bonferroni inequalities, the sum of the first terms in the formula is alternately an upper bound and a lower bound for the LHS. This can be used in cases where the full formula is too cumbersome.
For a general measure space
A measure space is a basic object of measure theory, a branch of mathematics that studies generalized notions of volumes. It con