Programming - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Programming Updates in Maple 2023

ArrayTools

 > with( ArrayTools ):

SortBy

 • The new ArrayTools:-SortBy command allows one to easily sort a two-dimensional Array (like a Matrix) by a specific column or row. For example:
 > A := Matrix( [[5,1,3,8,1],[20,18,12,0,22],[15,3,11,15,3],[4,10,19,3,22]] );
 ${A}{≔}\left[\begin{array}{ccccc}{5}& {1}& {3}& {8}& {1}\\ {20}& {18}& {12}& {0}& {22}\\ {15}& {3}& {11}& {15}& {3}\\ {4}& {10}& {19}& {3}& {22}\end{array}\right]$ (1)
 > B := SortBy( A, 'column', 3 );
 ${B}{≔}\left[\begin{array}{ccccc}{5}& {1}& {3}& {8}& {1}\\ {15}& {3}& {11}& {15}& {3}\\ {20}& {18}& {12}& {0}& {22}\\ {4}& {10}& {19}& {3}& {22}\end{array}\right]$ (2)
 • Custom sorting options and keywords are supported, as is in-place sorting:
 > SortBy( A, 'row', 2, 'descending', 'inplace' ):
 > 'A' = A;
 ${A}{=}\left[\begin{array}{ccccc}{1}& {5}& {1}& {3}& {8}\\ {22}& {20}& {18}& {12}& {0}\\ {3}& {15}& {3}& {11}& {15}\\ {22}& {4}& {10}& {19}& {3}\end{array}\right]$ (3)

IsSubsequence

 • The new ArrayTools:-IsSubsequence command checks if a one-dimensional container is a subsequence of another. More precisely, A is a subsequence of B when there is a list of strictly increasing indices K such that A=B[K]. For example:
 > IsSubsequence( <1,3,5>, <1,2,3,4,5> );
 ${\mathrm{true}}$ (4)
 > IsSubsequence( <1,5,3>, <1,2,3,4,5> );
 ${\mathrm{false}}$ (5)
 > IsSubsequence( <2,4,6>, <1,2,3,4,5> );
 ${\mathrm{false}}$ (6)
 • The match option is used to customize how matches are determined. For example, to check a subsequence of floats, one can do the following:
 > B := Array( [ exp(1), Pi, gamma ] );
 ${B}{≔}\left[\begin{array}{ccc}{ⅇ}& {\mathrm{\pi }}& {\mathrm{\gamma }}\end{array}\right]$ (7)
 > A := evalf[5]( B[[2,3]] );
 ${A}{≔}\left[\begin{array}{cc}{3.1416}& {0.57722}\end{array}\right]$ (8)
 > IsSubsequence( A, B );
 ${\mathrm{false}}$ (9)
 > IsSubsequence( A, B, 'match' = 'float' );
 ${\mathrm{false}}$ (10)
 > IsSubsequence( A, B, 'match' = 'float', 'digits' = 5, 'ulp' = 1 );
 ${\mathrm{true}}$ (11)
 • The matching indices can also be returned:
 > A := [ "a", "e", "i", "o", "u" ];
 ${A}{≔}\left[{"a"}{,}{"e"}{,}{"i"}{,}{"o"}{,}{"u"}\right]$ (12)
 > B := [ seq( "a" .. "z" ) ];
 ${B}{≔}\left[{"a"}{,}{"b"}{,}{"c"}{,}{"d"}{,}{"e"}{,}{"f"}{,}{"g"}{,}{"h"}{,}{"i"}{,}{"j"}{,}{"k"}{,}{"l"}{,}{"m"}{,}{"n"}{,}{"o"}{,}{"p"}{,}{"q"}{,}{"r"}{,}{"s"}{,}{"t"}{,}{"u"}{,}{"v"}{,}{"w"}{,}{"x"}{,}{"y"}{,}{"z"}\right]$ (13)
 > K := IsSubsequence( A, B, 'output' = 'indices' );
 ${K}{≔}\left[{1}{,}{5}{,}{9}{,}{15}{,}{21}\right]$ (14)
 > EqualEntries( A, B[K] );
 ${\mathrm{true}}$ (15)

