Download presentation
Presentation is loading. Please wait.
1
Discrete Mathematics and its Applications
9/8/2019 University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter Slides adapted from Michael P. Frank’s Course Based on the Text Discrete Mathematics & Its Applications (5th Edition) by Kenneth H. Rosen A word about organization: Since different courses have different lengths of lecture periods, and different instructors go at different paces, rather than dividing the material up into fixed-length lectures, we will divide it up into “modules” which correspond to major topic areas and will generally take 1-3 lectures to cover. Within modules, we have smaller “topics”. Within topics are individual slides. The instructor can bring several modules to each lecture with him, to make sure he has enough material to fill the lecture, or in case he wants to preview or review slides from upcoming or recent past lectures. 9/8/2019 Michael P. Frank / Kees van Deemter (c) , Michael P. Frank
2
Rosen 5th ed., §1.8 ~60 slides, ~1.5 lectures
Module #4: Functions Rosen 5th ed., §1.8 ~60 slides, ~1.5 lectures 9/8/2019 Michael P. Frank / Kees van Deemter
3
Michael P. Frank / Kees van Deemter
Functions From calculus, you know the concept of a real-valued function f, which assigns to each number xR one particular value y=f(x), where yR. Example: f defined by the rule f(x)=x2 The notion of a function can be generalized to the concept of assigning elements of any set to elements of any set. Functions are also called operators. 9/8/2019 Michael P. Frank / Kees van Deemter
4
Function: Formal Definition
A function f from (or “mapping”) A to B (f:AB) is an assignment of exactly one element f(x)B to each element xA. Some further generalizations of this idea: Functions of n arguments: f: (A1 x A2... x An) B. A partial (non-total) function f assigns zero or one elements of B to each element xA. 9/8/2019 Michael P. Frank / Kees van Deemter
5
Michael P. Frank / Kees van Deemter
Graphs of Functions We can represent a function f:AB as a set of ordered pairs f ={(a,f(a)) | aA}. This makes f a relation between A and B: f is a subset of A x B. But functions are special: for every aA, there is at least one pair (a,b). Formally: aAbB((a,b)f) for every aA, there is at most one pair (a,b). Formally: a,b,c((a,b)f (a,c)f bc) A relation over numbers can be represent as a set of points on a plane. (A point is a pair (x,y).) A function is then a curve (set of points), with only one y for each x. 9/8/2019 Michael P. Frank / Kees van Deemter
6
Discrete Mathematics and its Applications
9/8/2019 Functions can be represented graphically in several ways: A B f • • f • • • • y • a b • Note that the inverses of the functions in the two diagrams on the left are not functions. Note also that the plot has gaps if the domain of the function is not the set R • • • x A B Bipartite Graph Plot Like Venn diagrams 9/8/2019 Michael P. Frank / Kees van Deemter (c) , Michael P. Frank
7
Functions We’ve Seen So Far
A proposition might be viewed as a function from “situations” to truth values {T,F} p=“It is raining.” s=our situation here,now p(s){T,F}. A propositional operator can be viewed as a function from ordered pairs of truth values to truth values: e.g., ((F,T)) = T. Another example: →((T,F)) = F. 9/8/2019 Michael P. Frank / Kees van Deemter
8
Michael P. Frank / Kees van Deemter
More functions so far… A predicate (or property)can be viewed as a function from objects to propositions: P :≡ “is 7 feet tall”; P(Mike) = “Mike is 7 feet tall.” A set S over universe U can be viewed as a function from the elements of U to ... 9/8/2019 Michael P. Frank / Kees van Deemter
9
Michael P. Frank / Kees van Deemter
Still More Functions A set S over universe U can be viewed as a function from the elements of U to … … {T, F}, saying for each element of U whether it is in S. (This is called the characteristic function of S) Suppose U={0,1,2,3,4}. Then S={1,3} S(0)=S(2)=S(4)=F, S(1)=S(3)=T. 9/8/2019 Michael P. Frank / Kees van Deemter
10
Michael P. Frank / Kees van Deemter
Still More Functions A set operator, such as or , can be viewed as a function from … to … 9/8/2019 Michael P. Frank / Kees van Deemter
11
Michael P. Frank / Kees van Deemter
Still More Functions A set operator such as or can be viewed as a function … … from (ordered) pairs of sets, to sets. Example: (({1,3},{3,4})) = {3} 9/8/2019 Michael P. Frank / Kees van Deemter
12
Michael P. Frank / Kees van Deemter
A new notation Sometimes we write YX to denote the set F of all possible functions f: XY. Thus, f YX is another way of saying that f: XY. (This notation is especially appropriate, because for finite X, Y, we have |F| = |Y||X|. ) 9/8/2019 Michael P. Frank / Kees van Deemter
13
A Trick that’s sometimes used
If we use representations F0, T1, then a subset TS is a function from S to {0,1}, Therefore, P(S) can be represented as {0,1}S (the set of all functions from S to {0,1} ) (Note that if we also represent 2:{0,1}, then P(S) can be represented as 2S . The powerset of S is sometimes written this way to stress the cardinality of the powerset.) 9/8/2019 Michael P. Frank / Kees van Deemter
14
Some Function Terminology
If f:AB, and f(a)=b (where aA & bB), then we say: A is the domain of f. B is the codomain of f. b is the image of a under f. a is a pre-image of b under f. In general, b may have more than 1 pre-image. The range RB of f is R={b | a f(a)=b }. We also say the signature of f is A→B. 9/8/2019 Michael P. Frank / Kees van Deemter
15
Michael P. Frank / Kees van Deemter
Range versus Codomain The range of a function may not be its whole codomain. The codomain is the set that the function is declared to map all domain values into. The range is the particular set of values in the codomain that the function actually maps elements of the domain to. (One might say: The range is the smallest set that could be used as its codomain.) 9/8/2019 Michael P. Frank / Kees van Deemter
16
Range vs. Codomain - Example
Suppose I declare to you that: “f is a function mapping students in this class to the set of grades {A,B,C,D,E}.” At this point, you know f’s codomain is: __________, and its range is ________. Suppose the grades turn out all As and Bs. Then the range of f is _________, but its codomain is __________________. {A,B,C,D,E} unknown {A,B} still {A,B,C,D,E} 9/8/2019 Michael P. Frank / Kees van Deemter
17
(n-ary) functions on a set
An n-ary function (also: n-ary operator) over (also: on) S is any function from the set of ordered n-tuples of elements of S, to S itself. E.g., if S={T,F}, can be seen as a unary operator, and , are binary operators on S. Another example: and are binary operators on the set of all sets. 9/8/2019 Michael P. Frank / Kees van Deemter
18
Operators over functions
If (“dot”) is an n-ary operator over B, then we can extend to also denote an operator over functions from A to B. E.g.: Given any binary operator :BBB, and functions f,g:AB, we define (f g):AB to be the function defined by: aA, (f g)(a) = f(a)g(a). 9/8/2019 Michael P. Frank / Kees van Deemter
19
Function Operator Example
,× (plus,times) are binary operators over R. (Normal addition & multiplication.) Therefore, we can also “add” and “multiply” functions f,g:RR: (f g):RR, where (f g)(x) = f(x) g(x) (f × g):RR, where (f × g)(x) = f(x) × g(x) 9/8/2019 Michael P. Frank / Kees van Deemter
20
Function Composition Operator
Note match here. For functions g:AB and f:BC, there is a special operator called compose (“○”). It composes (creates) a new function out of f and g by applying f to the result of applying g. We say (f○g):AC, where (f○g)(a) :≡ f(g(a)). g(a)B, so f(g(a)) is defined and f(g(a))C. Note that ○ is non-commutative (i.e., we don’t always have f○g = g○f). 9/8/2019 Michael P. Frank / Kees van Deemter
21
Function Composition Operator
“We don’t always have f○g = g○f “ Can you express this in predicate logic? 9/8/2019 Michael P. Frank / Kees van Deemter
22
Function Composition Operator
Discrete Mathematics and its Applications 9/8/2019 Function Composition Operator “We don’t always have f○g = g○f “ Can you express this in predicate logic? (fgx(f○g(x) =g○f (x))). [Do not write: fgx(f○g(x) g○f (x)))] (Note that this formula quantifies over functions as well as ordinary objects – something that is not possible in First Order Predicate Logic (FOPL), which is what was taught earlier in this course.) Two functions whose composition commutes for all their arguments are f(x)=x^2 and g(x)=square root of x. Two functions whose composition never commutes: f(x)=x^2 and g(x)=-x. 9/8/2019 Michael P. Frank / Kees van Deemter (c) , Michael P. Frank
23
Images of Sets under Functions
Given f:AB, and SA, The image of S under f is the set of all images (under f) of the elements of S. f(S) : {f(s) | sS} : {b | sS: f(s)=b}. The range of f equals the image (under f) of ... 9/8/2019 Michael P. Frank / Kees van Deemter
24
Images of Sets under Functions
Given f:AB, and SA, The image of S under f is the set of all images (under f) of the elements of S. f(S) : {f(s) | sS} : {b | sS: f(s)=b}. The range of f equals the image (under f) of f’s domain. 9/8/2019 Michael P. Frank / Kees van Deemter
25
Michael P. Frank / Kees van Deemter
One-to-One Functions A function is one-to-one (1-1), or injective, or an injection, iff every element of its range has only 1 pre-image. Formally: given f:AB, “x is injective” : (x,y: xy f(x)f(y)). In other words: only one element of the domain is mapped to any given one element of the range. In this case, domain & range have same cardinality. What about codomain? 9/8/2019 Michael P. Frank / Kees van Deemter
26
Michael P. Frank / Kees van Deemter
Codomain may be larger. 9/8/2019 Michael P. Frank / Kees van Deemter
27
One-to-One Illustration
Are these relations one-to-one functions? • • • • • • • • • • • • • • • • • • • • • • • • • • • 9/8/2019 Michael P. Frank / Kees van Deemter
28
One-to-One Illustration
Are these relations one-to-one functions? • • • • • • • • • • • • • • • • • • • • • • • • • • • One-to-one 9/8/2019 Michael P. Frank / Kees van Deemter
29
One-to-One Illustration
Are these relations one-to-one functions? • • • • • • • • • • • • • • • • • • • • • • • • • • • Not one-to-one One-to-one 9/8/2019 Michael P. Frank / Kees van Deemter
30
One-to-One Illustration
Are these relations one-to-one functions? • • • • • • • • • • • • • • • • • • • • • • • • • • • Not one-to-one Not even a function! One-to-one 9/8/2019 Michael P. Frank / Kees van Deemter
31
Sufficient Conditions for 1-1ness
For functions f over numbers, we say: f is strictly increasing iff x>y f(x)>f(y) for all x,y in domain; f is strictly decreasing iff x>y f(x)<f(y) for all x,y in domain; If f is either strictly increasing or strictly decreasing, then f must be one-to-one. Does the converse hold? 9/8/2019 Michael P. Frank / Kees van Deemter
32
Michael P. Frank / Kees van Deemter
If f is either strictly increasing or strictly decreasing, then f is one-to-one. Does the converse hold? 9/8/2019 Michael P. Frank / Kees van Deemter
33
Michael P. Frank / Kees van Deemter
If f is either strictly increasing or strictly decreasing, then f is one-to-one. Does the converse hold? NO E.g., f:NN such that if x is even then f(x)=x+1 if x is odd then f(x)=x-1 9/8/2019 Michael P. Frank / Kees van Deemter
34
Onto (Surjective) Functions
A function f:AB is onto or surjective or a surjection iff its range is equal to its codomain (bB, aA: f(a)=b). Consider “country of birth of”: AB, where A=people, B=countries. Is this a function? Is it an injection? Is it a surjection? 9/8/2019 Michael P. Frank / Kees van Deemter
35
Onto (Surjective) Functions
A function f:AB is onto or surjective or a surjection iff its range is equal to its codomain Consider “country of birth of”: AB, where A=people, B=countries. Is this a function? Yes (always 1 c.o.b.) Is it an injection? No (many have same c.o.b.) Is it a surjection? Probably yes .. 9/8/2019 Michael P. Frank / Kees van Deemter
36
Onto (Surjective) Functions
A function f:AB is onto or surjective or a surjection iff its range is equal to its codomain In predicate logic: 9/8/2019 Michael P. Frank / Kees van Deemter
37
Onto (Surjective) Functions
A function f:AB is onto or surjective or a surjection iff its range is equal to its codomain. In predicate logic: bBaA f(a)=b 9/8/2019 Michael P. Frank / Kees van Deemter
38
Onto (Surjective) Functions
A function f:AB is onto or surjective or a surjection iff its range is equal to its codomain (bBaA f(a)=b). Think: An onto function maps the set A onto (over, covering) the entirety of the set B, not just over a piece of it. E.g., for domain & codomain R, x3 is onto, whereas x2 isn’t. (Why not?) 9/8/2019 Michael P. Frank / Kees van Deemter
39
Onto (Surjective) Functions
E.g., for domain & codomain R, x3 is onto, but x2 is not. (Why not?) Consider f:RR such that, for all x, f(x)=x2. Consider any negative number a=-b in R. x(x2=a). So f is not surjective. Consider f:RR such that for all x, f(x)=x3. Consider any negative number a=-b in R. Let z be such that z3=b. Then (-z)3=-b=a 9/8/2019 Michael P. Frank / Kees van Deemter
40
Michael P. Frank / Kees van Deemter
The Identity Function For any domain A, the identity function I:AA (also written IA) on A is the function such that everything is mapped to itself In predicate logic: 9/8/2019 Michael P. Frank / Kees van Deemter
41
Michael P. Frank / Kees van Deemter
The Identity Function For any domain A, the identity function I:AA (also written IA) on A is the function such that everything is mapped to itself In predicate logic: aA I(a)=a. 9/8/2019 Michael P. Frank / Kees van Deemter
42
Michael P. Frank / Kees van Deemter
The Identity Function For any domain A, the identity function I:AA (also written IA) on A is the function such that aA I(a)=a. Is the identity function one-to-one (injective)? onto (surjective)? 9/8/2019 Michael P. Frank / Kees van Deemter
43
Michael P. Frank / Kees van Deemter
The Identity Function For any domain A, the identity function I:AA (also written IA) on A is the function such that aA I(a)=a. Is the identity function one-to-one (injective)? Yes onto (surjective)? Yes 9/8/2019 Michael P. Frank / Kees van Deemter
44
Identity Function Illustrations
The identity function: • • • y y = I(x) = x • • • • • • x Domain and range 9/8/2019 Michael P. Frank / Kees van Deemter
45
Michael P. Frank / Kees van Deemter
Illustration of Onto Are these functions onto their depicted co-domains? • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • 9/8/2019 Michael P. Frank / Kees van Deemter
46
Michael P. Frank / Kees van Deemter
Illustration of Onto Are these functions onto? • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • 9/8/2019 Michael P. Frank / Kees van Deemter
47
Michael P. Frank / Kees van Deemter
Illustration of Onto Are these functions onto? • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • onto not onto onto not onto 9/8/2019 Michael P. Frank / Kees van Deemter
48
Michael P. Frank / Kees van Deemter
Illustration of Onto Are these functions 1-1? • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • onto not onto onto not onto 9/8/2019 Michael P. Frank / Kees van Deemter
49
Michael P. Frank / Kees van Deemter
Illustration of Onto Are these functions 1-1? • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • not 1-1 onto not 1-1 not onto 1-1 onto 1-1 not onto 9/8/2019 Michael P. Frank / Kees van Deemter
50
Michael P. Frank / Kees van Deemter
Bijections A function is said to be a one-to-one correspondence, or a bijection iff it is both one-to-one and onto. 9/8/2019 Michael P. Frank / Kees van Deemter
51
Two terminologies for talking about functions
injection = one-to-one surjection = onto bijection = one-to-one correspondence 3 = 1&2 9/8/2019 Michael P. Frank / Kees van Deemter
52
Michael P. Frank / Kees van Deemter
Bijections For bijections f:AB, there exists an inverse of f, written f 1: BA Intuitively, this is the function that undoes everything that f does Formally, it’s the unique function such that ... 9/8/2019 Michael P. Frank / Kees van Deemter
53
Michael P. Frank / Kees van Deemter
Bijections For bijections f:AB, there exists an inverse of f, written f 1: BA Intuitively, this is the function that undoes everything that f does Formally, it’s the unique function such that (recall that IA is the identity function on A) 9/8/2019 Michael P. Frank / Kees van Deemter
54
Michael P. Frank / Kees van Deemter
Bijections Example 1: Let f: ZZ be defined as f(x)=x+1. What is f1 ? Example 2: Let g: ZN be defined as g(x)=|x|. What is g1 ? 9/8/2019 Michael P. Frank / Kees van Deemter
55
Michael P. Frank / Kees van Deemter
Bijections Example 1: Let f: ZZ be defined as f(x)=x+1. What is f1 ? f1 is the function (let’s call it h) h: ZZ defined as h(x)=x-1. Proof: h(f(x)) = (x+1)-1 = x 9/8/2019 Michael P. Frank / Kees van Deemter
56
Michael P. Frank / Kees van Deemter
Bijections Example 2: Let g: ZN be defined as g(x)=|x|. What is g1 ? This was a trick question: there is no such function, since g is not a bijection: There is no function h such that h(|x|)=x and h(|x|)=x (NB There is a relation h for which this is true.) 9/8/2019 Michael P. Frank / Kees van Deemter
57
Aside About Representations
It is possible to represent any type of discrete structure (propositions, bit-strings, numbers, sets, ordered pairs, functions) in terms of some combination of other structures. Perhaps none of these structures is more fundamental than the others. However, logic, and sets are often used as the foundation for all else E.g. in 9/8/2019 Michael P. Frank / Kees van Deemter
58
A Couple of Key Functions
In discrete math, we frequently use the following two functions over real numbers: The floor function ·:R→Z, where x (“floor of x”) means the largest integer x. I.e., x :≡ max({iZ|i≤x}). The ceiling function · :R→Z, where x (“ceiling of x”) means the smallest integer x. x :≡ min({iZ|i≥x}) 9/8/2019 Michael P. Frank / Kees van Deemter
59
Visualizing Floor & Ceiling
Discrete Mathematics and its Applications 9/8/2019 Visualizing Floor & Ceiling Real numbers “fall to their floor” or “rise to their ceiling.” 3 . 1.6=2 2 . 1.6 . 1 1.6=1 . 1.4= 1 In other words, it matters whether you first apply minus then apply ceiling/floor, or the other way round (i.e. first apply ceiling/floor then apply minus). 1 . 1.4 . 2 1.4= 2 . . . 3 3 3=3= 3 9/8/2019 Michael P. Frank / Kees van Deemter (c) , Michael P. Frank
60
Do these equalities hold?
x = x & x = x 9/8/2019 Michael P. Frank / Kees van Deemter
61
It depends on whether x is an integer
If xZ then x = x = x, so x = x = x & x = x = x But if xZ, then x x & x x E.g., 3.4 = 4 3 = 3.4 9/8/2019 Michael P. Frank / Kees van Deemter
62
Plots with floor/ceiling
Note that for f(x)=x, the graph of f includes the point (a, 0) for all values of a such that a0 and a<1, but not for the value a=1. {xR : x = 0} = (informally) = {0,..,0.1,..0.2,..,…0.9,…} does not include its limit 1. Sets that do not include all of their limit points are generally called open sets. In a plot, we draw a limit point of a curve using an open dot (circle) if the limit point is not on the curve, and with a closed (solid) dot if it is on the curve. 9/8/2019 Michael P. Frank / Kees van Deemter
63
Plots with floor/ceiling: Example
Plot of graph of function f(x) = x/3: f(x) Set of points (x, f(x)) +2 3 x +3 2 9/8/2019 Michael P. Frank / Kees van Deemter
64
Review of §1.8 (Functions)
Function variables f, g, h, … Notations: f:AB, f(a), f(A). Terms: image, pre-image, domain, codomain, range, one-to-one, onto, strictly (in/de)creasing, bijective, inverse, composition. Function unary operator f 1, binary operators , , etc., and ○. The RZ functions x and x. 9/8/2019 Michael P. Frank / Kees van Deemter
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.