# The Duality of Similarity and Metric Spaces
## 5 Duality of Similarity and Metric Space  
The relationship between distance and similarity is not obvious, as distance derives from spatial considerations and similarity relations derive from considering common and non-common features [1]. In many cases, distance is used to measure similarity, although this is far from intuitive and it is often a non-trivial task to find such a dual notion. Let us present a transformation of distance into similarity. **Theorem 5** (Duality of Distance and Similarity [13]). : _Generally, if a function \(f\colon\mathbb{R}\to[a,b]\subseteq\mathbb{R}\) is a monotonously decreasing convex function such that \(b=f(0)>0\) and \(\lim_{n\to\infty}f(n)=a\geq 0\), then_  
\[s(x,y)=f(d(x,y)). \tag{5}\]  
Proof. : We refer further to the related proof of Corollary 4. The range \([a,b]\) does not have to be a closed set. We might just denote \(a=\inf\{s(x,y)\}\) and \(b=\sup\{s(x,y)\}\). The condition \(a\geq 0\) is introduced in order to preserve the symmetry with the non-negativity of the values of the distance metric \(d(x,y)\). Once we allow a convex distortion of a metric space into a similarity space, this is not necessarily an isomorphic (isometric) transformation, and so the distances between points do not have to be preserved. Most importantly, the relative 'distances' (in the meaning of the inverse of partial order) between the points are preserved in accordance with geometric terminology, for instance \(d(x,z)\leq d(x,y)\implies s(x,z)\geq s(x,y)\) for any subsets \(x,y,z\). **Theorem 6** (Triangle Inequality of Similarity). : _Any decreasing monotonic convex transformation \(f\) of the triangular inequality of the metric \(d\) forms a triangular inequality of similarity \(s\):_  
\[d(x,z)\leq d(x,y)+d(y,z)\stackrel{{ f}}{{\longrightarrow}}s(x,z) +s(y,y)\geq s(x,y)+s(y,z), \tag{6}\]  
Proof. : Appendix A.5. Hence the condition of monotonously decreasing function preserves the triangle inequality. Because we measure similarities between objects, and not the distance, it is quite arguable that such a distortion would be more suitable. Moreover, many similarity metrics are not related to distance at all, but, conversely, distance is derived in many cases from similarity, for example, the passage from Jaccard similarity to the Jaccard distance [14]. The measure \(\mu\) (see Appendix A.6) of the symmetric difference of two sets can be considered as a distance between sets, well known as the _distance of Frechet-Nikodym-Aronszajn_. This distance is a particular case of the distance in the space of Lebesgue integrable functions. In fact, the distance between sets may be treated as the distance between the characteristic functions \(\chi_{x}\) and \(\chi_{y}\). These characteristic functions are defined on a set \(\mathbf{X}\) and indicate membership of an element in the subset \(x\), respectively \(y\). In classical set theory, its value is 1 for all elements of \(x\) and 0 for all elements of \(\mathbf{X}\) not in \(x\). Employing fuzzy set theory, we can give an uncertainty to the membership in the range of real values \(\chi\in[0,1]\). **Theorem 7** (Distance between Two Objects). : _Let \(x,y\) be subsets of set \(\mathbf{X}\). The symmetric difference between two objects is a distance metric._  
\[d(x,y)=\mu(x\triangle y)=\int|\chi_{x}-\chi_{y}|d\mu, \tag{7}\]  
_where \(x\triangle y=(x\cup y)\setminus(x\cap y)\) is the symmetric difference._  
Proof. : Appendix A.7. For better illustration, let us suppose two Lebesgue measurable sets \(A,B\). Let us imagine that these sets are described by non-negative real-valued functions \(f,g\) in Cartesian system \(\mathbb{R}^{1}\) or \(\mathbb{R}^{2}\) (\(A\) corresponds to \(f\) and \(B\) corresponds to \(g\)) [15]. The shaded gray area at the top of Figure 1 essentially shows the distance between objects. Then, we can calculate the area between functions \(f\) and \(g\) that corresponds area between sets \(A\) and \(B\).