New Language Features That Have Been Added to Maple V for Release 4
|
Maple Debugger:
|
|
•
|
The Maple debugger provides a full set of debugging facilities including watchpoints, breakpoints, and single-step, trace-back (immediately) after an error condition.
|
>
|
f:=proc(x) g(x+1) end: g:=proc(x) 1/x end: f(-1);
|
Error, (in g) division by zero
|
|
|
f called with arguments: -1
#(f,1): g(x+1)
| |
g called with arguments: 0
#(g,1): 1/x
| |
f called with arguments: -1
|
#(f,1): g(x+1)
|
g called with arguments: 0
|
#(g,1): 1/x
|
Error, (in g) division by zero
|
|
|
|
|
I/O library:
|
|
•
|
An extensive I/O library with a complete suite of functions including
|
•
|
A new function writedata() serves as a complement to readdata. The function readdata() can take a file descriptor.
|
|
|
setattribute/attributes:
|
|
•
|
The routine setattribute allows users to assign an attribute to an expression. Attributes can be queried using attributes.
|
>
|
setattribute(Rose, pink); attributes(Rose);
|
>
|
L:=setattribute( [ Rose, Candy], pink ); attributes(L);
|
|
|
Type Matching:
|
|
•
|
A new type matching facility, typematch, simplifies Maple coding.
|
>
|
typematch( x^3, c::(a::name ^ b::integer) );
|
>
|
printf(`a=%a, b=%a, c=%a \n`,a, b, c );
|
>
|
a := 'a': b := 'b': c := 'c':
|
|
A name as the third argument gets a replacement list (instead of doing the assignments).
|
>
|
typematch( x^3, c::(a::name ^ b::integer), 's'); s;
|
| (4) |
true
|
3
|
[a = x, b = 3, c = x ]
|
|
|
|
|
Special Parameter Type Declarations:
|
|
•
|
evaln: evaluate the argument to a name.
|
>
|
f:=proc(x::evaln) print(x) end: y:=3; f(y), f( y[y] );
|
•
|
uneval: do not evaluate the argument.
|
>
|
g:=proc(x::uneval) print(x) end: g(y), g(y[y]), g(diff(x^25,x));
|
| (6) |
|
Compare this behavior with the normal evaluation:
|
>
|
h:=proc(x) print(x) end: h(y), h(y[y]), h(diff(x^25,x));
|
>
|
type(x^4+y, quartic(x));
|
|
|
The algsubs Substitution Facility:
|
|
•
|
There is a new substitution facility algsubs which is more general than the present subs command.
|
>
|
algsubs( x+y=5, x+y+z );
|
|
|
C and Fortran:
|
|
•
|
Complete Fortran and C subroutines from Maple procedures. For C, the ansi form can be requested.
|
>
|
a :=proc(x) local y; y:=x+5; y:=sin(y)+3 end:
|
double a(x)
|
double x;
|
{
|
double y;
|
y = x+5;
|
y = sin(y)+3;
|
}
|
|
|
real function a(x)
|
real x
|
real y
|
y = x+5
|
y = sin(y)+3
|
return
|
end
|
|
|
|
|
Assertions:
|
|
•
|
The function ASSERT is used to guarantee pre- and post-conditions while a Maple procedure is executing.
|
|
|
Examples
|
|
>
|
|
Error, assertion failed, wrong addition
|
|
|
>
|
|
>
|
|
|
|
The add and mul Functions:
|
|
•
|
The add function is used to add up an explicit sequence of values. The mul function computes a product of an explicit sequence of values. Although one can use the for-loop statement to obtain the same effect, add/mul are generally more efficient than the for-loop versions because the for-loop versions construct many intermediate sums and products.
|
>
|
add( a[i]*x^i, i=0..5 );
|
| (15) |
2 3 4 5
|
a[0] + a[1] x + a[2] x + a[3] x + a[4] x + a[5] x
|
|
|
|
|
The map2 Function:
|
|
•
|
map2 is a map() function that expands on the second argument.
|
>
|
map2(op,1, [ x^3, y=z] );
|
|
|
The dismantle function:
|
|
•
|
The routine dismantle displays internal representation of data structures.
|
>
|
readlib(dismantle)( [ 1, x+3, y^x ] );
|
LIST(2)
EXPSEQ(4)
INTPOS(2): 1
SUM(5)
NAME(4): x
INTPOS(2): 1
INTPOS(2): 3
INTPOS(2): 1
POWER(3)
NAME(4): y
NAME(4): x
| |
LIST(2)
|
EXPSEQ(4)
|
INTPOS(2): 1
|
SUM(5)
|
NAME(4): x
|
INTPOS(2): 1
|
INTPOS(2): 3
|
INTPOS(2): 1
|
POWER(3)
|
NAME(4): y
|
NAME(4): x
|
|
|
|
|
Recording and Analysis of Run-time Information:
|
|
>
|
fib:=proc(n) option remember; if n<2 then n else fib(n-1)+fib(n-2) fi;end:
|
function depth calls time time% bytes bytes%
---------------------------------------------------------------------------
fib 5 9 0.000 0.00 6224 100.00
---------------------------------------------------------------------------
total: 5 9 0.000 0.00 6224 100.00
| |
function depth calls time time% bytes bytes%
|
---------------------------------------------------------------------------
|
fib 5 9 0.000 0.00 9648 100.00
|
---------------------------------------------------------------------------
|
total: 5 9 0.000 0.00 9648 100.00
|
|
|
|
|
Maplemint:
|
|
•
|
maplemint generates semantic information for a procedure and also checks for sections of code which can never be executed.
|
>
|
a:=proc()
local b; global c;
if (b=5) then
b:=6;
RETURN(true);
lprint(`test`);
fi;
end:
|
Procedure a()
These names were used as global names but were not declared: test
These global variables were declared, but never used: c
These local variables were used before they were assigned a value: b
There is unreachable code following a RETURN or return statement at
statement 4: lprint(test)
| |
This code is unreachable:
|
lprint(test)
|
These global variables were declared, but never used:
|
c
|
These local variables were used before they were assigned a value:
|
b
|
|
|
|
|
Miscellaneous Functions:
|
|
•
|
hasfun tests an expression for a specified function:
|
| (18) |
•
|
hasoption selects an option from a list or set of options:
|
>
|
Options := [title=sin(w*x), numpoints=99, style=POINT];
|
| (21) |
Options :=
|
[title = sin(w x), numpoints = 99, style = POINT]
|
|
|
>
|
hasoption( Options, style, 's', 'Options' );
|
| (23) |
POINT
|
[title = sin(w x), numpoints = 99]
|
|
|
•
|
applyop applies a function to specified operand(s) of an expression:
|
>
|
e := (z+1)*ln(z*(z^2-2));
|
2
|
e := (z + 1) ln(z (z - 2))
|
|
|
>
|
applyop(expand,[2,1],e);
|
•
|
depends checks for mathematical dependence:
|
>
|
depends(sin(x)+cos(z),{x,y});
|
>
|
depends(int(f(x),x=a..b),x);
|
|
The command remove does the opposite of select. It removes items from a list, set, sum, product, or function according to a boolean value.
|
>
|
select(isprime, integers);
|
| (29) |
>
|
remove(isprime, integers);
|
| (30) |
•
|
ispoly is a predicate function for testing and picking apart polynomials:
|
>
|
ispoly( 3*x^2-11*x+5, quadratic,x, 't0','t1','t2'); t0,t1,t2;
|
|
coeff(a,x,i); where a is a polynomial in x works without the need of using collect.
|
>
|
coeff( (1+x+x^2)^100000, x, 5 );
|
| (32) |
|
|
Remember Tables:
|
|
•
|
Remember tables of functions can be printed together with the functions:
|
>
|
interface(verboseproc=3):
|
>
|
fib:=proc(n::nonnegint) option remember;
if n=1 or n=0 then 1 else fib(n-1)+fib(n-2) fi end:
|
| (34) |
proc(n::nonnegint)
|
option remember;
|
if n = 1 or n = 0 then 1
|
else fib(n - 1) + fib(n - 2)
|
end if
|
end proc
|
# fib(0) = 1
|
# fib(1) = 1
|
# fib(2) = 2
|
# fib(3) = 3
|
# fib(4) = 5
|
# fib(5) = 8
|
|
|
|
|
Language changes:
|
|
•
|
:: (new) binding operator, which binds variables to the matched components in type tests, and in parameter declaration.
|
•
|
The <> operator is now user definable; <|> and <||> are now removed.
|
•
|
<> gets transformed upon entry to a call to the anglebracket() function.
|
>
|
anglebracket:=proc() f([ args ]) end: <x,y,z,t>;
|
•
|
Selection operation l[i..j] where l is a list (set) now returns a list (set).
|
| (36) |
•
|
Negative selectors can now be used. The -1th element is the last, the -2th the second last, and so on:
|
•
|
Extraction of operands from an expression (op): if the first argument to op is a list, the elements of the list refer to a sub-operand of the input at the increasing levels of nesting:
|
| (39) |
>
|
op([2,1],w) = op(1, op(2, w) );
|
| (42) |
| (43) |
>
|
subsop( [2,0]=h, [2,3]=w, 3=a, p );
|
| (44) |
|
|