updates/Maple18/Language - Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : updates/Maple18/Language

Language and Programming

 

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

• 

New URL Package

• 

New InertForm Package

• 

Compiler Run-time Library

• 

Random Tools

• 

Improvements to the sort Command

• 

String Tools

• 

Improvements to the Code Editor

• 

Interface and Kernelopts

• 

indexorder option to entries and indices

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.

 

RandomTools:-Generate 'Matrix'integer,5,5 ;

41914641181555091872234104582583992576035016138460854377346893473196126312907074443347787823944240070611210866386760247472936313155717390344272687289394678455928124983211349625496289329025390621784326479227764725926376312849298634319212289017920217215189980124762256227195359783377290195444176

(1)

RandomTools:-Generate 'Matrix' polynom integer range=0..1, x, degree=10 , 4, 4  ;

x10+x9+x8+x6+x4+x3+x2+xx10+x9+x8+x3+x2+1x8+x7+x5+x4+x3+1x10+x9+x5+1x9+x8+x7+x6+x4+xx10+x7+x4+x2x10+x8+x7+x6+x4+x3+x2+1x10+x9+x8+x7+x5+x2+x+1x10+x8+x5+x+1x10+x7+x5+x4+x3+1x9+x7+x3+x+1x10+x7+x3+x2+xx10+x9+x7+x6+x5+x3+1x10+x9+x8+x7+x5+x4+x3x10+x8+x6+x4+xx7+x6+x5+x4

(2)

RandomTools:-Generate 'Vector'float, 10, datatype=float8  ;

0.1565543158008720.4685940737776020.8972767110160910.3667643282420850.1691914540275610.1556964240116740.4197962330359370.5399055419679670.5118393473904280.896408024321359

(3)

RandomTools:-Generate 'Vectorrow' floatdigits=4, integerrange=5..10  ;

0.052060.30840.0053010.00018050.00072950.022270.0042610.78160.0005706

(4)

timereal RandomTools:-Generate list integer, 106   ;

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.

 

sort  9, 4, 7, 2, 5, 8, 3, 6, 1 ,key=xx1 ;

1,2,3,4,5,6,7,8,9

(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.

 

L   seq i, i in combinat:-randperm 3105   :

timereal sort L, x,yx1  y1  ;

11.040

(7)

timereal sort L, key=xx1  ;

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.

 

sort1, 1, 2, 1, 3, 1, 1, 2, 2, 2, 3, 2, 1, 3, 2, 3, 3, 3, x, yx1  y1 ;

1,1,1,2,1,3,2,1,2,2,2,3,3,1,3,2,3,3

(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.

 

sort  1&comma;1&comma; 2&comma;1&comma; 3&comma;1&comma; 1&comma;2&comma; 2&comma;2&comma; 3&comma;2&comma; 1&comma;3&comma; 2&comma;3&comma; 3&comma;3 &comma;strict&equals;x&comma;yx1<y1 &semi;

1&comma;1&comma;1&comma;2&comma;1&comma;3&comma;2&comma;1&comma;2&comma;2&comma;2&comma;3&comma;3&comma;1&comma;3&comma;2&comma;3&comma;3

(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.

 

StringTools:-DifferencePositions edit&comma; tide 

1&comma;2&comma;3&comma;4

(11)

StringTools:-IsDerangement edit&comma; tide 

true

(12)

StringTools:-SnarftiDE&comma; &apos;lower&apos;&semi;

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  table 1.&equals;one&comma; 2. &equals; two&comma;3.&equals;three&comma; 4. &equals; four&comma; 5.&equals;five&comma; 6.&equals;six&comma; 7. &equals; seven&comma; 8.&equals;eight&comma; 9.&equals;nine&comma; 10.&equals;ten &semi;

t:=table2.&equals;two&comma;6.&equals;six&comma;7.&equals;seven&comma;5.&equals;five&comma;3.&equals;three&comma;10.&equals;ten&comma;4.&equals;four&comma;1.&equals;one&comma;8.&equals;eight&comma;9.&equals;nine

(14)

entriest&semi;

two&comma;six&comma;seven&comma;five&comma;three&comma;ten&comma;four&comma;one&comma;eight&comma;nine

(15)

entriest&comma;indexorder&semi;

one&comma;two&comma;three&comma;four&comma;five&comma;six&comma;seven&comma;eight&comma;nine&comma;ten

(16)

See Also

What's New in Maple18


Download Help Document

Was this information helpful?



Please add your Comment (Optional)
E-mail Address (Optional)
What is ? This question helps us to combat spam