0% found this document useful (0 votes)
5 views

CS 201 Lecture 8 - Functions

Uploaded by

aljubehjihad
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)
5 views

CS 201 Lecture 8 - Functions

Uploaded by

aljubehjihad
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
You are on page 1/ 19

Dr.

Kholoud Nairoukh
Department of Computer Science
German-Jordanian University
Lecture 8
• A function can be naturally generalized to the
concept of assigning elements of any set to
elements of any set. (Also known as a map.)

Dr. Kholoud Nairoukh


• For any sets A, B, we say that a function f
from (or “mapping”) A to B (f:A→B) is a
particular assignment of exactly one element
f(x)B to each element xA.

Dr. Kholoud Nairoukh


• Functions can be represented graphically in
several ways:

f A B
• •
f • •
a• • • y
b •



A x
B Bipartite Graph Plot
Like Venn diagrams
Dr. Kholoud Nairoukh
• If it is written that f:A→B, and f(a)=b
(where aA & bB), then we say:
– A is the domain of f. We also say
– B is the codomain of f. the signature
of f is A→B.
– 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 RB of f is R={b | a f(a)=b }.

Dr. Kholoud Nairoukh


• “f is a function mapping students in this
class to the set of grades A,B,C,D,E}.”

• At this point, the f’s codomain is:


{A,B,C,D,E} , and its range is unknown!

• Suppose the grades turn out all As and Bs.


Then the range of f is {A,B}, but its codomain
is still {A,B,C,D,E}! .

Dr. Kholoud Nairoukh


Example

Dr. Kholoud Nairoukh


• If • (“dot”) is any operator over B, then we
can extend • to also denote an operator over
functions f:A→B.

• Example: Given any binary operator •:BB→B,


and functions f,g:A→B, we define
(f • g):A→B to be the function defined by:
aA, (f • g)(a) = f(a)•g(a).

Dr. Kholoud Nairoukh


• +,× (“plus”,“times”) are binary operators over
R. (Normal addition & multiplication.)

• Therefore, we can also add and multiply


functions f,g:R→R:
(f + g):R→R, where (f + g)(x) = f(x) + g(x)
(f × g):R→R, where (f × g)(x) = f(x) × g(x)

Dr. Kholoud Nairoukh


• For functions g:A→B and f:B→C, 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):A→C, where (f○g)(a) :≡ f(g(a)).
– Note g(a)B, so f(g(a)) is defined and C.
– Note that ○ (like Cartesian , but unlike
+,,) is non-commuting. (Generally, f○g 
g○f.)
Dr. Kholoud Nairoukh
• 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:A→B,
“x is injective” : (x,y: xy  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? May be larger!
Dr. Kholoud Nairoukh
Dr. Kholoud Nairoukh
• 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 is one-to-one.

• Example: x3
– Converse is not necessarily true. Example: 1/x

Dr. Kholoud Nairoukh


• A function f:A→B is onto or surjective or a
surjection iff its range is equal to its codomain
(bB, aA: 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?)

Dr. Kholoud Nairoukh


Dr. Kholoud Nairoukh
• A function f is said to be a one-to-one
correspondence, or a bijection, or reversible,
or invertible, iff it is
both one-to-one and onto.

• For bijections f:A→B, there exists an inverse


of f, written f −1:B→A, which is the unique
function such that
– (where IA is the identity function on A)
−1
f  f = IA
Dr. Kholoud Nairoukh
• In discrete math, we will frequently use the
following two functions over real numbers:

– The floor function ·:R→Z, where x


(“floor of x”) means the largest (most
positive) integer  x. I.e., x :≡
max({iZ|i≤x}).
– The ceiling function · :R→Z, where x
(“ceiling of x”) means the smallest (most
negative) integer  x. x :≡ min({iZ|i≥x})

Dr. Kholoud Nairoukh


Dr. Kholoud Nairoukh
• Function variables f, g, h, …
• Notations: f:A→B, f(a), f(A).
• Terms: image, preimage, domain, codomain,
range, one-to-one, onto, strictly
(in/de)creasing, bijective, inverse,
composition.
• Function unary operator f−1,
binary operators +, −, etc., and ○.
• The R→Z functions x and x.

Dr. Kholoud Nairoukh

You might also like