Uploaded by Kevin M.

lecture-01-full

advertisement
CS 225: Discrete Computational Structures
Lecture 01-*:
Introduction to Discrete Math
Prof. Jason Sauppe
Spring 2024
jsauppe@uwlax.edu
https://cs.uwlax.edu/~jsauppe/
Lecture 01-1a:
Speaking Mathematically
CS 225
2
What is Mathematics?
It is a language! The mathematical language is designed to be:
• Clear and unambiguous
• Precise
• Expressive
Other languages:
• English: designed for humans to understand; flexible and expressive;
ambiguity can usually be resolved from context
• Java: designed for computers to understand; very precise and
structured; ambiguity should be avoided
Just like programming languages, mathematics has its own syntax,
semantics, and code conventions that we need to know in order to
read and write mathematics.
CS 225
3
Lecture 01-1b:
Variables
CS 225
4
A Motivating Question
Question
Is there a number such that doubling it and adding 3 is the same as
squaring it?
• What is “it”?
• Reasonable in conversation, but potentially ambiguous
• Such ambiguity gets more complicated as we go on...
• Sentences can become excessively wordy
Definition
A variable is a symbol that serves as a placeholder for some object or
quantity.
We can use a variable (e.g., x) to represent the number of interest here!
CS 225
5
Answering the Question
The Revised Question
Is there a number x such that 2x + 3 = x2 ?
We can answer this question by using algebra to rewrite the equation
that we want to satisfy:
x2 = 2x + 3 ⇔ x2 − 2x − 3 = 0
⇔ (x − 3)(x + 1) = 0
⇔ x − 3 = 0 or x + 1 = 0
⇔ x = 3 or x = −1
(⇔ means “if and only if”)
So the answer here is yes: 3 and −1 both satisfy the desired property.
CS 225
6
Test Yourself
Question
Are there two numbers such that the sum of their squares equals the
square of their sum?
Rewrite the question using variables and then answer it.
Solution
Question: Are there numbers x and y such that x2 + y 2 = (x + y)2 ?
Answer: Yes.
Proof:
Let x = 0 and y = 0. {
Then x2 + y 2 = 02 + 02 = 0 + 0 = 0.
Also, (x + y)2 = (0 + 0)2 = 02 = 0.
So x2 + y 2 = (x + y)2 .
}
CS 225
7
Lecture 01-2a:
Statements
CS 225
8
Mathematical Statements
Definition
A statement (proposition) is a sentence that is either true or false but
not both.
Examples:
• Two plus two equals four.
2 + 2 = 4 (true)
• The square of six is twelve.
62 = 12
(false)
• The square of any integer is non-negative.
(true)
• Every prime number greater than 2 is odd.
(true)
A sentence that is not a statement:
• This class is interesting.
CS 225
9
Types of Statements
Statements can be subdivided into the following types:
• A universal statement says that all elements in a set satisfy a
certain property. Examples:
• Every integer is even or odd.
• All prime numbers are odd.
• For all real numbers r, r 2 ≥ 0.
(true)
(false)
(true)
• An existential statement says that at least one element in a set
satisfies a certain property. Examples:
• Some prime numbers are even.
• There is an integer that is both even and odd.
• There is an integer that is neither positive nor negative.
(true)
(false)
(true)
• A conditional statement is says that if one statement is true then
another statement is also true. Examples:
• If 378 is divisible by 18, then 378 is divisible by 6.
• If Rufus is a dog, then Rufus is a mammal.
CS 225
(true)
(true)
10
Examples of Combined Statements
We can further subdivide universal and existential statements into the
following:
Statement
Universal
Statement
Universal
Existential
Statement
CS 225
Universal
Conditional
Statement
Existential
Statement
Conditional
Statement
Existential
Universal
Statement
11
Lecture 01-2b:
Sets
CS 225
12
Sets
Definition
A set is a collection of elements, or objects.
Definition
Set roster notation specifies a set by listing the elements that belong to
the set (order and repetition are irrelevant). Commas are used to
separate the elements, and brackets {} are used to enclose the list.
Examples:
• The set containing the numbers 0 and 1: {0, 1}
• The set containing the first three prime numbers:
{2, 3, 5} = {5, 2, 3} = {2, 2, 3, 3, 3, 5, 5, 5, 5, 5}
(Remember: order and repetition don’t matter!)
CS 225
13
Set Roster Notation:
Ellipsis
For sets with more than a handful of elements, we can use an ellipsis
(. . .) to indicate the continuation of a pattern. Some examples:
• Set of first 100 positive integers: {1, 2, 3, . . . , 100}
• Set of all positive integers: Z+ = {1, 2, 3, . . .}
• Set of all negative integers: Z− = {. . . , −3, −2, −1}
• Set of all integers: Z = {. . . , −2, −1, 0, 1, 2, . . .}
Definition
Ellipsis originates from the Ancient Greek word that means “omission” or
“falling short”. In mathematics, it is typically read as “and so forth”.
Representing the set of all real numbers using set roster notation and
ellipses proves problematic: no pattern suffices to generate all elements!
We’ll use R to denote the set of all real numbers.
CS 225
14
“Element Of ” Operator
Definition
For a set S and an element x, the statement “x is an element of S”,
denoted x ∈ S, is true if and only if x is in S.
The statement “x is not an element of S”, denoted x ∈
/ S, is true if
and only if x is not in S.
Some examples:
True statements:
False statements:
• 57 ∈ {1, 2, 3, . . .}
• 3 ∈ {0, 2, 4, 6, . . .}
• −3 ∈ Z
• 0 ∈ Z+
• −3 ∈
/
• π∈
/R
Z+
• 3.4 ∈
/Z
• π∈Z
Syntax errors:
• 2∈8
The right (second) operand
for the “element of”
operator must be a set!
• 17 ∈ R
CS 225
15
The Empty Set and Nested Sets
Definition
The empty set, denoted as ∅ or {} is the set that contains no elements.
Sets can contain anything, even other sets!
• {{1}, 2}
• {1, 2}
• {{1}, {2}}
• {1, {2}}
None of the above sets are equal, though:
{1, 2} =
6 {{1}, {2}} =
6 {{1}, 2} =
6 {1, {2}}
• {1, 2} is the set containing the integers 1 and 2
• {1, {2}} is the set containing the integer 1 and “the set containing
the integer 2” (as a single object)
CS 225
16
Subsets
Definition
For two sets A and B, the statement “A is a subset of B”, denoted
A ⊆ B, is true if and only if every element of A is an element of B.
The statement “A is not a subset of B”, denoted A * B, is true if and
only if there is an element in A that is not in B.
Examples (all of which are true statements):
• {1, 2, 3} ⊆ {1, 2, 3, 4, 5}
• {1, 2, 3} ⊆ {1, 2, 3}
• {1, 2, 3} * {2, 3} but {2, 3} ⊆ {1, 2, 3}
• {1, 2, 3} * {1, 3, 5, 7} and {1, 3, 5, 7} * {1, 2, 3}
Syntax errors: 2 ⊆ {8}, {8} ⊆ 16
Both operands for the “subset of” operator must be sets!
CS 225
17
Lecture 01-3a:
More Set Notation
CS 225
18
Proper Subsets
Definition
For two sets A and B, the statement “A is a proper subset of B”,
denoted A ⊂ B, is true if and only if A ⊆ B and there is an element in
B that is not in A.
Examples:
• {1, 2} ⊂ {1, 2, 3} (we also have {1, 2} ⊆ {1, 2, 3})
• Z+ ⊂ Z and Z ⊂ R
This is somewhat analogous to < and ≤ with numbers:
• 3≤5
T
• {1, 2, 3} ⊆ {1, 2, 3, 4, 5} T
• {1, 2, 3} ⊂ {1, 2, 3, 4, 5} T
• 3<5
T
• {1, 2, 3} ⊆ {1, 2, 3}
T
• 3≤3
T
• {1, 2, 3} ⊂ {1, 2, 3}
F
• 3<3
F
CS 225
19
Test Yourself
Identify the syntactically correct statements and their truth values.
• 2 ∈ {1, 2, 3}
T
• {2} ∈ {1, 2, 3}
F
• {2} ⊆ {1, 2, 3}
T
• 2 ⊆ {1, 2, 3}
Syntax Error: ⊆ can only be used with sets
• {2} ⊆ {{1}, {2}}
F
• {2} ∈ {{1}, {2}}
T
• {1, 2} ⊆ {{1}, {2}}
F
• {1, 2} ∈ {{1}, {2}}
F
• {1, 2} ∈ {1, 2}
F
• {1, 2} ⊆ {1, 2}
T
• {2, 1} ⊂ {1, 2, 1}
F
CS 225
20
Lecture 01-3b:
Predicates and Set Builder Notation
CS 225
21
Statements and Predicates
Recall:
Definition
A statement (proposition) is a sentence that is either true or false but
not both.
The sentence “2 is even” is a (true) statement.
What about the sentence “n is even”? Without knowing what n is, we
cannot evaluate whether this is true or false!
Definition
A predicate is a sentence that contains a finite number of variables that
becomes a statement when the variables are replaced with actual values.
The sentence “n is even” is a predicate. (In English, the predicate is the
portion of a sentence that gives information about the subject.)
CS 225
22
Predicates and Predicate Symbols
Examples of predicates:
• n is even.
• x is a professor at UW–L.
• y evenly divides z.
The variables in a predicate are called predicate variables.
Predicate symbols are used to represent predicates, e.g.:
• E(n) = “n is even”
• P (x) = “x is a professor at UW–L”
• Q(y, z) = “y evenly divides z”
Then:
• E(7) is the statement “7 is even” (which is false).
• Q(4, 8) is the statement “4 evenly divides 8.” (true)
• Q(5, 8) is the statement “5 evenly divides 8.” (false)
CS 225
23
Set Builder Notation
Definition
Set builder notation is used to specify a set T by filtering elements
from another set S using a predicate (property) P :
T = {x ∈ S | P (x)}
T is the set of elements from S that satisfy predicate P .
Examples:
• The set of positive even integers: {x ∈ Z+ | x is even}
• The set of integers between −2 and 5: {x ∈ Z | −2 ≤ x ≤ 5}
• Let S = {2, 5, 7, 12, 15} and T = {x ∈ S | x is odd}.
So T = {5, 7, 15} in set roster notation.
The predicate can be thought of as a function that returns a boolean value (T/F) for
any given input; values resulting in T get included.
CS 225
24
Lecture 01-3c:
Ordered Pairs and Cartesian Product
CS 225
25
Ordered Pairs
Definition
For two elements a and b, the notation (a, b) denotes the ordered pair
with a as the first element and b as the second. Order and repetition
matter. For ordered pairs (a, b) and (c, d), (a, b) = (c, d) if and only if
a = c and b = d.
Examples:
• The ordered pair with 1 first and 2 second: (1, 2)
• The ordered pair with 2 first and 1 second: (2, 1) 6= (1, 2)
• The ordered pair with 1 first and 1 second: (1, 1) 6= 1
• ((1, 2), 3) is the ordered pair whose first component is the ordered
pair (1, 2) and second component is the number 3
• (((1, 2), 3), 4) is an ordered pair, but (1, 2, 3, 4) is an ordered 4-tuple
CS 225
26
Cartesian Product
Definition
For sets A and B, the Cartesian product of A and B, denoted A × B,
is the set of all ordered pairs (a, b) with a ∈ A and b ∈ B. That is,
A × B = {(a, b) | a ∈ A and b ∈ B}.
Example: Let A = {1, 2, 3}, B = {x, y}. Then:
A × B = {(1, x), (1, y), (2, x), (2, y), (3, x), (3, y)}
B × A = {(x, 1), (x, 2), (x, 3), (y, 1), (y, 2), (y, 3)}
B × B = {(x, x), (x, y), (y, x), (y, y)}
Also, A × B 6= B × A, so order matters for the Cartesian product (it
determines which elements can be the first elements in the ordered
pairs). (Order in which the pairs are listed is irrelevant though.)
CS 225
27
Size of a Set
Definition
For a finite set A, the cardinality of A, denoted |A|, is the number of
unique elements in A.
Examples:
• |{1, 2, 3}| = 3
• |{1, 2, 1}| = 2
• |{}| = 0
For A = {1, 2, 3} and B = {x, y} from the previous slide, we have
A × B = {(1, x), (1, y), (2, x), (2, y), (3, x), (3, y)}
so |A × B| = 6. In general, |A × B| = |A| · |B| for any sets A and B.
CS 225
28
Comic of the Day
https://xkcd.com/2343/
CS 225
29
Lecture 01-4a:
Relations
CS 225
30
Relations
Definition
For sets A and B, a relation R from A to B is a subset of A × B (i.e.,
R ⊆ A × B). For any x ∈ A and y ∈ B, x is related to y by R, written
x R y, if and only if (x, y) ∈ R. We write x 6R y if and only if (x, y) ∈
/ R.
The set A is the domain of R, and B is the co-domain.
Example: Let A = {1, 2} and B = {3, 4, 5}. Then:
• A × B = {(1, 3), (1, 4), (1, 5), (2, 3), (2, 4), (2, 5)}
• R1 = {(1, 3), (1, 4), (2, 3), (2, 5)} is a relation from A to B because
R1 ⊆ A × B
• R2 = {(2, 4)} is a is a relation from A to B because R2 ⊆ A × B
• R3 = {(1, 3), (1, 1), (2, 3)} is not a relation from A to B because
R2 * A × B (in particular, (1, 1) ∈ R3 and (1, 1) ∈
/ A × B)
CS 225
31
Drawing Relations
We can represent relations graphically by drawing the elements from the
two sets and arrows between them to indicate relationships.
Example: Let A = {1, 2}, B = {3, 4, 5}, and
R1 = {(1, 3), (1, 4), (2, 3), (2, 5)}, which is a relation from A to B. We
can draw R1 as:
A
R1
y
B
3
1
4
2
5
CS 225
32
Test Yourself
Let A = {0, 1} and B = {x, y}. Determine whether each set below is a
relation from A to B, a relation from B to A, both, or neither.
• R1 = {(0, x)}
• R2 = {(0, x), (0, y)}
(relation from A to B)
• R3 = {(0, y), (1, x), (y, 1)}
(neither)
• R4 = {(x, 0), (y, 0), (x, 1)}
(relation from B to A)
• R5 = {}
(both)
CS 225
(relation from A to B)
33
Lecture 01-4b:
Relations Defined by Rules
CS 225
34
Relations with Rules
From the definition, a relation from A to B is a subset of A × B. So we
can specify any relation R from A to B simply by specifying (e.g.,
listing) the ordered pairs that belong to R.
Relations can also be specified by using a pattern or rule that
determines how the elements relate (assuming such patterns exist).
Example: Let S be the set of all students and C be the set of all classes
at UWL.
• Let T be the relation from S to C defined by the rule x T y if and
only if student x is taking class y, for all (x, y) ∈ S × C.
• Let P be the relation from S to C defined by the rule x P y if and
only if student x has passed class y, for all (x, y) ∈ S × C.
Relations provide a formal way to represent connections between
objects in one set and objects in another! (very useful for databases)
CS 225
35
Relations with Rules: Another Example
Example: Let A = {0, 1, 3}, let B = {1, 2, 4}, and let R be a relation
from A to B defined by the rule x R y if and only if |x − y| ≤ 1, for all
(x, y) ∈ A × B.
Then:
A × B = {(0, 1), (0, 2), (0, 4),
A
(1, 1), (1, 2), (1, 4),
(3, 1), (3, 2), (3, 4)}
R = {(0, 1),
(1, 1), (1, 2),
R
y
B
0
1
1
2
3
4
(3, 2), (3, 4)}.
CS 225
36
Lecture 01-4c:
Functions
CS 225
37
Functions
Definition
A function F from a set A to a set B is a relation with domain A and
co-domain B with the property that every element in A relates to exactly
one element in B.
Example: Let A = {0, 1, 3}, let B = {1, 2, 4}, and let F be a relation
from A to B defined by the rule x F y if and only if y = x + 1 for all
(x, y) ∈ A × B.
A
F
B
Then
y
F = {(0, 1), (1, 2), (3, 4)}.
Additionally, F is a function.
CS 225
0
1
1
2
3
4
38
Notation for Functions
Definition
For a function F from A to B and any element x ∈ A, the one element
in B that x relates to is denoted F (x), read as “F of x”.
Note that multiple elements may map to the same place without
violating the definition of a function; as shown below:
A
F
y
B
Functions provide a formal way to represent a mapping from objects in
one set (the “inputs”) to objects in another set (the “outputs”).
CS 225
39
Test Yourself:
Identify the Functions
CS 225
(a)
(b)
(c)
(d)
40
Download