text: """ This module provides functions to compute distances between orders.
  """
  
  import numpy as np
  
  def distanceMatrix(instance, distanceFunction):
  	""" Returns a matrix of the pairwise distance between all orders of the instance.
  
  		:param instance: The instance to take the orders from.
  		:type instance: preflibtools.instance.preflibinstance.PreflibInstance
  		:param distanceFunction: The distance function to use. It should take two orders as input.
  		:type distanceFunction: function
  
  		:return: A Numpy array of the pairwise distances, coordinates being the index of the orders in the order
  			list of the instance. 
  		:rtype: numpy array 
  	""" 
  	profile = instance.fullProfile()
  	nbVoters = len(profile)
  	res = np.zeros((nbVoters, nbVoters))
  	for i in range(nbVoters):
  		for j in range(i + 1, nbVoters):
  			res[(i, j)] = distanceFunction(profile[i], profile[j])
  			res[(j, i)] = distanceFunction(profile[j], profile[i])
  	return res
  
  def kendallTauDistance(order1, order2):
  	""" Returns the Kendall's tau distance between two orders.
  
  		:param order1: The first order.
  		:type order1: tuple
  		:param order2: The second order.
  		:type order2: tuple
  
  		:return: The Kendall's tau distance between the two orders.
  		:rtype: int
  	"""
  	if len(order1) != len(order2):
  		raise ValueError("Rankings must have the same length to compute their Kendall's tau distance")
  	res = 0
  	norm = 0
  	for j1 in range(len(order1)):
  		for j2 in range(j1 + 1, len(order1)):
  			if (order2.index(order1[j1]) > order2.index(order1[j2])):
  				res += 1
  			norm += 1
  	return res / norm
  
  def spearmanFootruleDistance(order1, order2):
  	""" Returns the Spearman's footrule distance between two orders.
  
  		:param order1: The first order.
  		:type order1: tuple
  		:param order2: The second order.
  		:type order2: tuple
  
  		:return: The Spearman's footrule distance between the two orders.
  		:rtype: float
  	"""
  	if len(order1) != len(order2):
  		raise ValueError("Rankings must have the same length to compute their Spearman's footrule distance")
  	res = 0
  	for j in range(len(order1)):
  		res += abs(j - order2.index(order1[j]))
  	return res / np.floor(len(order1)**2 / 2)
  
  def sertelDistance(order1, order2):
  	""" Returns the Sertel's distance between two orders.
  
  		:param order1: The first order.
  		:type order1: tuple
  		:param order2: The second order.
  		:type order2: tuple
  
  		:return: The Sertel's distance between the two orders.
  		:rtype: float
  	"""
  	if len(order1) != len(order2):
  		raise ValueError("Rankings must have the same length to compute their Sertel's distance")
  	for j in range(len(order1)):
  		if order1[j] != order2[j]:
  			break
  	return (len(order1) - 1 - j) / (len(order1) - 1)