Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
40 views

Class12 (Function)

This document discusses functions and their key properties in discrete mathematics. It defines a function as a mapping from a domain set to a codomain set that assigns each element of the domain to exactly one element of the codomain. The document provides examples of valid and invalid functions and discusses representing functions explicitly by listing assignments or compactly with a formula. It also defines important sets associated with functions, such as the domain, codomain, range, images, and pre-images.

Uploaded by

Ilham Hafiz
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views

Class12 (Function)

This document discusses functions and their key properties in discrete mathematics. It defines a function as a mapping from a domain set to a codomain set that assigns each element of the domain to exactly one element of the codomain. The document provides examples of valid and invalid functions and discusses representing functions explicitly by listing assignments or compactly with a formula. It also defines important sets associated with functions, such as the domain, codomain, range, images, and pre-images.

Uploaded by

Ilham Hafiz
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 17

CS 441 Discrete Mathematics for CS

Lecture 12

Functions

Milos Hauskrecht
milos@cs.pitt.edu
5329 Sennott Square

CS 441 Discrete mathematics for CS M. Hauskrecht

Functions
• Definition: Let A and B be two sets. A function from A to
B, denoted f : A → B , is an assignment of exactly one element
of B to each element of A. We write f(a) = b to denote the
assignment of b to an element a of A by the function f.

A f: A → B B

CS 441 Discrete mathematics for CS M. Hauskrecht


Functions
• Definition: Let A and B be two sets. A function from A to
B, denoted f : A → B , is an assignment of exactly one element
of B to each element of A. We write f(a) = b to denote the
assignment of b to an element a of A by the function f.

A f: A → B B

Not allowed !!!

CS 441 Discrete mathematics for CS M. Hauskrecht

Representing functions
Representations of functions:
1. Explicitly state the assignments in between elements of the
two sets
2. Compactly by a formula. (using ‘standard’ functions)

Example1:
• Let A = {1,2,3} and B = {a,b,c}
• Assume f is defined as:
• 1→c
• 2→a
• 3→c
• Is f a function ?

CS 441 Discrete mathematics for CS M. Hauskrecht


Representing functions
Representations of functions:
1. Explicitly state the assignments in between elements of the
two sets
2. Compactly by a formula. (using ‘standard’ functions)

Example1:
• Let A = {1,2,3} and B = {a,b,c}
• Assume f is defined as:
• 1→c
• 2→a
• 3→c
• Is f a function ?
• Yes. since f(1)=c, f(2)=a, f(3)=c. each element of A is assigned
an element from B
CS 441 Discrete mathematics for CS M. Hauskrecht

Representing functions
Representations of functions:
1. Explicitly state the assignments in between elements of the
two sets
2. Compactly by a formula. (using ‘standard’ functions)
Example 2:
• Let A = {1,2,3} and B = {a,b,c}
• Assume g is defined as
• 1→c
• 1→b
• 2→a
• 3→c
• Is g a function?

CS 441 Discrete mathematics for CS M. Hauskrecht


Representing functions
Representations of functions:
1. Explicitly state the assignments in between elements of the
two sets
2. Compactly by a formula. (using ‘standard’ functions)
Example 2:
• Let A = {1,2,3} and B = {a,b,c}
• Assume g is defined as
• 1→c
• 1→b
• 2→a
• 3→c
• Is g a function?
• No. g(1) = is assigned both c and b.

CS 441 Discrete mathematics for CS M. Hauskrecht

Representing functions
Representations of functions:
1. Explicitly state the assignments in between elements of the
two sets
2. Compactly by a formula. (using ‘standard’ functions)
Example 3:
• A = {0,1,2,3,4,5,6,7,8,9}, B = {0,1,2}
• Define h: A → B as:
• h(x) = x mod 3.
• (the result is the remainder after the division by 3)
• Assignments:
• 0→ ?

CS 441 Discrete mathematics for CS M. Hauskrecht


Representing functions
Representations of functions:
1. Explicitly state the assignments in between elements of the
two sets
2. Compactly by a formula. (using ‘standard’ functions)
Example 3:
• A = {0,1,2,3,4,5,6,7,8,9}, B = {0,1,2}
• Define h: A → B as:
• h(x) = x mod 3.
• (the result is the remainder after the division by 3)
• Assignments:
• 0→ 0
• 1→?

