• No results found

Functions and Relations.pptx

N/A
N/A
Protected

Academic year: 2020

Share "Functions and Relations.pptx"

Copied!
40
0
0

Loading.... (view fulltext now)

Full text

(1)

Functions and Relations

Every function is a relation

(2)

Objectives for today

Relations

Binary relations and properties

Relationship to functions

n-ary relations

Definitions

CS application: Relational DBMS

(3)

Definition of a relation

At the very least, a relation is a set of ordered

pairs

An ordered pair consist of a

x

and

y-

coordinate

A relation

may be viewed as

ordered pairs, mapping

design, table, equation, or written in sentences

x

-values are inputs, domain, independent variable

y

-values are outputs, range, dependent variable

(4)

Binary Relations

Definition:

Let A and B be two sets. A binary

relation from A to B is a subset of A × B.

In other words, a binary relation R is a set of

ordered pairs (a

i

, b

i

) where a

i

A and b

i

B.

Notation: We say that

a R b if (a,b) R

a R b if (a,b) R

(5)

Example: Course Enrollments

• Let’s say that Alice and Bob are taking CS 441. Alice is also taking Math 336. Furthermore, Charlie is taking Art 212 and Business 444. Define a relation R that represents the relationship between people and classes.

Solution:

• Let the set P denote people, so P = {Alice, Bob, Charlie}

• Let the set C denote classes, so C = {CS 441, Math 336, Art 212, Business 444)

• By definition R P × C⊆

• From the above statement, we know that

(Alice, CS 441) R

• (Bob, CS 441) R∈

• (Alice, Math 336) R∈

• (Charlie, Art 212) R∈

• (Charlie, Business 444) R∈

• So, R = {(Alice, CS 441), (Bob, CS 441), (Alice, Math 336), (Charlie, Art 212), (Charlie, Business 444)}

(6)

We can also “relate” elements of more than

two sets―n-ary relations

Definition:

Let A1, A2, …, An be sets. An n-ary relation on these sets is a subset of A1 × A2 × … × An. The sets A1, A2, …, An are called the domains of the relation, and n is its

degree.

Example:

Let R be the relation on Z × Z × Z consisting of triples (a, b, c) in which a,b,c form an arithmetic progression. That is (a,b,c) R iff there exist some integer k such that ∈ b=a+k and c=a+2k.

What is the degree of this relation?What are the domains of this relation?

Are the following tuples (records) in this relation?(1,3,5) ??

(2,5,9) ??

(7)

N-ary relations

Solution

What is the degree of this relation? 3

What are the domains of this relation? Ints,

Ints, Ints

Are the following tuples (records) in this

relation?

(1,3,5) 3=1+2 and 5= 1+2*2

(2,5,9) 5=2+3 but 9 ≠ 2+2*3

(8)

n-ary relations

We can have relations between more than just 2 sets

A binary relation involves 2 sets and can be described by a set of pairs A ternary relation involves 3 sets and can be described by a set of triples …

An n-ary relation involves n sets and can be described by a set of n-tuples

Relations are used to represent computer databases

(9)

n-ary relations n-ary Relations

Note: N is the set of natural numbers {0,1,2,3,…} An example

Note: R could be considered as an extensional representation of the

ternary relation a<b<c, assuming domains are finite and really quite small

The relation has degree 3

The domains of the relation are the set of natural numbers

(10)

n-ary relations n-ary Relations

Note: N is the set of natural numbers {0,1,2,3,…} Z is the set of integers {…,-2,-1,0,1,2,…}

An example

Note: R could be considered as an extensional representation of the

ternary relation a<b<c, assuming domains are finite and really quite small

The relation has degree 4

(11)

Relational databases

Database is made up of records.

Typical operations on a database are

find records that satisfy a given criteria delete records

add records update records

Some everyday databases

student records health records tax information

telephone directories banking records

(12)

Relational databases The relational data model

Database made up of records, they are n-tuples, made up of fields

Student record might look as follows

(name,metricNo,faculty,gpa)

(Jones,200401986,Arts,4.9) (Lee,200408972,Science,3.6)

(Kuhns,200501728,Humanities,5.0) (Moore,200308327,Science,5.5)

