CSCI 115 Chapter 5 Functions. CSCI 115 §5.1 Functions

Preview:

Citation preview

CSCI 115

Chapter 5

Functions

CSCI 115

§5.1

Functions

§5.1 – Functions

• Function– Relation such that for every domain element a, |

f(a)| = 1– Mappings, transformations– f(a) = {b}

• f(a) = b• a = argument• b = function value

§5.1 – Functions

• Types of functions– Everywhere defined– Onto– One to one (1–1)– 1 – 1 Correspondence

• ED, Onto, 1–1

– Invertible Functions

§5.1 – Functions

• Theorem 5.1.1

defined everywhere is iff onto is (d)

onto is iff defined everywhere is (c)

1-1 also is (b)

thenfunction, a is If

1.-1 is iff to fromfunction a is Then (a)

function.any be :Let

1

1

1

1

1

ff

ff

f

f

fABf

BAf

§5.1 – Functions

• Theorem 5.1.2

B

A

A

B

ff

ff

BAf

ff

ff

BAf

1 (d)

1 (c)

then and between encecorrespond 1-1 a is If

1 (b)

1 (a)

Then function.any be :Let

1

1

§5.1 – Functions

• Theorem 5.1.4

1.-1 is then onto, is If (b)

onto. is then 1,-1 is If (a)

function. defined

everywherean be :let and elements, of

number same with thesets finite twobe and Let

ff

ff

BAf

BA

§5.1 – Functions

• 1-1 functions and cryptography– Allows coding AND decoding– Substitution codes

• Table from Example 18 (p. 188)

CSCI 115

§5.2

Functions for Computer Science

§5.2 – Functions for Computer Science

• mod–n (or modn)

• Factorial• Floor• Ceiling• Boolean• Hashing• Others

§5.2 – Functions for Computer Science

• Set– Collection of objects– Any element is unambiguously in the set or not– Characteristic function

• Fuzzy sets– Whether or not an element is in the set may be

‘fuzzy’– The set of all rich people

§5.2 – Functions for Computer Science

• Fuzzy sets– Function f defined on a set having values in the

interval [0, 1]• If f(x) = 0, x is not in the set• If f(x) = 1, x is in the set• If 0 < f(x) < 1 then f(x) is the degree to which x is

in the set– Degree of membership

– Ordinary sets are special cases of fuzzy sets

§5.2 – Functions for Computer Science

• Fuzzy set operations– Theorem 5.2.1 (Finding other degrees of membership)

• Let A and B be subsets of the same universal set U. Then:

( ) ( ) min{ ( ), ( )}

( ) ( ) max{ ( ), ( )}

( ) ( ) 1 ( )

A B a b

A B a b

AA

a f x f x f x

b f x f x f x

c f x f x

§5.2 – Functions for Computer Science

• Fuzzy Logic– Fuzzy predicates

• Values can be true, false, or somewhere in between– Schrodinger’s Cat– Quantum theory and computers

– Applications• Control theory

– Elevator operation– ABS systems in cars

• Expert systems

CSCI 115

§5.3

Growth of Functions

§5.3 – Growth of Functions

• Algorithmic Analysis– Efficiency

• Number of steps (running time)

– Comparison

§5.3 – Growth of Functions

• Definitions– Let f and g be functions whose domains are

subsets of Z+. • We say f is O(g) (read f is big-Oh of g) if

constants c and k s.t. |f(n)| c |g(n)| n k.

• We say f and g have the same order if f is O(g) and g is O(f)

• We say f is lower order than g (or f grows more slowly than g) if f is O(g) but g is not O(f)

§5.3 – Growth of Functions

• Definition– We define a relation Θ (called big-theta) on

functions whose domains are subsets of Z+ as:f Θ g iff f and g have the same order.

• Theorem 5.3.1– The relation Θ is an equivalence relation.

§5.3 – Growth of Functions

• Equivalence classes of Θ– Equivalence classes (called Θ–classes) consist

of functions of the same order– One Θ–class is said to be lower than another if

any of the functions in the first is lower than any in the second

– Θ–classes provide the necessary information to do algorithmic analysis

§5.3 – Growth of Functions• Image from page 203 of the text

CSCI 115

§5.4

Permutation Functions

§5.4 – Permutation Functions

• Permutation– 1-1 correspondence from a set onto itself

• Theorem 5.4.1– If A = {a1, a2, …, an} with |A| = n, then n!

permutations of A

§5.4 – Permutation Functions

• Cycle of length r– If p(a1) = a2, p(a2) = a3, …, p(ar-1) = ar and

p(ar) = a1, this is called a cycle of length r, and is denoted (a1, a2,…, ar)

• Disjoint cycles

§5.4 – Permutation Functions

• Theorem 5.4.2– A permutation of a finite set that is not the identity

or a cycle can be written as a product of disjoint cycles of length greater than or equal to 2

§5.4 – Permutation Functions

• Transposition– Cycle of length 2

– Every cycle can be written as a product of transpositions as follows:• (b1, b2, …, br) = (b1, br)(b1, br-1) … (b1, b2)

§5.4 – Permutation Functions

• Even permutation– A permutation that can be written as the

product of an even number of transpositions

• Odd permutation– A permutation that can be written as the

product of an odd number of transpositions

§5.4 – Permutation Functions

• Theorem 5.4.3– A permutation cannot be both even and odd

• Theorem 5.4.4– Let A = {a1, a2, …, an}, with |A| = n 2. Then

there are n!/2 even permutations of A, and n!/2 odd permutations of A.

§5.4 – Permutation Functions

• Transposition codes– Encrypt by using the following transposition

MATH IS GREAT

(1, 10, 7) (11, 3, 2, 8) (5, 4, 9)

– Decrypt the following

Message: OICLPCYIGULSOYRRVTTEA

Transposition Code: (16, 15, 6, 1, 3, 7, 11, 2) (8, 13, 4, 5, 19) (14, 10) (21, 20, 17)

§5.4 – Permutation Functions

• Transposition codes– Keyword Columnar Transposition – Example 8

Using the keyword “JONES” to encrypt:THE FIFTH GOBLET CONTAINS THE GOLD

Result:FGTAHDTFBONGEHETTLHTLNSOIOCIEX

§5.4 – Permutation Functions

• Transposition codes– Keyword Columnar Transposition

Use the keyword “BASEBALL” to decrypt:

AAK7ENWHRSOER9SAETOELNNWIDYELXBO1DXKTI3R

Using a keyword columnar transposition

Recommended