The Definition of a Function
A function is a relation between a set of inputs and a set of outputs. In which each input maps out directly to a single output. This concept is very central to that of programming because a programmer would use a function to do multiple different portions of work in the program continuously.
What is covered
- Definition of a Function
- Domain, co-domain, and range of a function
- Image and pre-image (antecedent) of an element
Function Definition- as said before, it is a set, which you can go see the previous two weeks of content to figure out what a set it. But it is a set of inputs that each map to a single output in another set of outputs. It is the exact relation that transforms the original set of inputs and maps it to a value in the set of outputs.
In the above example, you have an input set of a couple of strings, the output set is then characterized as the number of characters in a given string. You can then basically use some form of a function to help you achieve a result in the output, this time by counting the given characters.
Definition: A function f from a set A to a set B is an assignment of exactly one element of B to each element of A, meaning no duplicates and is written as:
f: A → B
//this is read as `f maps A to B`
//and is so defined as
x ∈ A: x → f(x) = y (y ∈ B)
This basically says if x is an element of A, if x is transformed by the function it becomes a variable y which by definition must be an element of B
The main difference between a function in something like the above definition, or in continuous math like algebra or even calculus, is that a function in programming can be used to have multiple of the same input always return the same output, or have multiple outputs for a single input if the random function is put in for example. There is obviously also many points of data that can be put into a given function as well.
Terminology of Functions
Given a function: f: A → B: x ∈ A → f(x) = y ∈ B
This is true for when A is the set of all inputs and is therefore logically called the domain of f. So we can say
Then you have B which is the set of outputs and is called the co-domain of f written and denoted by
The set containing ALL of the outputs is called the range of f and is written therefore as
Then as for the individual inputs and outputs of each of these sets, x, y you have the y being called the image of x which is because it is from the pre-image of x that y was able to be gotten. In tandem then of course you call x the pre-image of y because it is the value before any imaging happened. For this we write
Clarification on the co-domain and the actual range. So the co-domain or B is basically the set of all possible output values that are declared as part of the function’s definition f: x→y. The range is the actual real values that are outputted when the function produces when elements from the domain are plugged in.
In essence the co-domain is what you CAN get out like all integers or all strings or whatever and the range is what you actually get back from putting in your domain. R ⊆ co-Df
Example to demonstrate domain, co-domain, and range of a function
Here is the existing example that occurred before hand. Below are my own personal ideas for what I believe the domain, co-domain, and range are.
Domain: the domain in the above example is the actual set of values that got passed in, so Set A where A = {On, Sea, Land, Sky}
Range: is the set of output that you actually got back so
Co-Domain is the overall encompassing set of all possible outputs that can be gotten from a given input, so basically everything that is possible for you to get back, denoted in this case by Set B = {x | x ∈ ℕ and x≠0} the last bit is assuming that we do not count "" as an input.
I might have only been slightly wrong on the co-domain actually, it seems that B can be generally defined as a finite set of outputs
For the images:
The images and pre-images once again are not too bad as it seems, they are just the relation to a given output and it’s input. This is primarily important for functions that pass the vertical line test and only ever output a single output for a given input.
As it can be seen, the image of a value is it’s output from the function, and then an output’s pre-image is it’s given input, this is shown as f(on) = 2 and then Pre-images(2) = {on} where Pre-Images of two is naturally a subset of A and can define more than one element: so Pre-images(3) = {Sea, Sky} for example.
Relations that are NOT functions
The two reasons why this is a relation and not an outright function are listed outright on the bottom of the image, not every single given input in the input set has an output, and there are several different possible outputs for a given input.
Notice however, if you did actually reverse the order of what you consider to be the input and what you consider to the be the output, that being that the names become the input and the grades become the output, you get a function!
Exercises for Practice
Exercise 1:
Given the following function: f: Z → Z f(x) = |x|
- Find the domain, co-domain, and range of the function f.
domain = A = Zthis basically means all integers in the setZas defined inf: Z → Zco-domain = B = Z, for the same reason that A isZ.- The
rangeof the function is screenshotted below, but basically means that the range is the values that are greater than or equal to zero
- Also find the set of
pre-images(1)pre-images(1) = {-1, 1}
Exercise 2:
Given the following function: g:R→R with g(x)=x^2+1
- Find the domain, co-domain, and range of the function g
- Domain:
Ras defined by the function definition - Co-Domain:
Ras defined by the function definition - Range:
{x^2+1 | x ∈ R}but thats cheating so simplifying it we get{y : y ∈ ℕ ^ y ≥ 1}which written as an actual range becomes:[1, ∞)
- Domain:
- Find the pre-images of 5
pre-images(5)={2, -2}this is becauseg(2) = g(-2) = 5
Plotting Functions:
Function Definitions:
- Linear Functions
- Quadratic Functions
- Exponential Functions
A linear function is one where the highest power of your variable is one, and where you have a given form of f(x) = ax + b where a and b are real numbers.
In this form, the y=mx+b form, this function is always a straight line, but the line passes through point (0, b) with a slope of ∇a
This is the example portion of this bad boy, and it basically goes over the basic value of what a linear function is. It just says that the function is increasing if it has a slope that is greater than zero and is decreasing otherwise, giving the mathematical definition for it.
He also then gives out the definitions for a quadratic function this being f(x) = ax^2 + bx + c where a, b, c are all integers and a is not equal to zero. This function generally follows the formation of a parabola, and is characterized by such. You know what the fuck a quadratic function looks like, I ain’t gonna screenshot his graph.
The domain of a function f(x) = x^2 is all real numbers, as it would be for any regular quadratic function as well. The range is the set of real positive numbers, at least based on the values of what a b and c are.
A exponential function is of the form f(x) = b^x where b>0 and b ≠ 1. This of course generally means that you have some value that can change exponentially, with the variable value inside of the exponent.
The domain of kind of a function would be all real numbers: (-∞, ∞) and then the range would be (0, ∞), at least I assume so
He also gives some algebraic manipulations of exponential values:
Injective and surjective Functions
An injective function is a one-to-one function.
A Surjective Function are onto functions.
Injective (one-to-one) functions:
Let f: A → B be a function. f is said to be injective if and only if:
∀a,b ∈ A, if a ≠ b then f(a) ≠ f(b)which is equivalent to∀a,b ∈ A, if f(a)=f(b) then a=bwhich makes sense because:p → q ≡ ¬q → ¬p
What this is basically saying that for all a, b inside of the input set A, no elements product the same output. This is to say that if you plug in a single input, as long as this input is not equal to another input, then the output will always be different.
This is the basic standard definition of a function, and not a relation, and it basically means that a function is injective if it has a one-to-one output to input ratio
Therefore, in order to show that a given function is not subjective, you just need to showcase that there are in fact two inputs that do result in the same output. So logically speaking so: ¬(∀a,b ∈ A, if a ≠ b, then f(a)≠f(b)) which of course is equal to ∃a,b ∈ A, a ≠ b and f(a) = f(b), don’t you just love it when logic theory works?
Example of Injective and Not Injective Functions:
As we can see the function on the left is injective because each input corresponds to one output inside of the co-domain of the function. This however is not true for the function on the right as the mod operator will always return either a one or a two, written as: ∀ x ∈ ℤ, x mod 2 = 1 ∧ x mod 2 = 0
Example of Linear function
Let’s show that the function f: R→R with f(x) = 2x+3 is an injection
Proof 1:
- Let
a, b ∈ R, show that iff(a) = f(b), thena=b - Assume:
f(a) = f(b)→2a+3 = 2b+3 - If you subtract 3 from both sides and divide by 2 then you get
a=band this is enough to show that the function is injective
Proof 2: - Let
a, b ∈ R, show that ifa≠b, thenf(a)≠f(b) - Assume
a ≠ b, we can then manipulate this to showcase that the given function does not equal itself when a and b are plugged in. So you multiply both sides by 2 and then add three and get2a+3 ≠ 2b+3
Example of Quadratic function
Let’s show that the function f: R→R with f(x) = x^2 is NOT an injection
Proof 1:
- We have to try and prove that
∃a,b ∈ A, a ≠ b and f(a) = f(b) - We can say that
b = -a because -a ≠ a when a ≠ 0 - This means that
f(-a) = f(a), so(-a)^2 = a^2, which then simplifieda^2 = a^2, therefore the functionf(x) = x^2is NOT an injection
Now notice that if you change the domain from f: R^+ → R then the function f(x)=x^2 becomes injective. This is because you limited the domain of the function to only be positive values:
Proof 1:
- Same proof applies as a regular injective function, let
∀a,b ∈ R^+, if f(a) = f(b) then a = b - Assume
f(a) = f(b)over the domain R^+, thena^2 = b^2, if you square root both sides you geta = b. - This therefore shows that over the domain of all real positive numbers the function
x^2is injective.
Surjective (onto) function
Let f: A → B be a function.
f is said to be a surjective (onto) function if and only if every element of the co-domain of f, B, has at least one pre-image in the domain of f, A.
In math terms: ∀ y ∈ B | ∃x ∈ A : y=f(x)
Now what this means as a general explanation is that for every single element inside of the co-domain, has at least one pre-image in the domain. Basically this means that the input covers all of the possible output and no values are skipped, so a function of f(x) = x pretty much would be surjective on the domain ℝ → ℝ but if the domains differed then it would not be: ℤ → ℝ, all of the output can be hit by the input.
Example on surjective Linear function:
Let’s show that the function f: R→R with f(x) = 2x+3 is a surjective
Proof:
- We need to show that
∀ y ∈ B | ∃x ∈ A : y=f(x) - Assume:
f(x) = y→2x+3 = yso therefore moving the values aroundx = (y-3)/2 ∈ ℝThe thing is that no matter the value of Y, you can then find an element of X which is basically equal to the value just described - So you basically reverse the equation just a bit so that way you can check if indeed all of your inputs convert into all of your outputs
Example on non-surjective quadratic function:
Let’s show that the function f: R→R with f(x) = x^2 is NOT a surjective
Proof:
- We need to show that
∃y ∈ B | ∀x ∈ A : y≠f(x) - The co-domain of this function is obviously equal to R as is defined by the function. However all of the images are either zero or are positive. This means there is no mapping for the negative inputs because they all become positive. This does mean however that the function is surjective if we restrict it’s domain to only
Worksheet
Reading:
Read the following extracts to consolidate your knowledge of these topics: the definition of a function; the domain and co-domain; the range; injection (one-to-one); surjection (onto); and plotting functions.
Once you’ve finished the reading, please attempt the following exercises:
pp.123–124, exercises 1–4 and 25, 26, 41, 43.
Further reading
If you would like to explore and practice these concepts further, you can read the extract from the Oscar Levin book below:
Levin, O. Discrete Mathematics: An Open Introduction. (Colorado: University of Northern Colorado, 2019) 3rd edition [ISBN 9781792901690] pp.45–50.
(This work is licensed under the Creative Commons Attribution-Share Alike 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/4.0/.)
And complete the exercises on p.51, 1–3, 5, 7.
Book Reading:
Terminology:
This chapter as it says presents two mathematical entities: functions & matrices. The concept of a function is central to all parts of math and other learning. Where matrices are important in places like computer science, engineer, and natural/social sciences.
Domain and Co-Domain
Below-hand is the image of what a function is inside of mathematics, it consists of a set A of mathematicians names and then a given output set B which is representative of each of their Quality Point Averages.
There are TWO properties to take note of. Each of the given values in the set of majors A does in fact have an output inside of the set of QPA B. AND each of the inputs has a unique output. This means that each input has exactly one output, even if it is the same as another input’s output.
The Math Definition:
- Let
XandYbe two nonempty sets. A function fromXtoYis a rule that assigns each elementx ∈ Xa unique corresponding elementy ∈ Y. Functions are generally denoted by the lettersf, g, h, ietc.
In a given function that relates two sets X and Y you would write this as f: X → Y. In this notation, the set X is called the domain of the function, and serves as all of the inputs into the given function. In tandem then, you have Y which is the co-domain of the function, and represents the domain in which all of the possible outputs of the function actually fall.
If X = Y, that is to say that the domain of a function is equal to the co-domain of the function, then it is said that f is: “a function on X”.
Images and Pre-Images
As the image above says, if you do in fact have a function that corresponds to the proper elements of a function, that is to say that every single element in the input set has an single element in the output set, then the x value aka the input, is called the pre-image, and then it’s corresponding y value, aka output, is called the image
Range
If you have a given function f: X → Y and A ⊆ X then f(A) denotes the set f(a) | a ∈ A. This is basically a really fancy way of saying that hey, if I have a subset of the domain, that is either part or the whole domain, and then I input all of these given values inside of the function, I would get a subset of the co-domain that could include the whole co-domain or only a part of it. This is called the range
The fancy proof for this:
Basically this is saying that you put in the values of your domain and then whatever you get out is your range, this can be either the whole co-domain or only part of it depending on the situation.
Examples
Programming languages provide built-in functions, like take round() for example. This function takes in a set of a double basically, and then outputs a integer. This means that it has a domain of ℝ so all real numbers, and then outputs a range of ℤ which is all negative and positive integers. This means that the domain of these functions is ℝ and then the co-domain is ℤ, so in theory you have a larger domain than co-domain.
There are sometimes function definitions that would consist of more than one formula, and such things are called piece-wise definitions. So in a regular function you undergo a singular formula in order to get to your given set of values, but inside of a piece-wise definition you might undergo multiple different formulas in conjunction:
So imaging this, each town in a given state charges each of it’s households a minimum of $75 for up to 4000 cubic feet of water every single six months. If they were to reach above this limit in 6 months time, they are charged 60 cents extra for every 100 cubic feet more water they use.
So in this scenario this is actually a piece-wise definition of a function, this is because you have a base value and then based on some condition, the value suddenly changes, which means that the given function changes how it behaves in this time as well. You can represent this using a piece-wise definition:
You can also make graphs of each function as a means of using them to study your function outright, this makes logical sense because with a function definition you can make a good approximation of where each point will be if you have the correct domain. So for a function with a domain of ℝ then it can be safe to say that your function has lines, but if it is more discrete with only a domain of ℤ then it is represented only by dots
Function manipulations:
If a function has the same given co-domain as another function, then they can be combined in order to construct new functions. So take for example functions: f: X → ℝ and g: Y → ℝ
You can manipulate these functions in a product and sum:
(f+g)(x) = f(x) + g(x)(fg)(x) = f(x) * g(x)
This works for all places where both f and g are defined. Therefore dom(f+g) = dom(fg) = dom(f) ∩ dom(g). So basically in all of the places where the domain of f and g intersect, which is great whenever in the above example for example X + Y
This means that if there is only a portion of a given domain that is shared by the two functions, then the product and sum of those two functions is only defined on that portion.
Special Functions
These are functions that are very important inside of discrete mathematics and are used in several proofs and different ideas.
Polynomial Functions:
A polynomial function of f: ℝ → ℝ defined by Where the elements of a ∈ ℝ, n ∈ W (whole numbers). The expression denoted by f(x) is a polynomial degree n in x. When n=1 the f is linear, when it is 2, it is quadratic, so on and so forth.
This is pretty self-explanatory
Exponential and Logarithmic Functions:
Let a ∈ ℝ+, where a≠1, and x any real number. The function of f: ℝ → ℝ+ is defined by is called an exponential function, with the base a. The most frequent exponential function base inside of computer science is base 2, so
Then you have: Let a ∈ ℝ+, where a≠1, and x and y are any real numbers such that . Then, x is called the logarithm of y to the base a, denoted by . Logically speaking this then means that The most common form of a logarithmic function seen in computer science is of course the base two logarithmic function. This is generally denoted as lg(x) = log2(x)
Absolute value function
Floor and Ceiling Functions
Properties of Functions:
Identity Function:
A function f on X is the identity function, so if f(x) = x for every x in X, then it is denoted by , and leaves every single input unchanged. Examples:
Injection:
A function f: X → Y is an injection or a one-to-one function if different input values all yield different output values.
- Thus, the formal proof is that
fis injective, if and only ifx1 ≠ x2implies thatf(x1) ≠ f(x2). - Equally this would then mean, as proof by contrapositive, that if
f(x1) = f(x2), thenx1 = x2. Only iffis of course an injective function.
You can basically think of this as a function that would pass the horizontal line test. If a function passes the horizontal line test, then it is in fact a injective function, however if it does not (like for example a quadratic), then it is considered to not be injective. This can of course be changed given the domain of a function, if you restrict the domain of a quadratic to only be real positive numbers, then it is injective.
Surjection
A function f: X → Y is a surjection (or an onto function) if for every y in Y there exists an X in X such that f(x)=y. That is to say that for every single element in the co-domain, there is at least one pre-image in x. So the range and co-domain need to be equal.
In essence this means that there needs to be an input for every single possible output in the co-domain of a function. So a function like f: ℝ → ℝ where f(x)=x for example, would be a surjective function, this is because for all real numbers in the co-domain, there is a corresponding input in the domain.
This changes however if you have something like f: ℤ → ℝ f(x)=x because now not all of the values in the co-domain have a corresponding pre-image in the domain. This is because Z fundamentally does not hold none-integer values:
Bijective Functions
A function is a bijection or a one-to-one correspondence if it considered to be both injective and surjective. So functions like f(x) = x or f(x) = x^3 on a real domain and co-domain end up being bijective because they are both injective and surjective. However if you limit their domain then they can become only one and not the other. Or even neither. Below are some other examples:





