relations (in relDB) also called tables

(13)

Relational databases The relational data model

Example from the book Attributes: name, metric No, Dept and GPA

(14)

Relational databases The relational data model

primary key:

An attribute/domain/column is a primary key when the value of this attribute uniquely defines tuples

i.e. no two tuples have the same value for that attribute

Name cannot be a primary key, neither can Dept or GPS metricNo is a primary key

(15)

Relational databases The relational data model

The current collection of n-tuples (records) in the relation (table) is called the extension of the relation

The permanent aspects of the relation (table) such as the attribute names is called the intention of the relation

(16)

Relational databases The relational data model

A composite key is a combination of attributes That uniquely define tuples

(17)
(18)
(19)

Functions

Function of x – a relation in which no two

ordered pairs have the same x-value

Examples:

(5, 5) and (5, 2)

not a function

(3, 5) and (5, 2)

function

(13, -24) and (13, 76) not a function

(1, 24) and (7, 24)

function

(20)

9/22/20 09:20 PM 1-6 Relations and Functions 20

Function Notation

f(x

) means function of

x

and is read “

f

of

x

.”

f(x

) = 2

x

+ 1 is written in function notation.

The notation

f(

1)

means to replace

x

with

1

resulting in

the function value.

f

(1) = 2

x

+ 1

f

(1) = 2(1) + 1

(21)

Terms related to functions

Domain, codomain, range, image and pre-image

Domain: If f is a function from A to B , we say that

A is the domain of f and B is the codomain of f.

If f(a) = b, we say that b is the image of a and a is

the pre-image of b.

The range of f is also the set of all images of

elements of A. Also if f is a function from A to B,

we say that f maps A to B.

(22)

Example 1

9/22/20 09:20 PM 1-6 Relations and Functions 22

What is the domain?

{0, 1, 2, 3, 4, 5}

What is the range?

{-5, -4, -3, -2, -1, 0}

(23)

Example 2

Choice One

Choice Two

9/22/20 09:20 PM 1-6 Relations and Functions 23

3

1

0

–1

2

3

2

–1

3

2

3

–2

0

Which mapping represents a function?

(24)

Example 3

A.

B.

9/22/20 09:20 PM 1-6 Relations and Functions 24

Which mapping represents a function?

(25)

Example 4

a. The items in a store to their prices on a certain date

b. Types of fruits to their colors

9/22/20 09:20 PM 1-6 Relations and Functions 25

Which situation represents a function?

There is only one price for each different item on a certain date. The relation from items to price makes it a function.

(26)

Vertical Line Test

9/22/20 09:20 PM 1-6 Relations and Functions 26

Vertical Line Test:

a relation is a

function

if a

vertical line drawn through its graph, passes

through only one point.

AKA: “The Pencil Test”

