edit distance implementation to merge traces