Function

See disclaimer about the slides.
See learning objectives and soures.

Definition

A function $f$ from a set $A$ (the domain) to a set $B$ (the codomain) associates to each element $x$ of $A$ exacty one element $y$ of $B$.
Notations: $f : A \to B$ and $f(x)=y$.

Examples

name of students.
parent of students.
$f(x)=x^2$ ?
$f(x)=\sqrt x$ ?

Concepts

Let $f : A \to B$.
If $y=f(x)$, then $y$ is the image of $x$ and $x$ is a preimage of $y$.
Some authors consider preimages and/or images of sets only, not single elements.
If $C \subset A$, the $f(C)=\{f(x) \mid x \in C\}$ is the image of $C$.
The image of $A$ is called the range of $f$, e.g., range of temperature in Portland in July.

Example I

function_2.png

Discuss during the lecture why this is a function and identify all the above concepts.

Some functions

Floor, ceiling, truncate, round (are they in your favorite language?)
Show during lecture the behavior of these functions and then define them.

Graph of a function

Given a function $f : A \to B$, the graph of $f$ is the set $\{(x,f(x)) \mid x \in A\}$.
Compute during lecture the graph of the function of Example I.

Properties

Injective (one-to-one): $\forall x, y \in A, f(x) = f(y) \to x = y$.
Same output implies same input.
Different inputs produce different outputs

Surjective (onto): $\forall y \in B, \exists x \in A, y=f(x)$.
Every element (of the codomain) is an output (of some input).

Bijective: both injective and surjective.

Discuss during the lecture whether the function of Example I has these properties and why.
How does the diagram help?

Composition (definition)

If $f : A \to B$ and $g : B \to C$, then the composition of $f$ and $g$ (the order is that of Lerma textbook, some authors reverse it) is denoted $(g \circ f) : A \to C$ and is defined by $(g \circ f)(x) = g(f(x))$.

What is the composition of applying first mother and then father? Maternal grandfather.

Composition (example)

Consider $f : {\mathbb N} \to {\mathbb N}$ defined by $f(x)=2x$ and $g : {\mathbb N} \to {\mathbb N}$ defined by $g(x)=x+3$.
Discuss during lecture the compositions $f \circ g$ and $g \circ f$.

Inverse

The function $1_A : A \to A$ defined by $\forall x \in A ~ (1_A(x)=x)$ is called the identity function for $A$.
If $f : A \to B$ is bijective, then there exists a unique function $f^{-1} : B \to A$, called the inverse of $f$, such that $f \circ f^{-1} = 1_B$ and $f^{-1} \circ f = 1_A$.

Operator

A function from $A \times A$ to $A$, e.g., ''+'' over $\mathbb Z$ (binary). Extends to unary and ternary.

Programming (optional)

Programming with functions

There are programming languages where the program is a set of function definitions and an execution is the evaluation of an expression.
For a taste of functional programming assume:
	seq(n) = [0,1,2,...n]
	dist(a,[b1,b2,...bn]) = [(a,b1),(a,b2),...(a,bn)]
	map(f,[b1,b2,...bn]) = [f(b1),f(b2),...f(bn)]
	add(x,y) = addition (similar subtraction, multiplication,...)
	tail([b1,b2,...bn]) = [b2,...bn]
and compute, e.g., [1,2,3,4,5], [0,2,4,6,8], [5,4,3,2,1], etc.