# DamerauLevenshtein() vs Levenshtein() why the same distance?

**URL:** <https://discourse.julialang.org/t/dameraulevenshtein-vs-levenshtein-why-the-same-distance/46393>\
**Category:** General Usage\
**Created:** [September 10, 2020, 3:46pm UTC](https://discourse.julialang.org/t/dameraulevenshtein-vs-levenshtein-why-the-same-distance/46393 "2020-09-10T15:46:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![programista](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/programista/32/5372_2.png) [@programista](https://discourse.julialang.org/u/programista)\
**Post date:** [September 10, 2020, 3:46pm UTC](https://discourse.julialang.org/t/dameraulevenshtein-vs-levenshtein-why-the-same-distance/46393/1 "2020-09-10T15:46:50Z")

</div>

I expected a shorter distance for Damerau Levenshtein because there is an exchange of two letters. Why are there the same results?

```julia
julia> compare("martha", "martht", DamerauLevenshtein())
0.8333333333333334

julia> compare("martha", "martht", Levenshtein())
0.8333333333333334

```

Paul

---

<div class="post-metadata">

**Author:** ![mastrof](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mastrof/32/17443_2.png) [@mastrof](https://discourse.julialang.org/u/mastrof)\
**Post date:** [September 10, 2020, 6:08pm UTC](https://discourse.julialang.org/t/dameraulevenshtein-vs-levenshtein-why-the-same-distance/46393/2 "2020-09-10T18:08:37Z")

</div>

This does not really look like a Julia question.  
I guess you should at least specify what package are you calling these functions from and why you would expect a different result.

I suppose you refer to [StringDistances.jl](https://github.com/matthieugomez/StringDistances.jl)(but I might be wrong).  
By the way, I believe the result is correct: the strings “martha” and “martht” are only separated by a transformation of ‘a’ into ‘t’, hence you have 1-1/6=0.8[3] in both cases.  
Instead, where you see the difference between the two metrics is by comparing e.g. “martha” and “martah”: with the Damerau-Levenshtein metric you can swap adjacent letters and hence the two strings are separated by a single edit; with the Levenshtein metric you have to apply 2 separate edits ‘a’-\>‘h’ and ‘h’-\>‘a’ and hence you get a bigger distance.

```julia
julia> compare("martha", "martah", DamerauLevenshtein())
 0.8333333333333334

julia> compare("martha", "martah", Levenshtein())
 0.6666666666666667

```

Now Levenshtein returns a smaller value because, as stated in the docs, _The function_ `compare` _is defined as 1 minus the normalized distance between two strings_, hence it returns “closeness” between the two strings rather than distance.
