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:A→Bsource 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):x∈A}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 n∈Nsource 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: ×:N2→Nsource 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:N→Rsource 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:N→Nsource 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:N→Nsource 103 be defined such that g(x)=x+2−1source 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:N→Nsource 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:A→Bsource 30 is surjective iff Bsource 30 is also the range of fsource 31, i.e., for every y∈Bsource 31 there is at least one x∈Asource 32 such that f(x)=ysource 32, or in symbols: (∀y∈B)(∃x∈A)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:A→Bsource 65 is injective iff for each y∈Bsource 66 there is at most one x∈Asource 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:N→Nsource 77 given by f(x)=1source 77 is neither injective, nor surjective.

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

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

The function f:N→Nsource 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:A→Bsource 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:A→Bsource 24 be a function. The graph of fsource 25 is the relation Rf⊆A×Bsource 25 defined by Rf={⟨x,y⟩:f(x)=y}.source 27

source 24

Proposition: Relations that are function graphs

Let R⊆A×Bsource 43 be such that:

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

  2. for every x∈Asource 46 there is some y∈Bsource 46 such that ⟨x,y⟩∈Rsource 46.

Then Rsource 49 is the graph of the function f:A→Bsource 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 z≠ysource 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:A→Bsource 79 be a function with C⊆Asource 79.

The restriction of fsource 81 to Csource 81 is the function f↾C:C→Bsource 82 defined by (f↾C)(x)=f(x)source 83 for all x∈Csource 83. In other words, f↾C={⟨x,y⟩∈Rf:x∈C}source 84.

The application of fsource 87 to Csource 87 is f[C]={f(x):x∈C}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:B→Asource 28 is an inverse of a function f:A→Bsource 28 if f(g(y))=ysource 29 and g(f(x))=xsource 29 for all x∈Asource 29 and y∈Bsource 30.

source 27

If fsource 33 has an inverse gsource 33, we often write f−1source 33 instead of gsource 33.

Proposition: Injective functions have left inverses

If f:A→Bsource 63 is injective, then there is a left inverse g:B→Asource 64 of fsource 64 so that g(f(x))=xsource 64 for all x∈Asource 64.

source 62

Proof

Suppose that f:A→Bsource 69 is injective. Consider a y∈Bsource 69. If y∈ran(f)source 70, there is an x∈Asource 70 so that f(x)=ysource 70. Because fsource 71 is injective, there is only one such x∈Asource 71. Then we can define: g(y)=xsource 72, i.e., g(y)source 72 is “the” x∈Asource 72 such that f(x)=ysource 72. If y∉ran(f)source 73, we can map it to any a∈Asource 73. So, we can pick an a∈Asource 74 and define g:B→Asource 74 by: g(y)={xif f(x)=yaif y∉ran(f).source 75 It is defined for all y∈Bsource 81, since for each such y∈ran(f)source 81 there is exactly one x∈Asource 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:A→Bsource 87 has a left inverse gsource 87, then fsource 87 is injective.

source 86

Proposition: Surjective functions have right inverses

If f:A→Bsource 92 is surjective, then there is a right inverse h:B→Asource 93 of fsource 93 so that f(h(y))=ysource 93 for all y∈Bsource 94.

source 91

Proof

Suppose that f:A→Bsource 98 is surjective. Consider a y∈Bsource 98. Since fsource 99 is surjective, there is an xy∈Asource 99 with f(xy)=ysource 99. Then we can define: h(y)=xysource 100, i.e., for each y∈Bsource 100 we choose some x∈Asource 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 y∈Bsource 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 y∈Bsource 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 y∈Bsource 113, f(h(y))=ysource 113.

End of proof.

Exercise: A right inverse implies surjectivity

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

source 116

Proposition: Bijective functions have inverses

If f:A→Bsource 128 is bijective, there is a function f−1:B→Asource 129 so that for all x∈Asource 129, f−1(f(x))=xsource 130 and for all y∈Bsource 130, f(f−1(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 f−1source 139, show that it is a function, and show that it is an inverse of fsource 140, i.e., f−1(f(x))=xsource 140 and f(f−1(y))=ysource 140 for all x∈Asource 141 and y∈Bsource 141.

source 137

Proposition: Left and right inverses coincide

Show that if f:A→Bsource 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:A→Bsource 40 and g:B→Csource 40 be functions. The composition of fsource 41 with gsource 41 is g∘f:A→Csource 41, where (g∘f)(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 (g∘f)(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 (g∘f)(x)=2(x+1)source 49.

source 45

Exercise: Composition preserves injectivity

Show that if f:A→Bsource 53 and g:B→Csource 53 are both injective, then g∘f:A→Csource 54 is injective.

source 52

Exercise: Composition preserves surjectivity

Show that if f:A→Bsource 58 and g:B→Csource 58 are both surjective, then g∘f:A→Csource 59 is surjective.

source 57

Exercise: Graph of a composite function

Suppose f:A→Bsource 63 and g:B→Csource 63. Show that the graph of g∘fsource 64 is Rf∣Rgsource 64.

source 62

Partial Functions

Definition: Partial function and its domain

A partial function f:A⇀Bsource 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 x∈Asource 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)={x∈A:f(x)↓}source 27.

source 20

Example: Total functions as partial functions

Every function f:A→Bsource 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:R⇀Rsource 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:A⇀Bsource 43, define the partial function g:B⇀Asource 43 by: for any y∈Bsource 44, if there is a unique x∈Asource 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 x∈dom(f)source 46, and f(g(y))=ysource 47 for all y∈ran(f)source 47.

source 42

Definition: Graph of a partial function

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

source 50

Proposition: Single-valued relations define partial functions

Suppose R⊆A×Bsource 59 has the property that whenever Rxysource 59 and Rxy′source 60 then y=y′source 60. Then Rsource 60 is the graph of the partial function f:A⇀Bsource 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 x∈Asource 63 there is a y∈Bsource 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 y′≠ysource 68 such that Rxy′source 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.