Designed for mathematical computation, the Maple language combines the best principles from procedural, functional, and object-oriented programming. Maple 17 adds many useful features to your Maple programming toolkit. Maple 17 has added several changes to how you interact with variables including improving subscript handling, reclaiming the use of variable names like 'I', 'D', and 'Gamma', and adding support for thread-local variables.
Details and Examples
You can now reclaim variables such as 'D', 'I' or 'gamma' for use in your calculations.
By declaring 'D' local at the top-level, a new local variable has been created with the name 'D' and made the default in the current name-space in a way similar to that of using the short-name to access package exports after using the "with" command to load a package. The global version of this name, the differential operator, is still available by prefixing the name with colon-dash.
Any variable can be declared local, even ones that are not protected.
The global versions remain available via :-.
The imaginary unit, I, also obeys a local declaration even though it is a special alias governed by interface(imaginaryunit). In this case the name of the global version becomes _I instead of :-I.
The select, remove, and selectremove commands are ideal for searching for data. The default behavior of these commands is to return a result object of exactly the same size and dimensions as the one you passed in, with NULL's in place of removed items. Automatic flattening of NULLs makes the behavior different in lists compared to Arrays.
NULL is automatically removed from lists.
This is not the case for Arrays.
This paradigm was mirrored in selectremove.
Now, in Maple 17, you can use an option to force the removal of NULL from arrays and tables. The option, flatten, is noted in square brackets after the command name.
Multi-dimensional data is flattened into a one-dimensional array.
A new feature in Maple 17 is the output option for the sort command. It can be used by programmers to find out what reordering, or permutation, is applied to a list or Vector in order to sort it, rather than just the sorted result. This is often useful if there are multiple lists of corresponding elements that all need to be sorted according to the values of one of these lists.
For example, suppose we have corresponding lists of English and French words for numbers:
We would like all of these lists to be in numerical order. We can do this by sorting with the 'output' = 'permutation' option:
This tells us that the first element of the sorted list is the fourth element of the original list (because the first entry of is four); the second element of the sorted list is the first element of the original list, and so on. Thus, we can obtain the sorted lists as follows:
There is a slightly more efficient way of achieving this same result: In order to find the permutation , Maple already created the sorted version of . In above, we recreate that list as . We can do that in one step, using the option 'output' = ['permutation', 'sorted']:
The output option is applicable when sorting a list, a Vector, or a one-dimensional Array. It can be used together with any predefined or custom sort order.
In this example, we sort a Vector and its element-wise derivative by length:
Finally, in the following example, we take random points in the unit circle (using the rejection method). We then sort them by absolute value of the x-coordinate and color them in order.
In Maple 17, module local variables can be declared thread local, meaning that they store a different value for each thread that access the variable. This allows for complex algorithms that need to maintain state to be written in a thread safe manner.
A module that wants to maintain internal state generally will not work correctly when executed in parallel. Consider the following example: the Mapper module maintains an internal state using the variables func and data. The setMapper routine is used to set these variables. When ModuleApply is called, it maps func over the given data.
If you execute the adder and multer commands in parallel, you can get incorrect results. Executing the following statement multiple times will show different results, some of which will be incorrect.
Incorrect results are computed because the func and data state variables are shared between threads. Thus when one thread changes func's value, the other thread is also affected. In Maple 17, this can be fixed by declaring the state variables as thread_local . This means that each thread will maintain its own value for the state variables. Thus changing the value in one thread will not effect other threads.
Executing this version, using the thread local variables, will return the expected result.