Take a pencil and move it from left to right (

–x

to

(27)

Vertical Line Test

9/22/20 09:20 PM 1-6 Relations and Functions 27

Would this

graph be a

function?

(28)

Vertical Line Test

9/22/20 09:20 PM 1-6 Relations and Functions 28

Would this

graph be a

function?

(29)

9/22/20 09:20 PM 1-6 Relations and Functions 29

Is the following function

discrete or continuous? What

is the Domain? What is the

Range?

Discrete

-7, 1, 5, 7, 8, 10

 

 

 

1, 0, -7, 5, 2, 8

 

 

(30)

9/22/20 09:20 PM 1-6 Relations and Functions 30

Is the following function

discrete or continuous? What

is the Domain? What is the

Range?

continuous

8,8

      

6,6

(31)

9/22/20 09:20 PM 1-6 Relations and Functions 31

Is the following function

discrete or continuous? What

is the Domain? What is the

Range?

continuous

0,45

       

10,70

(32)

9/22/20 09:20 PM 1-6 Relations and Functions 32

Is the following function

discrete or continuous? What

is the Domain? What is the

Range?

discrete

-7, -5, -3, -1, 1, 3, 5, 7

 

 

 

(33)

One-to-one function

If a function does not assign the same value to

two different domain elements we call such a

function

one-to-one or injective

.

(34)

Onto function

For some functions the range and codomain

are equal, i.e. every member of the codomain

is the image of some element of the domain.

Such functions are called

onto functions

or

surjections

.

(35)

One-to-one correspondence

A function f is a one-to-one correspondence or a

bijection, if it is both one-to-one and onto.

Example: Let f be the function from {a, b, c, d} to [1, 2,

3, 4} with f(a) =4, f(b) = 2, f(c) = 1, and f(d) = 3. Is f a

bijection?

The function f is one and also onto. It is

one-to-one because no two values in the domain are assigned

the same function value. It is onto because all four

elements of the codomain are images of elements in

the domain. Hence f is a bijection.

(36)

Inverse Functions and Composition of

Functions

Inverse function

Let f be a one-to-one correspondence from the set A to the

set B. The

inverse function

of f is the function that assigns

to an element b belonging to B the unique element a in A

such that f(a) = b. The inverse function of f is denoted by f

-1

(b) = a when f(a) = b.

Note:

f

-1

is just a notation and is not the same as 1/f

A one-to-one correspondence is invertible because we can

define an inverse of that function. A function is not

invertible if it is not a one-to-one correspondence, because

the inverse of such a function does not exist.

(37)

Composition of functions

Let g be a function from the set A to the set B and let f be

a function from the set B to the set C. The composition of

the functions f and g, denoted by fog is defined as

(fog)(a) = f(g(a))

To find (fog)(a) we first apply the function g to a to obtain

g(a) and then we apply the function f to the result g(a) to

obtain

(fog)(a) = f(g(a))

Note that the composition fog cannot be unless the

range of g is a subset of the domain of f.

(38)

• Example:

• Let f and g be the functions from the set of integers to the set of integers defined by

f(x) = 2x + 3 and g(x) = 3x + 2. What is the composition of f and g? What is the

composition of g and f?

Both the compositions of fog and gof are defined.(fog)(x) = f(g(x))

=f(3x + 2) = 2(3x + 2) +3 = 6x + 7.and

(gof)(x) = g(f(x)) = g(2x + 3)

= 3(2x + 3) + 2 = 6x + 11

Remarks: The two results show that composition of functions is not commutative.

(39)

Ceiling and floor functions

Two important functions in discrete maths are the

floor

and

ceiling

functions.

Assume

x

is a real number:

The

floor function

rounds x

down to the closest

integer

less than or equal to x

, and the

ceiling

function

rounds x to the

closest integer greater than

or equal to x

. These functions are often used when

objects are counted. They play an important role in

the analysis of the number of steps used by

procedures to solve problems of a particular size.

(40)

The value of the floor function at x is denoted by

Lx˩

.

The value of the ceiling function at x is denoted by

Гx˥

.

The floor function is also called the

greatest integer

function

and it is often denoted by

[x]

.

Examples:

These are some values of the floor and ceiling

functions.

L1/2˩ =0, Г1/2˥ = 1, L-1/2˩ = -1, Г-1/2˥ = 0, L3.1˩ = 3,

Г3.1˥ = 4, L7˩ = 7, Г7˥ = 7

References

Related documents

Material and Methods: The dysfunction and quality of life scores from 25 children with ECC were evaluated before treatment (T0), one month (T1) and three months after treatment

The primary outcome was functional status (FIQ), and the secondary outcomes were clinical severity (CGI-S), pain catastrophizing (PCS), anxiety (HADS-A), depression (HADS-D),

For Level I requirements #1 and #2 we choose to use the Xerox/NASA Docushare system called NX. This augmented COTS toolset provides state-of-the-art configuration

To examine this question, we developed a metric, described in equation (5), to estimate the total number of unknown or latent vulnerabilities in a large software system. The

As an example of using different basis functions, we anticipate some of the empirical results presented in the next section and after pricing an European option we calculate

of Arts and Sciences 36 faculty members* Institute of Medicine 12 faculty members* MacArthur Fellows 4 faculty members* National Academy of Engineering 10 faculty members*

We also find that asset market risk factors such as exchange rates or stock market shocks affect the term structure of oil futures prices in a much more homogeneous way

Even for those who choose not to incorporate social or economic justice ideals into their clinical program, practice ready can, and should, mean preparing law students to