0% found this document useful (0 votes)
14 views4 pages

Functions in Discrete Mathematics

The document provides lecture notes on functions in discrete mathematics, detailing concepts such as domain, codomain, injective, surjective, and bijective functions. It includes examples of various functions, including floor and ceiling functions, modulus operators, and hash functions, as well as matrix operations and linear functions. Additionally, it discusses projections and linear congruential generators for generating pseudo-random numbers.

Uploaded by

Thinh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views4 pages

Functions in Discrete Mathematics

The document provides lecture notes on functions in discrete mathematics, detailing concepts such as domain, codomain, injective, surjective, and bijective functions. It includes examples of various functions, including floor and ceiling functions, modulus operators, and hash functions, as well as matrix operations and linear functions. Additionally, it discusses projections and linear congruential generators for generating pseudo-random numbers.

Uploaded by

Thinh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Mathematics for Computing – Discrete Mathematics

1
Lecturer: Dr Nguyen Hieu Thao
Email: [Link]@[Link]

Lecture Notes: Functions


(Week 4)1

A function (or a mapping) f from a set X to a set Y assigns to each element x of X exactly
one element y of Y , often denoted by y = f (x). We write f : X → Y or x 7→ f (x); for x ∈ X we
denote its image by f (x).

(a) The set X is the domain of f and denoted by domf , and the set Y is the codomain of f .

(b) The set {(x, y) ∈ X × Y | y = f (x)} is the graph of f and denoted by gphf . Note that

y = f (x) ⇐⇒ (x, y) ∈ gphf.

(c) The set {f (x) | x ∈ X} is the range of f . The range is a subset of the codomain.

(d) A function from X × X to X is a binary operator on X.

(e) A function from X to X is a unary operator on X.

(f) A function f from X to Y is one-to-one (or injective) if f (x1 ) = f (x2 ) ⇒ x1 = x2 for


all x1 , x2 ∈ X.
(g) A function f from X to Y is onto (or surjective) if for every y ∈ Y , there exists x ∈ X
with f (x) = y.

(h) A function that is both injective and surjective is bijective.

(i) For a bijective function f from X to Y , the inverse (function) of f , denoted by f −1 , is the
function from Y to X given by

f −1 (y) = x ⇐⇒ f (x) = y, ∀y ∈ Y.

(j) Let f be a function from X to Y and let g be a function from Y to Z. The composition
of g with f , denoted by g ◦ f , is the function from X to Z given by

x 7→ (g ◦ f )(x) = g(f (x)), ∀x ∈ X.

1 Most of the content of this document is taken from the book [1].
2

Examples of functions

(a) The floor function. The floor of x, denoted by bxc, is the greatest integer less than or
equal to x.

(b) The ceiling function. The ceiling of x, denoted by dxe, is the least integer greater than or
equal to x.

(c) Modulus operators. Given n ∈ Z+ , the modulus function with modulus n returns for
each integer x the remainder when x is divided by n, denoted by ‘x mod n’ and read as ‘x
modulo n’.

(d) A hash function is any function that takes a data to be stored or retrieved and computes
for each data item the first choice for a location for that item. The values returned by a
hash function are hash values (or hash codes or simply hashes). For example, to store
arbitrary nonnegative integers in computer memory cells indexed from 0 to n − 1 (for some
n ∈ Z+ ), one approach is to use the modulus function mod n as a hash function. Symbolically,

h(x) = x mod n, x = 0, 1, . . . .

Johnsonbaugh-50623 book If February
the calculated 14:23 is already occupied, a collision occurs, that is, a collision occurs
3, 2017 position

for a hash function h if h(x) = h(y), but x 6= y. To handle collisions, a collision resolution
policy is required. One simple collision resolution policy is to find the next highest (with 0
116 Chapter 3 ◆ Functions,
assumed to Sequences,
follow n and
− 1)Relations
unoccupied cell.

