Reading preferences

Optional display controls need JavaScript. All reading content and navigation work without it.

How to use Read

This page follows the source chapter in ordinary reading order. Equations remain native MathML so compatible screen readers and braille systems can navigate their internal structure. Each small source link returns to the exact source line.

Basics

Definition: Function

A function f:ABsource 29 is a mapping of each element of Asource 30 to an element of Bsource 30.

We call Asource 32 the domain of fsource 32 and Bsource 32 the codomain of fsource 33. The elements of Asource 33 are called inputs or arguments of fsource 34, and the element of Bsource 34 that is paired with an argument xsource 34 by fsource 35 is called the value of fsource 35 for argument xsource 35, written f(x)source 36.

The range ran(f)source 38 of fsource 38 is the subset of the codomain consisting of the values of fsource 39 for some argument; ran(f)={f(x):xA}source 39.

source 28

The diagram in Figure: Function from a three-element domain to a four-element codomain may help to think about functions. The ellipse on the left represents the function's domain; the ellipse on the right represents the function's codomain; and an arrow points from an argument in the domain to the corresponding value in the codomain.

Function from a three-element domain to a four-element codomain

Three domain elements each have exactly one outgoing arrow. All three arrows end at the same codomain element, leaving three codomain elements unused.

Function from a three-element domain to a four-element codomainThree domain elements each have exactly one outgoing arrow. All three arrows end at the same codomain element, leaving three codomain elements unused. domaincodomain
  1. Domain: three elements.
  2. Codomain: four elements.
  3. Mapping: three arrows, one from each domain element; one codomain element receives all three arrows and the other three receive none.

source 50

Example: Multiplication on natural numbers

Multiplication takes pairs of natural numbers as inputs and maps them to natural numbers as outputs, so goes from N×Nsource 59 (the domain) to Nsource 60 (the codomain). As it turns out, the range is also Nsource 61, since every nNsource 61 is n×1source 61.

source 57

Example: Multiplication and square-root mappings

Multiplication is a function because it pairs each input—each pair of natural numbers—with a single output: ×:N2Nsource 66. By contrast, mapping a natural number nsource 67 to a real xsource 67 such that x2=nsource 68 is not functional, since each positive integer nsource 68 has two square roots: nsource 69 and nsource 69. We can make it functional by only returning the positive square root: X:NRsource 70.

source 64

Example: Student grades and parents

The relation that pairs each student in a class with their final grade is a function—no student can get two different final grades in the same class. The relation that pairs each student in a class with their parents is not a function: students can have zero, or two, or more parents.

source 74

Example: Successor function and its range

Let f:NNsource 93 be defined such that f(x)=x+1source 93. This is a definition that specifies fsource 94 as a function which takes in natural numbers and outputs natural numbers. It tells us that, given a natural number xsource 96, fsource 96 will output its successor x+1source 96. In this case, the codomain Nsource 97 is not the range of fsource 97, since the natural number 0source 98 is not the successor of any natural number. The range of fsource 99 is the set of all positive integers, Z+source 99.

source 92

Example: Extensionally equal successor functions

Let g:NNsource 103 be defined such that g(x)=x+21source 103. This tells us that gsource 104 is a function which takes in natural numbers and outputs natural numbers. Given a natural number nsource 105, gsource 105 will output the predecessor of the successor of the successor of xsource 106, i.e., x+1source 107.

source 102

Example: Function defined by even and odd cases

