Sei sulla pagina 1di 23

Discrete Structures for Computer Science

- Functions
Dr.N.L.Bhanu Murthy
BITS Pilani
Hyderabad Campus
Functions

From calculus, you are familiar with the concept of a real-


valued function f,
which assigns to each number x a particular value
y=f(x), where y.
But, the notion of a function can also be naturally
generalized to the concept of assigning elements of any
set to elements
of any set. (Also known as a map.)

BITS Pilani, Hyderabad Campus


Function: Formal Definition

Def. For any sets A, B, we say that a function f from (or


mapping) A to B (f:AB) is a particular assignment of
exactly one element f(x)B to each element xA.

Functions of n arguments

BITS Pilani, Hyderabad Campus


Graphical Representations

Functions can be represented graphically in several ways:

f A B

f y
a
b


x
A
B Bipartite Graph Plot
Like Venn diagrams

BITS Pilani, Hyderabad Campus


Functions Weve Seen So Far

Remark. A proposition can be viewed as a function from


situations to truth values {T,F}
A logic system called situation theory.
Ex.
p=It is raining.; s=our situation here, now
p(s){T,F}.

Remark. A propositional operator can be viewed as a
function from ordered pairs of truth values to truth
values:
Ex.
((F,T)) = T.
((T,F)) = F.

BITS Pilani, Hyderabad Campus


More functions so far

Remark. A predicate can be viewed as a function from


objects to propositions (or truth values).
Ex.
P : is 7 feet tall;
P(Mike) = Mike is 7 feet tall. = False.

Remark. A bit string B of length n can be viewed as a


function from the numbers {1,,n}
(bit positions) to the bits {0,1}.
Ex.
B=101 B(3)=1.

BITS Pilani, Hyderabad Campus


Still More Functions

Remark. 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.
Ex.
S={3} S(0)=F, S(3)=T.
Remark. A set operator such as ,, can be viewed
as a function from pairs of sets to sets.
Ex.
(({1,3},{3,4})) = {3}

BITS Pilani, Hyderabad Campus


BA: Set of all functions

Def. The set of all possible functions f:AB is BA.


Theo. For finite A, B (={T,F}), |2A | = 2|A|.
Remark. The power set of S is 2S .
Let 2:{0,1}. Then a subset TS is just a function
from S to 2.

BITS Pilani, Hyderabad Campus


Some Function Terminology

Def. Let f:AB, and f(a)=b (where aA & bB). Then


A is the domain of f.
We also say
B is the codomain of f.
the signature
b is the image of a under f.
of f is AB.
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 }.

BITS Pilani, Hyderabad Campus


Range versus Codomain

Remarks.
The range of a function might 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.

BITS Pilani, Hyderabad Campus


Range vs. Codomain - Example
Ex. 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}.
{A,B,C,D,E}
At this point, you know fs codomain is: __________,
unknown!
and its range is ________.
Suppose the grades turn out all As and Bs.
{A,B}
Then the range of f is _________, but its codomain is
still {A,B,C,D,E}!
__________________.

BITS Pilani, Hyderabad Campus


Operators (general definition)

Def. An n-ary operator over (or on) the set S is any


function from the set of ordered n-tuples of elements
of S, to S itself.
Ex. If S={T,F},
can be seen as a unary operator, and
, are binary operators on S.
Ex. and are binary operators on the set of all sets.

BITS Pilani, Hyderabad Campus


Constructing Function Operators

If (dot) is any operator over B, then we can extend to


also denote an operator over functions f:AB.
Ex. 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).

BITS Pilani, Hyderabad Campus


Function Operator Example

, (plus,times) are binary operators over . (Normal


addition & multiplication.)
Therefore, we can also add and multiply functions
Def. Let f, g: .
(f g): , where (f g)(x) = f(x) g(x)
(f g): , where (f g)(x) = f(x) g(x)

BITS Pilani, Hyderabad Campus


Function Composition Operator

Def. Let g:AB and f:BC. The composition of f and g,


denoted by fg, is defined by
(fg)=f(g(a)).

A g B f C

.a . g(a) . f(g(a))

Remark. (like Cartesian , but unlike +,,) is non-


commuting. (Generally, fg gf.)

BITS Pilani, Hyderabad Campus


Images of Sets under Functions

Def. Let f:AB, and SA.


The image of S under f is simply the set of all images
(under f) of the elements of S.
f(S) : {f(s) | sS}
: {b | sS: f(s)=b}.
Note the range of f can be defined as simply the image
(under f) of fs domain!

BITS Pilani, Hyderabad Campus


One-to-One Functions
Def. 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,
f is injective : (x,y: xy f(x)f(y)).

Only one element of the domain is mapped to any given


one element of the range.
Domain & range have same cardinality. What about
codomain?
Memory jogger: Each element of the domain is injected
into a different element of the range.
Compare each dose of vaccine is injected into a
different patient.
BITS Pilani, Hyderabad Campus
One-to-One Illustration

Bipartite (2-part) graph representations of functions that


are (or not) one-to-one:









Not one-to-one Not even a
One-to-one function!

BITS Pilani, Hyderabad Campus


Sufficient Conditions for 1-1ness

For functions f over numbers, we say:


f is strictly (or monotonically) increasing iff
x>y f(x)>f(y) for all x,y in domain;
f is strictly (or monotonically) 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 is
one-to-one.
Ex.
f(x) = x3
f(x) = 1/x (Converse is not necessarily true)

BITS Pilani, Hyderabad Campus


Onto (Surjective) Functions

Def. A function f:AB is onto or surjective or a


surjection iff its range is equal to its codomain (bB,
aA: f(a)=b).

Remark. An onto function maps the set A onto (over,


covering) the entirety of the set B, not just over a
piece of it.

Ex. Let f: .
f(x) = x3 is onto,
f(x) =x2 is not onto. (Why?)

BITS Pilani, Hyderabad Campus


Illustration of Onto

Some functions that are, or are not, onto their codomains:










Onto Not Onto Both 1-1 1-1 but
(but not 1-1) (or 1-1) and onto not onto

BITS Pilani, Hyderabad Campus


Bijections
Def. A function f is said to be a bijection, (or a one-to-one
correspondence, or reversible, or invertible,) iff
it is both one-to-one and onto.

BITS Pilani, Hyderabad Campus


Thank You!!

BITS Pilani, Hyderabad Campus

Potrebbero piacerti anche