Discrete Mathematics Recommended books Some related courses

advertisement
K.H. Rosen. Discrete Mathematics and its Applications,
McGraw Hill 1995.
Discrete Mathematics
J.L. Gersting. Mathematical Structures for Computer Science,
Freeman 1993.
Philippa Gardner
This course is based on previous lecture notes by Iain Phillips.
J.K. Truss. Discrete Mathematics for Computer Science,
Addison-Wesley 1991.
R. Johnsonbaugh. Discrete Mathematics, Prentice Hall 2000.
C. Schumacher, Fundamental Notions of Abstract
Mathematics, Addison-Wesley 2001.
2
1
Some related courses
Assessed work
1. Mathematical reasoning: logic
2. Mathematical reasoning: programming
3. Mathematical reasoning: discrete maths (continued)
Week 7: submission date Tuesday, November 23th.
4. Haskell
Week 9: submission date Tuesday, December 7th.
5. Databases
In particular, we will use some of the notation introduced in the
logic course:
A∧B
Assessed exercises
A∨B
¬A A → B
A↔B
∀x.A
Assessed Test in week 11.
Exam at the end of the year.
∃x.A
3
4
Motivation: functions
Motivation: sets
Haskell function
Sets are like types in Haskell.
Haskell type declaration:
data Bool = False | True
Set of Boolean values: {False , True}
List of Boolean values:
[True, False, True, False]
Set equality {False, True} = {True, False, True, False}
myand
myand
myand
myand
myand
:: Bool -> Bool -> Bool
False False = False
False True = False
True False = False
True True = True
Computable function described for example using Turing
machines.
This course explores the notion of mathematical function.
5
6
Exercise
Motivation: relations
Are these Haskell functions equivalent?
Examples
1. The class of the first-year Computer Science students,
year 2002.
2. George W Bush is the son of George Bush
myand
myand
myand
myand
myand
:: Bool -> Bool -> Bool
False False = False
False True = False
True False = False
True True = True
3. 2 < 3
4. One program is equivalent to another program.
7
myand’ :: Bool -> Bool -> Bool
myand’ False x = False
myand’ True x = x
8
Answer
Equivalence of Haskell Functions
The functions myand and myand’ do not behave in the same
way in the presence of the constant function bottom:
bottom :: Bool
bottom = bottom
Is the following function equivalent to myand and myand’?
myand’’ :: Bool -> Bool -> Bool
myand’’ b1 b2 = if b1 then b2 else False
Two Haskell functions f : A → B and g : A → B
behave in the same way if and only if, for all terms a
in type A, then if f a terminates then g a terminates
and f a = g a, and if f a does not terminate then g a
does not terminate.
In this course, we explore the abstract concept of relations.
10
9
Sets
Exercise
Are the following Haskell functions equivalent?
Informal definition
g [] y
False = 1
g [] True False = 2
g xs y
z
= 3
A set is a collection of objects (or individuals) taken from a
pool of objects. The objects in a set are also called the
elements, or members, of the set. A set is said to contain its
elements.
g’ [] y
g’ xs y
We write x ∈ A when object x is a member of set A.
False = 1
z
= 3
We write x 6∈ A, or ¬(x ∈ A), when x is not a member of A.
11
12
Examples
Comparing sets: subsets
1. vowels {a, e, i, o, u}
2. arbitrary (nonsense) set {1, 2, e, f, 5, Imperial}
3. natural numbers N = {0, 1, 2, 3, . . .}
4. integers Z = {. . . , −3, −2, −1, 0, 1, 2, 3, . . .}
Let A, B be any two sets, Then A is a subset of B, written
A ⊆ B, if and only if all the elements of A are also elements of
B: that is,
A ⊆ B ⇔ ∀ objects x.(x ∈ A → x ∈ B)
5. primes P = {x ∈ N : x is a prime number}
Object x comes from an underlying universe of discourse,
sometimes written U .
6. empty set ∅ = { }
7. nested sets, such as {{a, e, i, o, u}, {∅}}
13
14
Examples
Analogy
Similar to sublist from the Haskell course.
The following function h takes a list of integers and an integer
n, and returns a sublist of elements less than n:
h:: [Int] -> Int -> [Int]
h xs n = filter (<n) xs
A ⊆ A,
{a, b} ⊆ {a, b, c}
{c, c, b} ⊆ {a, b, c, d}
N ⊆ Z
∅ ⊆ {1, 2, 5}
Caution: lists are different from sets.
15
A set
16
Comparing sets: equality
Let A, B, C be arbitrary sets. If A ⊆ B and B ⊆ C then
A ⊆ C.
Proof
Assume that A, B and C are arbitrary sets.
Let A, B be any two sets. Then A equals B, written A = B, if
and only if A ⊆ B and B ⊆ A: that is,
A=B ⇔A⊆B∧B ⊆A
Assume that A ⊆ B and B ⊆ C.
Assume x ∈ A.
By assumption, we know that A ⊆ B.
By the definition of the subset relation, x ∈ B.
The sets {a, b, c} and {b, a, a, c} are equal sets.
The lists [a, b, c] and [b, a, a, c] are not equal lists.
We also know that B ⊆ C, and hence x ∈ C as required.
17
18
Constructing Sets
Basic Set Constructors
List elements inside curly brackets:
V = {a, e, i, o, u}
N = {0, 1, 2, . . .} {∅, {a}, {b}, {a, b}}
Let A and B be any sets:
Define a set by stating the property that its elements must
satisfy:
Union
A ∪ B = {x : x ∈ A ∨ x ∈ B}
Intersection
A ∩ B = {x : x ∈ A ∧ x ∈ B}
P = {x ∈ N : x is a prime number}
Difference
A − B = {x : x ∈ A ∧ x 6∈ B}
R = {x : x is a real number}
Symmetric difference
A 4 B = (A − B) ∪ (B − A)
Russel’s paradox
S = {X : X 6∈ X} is not well-defined.
20
19
Properties of operators
Example
Commutativity
Idempotence
A∪B =B∪A
A∪A=A
A ∪ B = {1, 3, 5, 6, 7, 9, 10, 11}
A∩B =B∩A
A∩A=A
A ∩ B = {3, 5}
Associativity
Empty set
A − B = {1, 7, 9}
A ∪ (B ∪ C) = (A ∪ B) ∪ C
A∪∅=A
A 4 B = {1, 7, 9, 6, 10, 11}
A ∩ (B ∩ C) = (A ∩ B) ∩ C
A∩∅=∅
Distributivity
Absorption
A ∪ (B ∩ C) = (A ∪ B) ∩ (A ∪ C)
A ∪ (A ∩ B) = A
A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C)
A ∩ (A ∪ B) = A
Let A = {1, 3, 5, 7, 9} and B = {3, 5, 6, 10, 11}. Then
It is often helpful to illustrate these combinations of sets using
Venn diagrams.
21
22
Proposition Let A, B and C be arbitrary sets. Then
A ∪ (B ∩ C) = (A ∪ B) ∩ (A ∪ C).
Proposition Let A, B and C be arbitrary sets. Then
A ∪ (B ∩ C) = (A ∪ B) ∩ (A ∪ C).
Proof Let A, B and C be arbitrary sets. We prove
Alternative Proof
1. A ∪ (B ∩ C) ⊆ (A ∪ B) ∩ (A ∪ C)
Let A, B and C be arbitrary sets.
2. (A ∪ B) ∩ (A ∪ C) ⊆ A ∪ (B ∩ C)
A ∪ (B ∩ C) = {x : x ∈ A ∨ x ∈ (B ∩ C)}
To prove part 1, assume x ∈ A ∪ (B ∩ C) for arbitrary x.
= {x : x ∈ A ∨ (x ∈ B ∧ x ∈ C)}
By definition, x ∈ A or x ∈ B ∩ C.
= {x : (x ∈ A ∨ x ∈ B) ∧ (x ∈ A ∨ x ∈ C)}
By definition, either x ∈ A, or x is in both B and C.
= {x : (x ∈ A ∪ B)∧(x ∈ A ∪ C)}
By distributivity, x ∈ A or x ∈ B, and x ∈ A or x ∈ C.
= {x : x ∈ (A ∪ B) ∩ (A ∪ C)}
This means that x ∈ A ∪ B and x ∈ A ∪ C, and hence
x ∈ (A ∪ B) ∩ (A ∪ C). Exercise Prove part 2.
23
We will go through some more examples in the tutorial.
24
Definition
The statement A ∪ (B ∩ C) = (A ∩ B) ∪ (A ∩ C) is false.
A simple counter-example is A = {a}, B = {b} and
C = {c}, where a, b and c are different. The statement is true
when A − (B ∪ C) = ∅ and (B ∩ C) − A = ∅.
The statement A ∪ (B ∩ C) = (A ∩ B) ∪ C is false.
Let A be a finite set. The cardinality of A, written |A|, is the
number of elements contained in A.
Notice the similarity with the length function over lists.
Examples
|{a, e, i, o, u}| = 5
A counter-example is A = {a}, B = ∅ and C = {c} for a
different from c. The statement is true when A − (B ∪ C) = ∅
and C − (A ∪ B) = ∅.
|∅| = 0
|N | = undefined for now
25
26
Powerset
Proposition
Let A and B be finite sets. Then |A ∪ B| = |A| + |B| − |A ∩ B|
Definition Let A be any set. Then the powerset of A,
written P(A), is {X : X ⊆ A}.
Examples
Informal proof
The number |A| + |B| counts the elements of A ∩ B twice, so
we abstract A ∩ B to obtain the result.
A consequence of this proposition is that, if A and B are
disjoint sets, then |A ∪ B| = |A| + |B|.
P({a, b}) = {∅, {a}, {b}, {a, b}}
P(∅) = {∅}
P(N ) = {∅, {1}, {2}, . . . , {1, 2}, {1, 3}, . . . ,
{2, 3}, . . . , {1, 2, 3}, . . .}
Proposition Let A be a finite set with |A| = n. Then
|P(A)| = 2n . Proof given in lectures and notes. Not required
27
28
Cartesian (or binary) product
An ordered pair (a, b) is a pair of objects a and b where the
order of a and b matters.
For any objects a,b, c, d, we have (a, b) = (c, d) if and only if
a = c and b = d.
Definition
Let A and B be arbitrary sets. The Cartesian (or binary)
product of A and B, written A × B, is
{(a, b) : a ∈ A ∧ b ∈ B}.
Examples
1. The coordinate system of real numbers R2 .
2. Computer marriage bureau: let M be the set of men
registered and W the set of women, then the set of all
possible matches is M × W .
3. Products are analogous to the product types of Haskell.
(Int, Char) is Haskell’s notation for the product Int × Char.
We sometimes write A2 instead of A × A.
29
30
Proposition
Let A and B be finite sets. Then |A × B| = |A| × |B|.
Proof Suppose that A and B are arbitrary sets with
A = {a1 , . . . , am } and B = {b1 , . . . , bn }. Draw a table with
m rows and n columns of the members of A × B:
(a1 , b1 ) (a1 , b2 ) . . .
(a2 , b1 ) (a2 , b2 ) . . .
...
Such a table has m × n entries.
n-ary product
For any n ≥ 1, an n-tuple is a sequence (a1 , . . . , an ) of n
objects where the order of the ai matter.
Definition Let A1 , . . . , An be arbitrary sets. The n-ary
Sn
product of the Ai , written A1 × . . . × An or i=1 Ai , is
{(a1 , . . . , an ) : ai ∈ Ai for 1 ≤ i ≤ n}.
The n-ary product of As is written An , with A2 corresponding
to the Cartesian product.
You do not need to remember this proof.
31
32
1. The three dimensional space of real numbers R3 .
2. The set timetable = day × time × room × courseno.
A typical element is (Wednesday, 11.00, 308, 140).
In Haskell notation, this timetable example can be given
by:
type Day = String
type Time = (Int, Int)
...
type Timetable = (Day, Time, Room, CourseNo)
(Wednesday, (11,00), 308, 140) :: Timetable
33
who : Name;
height : Real;
age : [0...120];
eyeColour : Colour;
dateOfBirth : Date
END
Just like products, records can be nested:
Date = RECORD
day : [1...31];
month : [1...12];
year : [1900...1990]
END
34
This record is like a Haskell type augmented with projector
functions:
type
type
type
type
Name =
Colour
Date =
Person
String
= String
(Int, Int)
= (Name, Float, Int, Colour, Date)
This fact can be simply proved by the induction principle
introduced next term.
who :: Person -> Name
height :: Person -> Float
age :: Person -> Int
eyeColour :: Person -> Colour
dateOfBirth :: Person -> Date
height (_, h, _, _, _) = h
...
35
36
Future
We can form the product of three sets in three different ways:
A×B×C
(A × B) × C
A × (B × C)
There is a natural correspondence between these three sets.
We will make this intuition precise later in the course.
37
Proposition Let Ai be finite sets for each 1 ≤ i ≤ n. Then
|A1 × . . . × An | = |A1 | × . . . × |An |.
Download