Bijective Functions
Learn about bijective functions.
We'll cover the following...
Bijective functions
If a function is both injective and surjective, it is called a bijective function— also called a one-to-one correspondence or simply a correspondence. In a bijective function, every element of the domain maps to a unique element of the codomain, and every element in the codomain has a preimage. This means a bijective function pairs up all the domain and codomain elements.
Examples
Take the following sets:
Using these sets, we define the following function:
Because the function 
The illustration given below shows the 
Here are a few more examples of bijective functions:
Checking if a function is bijective using Python
Let’s explore the following code to check if a given function is a bijective function. Please feel free to make changes and experiment with the given code.
def is_function(domain, codomain, function):# Check that the image of every element in the domain is defined.for element in domain:# Check if there exists an image of the elementif not any(pair[0] == element for pair in function):# If the image of element does not exist, return Falsereturn False# Check if each element of the domain has only one imagepreimages = set()for pair in function:if pair[0] in preimages:return Falsepreimages.add(pair[0])# Check that the range is a subset of the codomain.for pair in function: # pair = (element, image)# Check if every element has an image in the codomainif pair[1] not in codomain:# If the image of any element is not in the codomain, return Falsereturn Falsereturn Truedef is_injective(domain, codomain, function):# Check if every domain element has a unique image.image = set()for pair in function:if pair[1] in image:# A codmain element is an image of more than one domain elements.return Falseimage.add(pair[1])return Truedef is_surjective(domain, codomain, function):# Check if every element of the codomain has a preimage.for element in codomain:if not any(pair[1] == element for pair in function):return False# If the function is surjectivereturn Truedef is_bijective(domain, codomain, function):return is_injective(domain, codomain, function) and is_surjective(domain, codomain, function)# Define the domaindomain = {1, 2, 3, 4, 5}# Define the codomaincodomain = {6, 7, 8, 9, 10}# Define the functionf = {(1, 7), (2, 6), (3, 9), (4, 8), (5, 10)}#check if f is a valid functionif is_function(domain, codomain, f):#check if f is a bijective functionif is_bijective(domain, codomain, f):print('The function is bijective.')else:print('The function is not bijective.')else:print('Use a valid function.')
Code explanation
- Lines 1–22: We define a - is_functionfunction that takes three arguments, i.e.,- domain,- codomain, and- function. It checks if the argument- functionis a valid function with the- domainand the- codomain. It returns- Falseif- functionis not a valid function.
- Lines 24–32: We define a - is_injectivefunction that takes three arguments, i.e.,- domain,- codomain, and- function. It checks if the passed- functionis injective by checking if every- domainelement has a unique image. It returns- Trueif the function is injective and returns- Falseotherwise.
- Lines 34–41: We define a - is_surjectivefunction that takes three arguments, i.e.,- domain,- codomain, and- function. It checks if the passed- functionis surjective or not by checking if every- codomainelement has a preimage. It returns- Trueif the function is surjective and returns- Falseotherwise.
- Lines 43–44: We define a - is_bijectivefunction that takes three arguments, i.e.,- domain,- codomain, and- function. It checks if the passed- functionis bijective.
- Lines 46–50: We define the sets - domain,- codomain, and- f.
- Lines 52–59: We check if - fis a valid function from the- domainto the- codomain, and if it is, we check if- fis a bijective function. We print messages according to each situation.
Types of functions
A function is always one of the four types listed below:
- Neither injective nor surjective 
- Only injective but not surjective 
- Only surjective and not injective 
- Both injective and surjective, which means bijective 
Let’s look at a few examples of functions showing each of these cases. These functions are defined using the following sets:
An example of all four types of functions is given in the following table.
| Type | Function | 
|---|---|
| Neither injective nor surjective |