Sunteți pe pagina 1din 14

Mathematics Exploration

Studying derangements

Derangements
Derangements, also called de Montmort number are a topic of combinatorial
mathematics. The term derangement comes from the word deranged (disordered,
disarranged) and the word arrangement, as it is a permutation with no fixed points, which
means it is an arrangement in which the order of the elements matter and an element cannot
be in its original position.
Notations used to designate the number of derangements in a set of size n are (), ()
or (Pronounced n subfactorial).
In order to explain this concept I will show a basic use of derangements in real life.
Suppose that there are 3 students numbered 1, 2, and 3. And that there are 3 bags also
numbered 1, 2, and 3. In how many ways can all of the students grab a bag that does not
belong to them? This is the number of derangements, and in order to find it, it is necessary
to find out the number of ways in which the elements can get arranged in such way that
none of them is in its original position.
We know that that there are 6 different ways to arrange these elements (3!), which are:

Figure 1: Possible permutations of 3 elements

2 3

2 3

All of the students receive their own bags.

3 2

Student 1 receives his own bag.

1 3

Student 3 receives his own bag.

3 1

Derangement

1 2

Derangement

2 1

Student 2 receives his own bag.

So, 3 = 2
This means that there are 2 ways in which none of the students would pick their own bag.
Now, lets generalize this example in order to find a relation. Lets suppose that student
number 1 takes a bag at random. In order for there to be a derangement there is 1
choices for him to make. Then there are two options, either the student who owns the bag
which student 1 took takes bag number 1 or he doesnt. If he does, then we will just need to
count the derangements for the 2 elements remaining, which leads to the following
relation: 1 2

however, if he doesnt, we will have to find the number of

ways in which 1 objects can be deranged as the remaining students have exactly one
forbidden option. From this, the following recursion is derived:
= 1 [ 2 + 1 ]
Surprisingly, this recursive relation also works out to find the value of n factorial:
! = 1

2 !+ 1 ! ]

Now, if we subtract 1 from :


