Period - Maple Help

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.
 • 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

 > $\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}\left['\mathrm{fibonacci}'\right]\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 }⌊\frac{{\mathrm{length}}{}\left({w}\right)}{{2}}⌋\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)