Relations and Functions CSRU 1100. Binary Relations A binary relation is a mapping between two sets...

35
Relations Relations and and Functions Functions CSRU 1100 CSRU 1100
  • date post

    19-Dec-2015
  • Category

    Documents

  • view

    230
  • download

    1

Transcript of Relations and Functions CSRU 1100. Binary Relations A binary relation is a mapping between two sets...

RelationsRelations and and FunctionsFunctions

CSRU 1100CSRU 1100

Binary RelationsBinary Relations

A A binary relationbinary relation is a is a mapping between two sets mapping between two sets as defined by a rule.as defined by a rule.

3 Requirements for a Relation3 Requirements for a Relation

• A DomainA Domain: This is the set we are going to : This is the set we are going to start with.start with.

• A CodomainA Codomain: This is the set we are going : This is the set we are going to relate with.to relate with.

• A RuleA Rule: This defines how the domain : This defines how the domain relates to the codomain.relates to the codomain.

Relation ExampleRelation Example

• Let A={1, 2, 3, 4} be the Let A={1, 2, 3, 4} be the domaindomain

• Let B = {10, 11, 12} be the Let B = {10, 11, 12} be the codomaincodomain

• Let’s make the Let’s make the rulerule be all the pairs be all the pairs defined in: defined in: L ={(1, 10), (1, 11), (2, 10), (2, 12), L ={(1, 10), (1, 11), (2, 10), (2, 12),

(3, 10), (4, 11)}(3, 10), (4, 11)}

Or we can be more concreteOr we can be more concrete

• DomainDomain: The set of all students at : The set of all students at FordhamFordham

• CodomainCodomain: The set of all Computer : The set of all Computer Science classes this fallScience classes this fall

• Rule: (x, y) is in the relation, if student x is Rule: (x, y) is in the relation, if student x is enrolled in class y in the fallenrolled in class y in the fall

Some relations are specialSome relations are special

• We call these special relations “functions” We call these special relations “functions” and you have probably met them before.and you have probably met them before.

• A A functionfunction is a way of transforming one set is a way of transforming one set of things (usually numbers) into another of things (usually numbers) into another set of things (also usually numbers).set of things (also usually numbers).

4 Components of All Functions4 Components of All Functions

• Every functions must haveEvery functions must have– A A NameName, typically we use a letter like f, g, or h, typically we use a letter like f, g, or h– A A DomainDomain – a set of values, there are no – a set of values, there are no

constraints on these valuesconstraints on these values– A A CodomainCodomain – a set of values, there are no – a set of values, there are no

constraints on these valuesconstraints on these values– A A RuleRule

TerminologyTerminologyf : Af : A B B

This means that the function f maps This means that the function f maps values in the Set A (the domain) values in the Set A (the domain) to the values in the Set B (the to the values in the Set B (the codomain)codomain)

Simple rulesSimple rules

• We can deal with the rules of functions the We can deal with the rules of functions the same way we dealt with relations.same way we dealt with relations.

Domain: {1, 2, 3}

Codomain: {5, 6, 7, 8}

Rule: {(1, 5), (2, 6), (3, 8)}

More Advanced RulesMore Advanced Rules

• Rules can also be written in the following Rules can also be written in the following stylestyle– f(a) = a + 4f(a) = a + 4– g(b) = b * b + 2g(b) = b * b + 2– h(c) = 5h(c) = 5

• These would readThese would read– ““f of a equals a plus 4”f of a equals a plus 4”– ““g of b equals b times b plus 2”g of b equals b times b plus 2”– ““h of c equals 5”h of c equals 5”

Rules continuedRules continued

• When we see rules we often ask what When we see rules we often ask what their value might be when given concrete their value might be when given concrete values.values.

• Take the formula from the previous pageTake the formula from the previous page• f(a) = a+4f(a) = a+4

• What is its value when a equals 7?What is its value when a equals 7?• Answer: 11Answer: 11

More RulesMore Rules

• To abbreviate this question you might just To abbreviate this question you might just ask what is f(7)?ask what is f(7)?

