Programming Updates in Maple 2023
New inverse functions for Box objects
New Units prefixes
with( ArrayTools ):
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]] );
B := SortBy( A, 'column', 3 );
Custom sorting options and keywords are supported, as is in-place sorting:
SortBy( A, 'row', 2, 'descending', 'inplace' ):
'A' = A;
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> );
IsSubsequence( <1,5,3>, <1,2,3,4,5> );
IsSubsequence( <2,4,6>, <1,2,3,4,5> );
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 ] );
A := evalf( B[[2,3]] );
IsSubsequence( A, B );
IsSubsequence( A, B, 'match' = 'float' );
IsSubsequence( A, B, 'match' = 'float', 'digits' = 5, 'ulp' = 1 );
The matching indices can also be returned:
A := [ "a", "e", "i", "o", "u" ];
B := [ seq( "a" .. "z" ) ];
K := IsSubsequence( A, B, 'output' = 'indices' );
EqualEntries( A, B[K] );
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).
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.
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.
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.
A new grayscale color space is now supported called Gs. Colors are converted to grayscale by calculating their perceptual lightness.
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");
moduleColorTools:-Coloroptionobject;localcolorspace,coordinates,color_caption;end module=moduleColorTools:-Coloroptionobject;localcolorspace,coordinates,color_caption;end module
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");
and between color spaces
convert( ColorTools:-Color("Jab", "#9f1"), 'color', "HSL");
convert( [0.6, 1.0, 0.066666667], 'color', "RGB", "YUV");
convert( [0, 128, 0], 'color', "colorname");
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'='gradient', 'filter'=(c->ColorTools:-Color("Gs",c)));
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
P := [4,6,3,9,8,10,1,7,2,5]; # forward permutation
Y := X[P]; # permuted list
Q := InversePermutation(P); # inverse permutation
Y[Q]; # unpermuted list
Unpermute(Y,P); # unpermuted list
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 );
membertype( integer, Matrix([[1,2],[3,4]]) );
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 ) );
arcsech( RealBox( 0.23 ) );
arccot( ComplexBox( 4.3*I - 0.33 ) );
ComplexBox⁡module...end module,module...end module
For more information, see RealBox and ComplexBox.
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 1030, 1027, 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.
m__earth := Constant(M[Earth], units):
m__earth := convert(evalf(m__earth), units, ronnagrams);
m__sun := Constant(M[Sun], units):
m__sun := convert(evalf(m__sun), units, Qg);
The average (Newtonian) gravitational force between the Earth and the Sun is most compactly expressed in zettanewtons. (The prefix zetta-, meaning a factor of 1021, was introduced in 1991.)
G := evalf(Constant(G, units));
force__earth_sun := convert(G * m__sun * m__earth / Unit(AU^2), units, zettanewton);
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);
density__tea := ThermophysicalData:-Property("density", "water", T=95*Unit(Celsius), pressure=Unit(atm));
mass__tea := volume__tea * density__tea;
distance__moon := 384400*Unit(km);
force__tea_tea := convert(G * mass__tea^2 / distance__moon^2, units, qN);
We can express the Planck length in quectometers.
planck := Constant(l[P], units):
convert(evalf(planck), units, quectometer);
Download Help Document