CS 441 Discrete mathematics for CS M. Hauskrecht

Representing functions
Representations of functions:
1. Explicitly state the assignments in between elements of the
two sets
2. Compactly by a formula. (using ‘standard’ functions)
Example 3:
• A = {0,1,2,3,4,5,6,7,8,9}, B = {0,1,2}
• Define h: A → B as:
• h(x) = x mod 3.
• (the result is the remainder after the division by 3)
• Assignments:
• 0→0
• 1→ 1
• 2→ ?
Representing functions
Representations of functions:
1. Explicitly state the assignments in between elements of the
two sets
2. Compactly by a formula. (using ‘standard’ functions)
Example 3:
• A = {0,1,2,3,4,5,6,7,8,9}, B = {0,1,2}
• Define h: A → B as:
• h(x) = x mod 3.
• (the result is the remainder after the division by 3)
• Assignments:
• 0→ 0 3→ ?
• 1→ 1
• 2→ 2

Representing functions
Representations of functions:
1. Explicitly state the assignments in between elements of the
two sets
2. Compactly by a formula. (using ‘standard’ functions)
Example 3:
• A = {0,1,2,3,4,5,6,7,8,9}, B = {0,1,2}
• Define h: A → B as:
• h(x) = x mod 3.
• (the result is the remainder after the division by 3)
• Assignments:
• 0→ 0 3→ 0
• 1→1 4→ ?
• 2→ 2
Representing functions
Representations of functions:
1. Explicitly state the assignments in between elements of the
two sets
2. Compactly by a formula. (using ‘standard’ functions)
Example 3:
• A = {0,1,2,3,4,5,6,7,8,9}, B = {0,1,2}
• Define h: A → B as:
• h(x) = x mod 3.
• (the result is the remainder after the division by 3)
• Assignments:
• 0→ 0 3→ 0
• 1→ 1 4→ 1
• 2→ 2 …

Important sets in discrete math


Definitions: Let f be a function from A to B. We say that A is the
domain of f and B is the codomain of f. If f(a) = b, we say that
b is the image of a and a is a pre-image of b. The range of f is
the set of all images of elements of A. Also, if f is a function
from A to B, we say f maps A to B.
Example: Let A = {1,2,3} and B = {a,b,c}
• Assume f is defined as: 1 → c, 2 → a, 3 → c
• What is the image of 1?

CS 441 Discrete mathematics for CS M. Hauskrecht


Important sets in discrete math
Definitions: Let f be a function from A to B. We say that A is the
domain of f and B is the codomain of f. If f(a) = b, we say that
b is the image of a and a is a pre-image of b. The range of f is
the set of all images of elements of A. Also, if f is a function
from A to B, we say f maps A to B.
Example: Let A = {1,2,3} and B = {a,b,c}
• Assume f is defined as: 1 → c, 2 → a, 3 → c
• What is the image of 1?
• 1→c c is the image of 1
• What is the pre-image of a?

CS 441 Discrete mathematics for CS M. Hauskrecht

Important sets in discrete math


Definitions: Let f be a function from A to B. We say that A is the
domain of f and B is the codomain of f. If f(a) = b, we say that
b is the image of a and a is a pre-image of b. The range of f is
the set of all images of elements of A. Also, if f is a function
from A to B, we say f maps A to B.
Example: Let A = {1,2,3} and B = {a,b,c}
• Assume f is defined as: 1 → c, 2 → a, 3 → c
• What is the image of 1?
• 1→c c is the image of 1
• What is the pre-image of a?
• 2→a 2 is a pre-image of a.
• Domain of f ?

CS 441 Discrete mathematics for CS M. Hauskrecht