• This means substitute the 7 for the a and This means substitute the 7 for the a and solve the equation on the right hand side.solve the equation on the right hand side.

• Try out the following formulas and related Try out the following formulas and related questions on the next slide.questions on the next slide.

Formula ProblemsFormula Problems• f(x) = 2x + 3f(x) = 2x + 3• g(x) = 7g(x) = 7

• What is f(5)?What is f(5)?

• What is f(8)?What is f(8)?

• What is f(-4)?What is f(-4)?

• What is g(3)?What is g(3)?

• What is g(7)?What is g(7)?

• What is g(-10)?What is g(-10)?

So what is a function really?So what is a function really?

• A function is a certain way that three of the A function is a certain way that three of the components (domain, codomain and rule) components (domain, codomain and rule) are related.are related.

• Something is a function if (and only if) you Something is a function if (and only if) you can take can take everyevery value in the Domain, put value in the Domain, put the value in the formula, and get a single the value in the formula, and get a single value that is in the Codomainvalue that is in the Codomain

ExplanationExplanation

• Let’s look at an example.Let’s look at an example.– Suppose I define my Suppose I define my DomainDomain to be {1, 2, 3} to be {1, 2, 3}– And I define my And I define my CodomainCodomain to be {5, 6, 7, 8} to be {5, 6, 7, 8}– And my formula is f(x) =x + 5And my formula is f(x) =x + 5

• Is this a function?Is this a function?– To find out, we will go through each value of To find out, we will go through each value of

the domainthe domain

• Let me try the value 1. f(1) = 1+ 5 = 6Let me try the value 1. f(1) = 1+ 5 = 6– 6 is in my Codomain. So far it’s working.6 is in my Codomain. So far it’s working.

• Let me try the value 2. f(2) = 2 + 5 = 7Let me try the value 2. f(2) = 2 + 5 = 7– 7 is in my Codomain. It is still working.7 is in my Codomain. It is still working.

• Let me try the value 3. f(3) = 3 + 5 = 8Let me try the value 3. f(3) = 3 + 5 = 8– 8 is in my Codomain. It is still working.8 is in my Codomain. It is still working.

• I have tried all values in my domain, and I have tried all values in my domain, and they all worked.they all worked.

• Therefore, this Therefore, this is a function.is a function.

Domain = {1, 2, 3} Codomain = {5, 6, 7, 8} f(x) = x + 5

• Almost identical.Almost identical.

• Taking 1 from the domain worksTaking 1 from the domain works

• Taking 2 from the domain worksTaking 2 from the domain works

• Taking 3 from the domain fails.Taking 3 from the domain fails.– Why? It produces the value 8. This value is no Why? It produces the value 8. This value is no

longer part of my Codomain. So therefore this longer part of my Codomain. So therefore this example is example is not a functionnot a function

Domain = {1, 2, 3} Codomain = {5, 6, 7} f(x) = x + 5

• Ok, begin the same way (take values from Ok, begin the same way (take values from the domain and put them in the formula)the domain and put them in the formula)

• Choose 0. f(x) = 5 … it’s in the CodomainChoose 0. f(x) = 5 … it’s in the Codomain

• Choose 1. f(1) = 6 … it’s in the CodomainChoose 1. f(1) = 6 … it’s in the Codomain

• Choose -1. f(-1) = 4 ... it’s in the CodomainChoose -1. f(-1) = 4 ... it’s in the Codomain

• But we can’t do this foreverBut we can’t do this forever

Domain = Z (all integers) Codomain = Z (all integers) f(x) = x + 5

Dealing with infinite setsDealing with infinite sets

• Sometimes you can’t try all values in the Sometimes you can’t try all values in the domain because its infinite. domain because its infinite.

• So you need to look for values that might So you need to look for values that might not work and try those. not work and try those.

• If you can’t find any domain values that If you can’t find any domain values that don’t work, can you make an argument don’t work, can you make an argument that all the domain values do work.that all the domain values do work.

