StringTools
PrefixDistance
compute the prefix distance between two strings
SuffixDistance
compute the suffix distance between two strings
Calling Sequence
Parameters
Description
Examples
PrefixDistance( s, t )
SuffixDistance( s, t )
s
-
Maple string
t
The PrefixDistance(s,t) and SuffixDistance(s,t) commands return integer measures of the distance between the two strings s and t.
Let s and t be arbitrary strings. The prefix distance PrefixDistance( s, t ) is defined to be length⁡s+length⁡t−2⁢CommonPrefix⁡s,t, and the suffix distance SuffixDistance⁡s,t is defined, similarly, to be length⁡s+length⁡t−2⁢CommonSuffix⁡s,t. Both are metrics.
Other string metrics available in this package include StringTools[HammingDistance] and 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.
useStringToolsinPrefixDistance⁡Mathematics,Mathematischeend use
6
with⁡StringTools:
PrefixDistance⁡abc,abd
2
PrefixDistance⁡abc,abcd
1
PrefixDistance⁡Elisabeth,Elyse
10
PrefixDistance⁡Connor,Constance
9
SuffixDistance⁡foe,Defoe
SuffixDistance⁡North America,Central America
12
SuffixDistance⁡North America,South America
SuffixDistance⁡abba,abba
0
Being metrics, both PrefixDistance and SuffixDistance satisfy the triangle inequality.
s≔Random⁡10,binary
s≔0000101110
t≔Random⁡10,binary
t≔1101110100
u≔Random⁡10,binary
u≔0100010001
SuffixDistance⁡s,t
18
SuffixDistance⁡s,u+SuffixDistance⁡u,t
40
See Also
string
StringTools[CommonPrefix]
StringTools[CommonSuffix]
StringTools[HammingDistance]
StringTools[Levenshtein]
Download Help Document