Language and Programming - Maple Help

Home : Support : Online Help : System : Information : Updates : Maple 18 : Language and Programming

 Language and Programming

Maple 18 includes the following enhancements to the Maple language and programming facilities:

 New URL Package A new URL package has been added to enable downloading and uploading data across networks. The URL package supports the http, https, and ftp protocols. This package extends the functionality previously available through the HTTP package.

New InertForm Package

The InertForm package gives you tools to prevent simplification and evaluation so that you can examine and work with exactly what was entered.

 Example

For details, see the InertForm in Maple 18 page.

 Compiler Run-time Library In Maple 18, the compiler run-time library was made thread-safe. The result is that an already-compiled procedure that is thread-safe can be run in multiple threads.   To do this, add option threadsafe to the procedure before compiling it, so that the compiler knows that the procedure is thread-safe. Note that adding this option does not make anything thread-safe in itself. It is the responsibility of the code author to ensure that their procedure is writen in a thread-safe way; this option simply informs the compiler that the authored code is thread-safe. For more information, see Procedure Options and Compiler:-Compile.

Random Tools

You can now generate random matrices and vectors using the RandomTools package by using the new flavors Matrix and Vector.  When generating matrices and vectors of floats and integers, these flavors are very fast.

In addition, the list flavor has been updated to generate lists of integers and floats much faster than in previous versions of Maple.

 >
 $\left[\begin{array}{rrrrr}{-}{4191464118}& {-}{155509187223}& {410458258399}& {-}{257603501613}& {84608543773}\\ {-}{468934731961}& {263129070744}& {433477878239}& {442400706112}& {108663867602}\\ {-}{47472936313}& {-}{155717390344}& {-}{27268728939}& {-}{467845592812}& {-}{49832113496}\\ {-}{254962893290}& {253906217843}& {-}{264792277647}& {259263763128}& {-}{492986343192}\\ {-}{122890179202}& {-}{172151899801}& {-}{247622562271}& {-}{95359783377}& {-}{290195444176}\end{array}\right]$ (1)
 >
 $\left[\begin{array}{cccc}{{x}}^{{10}}{+}{{x}}^{{9}}{+}{{x}}^{{8}}{+}{{x}}^{{6}}{+}{{x}}^{{4}}{+}{{x}}^{{3}}{+}{{x}}^{{2}}{+}{x}& {{x}}^{{10}}{+}{{x}}^{{9}}{+}{{x}}^{{8}}{+}{{x}}^{{3}}{+}{{x}}^{{2}}{+}{1}& {{x}}^{{8}}{+}{{x}}^{{7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091}\\ {0.366764328242085}\\ {0.169191454027561}\\ {0.155696424011674}\\ {0.419796233035937}\\ {0.539905541967967}\\ {0.511839347390428}\\ {0.896408024321359}\end{array}\right]$ (3)
 >
 $\left[\begin{array}{ccccccccc}{0.05206}& {0.3084}& {0.005301}& {0.0001805}& {0.0007295}& {0.02227}& {0.004261}& {0.7816}& {0.0005706}\end{array}\right]$ (4)
 >
 ${0.136}$ (5)

In previous versions of Maple, this takes more than 5 seconds to complete.

Improvements to the sort Command

Improvements to the sort command in Maple 18 offer faster sorting through automatic parallel execution and new key sorting, as well as guaranteed stable sorting.

 Parallel Sort In Maple 18, the sort command takes advantage of multiple cores. The following graph shows the timing difference between sorts of random permutations run in Maple 17 and Maple 18.  Parallel sorting is used for all of Maple's built-in sort algorithms, automatically taking advantage of all of the cores available on your computer. When a custom comparison function is given, sort will perform the operation in serial.

Key Sorting

Maple 18 adds support for key sorting.  Key sorting allows users to specify a function to map elements to keys. The input is then sorted by sorting the corresponding keys. For example, the following list of lists can be sorted by comparing the first element of each sublist.

 >
 $\left[\left[{1}\right]{,}\left[{2}\right]{,}\left[{3}\right]{,}\left[{4}\right]{,}\left[{5}\right]{,}\left[{6}\right]{,}\left[{7}\right]{,}\left[{8}\right]{,}\left[{9}\right]\right]$ (6)

In previous versions of Maple, this could be achieved by using a custom comparison function. Key sorting is faster because it only requires that the key function be called O(n) times, whereas a comparison function will be called O(n*log(n)) times. In addition, by performing the underlying sort operation with the default Maple comparison function, sorting can be performed in parallel.

The following example shows the timing difference (in seconds) between sorting with a comparison function and a key function.

 >
 >
 ${11.040}$ (7)
 >
 ${1.003}$ (8)

Stable Sorting

The Maple 18 sort function is now stable.  A stable sort function guarantees that equal elements are left in the same relative order in the output as in the input. This is most meaningful when sorting using a custom comparison function or a key sorting function. The following list is sorted according to the first element in the list. The lists whose first elements are equal end up in the same relative order (as shown by the second element) as specified in the input list.

 >
 $\left[\left[{1}{,}{1}\right]{,}\left[{1}{,}{2}\right]{,}\left[{1}{,}{3}\right]{,}\left[{2}{,}{1}\right]{,}\left[{2}{,}{2}\right]{,}\left[{2}{,}{3}\right]{,}\left[{3}{,}{1}\right]{,}\left[{3}{,}{2}\right]{,}\left[{3}{,}{3}\right]\right]$ (9)

Stable sorting is available for all built-in Maple sort algorithms and any custom comparison function that follows the guidelines outlined in the sort documentation. By default, the comparison function must be a non-strict (less than or equal to) comparison function. To use a strict (less than) comparison function, one must specify that using the strict option.

 >
 $\left[\left[{1}{,}{1}\right]{,}\left[{1}{,}{2}\right]{,}\left[{1}{,}{3}\right]{,}\left[{2}{,}{1}\right]{,}\left[{2}{,}{2}\right]{,}\left[{2}{,}{3}\right]{,}\left[{3}{,}{1}\right]{,}\left[{3}{,}{2}\right]{,}\left[{3}{,}{3}\right]\right]$ (10)

String Tools

There are three new commands in the StringTools package:

 • DifferencePositions: Convert a string to a list of characters.
 • IsDerangement: Test whether a string is a derangement of another string.
 • Snarf: Extract a prefix consisting of specified characters from a string.

 >
 ${1}{,}{2}{,}{3}{,}{4}$ (11)
 >
 ${\mathrm{true}}$ (12)
 >
 ${"ti"}$ (13)
 Improvements to the Code Editor Some usability improvements have been made to the Code Editor. For details, see Embedded Component Enhancements.
 Interface and Kernelopts A new interface variable, worksheetdir, returns the path to the directory of the active worksheet. For details, see interface. Two new kernel options, gctotaltime and gctotaltime[real], return the total amount of time spent performing garbage collection in CPU time and real time. For details, see kernelopts.

New Option "indexorder" for Entries and Indices

The entries and indices procedures accept a new option, indexorder.  The indexorder option causes the returned elements to be sorted by the values of the index. This is most useful for the entries command, where one wants the the entires of a table sorted based on the indices of the table. For example

 >
 ${t}{:=}{\mathrm{table}}\left(\left[{2.}{=}{"two"}{,}{6.}{=}{"six"}{,}{7.}{=}{"seven"}{,}{5.}{=}{"five"}{,}{3.}{=}{"three"}{,}{10.}{=}{"ten"}{,}{4.}{=}{"four"}{,}{1.}{=}{"one"}{,}{8.}{=}{"eight"}{,}{9.}{=}{"nine"}\right]\right)$ (14)
 > $\mathrm{entries}\left(t\right);$
 $\left[{"two"}\right]{,}\left[{"six"}\right]{,}\left[{"seven"}\right]{,}\left[{"five"}\right]{,}\left[{"three"}\right]{,}\left[{"ten"}\right]{,}\left[{"four"}\right]{,}\left[{"one"}\right]{,}\left[{"eight"}\right]{,}\left[{"nine"}\right]$ (15)
 > $\mathrm{entries}\left(t,\mathrm{indexorder}\right);$
 $\left[{"one"}\right]{,}\left[{"two"}\right]{,}\left[{"three"}\right]{,}\left[{"four"}\right]{,}\left[{"five"}\right]{,}\left[{"six"}\right]{,}\left[{"seven"}\right]{,}\left[{"eight"}\right]{,}\left[{"nine"}\right]{,}\left[{"ten"}\right]$ (16)