• Argument:Argument:– ““Regardless of what integer I take from the Regardless of what integer I take from the

domain, I can add 5 to that number and still domain, I can add 5 to that number and still have a value in the Codomain.”have a value in the Codomain.”

• Once you convince yourself of this Once you convince yourself of this argument than you know it is a functionargument than you know it is a function

Domain = Z (all integers) Codomain = Z (all integers) f(x) = x + 5

• Ok choose some valuesOk choose some values– Choose 0: f(0) = 6 … it worksChoose 0: f(0) = 6 … it works

– Choose 1: f(1) = 6 … it worksChoose 1: f(1) = 6 … it works

– Choose -1: f(-1) = 6 … it worksChoose -1: f(-1) = 6 … it works

• It always works… so it It always works… so it is a functionis a function

Domain = Z (all integers) Codomain = {4, 5, 6} f(x) = 6

Other Properties of FunctionsOther Properties of Functions

• Functions can have up to two different and Functions can have up to two different and very interesting properties.very interesting properties.– A function can be A function can be ontoonto– A function can be A function can be one-to-oneone-to-one

• In order to have one of these properties, it In order to have one of these properties, it first must be a function. If it is not a first must be a function. If it is not a function than these properties are function than these properties are irrelevantirrelevant

Onto FunctionsOnto Functions

• An An onto functiononto function is one for which “when is one for which “when you go through the process of determining you go through the process of determining that something is a function, you end up that something is a function, you end up arriving at each and every value in the arriving at each and every value in the Codomain”Codomain”

• OntoOnto is a property that you observe when is a property that you observe when you are determining if something is a you are determining if something is a functionfunction

Onto exampleOnto example

• If you want to know whether this is onto first you have to If you want to know whether this is onto first you have to figure out if it is a function or not.figure out if it is a function or not.

• Choose 1: f(1) = 11Choose 1: f(1) = 11• Choose 2: f(2) = 12Choose 2: f(2) = 12• Choose 3: f(3) = 13Choose 3: f(3) = 13• Choose 4: f(4) = 14Choose 4: f(4) = 14• It definitely is a function because every domain value It definitely is a function because every domain value

took us to a value in the Codomaintook us to a value in the Codomain• Is it onto? Is it onto? • Yes. Because we covered all of the Codomain values in Yes. Because we covered all of the Codomain values in

our computations.our computations.

Domain = {1, 2, 3, 4} Codomain = {11, 12, 13, 14} f(x) = x + 10

• Determine whether it is a functionDetermine whether it is a function• Choose 1: f(1) = 0Choose 1: f(1) = 0• Choose 2: f(2) = 1Choose 2: f(2) = 1• Choose 3: f(3) = 2Choose 3: f(3) = 2• So it is a function.So it is a function.• Is it onto?Is it onto?• No, we never arrived at the value 3 which No, we never arrived at the value 3 which

is in the Codomainis in the Codomain

Domain = {1, 2, 3,} Codomain = {0, 1, 2, 3} f(x) = x -1

• Is it a function?Is it a function?

• Choose 1: f(1) = 5Choose 1: f(1) = 5

• Choose 2: f(2) = 5Choose 2: f(2) = 5

• Choose 3: f(3) = 5Choose 3: f(3) = 5

• So it is a functionSo it is a function

• Is it onto? Is it onto?

• Yes. We reached every value in the Yes. We reached every value in the CodomainCodomain

Domain = {1, 2, 3,} Codomain = {5} f(x) = 5

One-to-OneOne-to-One

• To be To be one-to-oneone-to-one something first must be something first must be a function. If it is a function, then it might a function. If it is a function, then it might be one-to-one itbe one-to-one it

• ““Each value in the Codomain that is Each value in the Codomain that is reached can only be reached by one value reached can only be reached by one value in the domain”in the domain”

How does this work?How does this work?

• We must ask if it is a function?We must ask if it is a function?• Choose 1: f(1) = 2Choose 1: f(1) = 2• Choose 2: f(2) = 3Choose 2: f(2) = 3• Choose 3: f(3) = 4Choose 3: f(3) = 4• It is a function.It is a function.• Is it one-to-one? Well Is it one-to-one? Well