1 = [ 1 1 ( 2)
Which is equal as the opposite of the same formula down one value.
If we keep subtracting 1 we can see:

= (1)! [ 2 2 3 ]
= (1)! [ 3 3 4 ]
= (1)! [ 4 4 5 ]
=
= (1)!!! 2 2 1
So, ( 1) = (1)!!! 1 0
1 = 0, 2 = 1
= 1 + (1)!
This recursion was derived as mathematicians were looking for something easier to use
and to manipulate than = 1 2 + 1

and from this recursive

relation they were able to find a formula for the number of derangements !
= !

1 1 1 1 1
(1)!
! + 1
+ + +
=
0! 1! 2! 3! 4!
!

But in order to understand how this formula was derived and study the nature of
derangements I will use the recursive relation found earlier with the first fourteen terms.
= 1 + (1)!
We already know 1 = 0, 2 = 1
3 = 3 2 + (1)! = 3 1 + 1 = 3 1 = 2

4 = 4 3 + (1)! = 4 2 + 1 = 8 + 1 = 9
5 = 5 4 + (1)! = 5 9 + (1) = 45 1 = 44
6 = 6 5 + (1)! = 6 44 + 1 = 264 + 1 = 265
7 = 7 6 + (1)! = 7 265 + (1) = 1,855 1 = 1,854
8 = 8 7 + (1)! = 8 1,854 + 1 = 14,832 + 1 = 14,833
9 = 9 8 + (1)! = 9 14,833 + (1) = 133,497 1 = 133,496
10 = 10 9 + (1)!" = 10 133,496 + 1 = 1,334,960 + 1 = 1,334,961
11 = 11 10 + (1)!! = 11 1,334,961 + (1) = 14,684,571 1 = 14,684,570
12 = 12 11 + (1)!" = 12 14,684,570 + 1 = 176,214,840 + 1
= 176,214,841
13 = 13 12 + (1)!" = 13 176,214,841 + (1) = 2,290,792,933 1
= 2,290,792,932
Figure 2: Casio fx-9860 GII Finding D(14)

The value of D(14) was too big to be shown completely in my calculator as it is in the
10th order of magnitude, as seen above. So I decided to use Python1 as a tool to find larger
derangements.

1 Interpreted, interactive, object-oriented, extensible programming language.

Figure 3: Program created in python to find derangements (See Appendix 1)

I was not familiar with the language of Python so it took me 12 tries and around 40
minutes learning the basic syntax, statements, strings and operators but I finally was able to
find the number of derangements for specific values of n.
14 = 14 13 + (1)!" = 14 2,290,792,932 + 1 = 32,071,101,048 + 1
= 32,071,101,0489
After carrying out this recursion multiple times I started to notice that this equation
basically meant finding the product of and 1 and adding (for even values of n) or
subtracting (for odd values of n) one.
Furthermore, if we study the recursive formula a little deeper we can notice:
2 = 20 + 1 = 1
3 = 3(2) 1 = 31 1
4 = 431 4 + 1
5 = 5431 54 + 5 1
6 = 65431 654 + 65 6 + 1 = 265

https://www.python.org/

Which is very disorganized, however, by factorizing six factorial out of the equation we
get:
6 = 6!

1
1
1
1
1

+
= 265
2 32 432 5432 6!

And simplifying this expression gives:


6 = 6!

1 1 1 1 1 1 1
+ + +
= 265
0! 1! 2! 3! 4! 5! 6!

Generalizing the expression for a random number n results in the derangement formula
stated earlier.
1 1 1 1 1
(1)!
= !
+ + +
0! 1! 2! 3! 4!
!

Which can also be written as follows


!

= !
!!!

But why is this equation is equal to

!!!!
!

(1)!
!

It is a complex concept, but mathematicians achieved to discover that the probability of


derangements

!
!!

as n approaches infinity converges to . There are different ways in order


!

to prove this but one of the most straightforward ways is by analysing the relation between
the number of derangements and the Taylor series of expansion of ! .

In order to prove this I had to learn the inclusion-exclusion principle, a basic set theory
principle, which states that the number of elements in the union of two sets is equal to the
sum of the cardinality of each set minus the number of elements in the intersection:2
AB = A + B AB
!

In a set of 1,2 permutations of n elements which fix k elements. There are ! ways
to choose k elements that are to be fixed, and ! ways to arrange the remaining
elements. By using the inclusion-exclusion principle outlined previously, the number of
derangements would be:
!

!!!

Which would result again in the formula derived earlier:


!

= !
!!!

(1)!
!

And this is a remarkably interesting formula as it is related with the Taylor series for ! .h
A Taylor series is a representation of a function as an infinite sum of terms that are
calculated from the values of the function's derivatives at a single point3
If we compare the formula of D(n) previously derived and the Taylor series for ! at
= 1 we can see they are very similar:
!

= !
!!!

(1)!
!

1
=


2 http://mathworld.wolfram.com/Inclusion-ExclusionPrinciple.html
3 http://en.wikipedia.org/wiki/Taylor_series

!!!

(1)!
!

In fact, D(n) is the truncation of the Taylor series for ! at = 1, a concept that will be
further developed later on. For this reason:
()

This can be evidenced by filling in a table with the values of D(n) found previously, the
values of n! and finding the ratios

!
!!

and

!!
!

Figure 4: Table showing permutation, derangement and ratios n:n! & n:e for (2 < < 14)

10

12

14

24

720

40,320

3,628,800

479,001,600

87,178,291,200

265

14,833

1,334,961

176,214,841

32,071,101,048

0,7

8,829

264,9

14,832.899

1,334,960.9

176,214,840.4

32,071,101,047.6

0,5

0,375

0,368

0,36788194

0,36787946

0,3678794413

0,3678794412

*e = 2,718281828
This table shows different valuable pieces of information. First, it proves the assertion that
!

() as it is clearly evidenced how the values obtained using that formula are almost
the same as those in the n factorial line obtained with the recursive formula for the number
of derangements. And that small difference between those values is the reason, which made
mathematicians decide to truncate the values of

!!
!

. As the values obtained with this

formula were only a good approximation, something had to be done so this formula was
perfect. The first effort to achieve this consisted in rounding the value obtained, which
resulted in:
=

! 1
+
2

However, they realized that by adding 1 to the factorial before dividing by e they could
truncate in order to obtain a perfect formula for the number of derangements when > 1
=

! + 1

Also this table evidences that the limit of the probability derangements as n approaches
infinity is:
! 1
= 0.3678794412
!! !

lim

Although something that surprised me was the fact that when = 14 the probability of
a derangement was already exactly

!
!

, which made me wonder if I was doing something

wrong as the limit had converged really fast, so I decided to use the program in Python to
fin the probability of a derangement when = 15.
Figure 6: D(15)

(15)
= 0,3678794412
15!

This result confirmed that the probability converged to its limit when = 14.
Then, I realized that the convergence of the probability to its limit is so fast because of its
relation with the Taylor series.

Applications Of Derangements
Derangements are linked with many other topics in mathematics, such as number theory,
game theory, enumerative combinatorics, and cryptography.
Many centuries ago, people started using derangements to encrypt messages so enemies
or strangers were not able to understand the information being sent. A substitution cipher4
is an encoding method in which text is replaced with cipher text; in simple substitutions
single letters were replaced with its equivalent from a shifted or inverted alphabet, until
they came up with the idea of using more complex, deranged alphabets.
The on-line encyclopaedia of integer sequences (OEIS)5 only has the number of
derangements up to = 22 so in order to find the number of derangements for = 26 I
had to use my program. The image below shows the amount of possible derangements for
the alphabet.


4 http://practicalcryptography.com/ciphers/simple-substitution-cipher/
5 OEIS.org

Figure 6: Number of possible derangements of the alphabet

As seen above the amount of derangements for 26 elements is incredibly large: 1,4 10!" ,
which means that there are 1,4 10!" number of ways in which the alphabet could be
deranged.
Figure 7: Alphabet and randomly deranged alphabets
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
K P V X T S F B D M H G W Y J A O C N Z E I L R Q U
S X J U V I C Q B P D A K W M Z G T O R H F N L E Y
In this case for example, the word derangements could be written in such ways that it
would not even seem as a word due to the lack of vowels on the cypher text.
DERANGEMENTS
XTCKYFTWTYCN
UVTSWCVKVWRO
However, after writing this I realized that single messages contained the same deranged
alphabet, and thus, by using methods such as frequency analysis to study the different
words and letters messages could be deciphered eventually, which probably led to the
combination of more techniques to ensure a stronger encrypting.

Conclusion
To conclude this mathematical exploration I can comment on the beauty of derangements.
This topic is very interesting and it is connected to many other complex topics within
mathematics that unfortunately, due to time limitations I was not able to study.
Throughout this work I could understand the nature of derangements and understand how
the probability of a derangement converges very quickly to 36,8% which is actually a
significant probability as one would tend to think that the probability of there being a
permutation in which every element is in a different position to its original one would be
smaller.
This topic helped me to perfect my knowledge on permutations and expanded what I knew
about combinatorics ans also, I could apply topics within my range of knowledge to derive
equations related to derangements. By studying this topic, I learned many new concepts
such as the inclusion-exclusion principle, truncation and Taylors series. During this process
I gained an in depth understanding about derangements as I started from a particular
example of derangements and went through the process mathematicians carried out to
develop a better understanding of this topic. Throughout this investigation my interest in
mathematics was reinforced and I was forced to learn different concepts on my own and
face different challenges.
The most interesting thing I learned throughout this exploration was to use Sage and
Python, (although I only decided to include the program created in Python due to its
superior effectiveness) two technological tools that assist mathematicians carrying out
processes that can not be easily conducted on a scientific calculator.
To compliment my exploration, I would like to learn about ordinary and exponential
generating functions.

Appendix 1: Python program


from itertools import permutations
import math
def derangements(n):
return ( perm for perm in permutations(range(n))
if all(indx != p for indx, p in enumerate(perm)) )
def subfact(n):
if n == 2 or n == 0:
return 1
elif n == 1:
return 0
elif n.imag == 0 and n.real == int(n.real) and n > 0:
return (n-1) * ( subfact(n - 1) + subfact(n - 2) )
if __name__ == '__main__':
n=x
print("\n!%i = %i" % (n, subfact(n)))
I started by importing the modules of permutation and math using the from statement so I
only had to define what a derangement is. It was not necessary to declare explicitly the
variables as Python automatically declares when a value is assigned to a variable in order to
reserve memory space. Then I used the def statement to define what derangements are, and
within the parenthesis I included the parameters of the function. After that, I defined
derangements as subfactorial, and stated that if n was 2 or 0 the program would return 1,
derangements values for n=1,2 and 3 and gave the basic conditions for the function
including n>0. Then, I used the elif statement, which is similar to if as it allows to check
multiple expressions for truth value and execute a block of code as soon as one of the
conditions evaluates to true, with the condition of n=1 returns 0 and the first recursive
formula for D(N). %i is used to format integers and the print () command will give me the
amount of derangements for a specific value of n.

Bibliography

https://www.sagemath.org/
http://mathworld.wolfram.com/Inclusion-ExclusionPrinciple.html
http://planetmath.org/sites/default/files/texpdf/41991.pdf
http://practicalcryptography.com/ciphers/simple-substitution-cipher/
http://www.mathpages.com/home/kmath430.htm
Concrete mathematics page 194-198
http://epubs.siam.org/doi/pdf/10.1137/1.9781611972986.7

S-ar putea să vă placă și