Important sets in discrete math
Definitions: Let f be a function from A to B. We say that A is the
domain of f and B is the codomain of f. If f(a) = b, we say that
b is the image of a and a is a pre-image of b. The range of f is
the set of all images of elements of A. Also, if f is a function
from A to B, we say f maps A to B.
Example: Let A = {1,2,3} and B = {a,b,c}
• Assume f is defined as: 1 → c, 2 → a, 3 → c
• What is the image of 1?
• 1→c c is the image of 1
• What is the pre-image of a?
• 2→a 2 is a pre-image of a.
• Domain of f ? {1,2,3}
• Codomain of f ?
CS 441 Discrete mathematics for CS M. Hauskrecht

Important sets in discrete math


Definitions: Let f be a function from A to B. We say that A is the
domain of f and B is the codomain of f. If f(a) = b, we say that
b is the image of a and a is a pre-image of b. The range of f is
the set of all images of elements of A. Also, if f is a function
from A to B, we say f maps A to B.
Example: Let A = {1,2,3} and B = {a,b,c}
• Assume f is defined as: 1 → c, 2 → a, 3 → c
• What is the image of 1?
• 1→c c is the image of 1
• What is the pre-image of a?
• 2→a 2 is a pre-image of a.
• Domain of f ? {1,2,3}
• Codomain of f ? {a,b,c}
• Range of f ?

CS 441 Discrete mathematics for CS M. Hauskrecht


Important sets in discrete math
Definitions: Let f be a function from A to B. We say that A is the
domain of f and B is the codomain of f. If f(a) = b, we say that
b is the image of a and a is a pre-image of b. The range of f is
the set of all images of elements of A. Also, if f is a function
from A to B, we say f maps A to B.
Example: Let A = {1,2,3} and B = {a,b,c}
• Assume f is defined as: 1 → c, 2 → a, 3 → c
• What is the image of 1?
• 1→c c is the image of 1
• What is the pre-image of a?
• 2→a 2 is a pre-image of a.
• Domain of f ? {1,2,3}
• Codomain of f ? {a,b,c}
• Range of f ? {a,c}

CS 441 Discrete mathematics for CS M. Hauskrecht

Image of a subset
Definition: Let f be a function from set A to set B and let S be a
subset of A. The image of S is a subset of B that consists of the
images of the elements of S. We denote the image of S by f(S),
so that f(S) = { f(s) | s ∈ S }.
A f: A → B B
S f(S)

Example:
• Let A = {1,2,3} and B = {a,b,c} and f: 1 → c, 2 → a, 3 → c
• Let S = {1,3} then image f(S) = ?
CS 441 Discrete mathematics for CS M. Hauskrecht
Image of a subset
Definition: Let f be a function from set A to set B and let S be a
subset of A. The image of S is a subset of B that consists of the
images of the elements of S. We denote the image of S by f(S),
so that f(S) = { f(s) | s ∈ S }.
A f: A→B B
S f(S)

Example:
• Let A = {1,2,3} and B = {a,b,c} and f: 1 → c, 2 → a, 3 → c
• Let S = {1,3} then image f(S) = {c}.
CS 441 Discrete mathematics for CS M. Hauskrecht

Injective function
Definition: A function f is said to be one-to-one, or injective, if
and only if f(x) = f(y) implies x = y for all x, y in the domain of
f. A function is said to be an injection if it is one-to-one.
Alternative: A function is one-to-one if and only if f(x) ≠ f(y),
whenever x ≠ y. This is the contrapositive of the definition.

A f: A → B B

CS 441 Discrete mathematics for CS M. Hauskrecht


Injective function
Definition: A function f is said to be one-to-one, or injective, if
and only if f(x) = f(y) implies x = y for all x, y in the domain of
f. A function is said to be an injection if it is one-to-one.
Alternate: A function is one-to-one if and only if f(x) ≠ f(y),
whenever x ≠ y. This is the contrapositive of the definition.

A f: A → B B A f: A → B B

Not injective Injective function

CS 441 Discrete mathematics for CS M. Hauskrecht

Injective functions
Example 1: Let A = {1,2,3} and B = {a,b,c}
• Define f as
– 1→c
– 2→a
– 3→c
• Is f one to one?

CS 441 Discrete mathematics for CS M. Hauskrecht