ColorTools

 • The ColorTools package now supports the CAM02 color spaces JCh (cylindrical) and Jab (rectangular). These color spaces are now the most modern perceptual color spaces in Maple.  JCh is useful for making perceptually uniform changes to lightness (J), chromaticity/saturation (C), and hue (h).
 > ColorTools:-Color("JCh", "#9f1");
 ${⟨}\colorbox[rgb]{0.6,1,0.0666666666666667}{JCh : 0.852 0.926 0.353}{⟩}$ (16)
 • Jab is useful as a space where Euclidean distance is roughly the same as perceptual distance. These different applications are the reason why the J channel is not the same in the two spaces. ColorTools:-Gradient now uses Jab for its best mode.
 > ColorTools:-Color("Jab", "#9f1");
 ${⟨}\colorbox[rgb]{0.6,1,0.0666666666666667}{Jab : 0.907 -0.245 0.324}{⟩}$ (17)
 • The YUV rectangular color space is now supported, using exactly the same implementation as in ImageTools:-RGBtoYUV and ImageTools:-YUVtoRGB.  The Y channel is lightness, while U and V are rectangular coordinates of chromacity.
 > ColorTools:-Color("YUV", "#9f1");
 ${⟨}\colorbox[rgb]{0.6,1,0.0666666666666667}{YUV : 0.774 -0.348 -0.153}{⟩}$ (18)
 • The HSL cylindrical color space is now supported using a simple conversion from the existing HSV color space. The H is always the same between the two but the S saturation channel differs.
 > ColorTools:-Color("HSL", "#9f1");
 ${⟨}\colorbox[rgb]{0.6,1,0.0666666666666667}{HSL : 0.238 1 0.533}{⟩}$ (19)
 > ColorTools:-Color("HSV", "#9f1");
 ${⟨}\colorbox[rgb]{0.6,1,0.0666666666666667}{HSV : 0.238 0.933 1}{⟩}$ (20)
 • A new grayscale color space is now supported called Gs. Colors are converted to grayscale by calculating their perceptual lightness.
 > ColorTools:-Color("Gs", "Red");
 ${⟨}\colorbox[rgb]{0.498039215686275,0.498039215686275,0.498039215686275}{Gs : 0.532}{⟩}$ (21)
 • Colors do not roundtrip convert due to loss of information about hue and chroma but all true shades of gray do.
 > ColorTools:-Color("RGB", ColorTools:-Color("Gs", "#7e7e7e")) = ColorTools:-Color("RGB", "#7e7e7e");
 ${⟨}\colorbox[rgb]{0.494117647058824,0.494117647058824,0.494117647058824}{RGB : 0.494 0.494 0.494}{⟩}{=}{⟨}\colorbox[rgb]{0.494117647058824,0.494117647058824,0.494117647058824}{RGB : 0.494 0.494 0.494}{⟩}$ (22)
 • A new conversion color has been added to convert so that convert/color can be used to convert easily between supported color formats.
 > convert( ColorTools:-Color("Jab", "#9f1"), 'color', "hex");
 ${"#99FF11"}$ (23)
 and between color spaces
 > convert( ColorTools:-Color("Jab", "#9f1"), 'color', "HSL");
 ${⟨}\colorbox[rgb]{0.6,1,0.0666666666666667}{HSL : 0.238 1 0.533}{⟩}$ (24)
 > convert( [0.6, 1.0, 0.066666667], 'color', "RGB", "YUV");
 $\left[{0.774000000038000}{,}{-0.348133333188000}{,}{-0.152666666700000}\right]$ (25)
 > convert( [0, 128, 0], 'color', "colorname");
 ${"Green"}$ (26)
 • The ColorTools:-Swatches command now has two new options mode and filter. The mode option applies one of several preset styles. The filter option applies a procedure to each color before displaying it.
 > ColorTools:-Swatches("Colorwheel", 'mode'='wheel','filter'=(c->ColorTools:-CVDSimulation(c,"tritanomaly")));
 > ColorTools:-Swatches("Colorwheel", 'mode'='gradient', 'filter'=(c->ColorTools:-Color("Gs",c)));

ListTools

 • Two new related commands, ListTools:-InversePermutation and ListTools:-Unpermute, determine, respectively, the inverse of a permutation given the forward permutation, and an unpermuted list given the permuted list and forward permutation. For example:
 > with( ListTools ):
 > X := [seq("a".."j")]; # unpermuted list
 ${X}{≔}\left[{"a"}{,}{"b"}{,}{"c"}{,}{"d"}{,}{"e"}{,}{"f"}{,}{"g"}{,}{"h"}{,}{"i"}{,}{"j"}\right]$ (27)
 > P := [4,6,3,9,8,10,1,7,2,5]; # forward permutation
 ${P}{≔}\left[{4}{,}{6}{,}{3}{,}{9}{,}{8}{,}{10}{,}{1}{,}{7}{,}{2}{,}{5}\right]$ (28)
 > Y := X[P]; # permuted list
 ${Y}{≔}\left[{"d"}{,}{"f"}{,}{"c"}{,}{"i"}{,}{"h"}{,}{"j"}{,}{"a"}{,}{"g"}{,}{"b"}{,}{"e"}\right]$ (29)
 > Q := InversePermutation(P); # inverse permutation
 ${Q}{≔}\left[{7}{,}{9}{,}{3}{,}{1}{,}{10}{,}{2}{,}{8}{,}{5}{,}{4}{,}{6}\right]$ (30)
 > Y[Q]; # unpermuted list
 $\left[{"a"}{,}{"b"}{,}{"c"}{,}{"d"}{,}{"e"}{,}{"f"}{,}{"g"}{,}{"h"}{,}{"i"}{,}{"j"}\right]$ (31)
 > Unpermute(Y,P); # unpermuted list
 $\left[{"a"}{,}{"b"}{,}{"c"}{,}{"d"}{,}{"e"}{,}{"f"}{,}{"g"}{,}{"h"}{,}{"i"}{,}{"j"}\right]$ (32)

