Functions: Definition and Types

COS1501 - Theoretical Computer Science I · Functions and Relations

Functions: Definition and Types

A function is a special type of relation between two sets. It assigns each element from the first set, called the domain, to exactly one element in the second set, called the codomain. Functions are fundamental in mathematics and computer science, as they help us understand how inputs relate to outputs.

Definition of a Function

A function can be defined as a set of ordered pairs (x, y) where each x in the domain corresponds to exactly one y in the codomain. This means that for every input x, there is a unique output y. We denote a function f that maps an element x to an element y as f(x) = y.

Remember: A function must have a unique output for each input.

Example of a Function

Consider the function f defined as follows:

f(x) = 2x + 3

In this case, the input x is multiplied by 2 and then increased by 3. Let's evaluate this function for some values:

  • f(1) = 2(1) + 3 = 5
  • f(2) = 2(2) + 3 = 7
  • f(3) = 2(3) + 3 = 9

The outputs are 5, 7, and 9, respectively. Each input has a unique output, confirming that this is a valid function.

Types of Functions

Functions can be classified into several types based on their characteristics. Here are some common types:

1. One-to-One Functions

A function is one-to-one (injective) if different inputs map to different outputs. This means that if f(a) = f(b), then a must equal b.

Example of a One-to-One Function

Consider the function g defined as:

g(x) = x + 1

For this function:

  • If g(1) = 2, then g(2) = 3.
  • g(1) is not equal to g(2), which shows it is one-to-one.

2. Onto Functions

A function is onto (surjective) if every element in the codomain has at least one corresponding element in the domain. In other words, the function covers the entire codomain.

Example of an Onto Function

Consider the function h defined as:

h(x) = x^2

Here, the codomain is the set of non-negative real numbers. For every non-negative real number y, there exists an x such that h(x) = y. For instance:

  • h(2) = 4
  • h(-2) = 4

However, if the codomain were the set of all real numbers, then h would not be onto, as there is no x such that h(x) results in a negative number.

3. Bijective Functions

A function is bijective if it is both one-to-one and onto. This means that there is a perfect pairing between the elements of the domain and codomain.

Example of a Bijective Function

Consider the function j defined as:

j(x) = 2x

This function is both one-to-one and onto if we consider the domain and codomain to be the set of all real numbers. For every real number there is a unique output, and every output is achieved by a unique input.

Watch out: Be careful not to confuse one-to-one and onto functions. A function can be one-to-one without being onto, and vice versa.

Function Notation

Function notation is a way to represent functions in mathematics. The notation f(x) indicates that f is a function and x is the input value. You can also have multiple functions, such as f, g, and h, each with its own rule.

Example of Function Notation

Let us define two functions:

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

We can evaluate these functions at a specific x value:

  • f(4) = 4 + 2 = 6
  • g(4) = 3(4) = 12

Composite Functions

A composite function is formed when you apply one function to the result of another function. If you have two functions f and g, the composite function is denoted as (f ∘ g)(x) = f(g(x)).

Example of Composite Functions

Let f(x) = 2x and g(x) = x + 1. The composite function (f ∘ g)(x) is calculated as follows:

(f ∘ g)(x) = f(g(x)) = f(x + 1) = 2(x + 1) = 2x + 2

Tip: When calculating composite functions, remember to substitute the entire g(x) into f.

Inverse Functions

An inverse function reverses the effect of the original function. If f is a function and f has an inverse, denoted as f-1, then applying f followed by f-1 will return the original input.

Example of Inverse Functions

For the function f(x) = 2x + 3, we find the inverse as follows:

  1. Replace f(x) with y: y = 2x + 3
  2. Swap x and y: x = 2y + 3
  3. Solve for y: x - 3 = 2y → y = (x - 3)/2

The inverse function is:

f-1(x) = (x - 3)/2

Summary

  • A function is a relation that assigns each input exactly one output.
  • Functions can be one-to-one, onto, or bijective.
  • Function notation is used to represent functions and their inputs.
  • Composite functions combine two functions, while inverse functions reverse the effect of the original function.

Check your understanding

  1. Define a function and give an example.
  2. What is the difference between one-to-one and onto functions?
  3. How do you find the inverse of a function?
  4. What is a composite function? Provide an example.