SP20:Lecture 5 Functions

From CS2800 wiki

We spent a lot of time going through examples of things that are or are not functions or partial functions. We also briefly touched on quantifiers: for all and there exists.


Definition: Function
If [math]A [/math] and [math]B [/math] are sets, then a function from [math]A [/math] to [math]B [/math] (written [math]f : A \href{/cs2800/wiki/index.php/%E2%86%92}{→} B [/math]) is an unambiguous rule giving, for every input [math]x \href{/cs2800/wiki/index.php/%E2%88%88}{∈} A [/math], an output [math]f(x) \href{/cs2800/wiki/index.php/%E2%88%88}{∈} B [/math]. [math]A [/math] is called the domain of [math]f [/math]; [math]B [/math] is called the codomain.

When giving a function, you must indicate the domain, the codomain, and an unambiguous rule giving an output for every input.

The output of a function is unambiguous if there is only one output for any input. It is especially important to check this when the input of the function can be written in different ways. For example, [math]f : \href{/cs2800/wiki/index.php/Enumerated_set}{\{1,2\}} \href{/cs2800/wiki/index.php/%5Cto}{\to} \href{/cs2800/wiki/index.php/%E2%84%95}{ℕ} [/math] given by [math]f(1) := 2 [/math], [math]f(2) := 2 [/math], and [math]f(1+1):=4 [/math] is not unambiguous, because [math]2 = 1 + 1 [/math] so it is not clear if [math]f(2) = 2 [/math] or [math]f(2) = 4 [/math].

Specifying functions

When giving a function, you must indicate the domain, the codomain, and an unambiguous rule giving an output for every input. There are many, many ways to do this, as long as the output is clear. We gave a few examples during lecture:

direct specification

We can define the output of the function directly:

let [math]f(x) : \href{/cs2800/wiki/index.php?title=%E2%84%9D&action=edit&redlink=1}{ℝ} \href{/cs2800/wiki/index.php/%E2%86%92}{→} \href{/cs2800/wiki/index.php?title=%E2%84%9D&action=edit&redlink=1}{ℝ} [/math] be given by [math]f(x) := x^2 [/math]. The domain and codomain of [math]f [/math] are both [math]\href{/cs2800/wiki/index.php?title=%E2%84%9D&action=edit&redlink=1}{ℝ} [/math]; the image is [math]\{y ∈ \href{/cs2800/wiki/index.php?title=%E2%84%9D&action=edit&redlink=1}{ℝ} \href{/cs2800/wiki/index.php/%5Cmid}{\mid} y ≥ 0\} [/math].


We can draw a function:


The domain of [math]f [/math] is [math]\href{/cs2800/wiki/index.php/Enumerated_set}{\{a,b,c\}} [/math], and the codomain of [math]f [/math] is [math]\href{/cs2800/wiki/index.php/Enumerated_set}{\{1,2,3\}} [/math].

We might also write this as [math]f : \{a,b,c\} \href{/cs2800/wiki/index.php/%5Cto}{\to} \{1,2,3\} [/math] is given by [math]f(a):=2 [/math], [math]f(b):=1 [/math], and [math]f(c):=3 [/math].


Another way to draw a function is with a table:

x [math]f(x) [/math]
a 1
b 1
c 1

This almost describes a function; the domain is clearly [math]\{a,b,c\} [/math] (because if there were any other domain elements, [math]f [/math] would not be a function); and the rule is clear. However, the codomain is not clear: is it [math]\href{/cs2800/wiki/index.php/Enumerated_set}{\{1\}} [/math]? Or [math]\href{/cs2800/wiki/index.php/Enumerated_set}{\{1,2,3\}} [/math]? Or [math]\href{/cs2800/wiki/index.php/%E2%84%95}{ℕ} [/math], or [math]\href{/cs2800/wiki/index.php?title=%E2%84%9D&action=edit&redlink=1}{ℝ} [/math]? When describing a function with a table, the codomain should be specified somewhere.

function description

A function need not have an algorithm for constructing the output; a description of the output is also fine. For example, let [math]dji : Days \href{/cs2800/wiki/index.php/%E2%86%92}{→} ℝ [/math] give, on input [math]d [/math], the closing Dow-Jones Industrial average on day [math]d [/math].

Partial functions

A partial function is like a function, except that it does not need to give an output for every input. However, the outputs it does give must be unambiguous. One way to formalize this is by defining a partial function as a function from a restricted domain:

