StringTools - Maple Programming Help

# Online Help

###### All Products    Maple    MapleSim

Home : Support : Online Help : Programming : Names and Strings : StringTools Package : Combinatorics on Words : StringTools/Period

StringTools

 Period
 compute the period of a word

 Calling Sequence Period( w )

Parameters

 w - Maple string

Description

 • The Period(w) command computes the period of a string (word) w. A positive integer p is said to be a period of a string s if, for all integers i with $1<=i<=\mathrm{length}\left(s\right)-p$, one has ${s}_{i}={s}_{i+p}$. The least period of the string s is called the period of s.

Examples

 > $\mathrm{with}\left(\mathrm{StringTools}\right):$
 > $\mathrm{Period}\left("aaa"\right)$
 ${1}$ (1)
 > $\mathrm{Period}\left("abcde"\right)$
 ${5}$ (2)
 > $\mathrm{Period}\left("abcabc"\right)$
 ${3}$ (3)
 > $\mathrm{Period}\left("abcabcab"\right)$
 ${3}$ (4)
 > $\mathrm{seq}\left(\mathrm{Period}\left(\mathrm{Fibonacci}\left(n\right)\right),n=1..10\right)$
 ${1}{,}{2}{,}{2}{,}{3}{,}{5}{,}{8}{,}{13}{,}{21}{,}{34}{,}{55}$ (5)
 > $\mathrm{seq}\left(\mathrm{combinat}['\mathrm{fibonacci}']\left(n\right),n=1..10\right)$
 ${1}{,}{1}{,}{2}{,}{3}{,}{5}{,}{8}{,}{13}{,}{21}{,}{34}{,}{55}$ (6)
 > $\mathrm{seq}\left(\mathrm{Period}\left(\mathrm{ThueMorse}\left(n\right)\right),n=1..10\right)$
 ${1}{,}{2}{,}{3}{,}{3}{,}{3}{,}{5}{,}{6}{,}{6}{,}{6}{,}{6}$ (7)
 > $\mathrm{Periodic?}≔w→\mathrm{evalb}\left(\mathrm{Period}\left(w\right)\le \mathrm{floor}\left(\frac{\mathrm{length}\left(w\right)}{2}\right)\right)$
 ${\mathrm{Periodic?}}{:=}{w}{→}{\mathrm{evalb}}{}\left({\mathrm{StringTools}}{:-}{\mathrm{Period}}{}\left({w}\right){\le }{\mathrm{floor}}{}\left(\frac{{1}}{{2}}{}{\mathrm{length}}{}\left({w}\right)\right)\right)$ (8)
 > $\left(\mathrm{Period},\mathrm{length},\mathrm{Periodic?}\right)\left("ababababababababa"\right)$
 ${2}{,}{17}{,}{\mathrm{true}}$ (9)
 > $\left(\mathrm{Period},\mathrm{length},\mathrm{Periodic?}\right)\left("abcdeab"\right)$
 ${5}{,}{7}{,}{\mathrm{false}}$ (10)

 See Also

## Was this information helpful?

 Please add your Comment (Optional) E-mail Address (Optional) What is ? This question helps us to combat spam