Вы находитесь на странице: 1из 4

Discrete Mathematics 2002 Lecture 24, 13-September-2002

Sequences
• Recall: A sequence is an infinite list of nos in a
given order – e.g. 1, 3, 7, 15, 31, 63, 127, …
• There are 2 contrasting ways to describe this
(and other) sequences using formulas:
1: Use a recursive definition
t(1) = 1
t(n) = 2t(n – 1) + 1 (n > 1)
2: Use a non-recursive definition
t(n) = 2n – 1
• Either defn can be used, and both have their
advantages, depending on the circumstances
1

The Factorial Formula


• Example: A formula which appears in many
applications of maths is the factorial formula
• The factorial of a positive integer n is the product
of all the positive integers from 1 to n
• It is written as n! – so
n! = n × (n – 1) × (n – 2) × … × 3 × 2 × 1 (n > 0)
• Also, for convenience, we say 0! = 1
• Thus 1! = 1, 2! = 2 × 1 = 2, 3! = 3 × 2 × 1 = 6,
4! = 4 × 3 × 2 × 1 = 24, etc
2

Tattslotto
• Factorials often appear in formulas for the total
number of possible outcomes in a situation
• Example: In Tattslotto, the aim is to correctly
pick 6 nos from the nos 1–45
• The total no. of possible ways to do this is
45! / (6! × 39!) = 8,145,060
• So the chance of picking 6 nos correctly (a Div. 1
prize) in a single entry is about 1 in 8 million!
• Question: In Tattslotto, is it better to pick the nos
16, 17, 18, 19, 20, 21 or 9, 20, 23, 31, 37, 42?
3

1
Discrete Mathematics 2002 Lecture 24, 13-September-2002

A Recursive Formula for n!


• Example: Find a recursive formula for n!
• Solution: Firstly observe that
4! = 4 × 3 × 2 × 1 = 4 × (3 × 2 × 1) = 4 × 3!
Similarly, 5! = 5 × 4!, and, more generally,
n! = n × (n – 1)!
This last formula is also valid if n = 1 (b/c 0! = 1)
Thus factorials can be defined recursively by
0! = 1
n! = n × (n – 1)! (n > 0)
(N.B. This recursion starts with n = 0, rather than
n = 1 as in earlier examples) 4

Iterative Algorithm to Calculate n!


• The recursive defn can be used as the basis of an
iterative algorithm to calculate n!, as follows
1. Input n
2. t ← 1
3. For i = 1 to n do
3.1. t ← i × t
4. Output t
• A trace of this algorithm for n = 4 shows it does,
indeed, produce the correct value for 4! of 24
• This doesn’t prove that the algorithm works for
other values of n (although we can be reasonably
confident that it will do so) 5

The Collatz Sequence


• We’ll return to n! later (in work on recursive
algorithms in Section 7.5 – next lecture)
• Example: Here is another recursive sequence:
Let t(1) = any chosen positive integer, and for
n > 1, define t(n) by
t(n) = 3t(n – 1) + 1 if t(n – 1) is odd,
t(n) = 0.5 × t(n – 1) if t(n – 1) is even
• This is called the Collatz sequence (after Lothar
Collatz (1910–90), a German mathematician)
• It is also known as the 3X + 1 sequence
6

2
Discrete Mathematics 2002 Lecture 24, 13-September-2002

The Collatz Sequence (continued)


• e.g. if we choose t(1) = 3, then the sequence is
3, 10, 5, 16, 8, 4, 2, 1, 4, 2, 1, 4, 2, 1, …
• In fact, for any starting no., if the sequence ever
reaches 1, it will endlessly cycle through 1, 4 & 2
• If we start with t(1) = 13, the sequence is then
13, 40, 20, 10, 5, 16, 8, 4, 2, 1, 4, 2, 1, …
• So the sequence again reaches 1 (& then cycles
endlessly)
• At www.maths.ex.ac.uk/pumc/collatz.html
you can supply the starting no. (up to 9 digits),
and obtain the resulting sequence
7

The Collatz Sequence (summary)


• In all examples, the Collatz sequence eventually
reached the value of 1
• Q: Does this happen for all possible starting nos?
• A: Noone knows!
• However, it is known that if the value of t(1) is
between 1 and approx 100,000 trillion, the
Collatz sequence eventually reaches 1
• There remains the possibility, though, that for an
extremely large value of t(1), the sequence t(1),
t(2), t(3), … never reaches 1
• So here’s an opportunity to achieve fame (but
probably not fortune) 8

Recursive Defns for Concepts


that aren’t Sequences
• Recursive defns can also be used for concepts
other than sequences
• e.g. If A is a set, the concept of a subset of A can
be defined recursively by:
1. ∅ is a subset of A
2. If B is a subset of A, and a is an element of
A, then B ∪ {a} is a subset of A
• This is a recursive defn b/c the concept being
defined (‘subset of A’) appears in the defn itself
• Note that the recursive defn of a subset is very
different to our earlier defn of subset 9

3
Discrete Mathematics 2002 Lecture 24, 13-September-2002

Using the Recursive Defn of a Subset


• e.g: Show {a, c} is a subset of A = {a, b, c, d}
• Solution: This can be shown by a 3-step process:
1. ∅ is a subset of A by part 1 of the defn
2. Because ∅ is a subset of A and a is an
element of A, then ∅ ∪ {a} is a subset of A by
part 2 of the defn – i.e. {a} is a subset of A
3. Because {a} is a subset of A and c is an
element of A, then {a} ∪ {c} is a subset of A by
part 2 of the defn. – i.e. {a, c} is a subset of A
• In a similar way, the recursive defn can be
applied to generate all the subsets of A
10

Вам также может понравиться