Definition: Partial function
A partial function [math]f : A \href{/cs2800/wiki/index.php/%E2%86%9B}{↛} B [/math] is a subset [math]S⊆A [/math] (called the support of [math]f [/math]), along with a function [math]\tilde{f}:S \href{/cs2800/wiki/index.php/%E2%86%92}{→}B [/math] We say that [math]f(x)=y [/math] if [math]\tilde{f}(x) = y [/math] and [math]f(x) [/math] is undefined if [math]x \href{/cs2800/wiki/index.php/%5Cnotin}{\notin} S [/math].
Definition: Total
A partial function [math]f [/math] is total if the support is equal to the domain, i.e. if [math]f [/math] is a function.

Note that, somewhat confusingly, not all partial functions are functions. However, we do consider a (total) function to be a partial function. We use this terminology because it is standard in mathematics and because it simplifies proofs (so that we don't have to say "a partial or total function" in places where the same argument works for both).

To summarize,


is a partial function, but not a function (because it is not total), while


is a partial function, a function and a total function (also an injection, a surjection, a bijection, and a relation).


For all and there exists are quantifiers: they describe how to interpret a variable in a predicate.

For all

If [math]P [/math] is a predicate that depends on [math]x [/math], then "for all [math]x [/math], [math]P [/math]" is a proposition. It is true if every possible value of [math]x [/math] makes [math]P [/math] evaluate to true.

  • If your goal is to prove "for all [math]x\href{/cs2800/wiki/index.php/%E2%88%88}{∈}A [/math], P", you can proceed by choosing an arbitrary value [math]x∈A [/math] and then proving that P holds for that [math]x [/math].

The fact that [math]x [/math] is arbitrary does not mean you get to pick [math]x [/math]; on the contrary, your proof should work no matter what [math]x [/math] you choose. This means you can't use any property of [math]x [/math] other than that [math]x \href{/cs2800/wiki/index.php/%E2%88%88}{∈} A [/math].

  • If you know [math]P [/math] holds for all [math]x [/math], then you can conclude [math]P [/math] holds for any specific [math]x [/math]. For example, if you know for all [math]x \href{/cs2800/wiki/index.php/%E2%88%88}{∈} ℝ [/math], [math]x^2 ≥ 0 [/math], then you can conclude [math]7^2 ≥ 0 [/math] (since [math]7 ∈ ℝ [/math]).

There exists

If [math]P [/math] is a predicate depending only on [math]x [/math], then "there exists [math]x [/math] such that P" (written [math]\exists x, P [/math] or [math]\exists x~\href{/cs2800/wiki/index.php?title=S.t.&action=edit&redlink=1}{s.t.}~P [/math]) is a proposition. It is true if there is some value [math]x [/math] that makes [math]P [/math] evaluate to true.

[math]\href{/cs2800/wiki/index.php/%5Cexists}{\exists} [/math] is sometimes called the existential quantifier.

  • To prove that there exists an [math]x [/math] such that [math]P(x) [/math] holds, it suffices to give a specific [math]x [/math] and then prove that [math]P [/math] is true for that [math]x [/math]. Such a proof usually starts "let [math]x:= \cdots [/math]", and then goes on to prove that [math]P(x) [/math] holds for the given [math]x [/math]. [math]x [/math] is sometimes referred to as a witness for [math]P(x) [/math].
  • If you know there exists some [math]x [/math] satisfying [math]P [/math], you can use it in a proof by treating [math]x [/math] as an arbitrary value. [math]x [/math] is arbitrary because the only thing you know about [math]x [/math] is that it exists, not what its value is.
  • To disprove that there exists an [math]x [/math] satisfying [math]P [/math], you must disprove [math]P [/math] for an arbitrary [math]x [/math]. Put another way, the logical negation of "there exists an [math]x [/math] such that [math]P [/math]" is "for all x, not P".

When trying to prove an existential statement [math]\href{/cs2800/wiki/index.php/%E2%88%83}{∃x}, \href{/cs2800/wiki/index.php/Predicate}{P}(x) [/math], you need to give a specific value of [math]x [/math] (a witness).

Often, in a proof, it is not immediately obvious what the witness should be. Finding one often involves solving some equations or combining some known values.

One nice technique for finding a witness is to simply leave a blank space for the value of [math]x [/math] and continue on with your proof of [math]P(x) [/math]. As you go, you may need [math]x [/math] to satisfy certain properties (for example, maybe you need [math]x \gt 17 [/math] at one point, and later you need [math]x \lt 85 [/math]). You can make a "wishlist" on the side of your proof, reminding you of all the properties you want [math]x [/math] to satisfy. Once you've completed your proof, you can go back and find a specific value of [math]x [/math] (say, [math]50 [/math]) that satisfies all of your wishes.