StringTools - Maple Programming Help

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

StringTools

 IsPeriod
 test whether a number is a period of a word

 Calling Sequence IsPeriod( w, p )

Parameters

 w - Maple string p - positive integer; candidate period of w

Description

 • The IsPeriod(w,p) command tests whether the positive integer p is a period of the string 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}$. If p is a period of w, then the value true is returned; otherwise, false is returned.

Examples

 > $\mathrm{with}\left(\mathrm{StringTools}\right):$
 > $\mathrm{IsPeriod}\left("abc",1\right)$
 ${\mathrm{false}}$ (1)
 > $\mathrm{IsPeriod}\left("abc",2\right)$
 ${\mathrm{false}}$ (2)
 > $\mathrm{IsPeriod}\left("abc",3\right)$
 ${\mathrm{true}}$ (3)
 > $\mathrm{IsPeriod}\left("abababa",1\right)$
 ${\mathrm{false}}$ (4)
 > $\mathrm{IsPeriod}\left("abababa",2\right)$
 ${\mathrm{true}}$ (5)
 > $\mathrm{IsPeriod}\left("abababa",3\right)$
 ${\mathrm{false}}$ (6)
 > $\mathrm{IsPeriod}\left("abababa",4\right)$
 ${\mathrm{true}}$ (7)
 > $\mathrm{IsPeriod}\left("abababa",5\right)$
 ${\mathrm{false}}$ (8)
 > $\mathrm{IsPeriod}\left("abababa",6\right)$
 ${\mathrm{true}}$ (9)
 > $\mathrm{IsPeriod}\left("abababa",7\right)$
 ${\mathrm{true}}$ (10)
 > $\mathrm{select}\left(\mathrm{curry}\left(\mathrm{IsPeriod},"babbababbabbababbabbabab"\right),\left\{\mathrm{}\left(1..24\right)\right\}\right)$
 $\left\{{8}{,}{16}{,}{21}{,}{23}{,}{24}\right\}$ (11)