...

/

Bijective Functions

Bijective Functions

Learn about bijective functions.

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 f1f_1 is both injective and surjective, it is a bijective function. The following function is another example of a bijective function:

The illustration given below shows the f2f_2 function in which we can observe that each domain element is connected to exactly one outgoing arrow, and each codomain element is connected to exactly one incoming arrow.

Press + to interact
Example of a bijective function from the set A to the set B
Example of a bijective function from the set A to the set B

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.

Press + to interact
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 element
if not any(pair[0] == element for pair in function):
# If the image of element does not exist, return False
return False
# Check if each element of the domain has only one image
preimages = set()
for pair in function:
if pair[0] in preimages:
return False
preimages.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 codomain
if pair[1] not in codomain:
# If the image of any element is not in the codomain, return False
return False
return True
def 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 False
image.add(pair[1])
return True
def 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 surjective
return True
def is_bijective(domain, codomain, function):
return is_injective(domain, codomain, function) and is_surjective(domain, codomain, function)
# Define the domain
domain = {1, 2, 3, 4, 5}
# Define the codomain
codomain = {6, 7, 8, 9, 10}
# Define the function
f = {(1, 7), (2, 6), (3, 9), (4, 8), (5, 10)}
#check if f is a valid function
if is_function(domain, codomain, f):
#check if f is a bijective function
if 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_function function that takes three arguments, i.e., domaincodomain, and function. It checks if the argument function is a valid function with the domain and the codomain. It returns False if function is not a valid function.

  • Lines 24–32: We define a is_injective function that takes three arguments, i.e., domain, codomain, and function. It checks if the passed function is injective by checking if every ...

Access this course and 1400+ top-rated courses and projects.