]>
Book Contents Previous Section 9.47 List Next Section 9.49 Magma Book Index

## 9.48 LyndonWord

Initialisations

a:Symbol :='a

a

Type: Symbol
b:Symbol :='b

b

Type: Symbol
c:Symbol :='c

c

Type: Symbol
lword:= LyndonWord(Symbol)

LyndonWordSymbol

Type: Domain
magma := Magma(Symbol)

MagmaSymbol

Type: Domain
word := OrderedFreeMonoid(Symbol)

OrderedFreeMonoidSymbol

Type: Domain

All Lyndon words with a, b, c to order 3

LyndonWordsList1([a,b,c],3)$lword

[[[a],[b],[c]],[[a b],[a c],[b c]],[[a 2 b],[a 2 c],[a b 2],[a b c],[a c b],[a c 2],[b 2 c],[b c 2]]]

Type: OneDimensionalArray List LyndonWord Symbol

All Lyndon words of with a, b, c to order 3 in flat list

LyndonWordsList([a,b,c],3)$lword

[[a],[b],[c],[a b],[a c],[b c],[a 2 b],[a 2 c],[a b 2],[a b c],[a c b],[a c 2],[b 2 c],[b c 2]]

Type: List LyndonWord Symbol

All Lyndon words of with a, b to order 5

lw := LyndonWordsList([a,b],5)$lword

[[a],[b],[a b],[a 2 b],[a b 2],[a 3 b],[a 2 b 2],[a b 3],[a 4 b],[a 3 b 2],[a 2 b a b],[a 2 b 3],[a b a b 2],[a b 4]]

Type: List LyndonWord Symbol
w1 : word := lw.4 :: word

a 2 b

Type: OrderedFreeMonoid Symbol
w2 : word := lw.5 :: word

a b 2

Type: OrderedFreeMonoid Symbol

Let's try factoring

factor(a::word)$lword

[[a]]

Type: List LyndonWord Symbol
factor(w1*w2)$lword

[[a 2 b a b 2]]

Type: List LyndonWord Symbol
factor(w2*w2)$lword

[[a b 2],[a b 2]]

Type: List LyndonWord Symbol
factor(w2*w1)$lword

[[a b 2],[a 2 b]]

Type: List LyndonWord Symbol

Checks and coercions

lyndon?(w1)$lword

true

Type: Boolean
lyndon?(w1*w2)$lword

true

Type: Boolean
lyndon?(w2*w1)$lword

false

Type: Boolean
lyndonIfCan(w1)$lword

[a 2 b]

Type: Union(LyndonWord Symbol,...)
lyndonIfCan(w2*w1)$lword

"failed"

Type: Union("failed",...)
lyndon(w1)$lword

[a 2 b]

Type: LyndonWord Symbol
lyndon(w1*w2)$lword

[a 2 b a b 2]

Type: LyndonWord Symbol
Book Contents Previous Section 9.47 List Next Section 9.49 Magma Book Index