# Composing Functions With Sets Of Points Assignments

You have certainly dealt with functions before, primarily in calculus, where you studied functions from $\R$ to $\R$ or from $\R^2$ to $\R$. Perhaps you have encountered functions in a more abstract setting as well; this is our focus. In the last few sections of the chapter, we use functions to study some interesting topics in set theory.

By a function from a set $A$ to a set $B$ we mean an assignment or rule $f$ such that for every $a\in A$ there is a unique $b\in B$ such that $f(a)=b$. The set $A$ is called the domain of $f$ and the set $B$ is called the codomain. We say two functions $f$ and $g$ are equal if they have the same domain and the same codomain, and if for every $a$ in the domain, $f(a)=g(a)$.

(In the interest of full disclosure of dirty tricks, we should mention that the last paragraph is not really a definition at all! The problem is that the words "assignment'' and "rule'' are synonyms for "function.'' This problem can be "resolved'' by defining functions in terms of sets, but we don't really have a satisfactory definition of "set'' either. For now, all that is needed is an intuitive understanding of the concept and a way of showing two functions are equal.)

We often write $f\colon A\to B$ to indicate that $f$ is a function from $A$ to $B$. Sometimes the word "map'' or "mapping'' is used instead of "function.'' If $f\colon A\to B$ and $f(a)=b$, we say $b$ is the image of $a$ under $f$, and $a$ is a preimage of $b$ under $f$. When the function is clear from context, the phrase `under $f$' may be dropped.

Example 4.1.1 You are familiar with many functions $f\colon \R\to \R$: Polynomial functions, trigonometric functions, exponential functions, and so on. Often you have dealt with functions with codomain $\R$ whose domain is some subset of $\R$. For example, $f(x)=\sqrt x$ has domain $[0,\infty)$ and $f(x)=1/x$ has domain $\{x\in \R : x\ne 0\}$. It is easy to see that a subset of the plane is the graph of a function $f\colon \R\to \R$ if and only if every vertical line intersects it at exactly one point. If this point is $(a,b)$, then $f(a)=b$.

Example 4.1.2 Functions on finite sets can be defined by listing all the assignments. If $A=\{1,2,3,4\}$ and $B=\{r,s,t,u,v\}$ then "$f(1)= t,f(2)= s,f(3)= u,f(4)= t$'' defines a function from $A$ to $B$. The assignment can be done quite arbitrarily, without recourse to any particular formula.

Example 4.1.3 The following are not functions from $A=\{1,2,3,4,5\}$ to $B=\{r,s,t,u\}$: $$\matrix{f(1)= t & \quad & g(1)=u\cr f(2)= s & \quad & g(2)=r\cr f(3)= r & \quad & g(4)=s\cr f(3)= u & \quad & g(5)=t\cr f(4)= u & \quad & \cr f(5)= r & \quad & \cr}$$ The problem is that $f$ maps $3$ to two values and $g$ doesn't map $3$ to any values. When listing the assignments for a function the elements of the domain must appear exactly once. (Elements of the codomain may appear more than once or not at all. In example 4.1.2, the element $t$ of the codomain has two preimages and $r$ and $v$ have none. We will discuss this situation at length in later sections.)

Example 4.1.4 If $A$ and $B$ are non-empty sets and $b_0$ is a fixed element of $B$, we can define a constant function $f\colon A\to B$ by the formula $f(a)=b_0$ for all $a\in A$. There are as many constant functions from $A$ to $B$ as there are elements of $B$.

Example 4.1.5 For a set $A$ we define the identity function $i_A\colon A\to A$ by the rule $i_A(a)=a$ for all $a\in A$. In other words, the identity function maps every element to itself. Though this seems like a rather trivial concept, it is useful and important. Identity functions behave in much the same way that 0 does with respect to addition or 1 does with respect to multiplication.

Example 4.1.6 If $A\subseteq B$, define the inclusion function $f\colon A\to B$ by $f(a)=a$ for every $a\in A$. This is very similar to $i_A$; the only difference is the codomain.

Definition 4.1.7 If $f\colon A\to B$ and $g\colon B\to C$ are functions, define $g\circ f\colon A\to C$ by the rule $(g\circ f)(a)=g(f(a))$ for all $a\in A$. This is called the composition of the two functions. Observe that $f$ is the first function that is applied to an element $a$ though it is listed on the right. This violation of the usual left-to-right convention sometimes causes confusion.

Example 4.1.8 If $f\colon \R^+\cup\{0\}\to \R$ is given by $f(x)=\sqrt x$ and $g\colon \R\to\R$ is given by $g(x)=\sin x$, then $g\circ f\colon \R^+\cup\{0\}\to \R$ is given by $(g\circ f)(x)=\sin \sqrt x$. Note that $(f\circ g)(x)=\sqrt{\sin x}$ makes sense only for those $x$ such that $\sin x\ge 0$. In general, $f\circ g$ and $g\circ f$ are not necessarily equal, and (as in this case) they need not be defined at the same points.

## Composition of Functions

"Function Composition" is applying one function to the results of another:

The result of f() is sent through g()

It is written: (g º f)(x)

Which means: g(f(x))

### Example: f(x) = 2x+3 and g(x) = x2

"x" is just a placeholder. To avoid confusion let's just call it "input":

f(input) = 2(input)+3

g(input) = (input)2

Let's start:

(g º f)(x) = g(f(x))

First we apply f, then apply g to that result:

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

What if we reverse the order of f and g?

(f º g)(x) = f(g(x))

First we apply g, then apply f to that result:

(f º g)(x) = 2x2+3

We get a different result!

When we reverse the order the result is rarely the same.

So be careful which function comes first.

## Symbol

The symbol for composition is a small circle:

(g º f)(x)

It is not a filled in dot: (g · f)(x), as that means multiply.

## Composed With Itself

We can even compose a function with itself!

### Example: f(x) = 2x+3

(f º f)(x) = f(f(x))

First we apply f, then apply f to that result:

(f º f)(x) = 2(2x+3)+3 = 4x + 9

We should be able to do it without the pretty diagram:

(f º f)(x)= f(f(x))

= f(2x+3)

= 2(2x+3)+3

= 4x + 9

## Domains

It has been easy so far, but now we must consider the Domains of the functions.

The domain is the set of all the values that go into a function.

The function must work for all values we give it, so it is up to us to make sure we get the domain correct!

### Example: the domain for √x (the square root of x)

We can't have the square root of a negative number (unless we use imaginary numbers, but we aren't), so we must exclude negative numbers:

