You are on page 1of 26

Z Notation : Functions

Sub-topic
Introduction
Partial Function
Total Function
Further kinds of function

Surjective function
Injective function
Bijective function

Sub-topic

Operation on functions

Inverse of a function
Composition function
Overriding function

Functions

Special kind of relation.


Relations where every element in its domain is
related to at most one element in the range.
A relation not one-to-many or many-to-many kind.

Example

Let consider :

Lend books to students and other lecturers.


Relation is;
borrowedBy : BOOKTITLE PERSON
Problem : If have two books with the same title, Z
notation.
Do not know who has borrowed the book.
To overcome this problem, a library associates a
class number with each book and unique number.
New Relation : CLASSNUMBER BOOKTITLE
Where is the book? We need relation :
CLASSNUMBER PERSON

Functions

Partial function
The relation borrowedBy : no element of the
source should be related to more than one
element of the target.
General ;
A partial function from X to Y is a relation from
X to Y such that each element x in X is
related to at most one y in Y.
Declare as :
f: A B

Partial function

Definition :

A relation f : A B is a partial function iff it


satisfies the following condition :
XY =={f:X Y|x:X;y1,y2:Y
x|y1fx|y2 f y1=y2}

: if a function maps an element x to y1 and also to y2,


then since there cannot be any one-to-many
relationships, y1 and y2 must be the same element.

Partial function : Example


Let

consider :

No

person can have more than one tax code,


so the taxCode relation is thus a partial
function, if:
X = {sue, theQueen,joy,jane,val}
Y = { 4521,2330,3445}
A

possible partial function from X to Y :


taxCode: X Y

Functions

Total function
A function in which every element in the
domain is mapped to some element in the
range.
Declare as :

f: A B
-

is a partial function for which

dom f = A

Total Function

If every element of the source is mapped to


some element of the target, We say that the
partial function is a total function.
Example: No person can have more than one
age;
The ageOf relation is thus a partial function; but
because each person (including theQueen) has
an age of the ageOf relation is also a total
function.

Total Function

Example :
Each person is relate to only one number.
Every PERSON has an age.
So the domain of this function is the whole
of the source set, PERSON.
This means the function is total.
Relation relating each PERSON to their
age in years ;

Further kinds of function

Surjective functions

12

A function in which every element in the range


is related to some element in the domain

Surjective Functions

Denoted by:
: Partial surjective function

: Total surjective function

13

Surjective Functions

Example :
Let say we have a set of lecturers, LECTURER
and the courses, COURSE which taught by the
lecturers. A relation is teaches between
LECTURER and COURSE.
Lecturers are too busy to teach more than one
course. We wish to specify that there is at least
one lecturer teaching each course.

14

Declaration
of relation??

Surjective Functions

Example 2:
Let say we have a set of lecturers, LECTURER
and the courses, COURSE which taught by the
lecturers. A relation is teaches between
LECTURER and COURSE.
We wish to specify that there is every lecturer
must teach a course.

Declaration
of relation??
15

Further kinds of function

Injective Functions
A function in which each element of the range
is mapped to by only one element.
Denoted by :
: Partial Injective function
: Total Injective function

16

Injective Functions
Example :

Let us model marriage relationships using a


function from the set of men to the set of
women.
Specify that no wife has more than one
husband.(that no man is married to more
than one wife)

17

Declaration
of function??

Injective Functions
Example :

How to declare the marriedTo function to


specify that every man is married?

Declaration
of function??

18

Further kinds of function

Bijective Functions
If function, f, from X to Y is both a total
surjection and a total injection then f is
bijective function.

Denoted by :
: Bijective function

19

Inverse Functions
The inverse relation is always a relation, but..
the inverse function is not always a function.
Example :
ageOf = {sue

30, joy

Denoted by : ageOf

20

21, jane

21, val

29}

Function composition
simply relation composition where the relations
involved happen to be function.

the composition of function is always a function.

21

Functions overriding
applied to any two function f and g, of the same
type, and the result is another function.

the expression :
f g

define a new funtion with the following properties :


dom (f g)= dom f dom g

22

Functions overriding
Example 1:
f, g ; N

f ={3 9,4 16,5 25}


g={2 7,3 16,4 17}
So; f g= ????

23

Functions overriding
Example 2:
f, g ; N

f ={0

1, 1

1}

g={0

2,2

1}

So; f g= ????

24

Functions overriding
Example 3;
Let say a relation: shopprice: ITEM

the prices charged for items stocked in the shop.

Write expressions (using shopprice for the changed


state) to show how shopprice changes when the
following occur:

Item i has its price altered to p.

????
25

Functions overriding
Example 3;
Let say a relation: shopprice: ITEM

the prices charged for items stocked in the shop.

Item i has its price doubled.

????

26

You might also like