## Lecture 16: Functions and RelationsWe have already encountered functions many times and we often use functions when we program. Let us formalize what functions are in mathematical terms: Functions
A function from a set to a set is
associates (or maps) ## Example -1Consider and . Consider function . The function above can be represented or implicitly by the rule/formula . ## Example-2Functions can map many elements of to the same element of . But the rule is that each element of can only be mapped to one element of . Which of the following are functions? ## Example-3: Power Set SignatureWhile discussing power sets, we mentioned a correspondence between power-sets of a set and binary strings. We can indeed write it as a function. Let us take to be and . We write the function by using the mapping from every element of the power set and every element of . The table below shows the elements of the power set and the corresponding value of .
## Example-4: Mathematical functionsYou may have seen many examples of functions from your mathematics classes, thus far. , a function from takes an input natural number and yields an output natural number. is a function from , takes an input real number and yields a real number output. is a function from , takes an input real number and yields a real number output. is a function from , , takes an input real number and yields an integer output.
## Non-Examples of Functions.It remains to clarify what is It leaves an element of set unmapped. It maps an element of to multiple elements in .
If either case occurs then, the mapping fails to be a function. Consider the two mappings shown below. The mapping on the left fails to be a function because it does not map the elements from the domain, while the mapping on the right fails to be a function since is mapped to multiple elements. ## Mathematical non functionsStrictly speaking, many functions that we saw in calculus are not quite functions. The function is not a function from . It is a function however from . Here, we have removed the input from the domain.
The function is not a function from since it leaves all values unmapped. If we wish to be precise, we will define the type of to be .
The function is not defined for and can be defined to both positive and negative square roots when . For instance . If we wish to be precise, we define to be a function from , with the domain restricted to non-negative reals.
## RelationsFormally, a relation between sets and is defined as a subset of , i.e, . ## Example-1Let us take and . Consider the relation by Like functions, we may view the relation as a mapping. However, unlike functions, it is possible that is not related to any element in . could be related to multiple elements in .
The relation is visualized below: Functions are a special case of relations, wherein is mapped to *exactly*one element in .
## Example-2Here is another example of a relation over numbers: defined as Write down some examples of elements of . ## Example-3Consider sets and write the function defined by as a relation . ## Counting RelationsIf is a set with elements and with elements then how many relations can exist between and ? How many functions?
## Domains/Co-DomainsLet be a function . We say that is the domain of and is the co-domain. Similarly, let be a relation. We say that is the domain of the relation and is the co-domain. ## Relations On a SetA relation from set A to itself is called a Eg., Let . Consider a relation . The relation has the tuples . The graph looks as follows: The rule is we have nodes or vertices for each element in the set . If , we draw an arrow from to . Graphs are very useful as visualizations of relations. We will spend 2-3 weeks at the end of this course talking about properties of graphs. |