Injective functions
Example 1: Let A = {1,2,3} and B = {a,b,c}
• Define f as
– 1→c
– 2→a
– 3→c
• Is f one to one? No, it is not one-to-one since f(1) = f(3) = c, and
1 ≠ 3.
Example 2: Let g : Z → Z, where g(x) = 2x - 1.
• Is g is one-to-one (why?)

CS 441 Discrete mathematics for CS M. Hauskrecht

Injective functions
Example 1: Let A = {1,2,3} and B = {a,b,c}
• Define f as
– 1→c
– 2→a
– 3→c
• Is f one to one? No, it is not one-to-one since f(1) = f(3) = c, and
1 ≠ 3.
Example 2: Let g : Z → Z, where g(x) = 2x - 1.
• Is g is one-to-one (why?)
• Yes.
• Suppose g(a) = g(b), i.e., 2a - 1 = 2b - 1 => 2a = 2b
`` => a = b.

CS 441 Discrete mathematics for CS M. Hauskrecht


Surjective function
Definition: A function f from A to B is called onto, or surjective,
if and only if for every b ∈ B there is an element a ∈ A such that
f(a) = b.
Alternative: all co-domain elements are covered

A f: A →B B

CS 441 Discrete mathematics for CS M. Hauskrecht

Surjective functions
Example 1: Let A = {1,2,3} and B = {a,b,c}
– Define f as
• 1→c
• 2→a
• 3→c
• Is f onto?

CS 441 Discrete mathematics for CS M. Hauskrecht


Surjective functions
Example 1: Let A = {1,2,3} and B = {a,b,c}
– Define f as
• 1→c
• 2→a
• 3→c
• Is f onto?
• No. f is not onto, since b ∈ B has no pre-image.
Example 2: A = {0,1,2,3,4,5,6,7,8,9}, B = {0,1,2}
– Define h: A → B as h(x) = x mod 3.
• Is h onto function?

CS 441 Discrete mathematics for CS M. Hauskrecht

Surjective functions
Example 1: Let A = {1,2,3} and B = {a,b,c}
– Define f as
• 1→c
• 2→a
• 3→c
• Is f an onto?
• No. f is not onto, since b ∈ B has no pre-image.
Example 2: A = {0,1,2,3,4,5,6,7,8,9}, B = {0,1,2}
– Define h: A → B as h(x) = x mod 3.
• Is h an onto function?
• Yes. h is onto since a pre-image of 0 is 6, a pre-image of 1 is 4, a
pre-image of 2 is 8.

CS 441 Discrete mathematics for CS M. Hauskrecht


Bijective functions
Definition: A function f is called a bijection if it is both one-to-
one and onto.

A f: A →B B

CS 441 Discrete mathematics for CS M. Hauskrecht

Bijective functions
Example 1:
• Let A = {1,2,3} and B = {a,b,c}
– Define f as
• 1→c
• 2→a
• 3→b
• Is f is a bijection? Yes. It is both one-to-one and onto.

• Note: Let f be a function from a set A to itself, where A is finite.


f is one-to-one if and only if f is onto.
• This is not true for A an infinite set. Define f : Z → Z, where
f(z) = 2 * z. f is one-to-one but not onto (3 has no pre-image).

CS 441 Discrete mathematics for CS M. Hauskrecht


Bijective functions
Example 2:
• Define g : W → W (whole numbers), where
g(n) = [n/2] (floor function).
• 0 → [0/2] = [0] = 0
• 1 → [1/2] = [1/2] = 0
• 2 → [2/2] = [1] = 1
• 3 → [3/2] = [3/2] = 1
• ...
• Is g a bijection?

CS 441 Discrete mathematics for CS M. Hauskrecht

Bijective functions
Example 2:
• Define g : W → W (whole numbers), where
g(n) = [n/2] (floor function).
• 0 → [0/2] = [0] = 0
• 1 → [1/2] = [1/2] = 0
• 2 → [2/2] = [1] = 1
• 3 → [3/2] = [3/2] = 1
• ...
• Is g a bijection?
– No. g is onto but not 1-1 (g(0) = g(1) = 0 however 0 ≠ 1.

CS 441 Discrete mathematics for CS M. Hauskrecht

You might also like