To locate
Example 3.1.15 Hash a stored value
Functions x, wethat
Suppose compute
we havey cells
= h(x)in a and beginmemory
computer looking at location
indexed to If x is not
from 0 y.
10 (see Figure 3.1.6). We wish to store and retrieve arbitrary nonnegative integers
at this position, we look in the next-highest position (again, 0 is assumed to follow n − 1); if in
these cells. One approach is to use a hash function. A hash function takes a data item
x is notto in
be this position,
stored we and
or retrieved proceed to the
computes the next-highest
first choice for position,
a location and so item.
for the on. If
Forwe reach an
Go Online
For more on hash empty example, for our problem, to store or retrieve the number n, we might take as the first
cell or return to our original position, we conclude that x is not present; otherwise,
choice for a location, n mod 11. Our hash function becomes h(n) = n mod 11. Figure
functions, see
[Link]/V3y4pS
we obtain
3.1.6the position
shows of x.
the result of storing 15, 558, 32, 132, 102, and 5, in this order, in initially
empty cells.

132 102 15 5 257 558 32

0 1 2 3 4 5 6 7 8 9 10

Figure 3.1.6 Cells in a computer memory.


Table 1: Hash values of 15, 558, 32, 132, 102, 5 and 257 with hash function h(x) = x mod 11.
Now suppose that we want to store 257. Since h(257) = 4, then 257 should be
stored at location 4; however, this position is already occupied. In this case we say that
a collision has occurred. More precisely, a collision occurs for a hash function H if
H(x) = H(y), but x ̸ = y. To handle collisions, a collision resolution policy is required.
One simple collision resolution policy is to find the next highest (with 0 assumed to
follow 10) unoccupied cell. If we use this collision resolution policy, we would store
257 at location 6 (see Figure 3.1.6).
If we want to locate a stored value n, we compute m = h(n) and begin looking at


location m. If n is not at this position, we look in the next-highest position (again, 0 is
assumed to follow 10); if n is not in this position, we proceed to the next-highest position,
and so on. If we reach an empty cell or return to our original position, we conclude that
n is not present; otherwise, we obtain the position of n.
If collisions occur infrequently, and if when one does occur it is resolved quickly,
then hashing provides a very fast method of storing and retrieving data. As an example,
personnel data are frequently stored and retrieved by hashing on employee identification
3

(e) Matrix operations.

• The transpose At of a matrix A ∈ Mn×m is an m × n matrix given by

[At ]ij = Aji , (1 ≤ i ≤ m, 1 ≤ j ≤ n).

Note that (AB)t = B t At whenever they are well defined.

• The sum of two matrices of the same size is calculated elementwise.

• The multiplication of a matrix A and a scalar/number λ yields the matrix

(λA)ij = λAij , 1 ≤ i ≤ n, 1 ≤ j ≤ m.

• If A ∈ Mn×m and B ∈ Mm×k , then the product AB is the matrix defined by

m
X
[AB]ij = Ail Blj ,
l=1

where 1 ≤ i ≤ n and 1 ≤ j ≤ k. Hence AB ∈ Mn×k . Note that in general AB 6= BA.

• A matrix A ∈ Mn is invertible if there is a matrix B ∈ Mn such that

AB = BA = In .

The matrix B is the inverse of A and is denoted A−1 .

• The Frobenius norm of a matrix A ∈ Mn×m is defined by


v
u n X
m
uX
kAkF = t A2ij .
i=1 j=1

(f) Linear functions. A function of the form of matrix-vector multiplication is a linear func-
tion. For example,

f : Rn → Rm
x 7→ f (x) = M x

where x ∈ Rn is any vector and M ∈ Rm×n is a given matrix.

(i) When m ≥ n, f is injective if and only if rank(M ) = n.

(ii) When m ≤ n, f is surjective if and only if rank(M ) = m.

(iii) When m = n, f is bijective if and only if M is invertible.


4

(g) Consider four integers n, a, c and s, called the modulus, the multiplier, the increment, and
the seed respectively, satisfying 2 ≤ a < n, 0 ≤ c < n and 0 ≤ s < n. A linear congruential
generator yields a sequence of pseudo-randomized numbers by computing the next pseudo-
random number using its immediate predecessor. It is a function x from (the index set) N
to N given by

(i) x(0) = s;
(ii) x(k) = (ax(k − 1) + c) mod n for k = 1, 2, . . ..

(h) Projections. Consider the unit circle

S = (x1 , x2 ) | x21 + x22 = 1 ⊂ R2 .




Given any point x ∈ R2 , the set of points in S nearest to x, denoted by PS (x) and called the

projection of x on S. The function

PS : R2 → P(S), x 7→ PS (x)

is the projection onto S.

References
1. Johnsonbaugh, R.: Discrete Mathematics - Eighth Edition. Pearson Education, New York
(2018).

You might also like