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

COM555 Theory of Computation: Functions

The document discusses functions and their properties. Some key points: 1) A function maps inputs to outputs and can be represented as f(a)=b, where a is the input and b is the output. 2) The domain of a function is the set of possible inputs, and the range is the set of possible outputs. 3) Functions can be described using tables that list the inputs and corresponding outputs. 4) A function that returns TRUE or FALSE is called a predicate or property.

Uploaded by

Kurdeen Khairy
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views

COM555 Theory of Computation: Functions

The document discusses functions and their properties. Some key points: 1) A function maps inputs to outputs and can be represented as f(a)=b, where a is the input and b is the output. 2) The domain of a function is the set of possible inputs, and the range is the set of possible outputs. 3) Functions can be described using tables that list the inputs and corresponding outputs. 4) A function that returns TRUE or FALSE is called a predicate or property.

Uploaded by

Kurdeen Khairy
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 8

COM555

Theory of Computation
Lecture 3
Functions

Assoc Prof Dr Melike Sah Direkoglu


[email protected]
Functions
• A function is an object that sets up an input-output relationship.
If f is a function whose output value is b when the input value is
a, write it as
f(a)=b
• A function is also called a mapping. If f(a)=b, we say that f maps
a to b.
• Ex. Add function; takes pairs of numbers and the output is the
sum of those numbers:
add(x,y)= x + y
• Ex. Absolute function; takes a number x as input and returns
nonnegative x value
abs(-2)=abs(2)=2
Functions – Domain and Range
•• The
  set of possible inputs to the function is called its domain.
• The outputs of the function comes from a set called its range.
• The notation for saying that f is a function with domain D and
range R is
f: D R
• Eg. The abs function takes integers as input (Z), domain is Z,
and produces an output, range is Natural numbers (N).
abs: Z N
• Eg. The add function for integers; the domain is the set of
pairs of integers, Z x Z, and the range is integers, Z.
add: Z x Z Z
Functions – Using Table
•• One
  way to describe a function is using a table that lists
all possible inputs and gives the output for each input.
• Eg. f: {0, 1, 2, 3, 4} {0, 1, 2, 3, 4}. We can also write f as
f: n f(n)
0 1
1 2
2 3
3 4
4 0

f adds 1 and then takes modulo (mod) 5.


• What is function f? Mod 5 is remainder after division to 5.
Functions – Using Table (Cont.)
• Eg.
  Two dimensional table is used if the domain of
the function is the cartesian product of two sets, such
as g: x
• The entry at row i and column j is the value of g(i,j).
Such as g(0,0)=0, g(2,1)=3
g 0 1 2 3
0 0 1 2 3
1 1 2 3 0
2 2 3 0 1
3 3 0 1 2

• What is function g? g= ( i + j ) % 4
addition function modulo 4
Arity of Functions
• When
  the domain of a function is for some
sets ,…, , the input to f is a k-tuple ( and we
call arguments to f.
• A function with k arguments is called a k-ary
function, and k is called the arity of the
function.
• If k=1 (singe argument), the f is called a unary
function.
• If k=2, f is called a binary function.
Predicate/Property
• A predicate or property is a function whose
range is {TRUE, FALSE}.
• Eg. even is a property that is TRUE if its input
is an even number and FALSE if its input is an
odd number.
– even(4)=TRUE, even(9)=FALSE
• A property whose domain is a set of k-tuples
Ax…xA is called a relation, a k-ary relation,
such as the example beats game.
Predicate/Property (Cont.)
•  Eg. Beats game have values of TRUE or FALSE.
beats scissors paper Stone
Scissors FALSE TRUE FALSE
Paper FALSE FALSE TRUE
stone TRUE FALSE FALSE

• beats: {(scissors, paper), (paper, stone),


(stone, scissors),…,}{TRUE, FALSE}

You might also like