StringTools - Maple Programming Help

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

StringTools

 IsMonotonic
 test whether a string is monotonic

 Calling Sequence IsMonotonic( s )

Parameters

 s - string

Description

 • The IsMonotonic(s) command returns the value true if s is monotonic, and the value false otherwise. A string is monotonic if the sequence of characters it comprises is non-increasing or non-decreasing, when the characters are identified with their ASCII code points.
 • Every string can be factored into a product (concatenation) of monotonic substrings by using StringTools[MonotonicFactors].
 • If s is the empty string, the command returns true.

Examples

 > $\mathrm{with}\left(\mathrm{StringTools}\right):$
 > $\mathrm{IsMonotonic}\left(""\right)$
 ${\mathrm{true}}$ (1)
 > $\mathrm{IsMonotonic}\left("aaa"\right)$
 ${\mathrm{true}}$ (2)
 > $\mathrm{IsMonotonic}\left("abc"\right)$
 ${\mathrm{true}}$ (3)
 > $\mathrm{IsMonotonic}\left("cba"\right)$
 ${\mathrm{true}}$ (4)
 > $\mathrm{IsMonotonic}\left("cab"\right)$
 ${\mathrm{false}}$ (5)
 > $\mathrm{IsMonotonic}\left("abcba"\right)$
 ${\mathrm{false}}$ (6)
 > $\mathrm{andmap}\left(\mathrm{IsMonotonic},\mathrm{MonotonicFactors}\left(\mathrm{Random}\left(1000,'\mathrm{lower}'\right)\right)\right)$
 ${\mathrm{true}}$ (7)