Programming Facilities Changes in Maple 8
•
|
Maple 8 includes the following changes to programming facilities.
|
|
System Changes
|
|
|
Java External Call
|
|
•
|
Using the same mechanism for calling C and Fortran programs, Maple can now call static functions in a JavaTM class. Declare the function and argument types in define_external the same way you would when calling C or Fortran procedures, plus add the keyword JAVA, CLASSPATH=, and CLASS= to fully specify your function. Maple returns a procedure that automatically converts data into Java types and calls the Java function making it seem like the Java function was a built-in Maple procedure.
|
|
|
Named Repository Support
|
|
•
|
Maple repositories can now be uniquely named, and many can be saved in the same directory. Access to repositories is still controlled by the variable, libname, which can now specify either a directory, or an individual .lib file, or a mixture of both. The built-in march command lets you control the order of repositories in a directory by setting a priority attribute on the repositories. Libraries can also be marked as ``read-only''.
|
|
|
Directory Access Routines
|
|
•
|
Two new procedures, isdir, and listdir, help users manage files in directories, by providing the ability to list the contents of a directory. When iterating through the contents of a directory, isdir() helps to distinguish between subdirectories and regular files.
|
|
The new kernel option pathsep, helps write code that makes use of explicit path names in a platform independent way. The kernel option datadir provides a standard location for system and user data.
|
|
|
Debugging Modules
|
|
•
|
kernelopts(opaquemodules=false) makes it easier to debug code that uses modules. The effect of this command is to make local members of a module accessible outside the module. Normally only exported module members are accessible outside the module in order to provide encapsulation and data hiding. During code development and debugging however, it is often convenient to be able to inspect local members as well.
|
|
|
New Include Files
|
|
•
|
The new Maple include file userinfo.mi is provided in this release. It defines the macros `UI_INFO', `UI_TRACE' and `UI_DEBUG'. These macro names define the standard information levels used in the library for userinfo messages.
|
|
|
|
Higher Order Procedures
|
|
|
andmap and ormap
|
|
•
|
Two new built-in procedures andmap and ormap have been implemented. They allow you to determine, respectively, whether a predicate holds for each, or for some member or operand of an expression.
|
>
|
andmap( isprime, { seq( i, i = 2 .. 19 ) } );
|
| (1) |
>
|
andmap( type, { seq( i, i = 2 .. 19 ) }, 'integer' );
|
| (2) |
>
|
ormap( isprime, { seq( i, i = 2 .. 19 ) } );
|
| (3) |
>
|
ormap( type, { seq( 2*i, i = 2 .. 19 ) }, 'odd' );
|
| (4) |
|
|
member
|
|
|
The member procedure now accepts functions as a second argument as well as sets, lists, and modules.
|
>
|
member(3, F(2, 3), 'p');
|
| (5) |
| (6) |
|
|
membertype
|
|
•
|
The new membertype function behaves in a manner similar to the member function, except that the first argument is a type and it checks whether or not an object of the given type exists in the second argument. If a match is found and a third argument is given, that argument must be a name, and the name is assigned the position of the first occurrence of an object of the given type in the second argument.
|
>
|
membertype(integer, F(a, b, 1/2, 3), 'p');
|
| (7) |
| (8) |
>
|
membertype(fraction, [a, b, 1/2, 3], 'p');
|
| (9) |
| (10) |
>
|
membertype(string, {a, b, 1/2, 3}, 'p');
|
| (11) |
|
|
maptype
|
|
| (12) |
>
|
maptype( `+`, f, b*c );
|
| (13) |
| (14) |
>
|
maptype( `+`, f, a + b*c );
|
| (15) |
|
|
|
Verifications
|
|
•
|
The verification plot has been added for comparing 2-D plot data structures. By default, it is extremely strict, but options may be given to allow variations.
|
|
The verifications verify,function_shells and verify,function_bounds provide you with methods of comparing two plot data structures assumed to have come from the plots of functions. The first checks if each plot falls within an epsilon shell of the other, and the second checks that the union of the points of the plots have no more and no fewer extrema or constant regions than the individual plots.
|
>
|
P := plot(sin(x), x=0..10):
|
>
|
Q := plot(sin(x), x=0..10, numpoints=100):
|
>
|
verify(P, Q, 'plot(curves=function_shell(0.1))');
|
| (16) |
|
|
Changes to the Type System
|
|
|
`TypeTools`
|
|
•
|
Maple's type system is now ``module-aware''. The old method of introducing new types by assigning a type definition to a name of the form `type/foo` (which defines the type `foo') is deprecated in favor of the new method that uses the new TypeTools package. See TypeTools and updates/Maple8/packages for more information about the TypeTools package.
|
|
To define a new type `foo' in Maple, use the procedure TypeTools:-AddType. It takes the name of the type as its first argument, and a type definition as the second argument. The type definition may be a structured type or a procedure that implements a predicate (returning either true or false).
|
|
The name of a type need not be global.
|
| (17) |
>
|
AddType( 'oddprime', 'And( odd, prime )' );
|
| (18) |
| (19) |
| (20) |
>
|
m := module()
export oddprime, evenprime;
local deftypes;
option package, load = deftypes;
deftypes := proc()
use TypeTools in
AddType( evenprime, 2 );
AddType( oddprime, proc( expr )
print("local oddprime");
expr <> 2 and type( expr, 'prime' )
end )
end use
end proc;
deftypes();
end module;
|
| (21) |
| (22) |
| (23) |
| (24) |
| (25) |
>
|
type( 3, ':-oddprime' );
|
| (26) |
| (27) |
>
|
andmap( type, [ 2, 3, 5, 7 ], 'oddprime' );
|
| (28) |
>
|
ormap( type, [ 2, 3, 5, 7 ], 'evenprime' );
|
| (29) |
>
|
andmap( type, [ 3, 5, 7 ], 'oddprime' );
|
| (30) |
|
As the examples above show, it is possible to shadow a global type name with a local type name using the new mechanism.
|
|
The older method of defining new types by means of symbol concatenation is still supported in this release.
|
|
|
Type `assignable`
|
|
•
|
A new type which determines whether or not the object can be assigned to using either the assignment operator or the assign function.
|
>
|
type(f(x), 'assignable');
|
| (31) |
>
|
type(f[x], 'assignable');
|
| (32) |
>
|
type(f[x], 'assignable');
|
| (33) |
>
|
type((f+g)[3], 'assignable');
|
| (34) |
|
|
|
New and Improved Conversions
|
|
|
float
|
|
•
|
The conversion convert,float now accepts an option that specifies the setting of digits at which the conversion is to take place.
|
| (35) |
>
|
convert(Pi, 'float', 3);
|
| (36) |
|
|
compose
|
|
•
|
The new conversion convert,compose composes any number of conversions on the expression, applying them in order.
|
>
|
convert(sin(1), 'compose', 'list', 'float'(3));
|
| (37) |
>
|
convert([1, 2, exp(2)], 'compose', 'list', 'float'(4));
|
| (38) |
|
|
iupac
|
|
•
|
The new conversion convert/iupac converts from and to the atomic number of a chemical element of the Periodic Table, and its temporary IUPAC name or symbol.
|
| (39) |
>
|
convert(114, iupac, symbol);
|
| (40) |
|
|
Elementary and Special Functions
|
|
•
|
A major overhaul of the network of conversions among the elementary and basic special functions has been undertaken for this release. See updates,Maple8,symbolic for more information.
|
|
|
|
Packages with Programming Enhancements
|
|
|
ListTools
|
|
•
|
The routine ListTools,Enumerate converts the operands of a list into a list of pairs of the form , one for each expression in the input list. The first entry pos of each pair is the position of expr in the list, while the second entry is the expression expr itself.
|
>
|
L := [a, b, c, d, e, f]:
|
>
|
ListTools[Enumerate](L);
|
| (41) |
>
|
ListTools[Enumerate](L, 0);
|
| (42) |
|
|
Subpackage for linear algebra mod m
|
|
|
|
|