New Language Features That Have Been Added to Maple V for Release 4
Maple Debugger:
I/O library:
setattribute/attributes:
Type Matching:
Special Parameter Type Declarations:
The algsubs Substitution Facility:
C and Fortran:
Assertions:
Examples
The add and mul Functions:
The map2 Function:
The dismantle function:
Recording and Analysis of Run-time Information:
Maplemint:
Miscellaneous Functions:
Remember Tables:
Language changes:
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) numeric exception: division by zero
Error, (in g) division by zero
tracelast;
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
An extensive I/O library with a complete suite of functions including
open
close
read
fclose
feof
fflush
filepos
fopen
fprintf
fremove
fscanf
iostatus
readbytes
readline
sprintf
sscanf
writebytes
writeline
A new function writedata() serves as a complement to readdata. The function readdata() can take a file descriptor.
The routine setattribute allows users to assign an attribute to an expression. Attributes can be queried using attributes.
setattribute(Rose, pink); attributes(Rose);
Rose
pink
L:=setattribute( [ Rose, Candy], pink ); attributes(L);
L≔Rose,Candy
L := [Rose, Candy]
A new type matching facility, typematch, simplifies Maple coding.
typematch( x^3, c::(a::name ^ b::integer) );
true
printf(`a=%a, b=%a, c=%a \n`,a, b, c );
a=x, b=3, c=x^3
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;
a=x,b=3,c=x3
3
[a = x, b = 3, c = x ]
evaln: evaluate the argument to a name.
f:=proc(x::evaln) print(x) end: y:=3; f(y), f( y[y] );
y≔3
y
y3
y := 3
y[3]
uneval: do not evaluate the argument.
g:=proc(x::uneval) print(x) end: g(y), g(y[y]), g(diff(x^25,x));
yy
ⅆⅆxx25
y[y]
d 25
-- x
dx
Compare this behavior with the normal evaluation:
h:=proc(x) print(x) end: h(y), h(y[y]), h(diff(x^25,x));
33
25⁢x24
3[3]
24
25 x
y:='y':
New types:
type[linear], type[quadratic], type[cubic], type[quartic].
type(x^4+y, quartic(x));
There is a new substitution facility algsubs which is more general than the present subs command.
algsubs( x+y=5, x+y+z );
5+z
Complete Fortran and C subroutines from Maple procedures. For C, the ansi form can be requested.
readlib(C):
Error, could not find `C` in the library
a :=proc(x) local y; y:=x+5; y:=sin(y)+3 end:
C(a);
C⁡a
double a(x)
double x;
{
double y;
y = x+5;
y = sin(y)+3;
}
fortran(a);
fortran⁡a
real function a(x)
real x
real y
y = x+5
y = sin(y)+3
return
end
See fortran[procedure] and C[procedure].
The function ASSERT is used to guarantee pre- and post-conditions while a Maple procedure is executing.
kernelopts⁡ASSERT=true
false
ASSERT⁡2+2=5,`wrong addition`
Error, assertion failed, wrong addition
kernelopts⁡ASSERT=false
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.
L := [seq(i, i=1..5)]:
mul( x-i, i=L );
x−1⁢x−2⁢x−3⁢x−4⁢x−5
add( a[i]*x^i, i=0..5 );
a5⁢x5+a4⁢x4+a3⁢x3+a2⁢x2+a1⁢x+a0
2 3 4 5
a[0] + a[1] x + a[2] x + a[3] x + a[4] x + a[5] x
map2 is a map() function that expands on the second argument.
map2(op,1, [ x^3, y=z] );
x,y
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): 3
POWER(3)
NAME(4): y
Various routines to support the recording and analysis of runtime information are provided: profile, showprofile, exprofile, unprofile, excallgraph.
readlib(profile):
fib:=proc(n) option remember; if n<2 then n else fib(n-1)+fib(n-2) fi;end:
profile(fib);
fib(5);
5
showprofile(fib);
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 generates semantic information for a procedure and also checks for sections of code which can never be executed.
readlib(maplemint):
a:=proc() local b; global c; if (b=5) then b:=6; RETURN(true); lprint(`test`); fi; end:
maplemint(a);
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
hasfun tests an expression for a specified function:
e := sin(x)+exp(y)+1;
e≔sin⁡x+ⅇy+1
hasfun(e,exp);
hasfun(e,{sin,cos},x);
hasoption selects an option from a list or set of options:
Options := [title=sin(w*x), numpoints=99, style=POINT];
Options≔title=sin⁡w⁢x,numpoints=99,style=POINT
Options :=
[title = sin(w x), numpoints = 99, style = POINT]
hasoption( Options, style, 's', 'Options' );
s; Options;
POINT
title=sin⁡w⁢x,numpoints=99
[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));
e≔z+1⁢ln⁡z⁢z2−2
2
e := (z + 1) ln(z (z - 2))
applyop(expand,2,e);
z+1⁢ln⁡z⁢z2−2
(z + 1) ln(z (z - 2))
applyop(expand,[2,1],e);
z+1⁢ln⁡z3−2⁢z
(z + 1) ln(z - 2 z)
depends checks for mathematical dependence:
restart;
depends(sin(x)+cos(z),{x,y});
depends(int(f(x),x=a..b),x);
remove:
The command remove does the opposite of select. It removes items from a list, set, sum, product, or function according to a boolean value.
integers := [$10..20]:
select(isprime, integers);
11,13,17,19
remove(isprime, integers);
10,12,14,15,16,18,20
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;
5,−11,3
5, -11, 3
coeff:
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 );
83341666458332500020000
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:
8
print(fib);
procn::nonnegintoptionremember;ifn=1orn=0then1elsefib⁡n − 1+fib⁡n − 2end ifend proc#(0) = 1#(1) = 1#(2) = 2#(3) = 3#(4) = 5#(5) = 8
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
:: (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>;
xyzt
Selection operation l[i..j] where l is a list (set) now returns a list (set).
l := [1,3,5,7,9];
l≔1,3,5,7,9
l[1..3];
1,3,5
Negative selectors can now be used. The -1th element is the last, the -2th the second last, and so on:
l[-2];
7
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:
w := f(g(a,b),h(c,d));
w≔f⁡g⁡a,b,h⁡c,d
op([2,1],w) = op(1, op(2, w) );
c=c
op([-1,-1],w);
d
Similarly for subsop:
p := f(x,g(x,y,z),x);
p≔f⁡x,g⁡x,y,z,x
subsop( [2,3]=w, p );
f⁡x,g⁡x,y,f⁡g⁡a,b,h⁡c,d,x
subsop( [2,0]=h, [2,3]=w, 3=a, p );
f⁡x,h⁡x,y,f⁡g⁡a,b,h⁡c,d,a
Download Help Document