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 lengths+lengtht−2CommonPrefixs,t, and the suffix distance SuffixDistances,t is defined, similarly, to be lengths+lengtht−2CommonSuffixs,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.
useStringToolsinPrefixDistanceMathematics,Mathematischeend use
6
withStringTools:
PrefixDistanceabc,abd
2
PrefixDistanceabc,abcd
1
PrefixDistanceElisabeth,Elyse
10
PrefixDistanceConnor,Constance
9
SuffixDistancefoe,Defoe
SuffixDistanceNorth America,Central America
12
SuffixDistanceNorth America,South America
SuffixDistanceabba,abba
0
Being metrics, both PrefixDistance and SuffixDistance satisfy the triangle inequality.
s≔Random10,binary
s≔0000101110
t≔Random10,binary
t≔1101110100
u≔Random10,binary
u≔0100010001
SuffixDistances,t
18
SuffixDistances,u+SuffixDistanceu,t
40
See Also
string
StringTools[CommonPrefix]
StringTools[CommonSuffix]
StringTools[HammingDistance]
StringTools[Levenshtein]
Download Help Document