The Domain of √x is all non-negative Real Numbers

On the Number Line it looks like:

Using set-builder notation it is written:

{ x | x ≥ 0}

Or using interval notation it is:

[0,+∞)

It is important to get the Domain right, or we will get bad results!

## Domain of Composite Function

We must get both Domains right (the composed function and the first function used).

When doing, for example, (g º f)(x) = g(f(x)):

• Make sure we get the Domain for f(x) right,
• Then also make sure that g(x) gets the correct Domain

### Example: f(x) = √x and g(x) = x2

The Domain of f(x) = √x is all non-negative Real Numbers

The Domain of g(x) = x2 is all the Real Numbers

The composed function is:

(g º f)(x) = g(f(x))

= (√x)2

= x

Now, "x" normally has the Domain of all Real Numbers ...

... but because it is a composed function we must also consider f(x),

So the Domain is all non-negative Real Numbers

## Why Both Domains?

Well, imagine the functions are machines ... the first one melts a hole with a flame (only for metal), the second one drills the hole a little bigger (works on wood or metal):

 What we see at the end is a drilled hole, and we may think "that should work for wood or metal". But if we put wood into g º f then the first function f will make a fire and burn everything down!

So what happens "inside the machine" is important.

## De-Composing Function

We can go the other way and break up a function into a composition of other functions.

### Example: (x+1/x)2

That function can be made from these two functions:

f(x) = x + 1/x

g(x) = x2

And we get:

(g º f)(x) = g(f(x))

= g(x + 1/x)

= (x + 1/x)2

This can be useful if the original function is too complicated to work on.

## Summary

• "Function Composition" is applying one function to the results of another.
• (g º f)(x) = g(f(x)), first apply f(), then apply g()
• We must also respect the domain of the first function
• Some functions can be de-composed into two (or more) simpler functions.

Operations with FunctionsAlgebra Index