IsMonotonic - Maple Help

ArrayTools

 IsMonotonic
 determine if a 1-D list or rtable is decreasing, increasing, non-decreasing, or non-increasing

 Calling Sequence IsMonotonic( data ) IsMonotonic( data, section )

Parameters

 data - 1-D list or rtable of data of type realcons section - (optional) range of the form a..b, a.., ..b, or .., where a and b are integers. The default is .., which corresponds to the entire container.

Options

 • direction: Either increasing or decreasing. The default is increasing.
 • strict: Either true or false. The default is true.

Description

 • The IsMonotonic command determines if a 1-D list or rtable, or a section of it, is monotonic (increasing, non-decreasing, decreasing, or non-increasing).
 • If direction=increasing and strict=true, then the result is true if data[i+1]>data[i] for all valid indices i, and false otherwise.
 • If direction=increasing and strict=false, then the result is true if data[i+1]>=data[i] for all valid indices i, and false otherwise.
 • If direction=decreasing and strict=true, then the result is true if data[i+1]
 • If direction=decreasing and strict=false, then the result is true if data[i+1]<=data[i] for all valid indices i, and false otherwise.
 • If data has fewer than two elements, or the section contains fewer than two elements, the result is vacuously true.
 • If data is not an Array with lower index different than 1, you can use valid negative indices in section for counting backward. For example, if data is a Vector with 15 elements, then 5..-2 is a valid range for section (equivalent to 5..14), with -2 indicating the second element from the end. However, if data is an Array with lower index different than 1, you can only use valid literal indices.
 • Suppose the working precision of the session is larger than that of hardware floats (i.e. Digits>evalhf(Digits)), or use of hardware floats has been disabled (i.e. UseHardwareFloats=false). Here, IsMonotonic will use external code to determine monotonicity.

Examples

 > $\mathrm{with}\left(\mathrm{ArrayTools}\right):$

Example 1

 • Strictly increasing list:
 > $A≔\left[5,10,15,20\right]$
 ${A}{≔}\left[{5}{,}{10}{,}{15}{,}{20}\right]$ (1)
 > $\mathrm{dataplot}\left(A,\mathrm{view}=\left[0..5,0..20\right],\mathrm{color}=\mathrm{blue}\right)$
 > $\mathrm{IsMonotonic}\left(A,\mathrm{direction}=\mathrm{increasing},\mathrm{strict}=\mathrm{true}\right)$
 ${\mathrm{true}}$ (2)
 > $\mathrm{IsMonotonic}\left(A,\mathrm{direction}=\mathrm{decreasing},\mathrm{strict}=\mathrm{true}\right)$
 ${\mathrm{false}}$ (3)

Example 2

 • Increasing but not strictly increasing:
 > $B≔\left[5,10,10,20\right]$
 ${B}{≔}\left[{5}{,}{10}{,}{10}{,}{20}\right]$ (4)
 > $\mathrm{dataplot}\left(B,\mathrm{view}=\left[0..5,0..20\right],\mathrm{color}=\mathrm{blue}\right)$
 > $\mathrm{IsMonotonic}\left(B,\mathrm{direction}=\mathrm{increasing},\mathrm{strict}=\mathrm{true}\right)$
 ${\mathrm{false}}$ (5)
 > $\mathrm{IsMonotonic}\left(B,\mathrm{direction}=\mathrm{increasing},\mathrm{strict}=\mathrm{false}\right)$
 ${\mathrm{true}}$ (6)

Example 3

 • Not monotonic on the whole, but monotonic on subsections:
 > $C≔\mathrm{Array}\left(\left[2,3,4,5,4,3,2,3,4,5\right]\right)$
 ${C}{≔}\left[\begin{array}{cccccccccc}{2}& {3}& {4}& {5}& {4}& {3}& {2}& {3}& {4}& {5}\end{array}\right]$ (7)
 > $\mathrm{dataplot}\left(C,\mathrm{view}=\left[0..10,0..5\right],\mathrm{color}=\mathrm{blue}\right)$
 > $\mathrm{IsMonotonic}\left(C,\mathrm{direction}=\mathrm{increasing},\mathrm{strict}=\mathrm{false}\right)$
 ${\mathrm{false}}$ (8)
 > $\mathrm{IsMonotonic}\left(C,..4,\mathrm{direction}=\mathrm{increasing},\mathrm{strict}=\mathrm{true}\right)$
 ${\mathrm{true}}$ (9)
 > $\mathrm{IsMonotonic}\left(C,4..7,\mathrm{direction}=\mathrm{decreasing},\mathrm{strict}=\mathrm{true}\right)$
 ${\mathrm{true}}$ (10)
 > $\mathrm{IsMonotonic}\left(C,7..-1,\mathrm{direction}=\mathrm{increasing},\mathrm{strict}=\mathrm{true}\right)$
 ${\mathrm{true}}$ (11)

Example 4

 • Data can include infinity:
 > $L≔\left[-\mathrm{\infty },0,\mathrm{\infty }\right]$
 ${L}{≔}\left[{-}{\mathrm{\infty }}{,}{0}{,}{\mathrm{\infty }}\right]$ (12)
 > $\mathrm{IsMonotonic}\left(L,\mathrm{direction}=\mathrm{increasing}\right)$
 ${\mathrm{true}}$ (13)
 > $\mathrm{IsMonotonic}\left(L,\mathrm{direction}=\mathrm{decreasing}\right)$
 ${\mathrm{false}}$ (14)

Example 5

 • Consider the following long Array:
 > $\mathrm{data}≔\mathrm{Array}\left(1..{10}^{4},i↦i,\mathrm{datatype}=\mathrm{float}\left[8\right]\right):$
 • The Array is strictly increasing, and confirmation using the IsMonotonic command requires checking the elements all the way to the end:
 > $\mathrm{CodeTools}:-\mathrm{Usage}\left(\mathrm{IsMonotonic}\left(\mathrm{data}\right)\right)$
 memory used=8.11KiB, alloc change=0 bytes, cpu time=0ns, real time=0ns, gc time=0ns
 ${\mathrm{true}}$ (15)

Compatibility

 • Starting with Maple 2023, external C code is used for the auxiliary procedures that were formerly implemented in Maple and could be compiled by passing the compiled option. The compiled option is now deprecated, but it is still accepted for backwards compatibility.
 • The ArrayTools[IsMonotonic] command was introduced in Maple 2021.