StringTools - Maple Programming Help

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

StringTools

 PrimitiveRoot
 compute the primitive root of a word

 Calling Sequence PrimitiveRoot( w )

Parameters

 w - Maple string

Description

 • The PrimitiveRoot(w) command computes the primitive root of the word (string) w. The primitive root of w is the string r of minimal length for which there is a positive integer e such that w = Repeat( r, e ). That is, r is the smallest root of which w is a power.
 • 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{PrimitiveRoot}\left(""\right)$
 ${""}$ (1)
 > $\mathrm{PrimitiveRoot}\left("abc"\right)$
 ${"abc"}$ (2)
 > $\mathrm{PrimitiveRoot}\left("abcabc"\right)$
 ${"abc"}$ (3)
 > $\mathrm{PrimitiveRoot}\left("abcabcab"\right)$
 ${"abcabcab"}$ (4)
 > $\mathrm{PrimitiveRoot}\left("ababab"\right)$
 ${"ab"}$ (5)
 > $\mathrm{PrimitiveRoot}\left("abababa"\right)$
 ${"abababa"}$ (6)
 > $L≔\mathrm{remove}\left(\mathrm{IsPrimitive},\mathrm{Generate}\left(4,"abc"\right)\right)$
 ${L}{≔}\left[{"aaaa"}{,}{"abab"}{,}{"acac"}{,}{"baba"}{,}{"bbbb"}{,}{"bcbc"}{,}{"caca"}{,}{"cbcb"}{,}{"cccc"}\right]$ (7)
 > $\mathrm{L2}≔\mathrm{map}\left(\mathrm{PrimitiveRoot},L\right)$
 ${\mathrm{L2}}{≔}\left[{"a"}{,}{"ab"}{,}{"ac"}{,}{"ba"}{,}{"b"}{,}{"bc"}{,}{"ca"}{,}{"cb"}{,}{"c"}\right]$ (8)
 > $\mathrm{andmap}\left(\mathrm{IsPrimitive},\mathrm{L2}\right)$
 ${\mathrm{true}}$ (9)