StringTools
HammingDistance
compute the Hamming distance between two strings
Calling Sequence
Parameters
Description
Examples
HammingDistance( s, t )
s
-
Maple string
t
The HammingDistance(s,t) command returns an integer measure of the distance between the two strings s and t.
The Hamming distance between two strings s and t, of equal length, is the number of character positions where they differ. If strings s and t have respective lengths m and n where, without loss of generality, n<m, then the generalized Hamming distance between s and t is defined to be (m - n) + HammingDistance( s[ 1 .. n ], t ). The HammingDistance procedure computes this generalized metric.
For a different notion of the distance between two strings, see StringTools[Levenshtein].
All of the StringTools package commands treat strings as (null-terminated) sequences of 8-bit (ASCII) characters. Thus, there is no support for multibyte character encodings, such as unicode encodings.
useStringToolsinHammingDistance⁡Mathematics,Mathematischeend use
4
with⁡StringTools:
HammingDistance⁡abc,abd
1
HammingDistance⁡abc,abcd
HammingDistance⁡Elisabeth,Elyse
6
HammingDistance⁡Connor,Constance
Since it is a metric, the Hamming distance satisfies the triangle inequality.
s≔Random⁡1000,lower:
t≔Random⁡1000,lower:
u≔Random⁡1000,lower:
HammingDistance⁡s,t
955
HammingDistance⁡s,u+HammingDistance⁡u,t
1926
See Also
string
StringTools[Levenshtein]
Download Help Document