We can also define functions by cases. For instance, we could define h:NNsource 125 by h(x)={x2if x is evenx+12if x is odd.source 126 Since every natural number is either even or odd, the output of this function will always be a natural number. Just remember that if you define a function by cases, every possible input must fall into exactly one case. In some cases, this will require a proof that the cases are exhaustive and exclusive.

source 123

Kinds of Functions

Definition: Surjective function

A function f:ABsource 30 is surjective iff Bsource 30 is also the range of fsource 31, i.e., for every yBsource 31 there is at least one xAsource 32 such that f(x)=ysource 32, or in symbols: (yB)(xA)f(x)=y.source 33 We call such a function a surjection from Asource 36 to Bsource 36.

source 29

Definition: Injective function

A function f:ABsource 65 is injective iff for each yBsource 66 there is at most one xAsource 66 such that f(x)=ysource 66. We call such a function a injection from Asource 67 to Bsource 67.

source 64

Example: Injective and surjective combinations

The constant function f:NNsource 77 given by f(x)=1source 77 is neither injective, nor surjective.

The identity function f:NNsource 80 given by f(x)=xsource 80 is both injective and surjective.

The successor function f:NNsource 83 given by f(x)=x+1source 83 is injective but not surjective.

The function f:NNsource 86 defined by: f(x)={x2if x is evenx+12if x is odd.source 87 is surjective, but not injective.

source 76

Definition: Bijection

A function f:ABsource 113 is bijective iff it is both surjective and injective. We call such a function a bijection from Asource 115 to Bsource 115 (or between Asource 115 and Bsource 115).

source 112

Functions as Relations

Definition: Graph of a function

Let f:ABsource 24 be a function. The graph of fsource 25 is the relation RfA×Bsource 25 defined by Rf={x,y:f(x)=y}.source 27

source 24

Proposition: Relations that are function graphs

Let RA×Bsource 43 be such that:

  1. If Rxysource 45 and Rxzsource 45 then y=zsource 45; and

  2. for every xAsource 46 there is some yBsource 46 such that x,yRsource 46.

Then Rsource 49 is the graph of the function f:ABsource 49 defined by f(x)=ysource 50 iff Rxysource 50.

source 42

Proof

Suppose there is a ysource 54 such that Rxysource 54. If there were another zysource 54 such that Rxzsource 55, the condition on Rsource 55 would be violated. Hence, if there is a ysource 56 such that Rxysource 56, this ysource 56 is unique, and so fsource 56 is well-defined. Obviously, Rf=Rsource 57.

End of proof.

Definition: Function restriction and image

Let f:ABsource 79 be a function with CAsource 79.

The restriction of fsource 81 to Csource 81 is the function fC:CBsource 82 defined by (fC)(x)=f(x)source 83 for all xCsource 83. In other words, fC={x,yRf:xC}source 84.

The application of fsource 87 to Csource 87 is f[C]={f(x):xC}source 87. We also call this the image of Csource 88 under fsource 89.

source 78

Inverses of Functions

Definition: Inverse function

A function g:BAsource 28 is an inverse of a function f:ABsource 28 if f(g(y))=ysource 29 and g(f(x))=xsource 29 for all xAsource 29 and yBsource 30.

source 27

If fsource 33 has an inverse gsource 33, we often write f1source 33 instead of gsource 33.

Proposition: Injective functions have left inverses

If f:ABsource 63 is injective, then there is a left inverse g:BAsource 64 of fsource 64 so that g(f(x))=xsource 64 for all xAsource 64.

source 62

Proof

Suppose that f:ABsource 69 is injective. Consider a yBsource 69. If yran(f)source 70, there is an xAsource 70 so that f(x)=ysource 70. Because fsource 71 is injective, there is only one such xAsource 71. Then we can define: g(y)=xsource 72, i.e., g(y)source 72 is “the” xAsource 72 such that f(x)=ysource 72. If yran(f)source 73, we can map it to any aAsource 73. So, we can pick an aAsource 74 and define g:BAsource 74 by: g(y)={xif f(x)=yaif yran(f).source 75 It is defined for all yBsource 81, since for each such yran(f)source 81 there is exactly one xAsource 82 such that f(x)=ysource 82. By definition, if y=f(x)source 83, then g(y)=xsource 83, i.e., g(f(x))=xsource 83.

End of proof.

Exercise: A left inverse implies injectivity

Show that if f:ABsource 87 has a left inverse gsource 87, then fsource 87 is injective.

source 86

Proposition: Surjective functions have right inverses

If f:ABsource 92 is surjective, then there is a right inverse h:BAsource 93 of fsource 93 so that f(h(y))=ysource 93 for all yBsource 94.

source 91

Proof

Suppose that f:ABsource 98 is surjective. Consider a yBsource 98. Since fsource 99 is surjective, there is an xyAsource 99 with f(xy)=ysource 99. Then we can define: h(y)=xysource 100, i.e., for each yBsource 100 we choose some xAsource 101 so that f(x)=ysource 101; since fsource 101 is surjective there is always at least one to choose from. Note: Since fsource 102 is surjective, for every yBsource 103 the set {x:f(x)=y}source 103 is nonempty. Our definition of hsource 104 requires that we choose a single xsource 104 from each of these sets. That this is always possible is actually not obvious—the possibility of making these choices is simply assumed as an axiom. In other words, this proposition assumes the so-called Axiom of Choice, an issue we will revisit in the Choice chapter. However, in many specific cases, e.g., when A=Nsource 109 or is finite, or when fsource 109 is bijective, the Axiom of Choice is not required. (In the particular case when fsource 110 is bijective, for each yBsource 110 the set {x:f(x)=y}source 111 has exactly one element, so that there is no choice to make.) By definition, if x=h(y)source 112, then f(x)=ysource 113, i.e., for any yBsource 113, f(h(y))=ysource 113.

End of proof.

Exercise: A right inverse implies surjectivity

Show that if f:ABsource 117 has a right inverse hsource 117, then fsource 117 is surjective.

source 116

Proposition: Bijective functions have inverses

If f:ABsource 128 is bijective, there is a function f1:BAsource 129 so that for all xAsource 129, f1(f(x))=xsource 130 and for all yBsource 130, f(f1(y))=ysource 130.

source 127

Proof

Exercise.

End of proof.

Exercise: Construct the inverse of a bijection

Prove Proposition: Bijective functions have inverses. You have to define f1source 139, show that it is a function, and show that it is an inverse of fsource 140, i.e., f1(f(x))=xsource 140 and f(f1(y))=ysource 140 for all xAsource 141 and yBsource 141.

source 137

Proposition: Left and right inverses coincide

Show that if f:ABsource 155 has a left inverse gsource 155 and a right inverse hsource 156, then h=gsource 156.

source 154

Proof

Exercise.

End of proof.

Exercise: Prove left and right inverses coincide

Prove Proposition: Left and right inverses coincide.

source 163

Proposition: Inverses are unique

Every function fsource 168 has at most one inverse.

source 167

Proof

Suppose gsource 172 and hsource 172 are both inverses of fsource 172. Then in particular gsource 173 is a left inverse of fsource 173 and hsource 173 is a right inverse. By Proposition: Left and right inverses coincide, g=hsource 174.

End of proof.

Composition of Functions

Definition: Composition

Let f:ABsource 40 and g:BCsource 40 be functions. The composition of fsource 41 with gsource 41 is gf:ACsource 41, where (gf)(x)=g(f(x))source 42.

source 39

Example: Composing successor and doubling

Consider the functions f(x)=x+1source 46, and g(x)=2xsource 46. Since (gf)(x)=g(f(x))source 47, for each input xsource 47 you must first take its successor, then multiply the result by two. So their composition is given by (gf)(x)=2(x+1)source 49.

source 45

Exercise: Composition preserves injectivity

Show that if f:ABsource 53 and g:BCsource 53 are both injective, then gf:ACsource 54 is injective.

source 52

Exercise: Composition preserves surjectivity

Show that if f:ABsource 58 and g:BCsource 58 are both surjective, then gf:ACsource 59 is surjective.

source 57

Exercise: Graph of a composite function

Suppose f:ABsource 63 and g:BCsource 63. Show that the graph of gfsource 64 is RfRgsource 64.

source 62

Partial Functions

Definition: Partial function and its domain

A partial function f:ABsource 21 is a mapping which assigns to every element of Asource 22 at most one element of Bsource 22. If fsource 23 assigns an element of Bsource 23 to xAsource 23, we say f(x)source 23 is defined, and otherwise undefined. If f(x)source 24 is defined, we write f(x)source 25, otherwise f(x)source 25. The domain of a partial function fsource 26 is the subset of Asource 26 where it is defined, i.e., dom(f)={xA:f(x)}source 27.

source 20

Example: Total functions as partial functions

Every function f:ABsource 31 is also a partial function. Partial functions that are defined everywhere on Asource 32—i.e., what we so far have simply called a function—are also called total functions.

source 30

Example: Reciprocal as a partial function

The partial function f:RRsource 38 given by f(x)=1/xsource 38 is undefined for x=0source 39, and defined everywhere else.

source 37

Exercise: Partial inverse of a partial function

Given f:ABsource 43, define the partial function g:BAsource 43 by: for any yBsource 44, if there is a unique xAsource 44 such that f(x)=ysource 45, then g(y)=xsource 45; otherwise g(y)source 45. Show that if fsource 46 is injective, then g(f(x))=xsource 46 for all xdom(f)source 46, and f(g(y))=ysource 47 for all yran(f)source 47.

source 42

Definition: Graph of a partial function

Let f:ABsource 51 be a partial function. The graph of fsource 51 is the relation RfA×Bsource 52 defined by Rf={x,y:f(x)=y}.source 53

source 50

Proposition: Single-valued relations define partial functions

Suppose RA×Bsource 59 has the property that whenever Rxysource 59 and Rxysource 60 then y=ysource 60. Then Rsource 60 is the graph of the partial function f:ABsource 61 defined by: if there is a ysource 61 such that Rxysource 62, then f(x)=ysource 62, otherwise f(x)source 62. If Rsource 62 is also serial, i.e., for each xAsource 63 there is a yBsource 63 such that Rxysource 64, then fsource 64 is total.

source 58

Proof

Suppose there is a ysource 68 such that Rxysource 68. If there were another yysource 68 such that Rxysource 69, the condition on Rsource 69 would be violated. Hence, if there is a ysource 70 such that Rxysource 70, that ysource 70 is unique, and so fsource 71 is well-defined. Obviously, Rf=Rsource 71 and fsource 71 is total if Rsource 72 is serial.

End of proof.