PrefixDistance - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Mozilla Firefox.

Online Help

All Products    Maple    MapleSim


StringTools

  

PrefixDistance

  

compute the prefix distance between two strings

  

SuffixDistance

  

compute the suffix distance between two strings

 

Calling Sequence

Parameters

Description

Examples

Calling Sequence

PrefixDistance( s, t )

SuffixDistance( s, t )

Parameters

s

-

Maple string

t

-

Maple string

Description

• 

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.

Examples

> 

useStringToolsinPrefixDistance⁡Mathematics,Mathematischeend use

6

(1)
> 

with⁡StringTools:

> 

PrefixDistance⁡abc,abd

2

(2)
> 

PrefixDistance⁡abc,abcd

1

(3)
> 

PrefixDistance⁡Elisabeth,Elyse

10

(4)
> 

PrefixDistance⁡Connor,Constance

9

(5)
> 

SuffixDistance⁡foe,Defoe

2

(6)
> 

SuffixDistance⁡North America,Central America

12

(7)
> 

SuffixDistance⁡North America,South America

6

(8)
> 

SuffixDistance⁡abba,abba

0

(9)

Being metrics, both PrefixDistance and SuffixDistance satisfy the triangle inequality.

> 

s≔Random⁡10,binary

s≔0000101110

(10)
> 

t≔Random⁡10,binary

t≔1101110100

(11)
> 

u≔Random⁡10,binary

u≔0100010001

(12)
> 

SuffixDistance⁡s,t

18

(13)
> 

SuffixDistance⁡s,u+SuffixDistance⁡u,t

40

(14)

See Also

string

StringTools

StringTools[CommonPrefix]

StringTools[CommonSuffix]

StringTools[HammingDistance]

StringTools[Levenshtein]