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_function
function that takes three arguments, i.e.,domain
,codomain
, andfunction
. It checks if the argumentfunction
is a valid function with thedomain
and thecodomain
. It returnsFalse
iffunction
is not a valid function.Lines 24–32: We define a
is_injective
function that takes three arguments, i.e.,domain
,codomain
, andfunction
. It checks if the passedfunction
is injective by checking if every ...