– we only reached the value 2 by using x = 1.we only reached the value 2 by using x = 1.– we only reached the value 3 by using x = 2.we only reached the value 3 by using x = 2.– we only reached the value 4 by using x = 3.we only reached the value 4 by using x = 3.

• So it is one-to-oneSo it is one-to-one

Domain = {1, 2, 3,} Codomain = {1, 2, 3, 4} f(x) = x + 1

• Is it a function?Is it a function?– Choose 1: f(1) = 5Choose 1: f(1) = 5– Choose 2: f(2) = 5Choose 2: f(2) = 5– Choose 3: f(3) = 5Choose 3: f(3) = 5

• Is it one-to-one?Is it one-to-one?– No, because we reached the value 5 in three No, because we reached the value 5 in three

different ways.different ways.

Domain = {1, 2, 3,} Codomain = {5} f(x) = 5

• Is it a function?Is it a function?– f(-2) = 4, f(-1) = 1, f(0) = 0, f(1) = 1, f(2)=4f(-2) = 4, f(-1) = 1, f(0) = 0, f(1) = 1, f(2)=4

• So it is a functionSo it is a function

• Is it one-to-one?Is it one-to-one?– No. We can reach the value 4 in two ways.No. We can reach the value 4 in two ways.

Domain = {-2, -1, 0, 1, 2} Codomain = {0, 1, 2, 3, 4, 5, 6} f(x) = x*x

• Is it a function?Is it a function?

• Is it onto?Is it onto?

• Is it one-to-one?Is it one-to-one?

• If it has all of these properties then we call If it has all of these properties then we call it a it a bijectionbijection..

• Any function that is a bijection has an Any function that is a bijection has an inverse that we can compute.inverse that we can compute.

Domain = {2, 4, 6, 8} Codomain = {4, 8, 12, 16} f(x) = 2x

What is an inverse?What is an inverse?

• An An inverseinverse of a function is another function of a function is another function that reverses the process of the original that reverses the process of the original function.function.

• To create an inverseTo create an inverse– Make the old Codomain the new domainMake the old Codomain the new domain– Make the old domain the new CodomainMake the old domain the new Codomain– Swap the f(x) and the x in the formulaSwap the f(x) and the x in the formula– Use algebra to get the f(x) back by itselfUse algebra to get the f(x) back by itself

Inverse ExampleInverse Example

• New domain = {4, 8, 12, 16}New domain = {4, 8, 12, 16}

• New Codomain = {2, 4, 6, 8}New Codomain = {2, 4, 6, 8}

• To compute the new formula reverse the To compute the new formula reverse the f(x) and the xf(x) and the x

• x = 2f(x)x = 2f(x)

• Then solve for f(x)Then solve for f(x)

• f(x) = x / 2 … so that is our inversef(x) = x / 2 … so that is our inverse

Domain = {2, 4, 6, 8} Codomain = {4, 8, 12, 16} f(x) = 2x

Function CompositionFunction Composition

• We also have the ability to put functions together We also have the ability to put functions together – this is called composition– this is called composition

• f ◦ g which reads “f compose g”f ◦ g which reads “f compose g”• This means I insert the value of the function g This means I insert the value of the function g

into the function f.into the function f.• f(x) = x+5 g(x) = 2x + 3f(x) = x+5 g(x) = 2x + 3• The composition says put the value of g into fThe composition says put the value of g into f• f(2x+3) = (2x+3) + 5 = 2x + 8f(2x+3) = (2x+3) + 5 = 2x + 8

What is f ◦ g ?What is f ◦ g ?

What is g ◦ f?What is g ◦ f?

What is f ◦ f?What is f ◦ f?

What is g ◦ g ? What is g ◦ g ?

What is f ◦ g for g(2)? What is f ◦ g for g(2)?

Assume we have two functions with Domains and Codomains over all integers

f(x) = 3x – 2

g(x) = x * x