membertype

 • The membertype(T,S) function determines if there is an operand within the expression S of type T.  In Maple 2023 membertype has been extended to support a wider variety of base expressions, S, to scan.  It now supports products, sums, and rtables. For example:
 > membertype( integer, 97*x+4 );
 ${\mathrm{true}}$ (33)
 > membertype( integer, Matrix([[1,2],[3,4]]) );
 ${\mathrm{true}}$ (34)

New inverse functions for Box objects

 • For Maple 2023, RealBox and ComplexBox objects now support the inverse circular functions arcsec, arccsc, and arccot, as well as the inverse hyperbolic functions arcsech, arccsch, and arccoth.
 > arcsec( RealBox( 4.7 ) );
 ${⟨}{\text{RealBox:}}{1.35639}{±}{2.7043ⅇ-10}{⟩}$ (35)
 > arcsech( RealBox( 0.23 ) );
 ${⟨}{\text{RealBox:}}{2.14933}{±}{4.1295ⅇ-10}{⟩}$ (36)
 > arccot( ComplexBox( 4.3*I - 0.33 ) );
 ${⟨}{\text{ComplexBox:}}{\text{[3.12285 +/- 4.38103e-10]}}{+}{\text{[-0.235372 +/- 2.71693e-10]}}{\cdot }{I}{⟩}$ (37)
 • For more information, see RealBox and ComplexBox.

New Units prefixes

 • In November, 2022, the 27th meeting of the General Conference on Weights and Measures approved the new prefixes quetta-, ronna-, ronto-, and quecto- for SI units, meaning factors of ${10}^{30}$, ${10}^{27}$, ${10}^{-30}$, and ${10}^{-27}$, respectively. These prefixes are fully integrated into Maple 2023. We can express the Earth's mass in ronnagrams and the Sun's in quettagrams.
 > restart;
 > with(ScientificConstants):
 > m__earth := Constant(M[Earth], units):
 > m__earth := convert(evalf(m__earth), units, ronnagrams);
 $\mathrm{m__earth}{≔}{5.972190000}{}⟦{\mathrm{Rg}}⟧$ (38)
 > m__sun := Constant(M[Sun], units):
 > m__sun := convert(evalf(m__sun), units, Qg);
 $\mathrm{m__sun}{≔}{1990.000000}{}⟦{\mathrm{Qg}}⟧$ (39)
 • The average (Newtonian) gravitational force between the Earth and the Sun is most compactly expressed in zettanewtons. (The prefix zetta-, meaning a factor of ${10}^{21}$, was introduced in 1991.)
 > G := evalf(Constant(G, units));
 ${G}{≔}{6.67408}{×}{{10}}^{{-11}}{}⟦\frac{{{m}}^{{3}}}{{\mathrm{kg}}{}{{s}}^{{2}}}⟧$ (40)
 > force__earth_sun := convert(G * m__sun * m__earth / Unit(AU^2), units, zettanewton);
 $\mathrm{force__earth_sun}{≔}{35.44273898}{}⟦{\mathrm{ZN}}⟧$ (41)
 • The typical (Newtonian) gravitational force between two cups of tea, one on Earth and one on the moon, can be computed as follows.
 > volume__tea := Unit(cup);
 $\mathrm{volume__tea}{≔}⟦{\mathrm{cup}}⟧$ (42)
 > density__tea := ThermophysicalData:-Property("density", "water", T=95*Unit(Celsius), pressure=Unit(atm));
 $\mathrm{density__tea}{≔}{961.8879166}{}⟦\frac{{\mathrm{kg}}}{{{m}}^{{3}}}⟧$ (43)
 > mass__tea := volume__tea * density__tea;
 $\mathrm{mass__tea}{≔}{961.8879166}{}⟦{\mathrm{cup}}⟧{}⟦\frac{{\mathrm{kg}}}{{{m}}^{{3}}}⟧$ (44)
 > distance__moon := 384400*Unit(km);
 $\mathrm{distance__moon}{≔}{384400}{}⟦{\mathrm{km}}⟧$ (45)
 > force__tea_tea := convert(G * mass__tea^2 / distance__moon^2, units, qN);
 $\mathrm{force__tea_tea}{≔}{23.39159750}{}⟦{\mathrm{qN}}⟧$ (46)
 • We can express the Planck length in quectometers.
 > planck := Constant(l[P], units):
 > convert(evalf(planck), units, quectometer);
 ${0.00001616228373}{}⟦{\mathrm{qm}}⟧$ (47)