updates/R5/language - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

Home : Support : Online Help : updates/R5/language

Changes to the Maple Language in Maple V Release 5

  

Several changes and improvements have been made to the Maple programming language and system. A brief description of these changes and improvements follows.

 

Lexical scoping

Strings

Multiple Assignment

:

Other Language Changes

New Functions and Types

System

Lexical scoping

• 

Maple V Release 5 implements lexical scoping.

• 

Please see the help page updates/R5/highlights, or the lexical example worksheet for some examples illustrating the significance of this language change.

Strings

• 

A new feature of Maple is the ability to create strings. More information about strings is available in highlights, and examples have been provided in the strings example worksheet .

"This is a string";

This is a string

(1)
• 

Because strings require double quotation marks, the recall operator in Maple V Release 5, formerly written as ", is now written as %. Similarly, "" and """ become %% and %%%, respectively.

a := 2;

a2

(2)

b := 3;

b3

(3)

%;

3

(4)

%%;

3

(5)

b := 'b':

• 

Strings may be converted to names (or symbols) using the convert command.

convert( "A string", 'symbol' );

A string

(6)
• 

The percent character is reserved for system-defined names. Users should not use % at the beginning of a name.

Multiple Assignment

• 

Multiple assignments can be made in a single Maple instruction in Release 5.

ll := ["a", 1, "b", 2, "c", 3, "d" ];

lla,1,b,2,c,3,d

(7)

strings, numbers := select( type, ll, 'string' ), remove( type, ll, 'string' ):

strings;

a,b,c,d

(8)

numbers;

1,2,3

(9)

:

• 

The typematch operator ::, used frequently to provide for automatic type checking of arguments to procedures, used to be called :.

• 

Use of the single colon form of the typematch operator is no longer supported in Release 5. (A warning was issued in Release 4; now, it is an error.)

Other Language Changes

• 

The exponentiation operator `^` is now a function; this affects type.

• 

The following operators are now also functions: `<`, `<=`, `>`, `>=`, `=`, `<>`

• 

Allow checking for the types assigned to unevaluated names.

a := 2.5;

a2.5

(10)

type( 'a', name( integer ) );

false

(11)

type( 'a', name( float ) );

true

(12)
• 

Expressions of the following forms are now acceptable input.

  

'A'[i]

A[ 1 ] := "string";

A1string

(13)

'A'[ 1 ];

string

(14)
  

(expression)[i]

( a * b + c )[1];

2.5b+c1

(15)
  

<a>[i]

< a >[i];

2.5i

(16)
  

{set}[i]

{ 1, 2, 3, 4 }[ 2 ];

2

(17)
  

[list][i]

[ 4, 3, 2, 1 ][ 3 ];

2

(18)

New Functions and Types

Functions

  

Several new system level procedures have been added.

• 

The new function nprintf is like sprintf, but it returns a name instead of a string.

a := 5;

a5

(19)

nprintf( "The value of \"a\" is %d\n", a );

The value of "a" is 5

(20)

sprintf( "The value of \"a\" is %d\n", a );

The value of "a" is 5

(21)
• 

Use the procedure timelimit to limit the amount of CPU time spent on a computation.

f := proc(n::posint)
        local   i;
        for i from 1 to n do
                2^i;
        od;
end;

f:=procn::posintlocali&semi;foritondo2&Hat;iend doend proc

(22)

timelimit( 3, f( 10^6 ) );

 Error, (in f) time expired

• 

Operating system environment variables (on platforms that have them) can be retrieved using the new procedure getenv.

getenv( "PATH" );

 /u/maple/research/bin:/usr/bin:/usr/openwin/bin:/usr/ucb:/usr/local/bin

• 

The current directory of the Maple process can be queried, or set (on platforms that support this), using the procedure currentdir.

currentdir( "/" ): # old working directory is returned

currentdir(); # print cwd

/

(23)
• 

A new format %A has been added to printf.  It is essentially the same as the %a format except that backquotes are not put around names even though they might need it to be valid maple input.

Types

• 

The new type constructors And, Or, and Not allow you to construct new types from existing types by means of boolean combinations, or to test directly for boolean combinations of type.

type( Pi, 'And( constant, numeric )' );

false

(24)

type( Pi, 'And( constant, Not( numeric ) )' );

true

(25)

type( 3.14, 'And( constant, numeric )' );

true

(26)

`type/stringythingy` := 'Or( string, name )';

type/stringythingystringname

(27)

type( `foo`, 'stringythingy' );

true

(28)

type( "bar", 'stringythingy' );

true

(29)

type( 27, 'stringythingy' );

false

(30)
• 

Use the new type arctrigh to test for an expression that is a call to an inverse hyperbolic function.

type( sin( x ), 'arctrigh' );

false

(31)

type( arcsin( x ), 'arctrigh' );

false

(32)

type( sinh( x ), 'arctrigh' );

false

(33)

type( arcsinh( x ), 'arctrigh' );

true

(34)
• 

An optional additional argument allows you to check that the expression is an inverse hyperbolic function of some name.

type( arctanh( 2 * sin( x / y ) ), 'arctrigh( x )' );

true

(35)

type( arctanh( 2 * sin( x / y ) ), 'arctrigh( t )' );

false

(36)
• 

An object is of type atomic if it is a string, fraction, integer, float, indexed or symbol. You can test for objects of type atomic as in the following examples.

type( 2, 'atomic' );

true

(37)

type( a[i], 'atomic' );

true

(38)

type( "a string", 'atomic' );

true

(39)

type( ( x + y ) * z, 'atomic' );

false

(40)

type( 2/3, 'atomic' );

true

(41)
• 

If evalf returns a number of the form a + b * I, with a and b floating point numbers, or if evalf returns infinity or -infinity, then the solution is of type complex constant, called complexcons.

type( -infinity, 'complexcons' );

true

(42)

type( arcsinh( 1 + I ), 'And( complexcons, arctrigh )' );

true

(43)
• 

Arrays of hardware floating point numbers (hfarrays) are new in Maple V Release 5. They are of type hfarray.

a := hfarray( 0..2 );

aArray0..2&comma;0=Floatundefined&comma;1=Floatundefined&comma;2=Floatundefined&comma;datatype=float8&comma;storage=rectangular&comma;order=C_order

(44)

type( a, 'hfarray' );

true

(45)

type( a, 'array' );

false

(46)
• 

Objects that are of type integer, fraction, float, or string are said to be of type literal. Type literal is now a valid Maple type.

type( "a short string", 'literal' );

true

(47)

type( 1/5, 'literal' );

true

(48)

type( M[2,3], 'literal' );

false

(49)
• 

An integer that is not positive, nonposint, is a new Maple type introduced in this release.

type( 2, 'nonposint' );

false

(50)

type( 0, 'nonposint' );

true

(51)

type( -1, 'nonposint' );

true

(52)

type( -2/3, 'nonposint' );

false

(53)

type( -infinity, 'nonposint' );

false

(54)

type( infinity, 'nonposint' );

false

(55)
• 

procedure -- check for a procedure

• 

range -- check for a range

• 

A new type constructor, Range, allows you to construct a "type" that determines whether an object lies in a specified numeric range.

type( 2, 'Range( 1, 3 )' );

true

(56)

type( 5, 'Range( 1, 3 )' );

false

(57)
• 

A number that is algebraic and is expressed as a Maple radical or using RootOf notation is of type radalgnum.

map( type, [ 2/7, evalf( Pi ), RootOf( x^2 + 1 ), RootOf( z^2 - x, z ) ], 'radalgnum' );

true&comma;false&comma;true&comma;false

(58)
• 

You can test whether an expression is a radical algebraic function of its indeterminates, or of a specified set of indeterminates, using a type test against the type radalgfun.

• 

The hyperbolic functions have been ascribed the Maple type trigh. The hyperbolic functions are sinh, cosh, tanh, sech, csch and coth.

type( sin( x ), 'trigh' );

false

(59)

type( tanh( x ), 'trigh' );

true

(60)

type( arcsech( coth( x ) ), 'trigh' );

false

(61)
• 

Use the new Maple type symbol to test whether an object is a symbol. A symbol is a name that is not of type indexed

• 

There are several new types associated with the new Ore_algebra and Groebner packages: OreAlgebra, ClosedIdeal, CommAlgebra, ShortTermOrder, SkewParamAlgebra, SkewAlgebra, SkewPolynomial, TermOrder. Please see the corresponding help pages, and Ore Algebra example worksheets for further information.

System

Debugging

• 

Parser generated warnings now have line numbers.

• 

Tracing of builtin functions is now fully implemented.

• 

The tracelast command now gives line numbers (in a format that you can cut and paste to the stopat command).

• 

The tracelast command will tell you where a computation was interrupted by the user.

• 

New options for stoperror:

  

stoperror(interrupted); ,

  

stoperror("time expired"); ,

  

stoperror("assertion failed"); ,

  

stoperror(all); ,

  

stoperror("invalid argument"); .

• 

Setting interface(warnlevel = 4) warns about lexically scoped variables.

• 

The debugger has a where function that shows the call stack of a stopped procedure.

• 

There is a new WARNING function that users can use to issue warnings in their own procedures.

f := proc(x::integer)
        if x < 0 then
                WARNING( sprintf( "negative argument passed to %s", procname ) );
        fi;
        2*x;
end:

f(1);

2

(62)

f(0);

0

(63)

f(-2);

Warning, negative argument passed to f

−4

(64)
• 

The new kernelopts(dagtag) option maps between internal data structure IDs and their names.

kernelopts( dagtag = PROC );

32

(65)

kernelopts( dagtag = 1 );

INTNEG

(66)

seq( kernelopts( dagtag = i ), i = 1..46 );

INTNEG,INTPOS,RATIONAL,FLOAT,STRING,NAME,TABLEREF,DCOLON,CATENATE,POWER,PROD,SERIES,SUM,FUNCTION,UNEVAL,EQUATION,INEQUAT,LESSEQ,LESSTHAN,AND,NOT,OR,EXPSEQ,LIST,LOCAL,PARAM,LEXICAL,PROC,RANGE,SET,TABLE,HFARRAY,ASSIGN,FOR,IF,READ,SAVE,STATSEQ,STOP,HASH,HASHTAB,GARBAGE,FOREIGN,CONTROL,PROMPT,DEBUG

(67)
• 

A detailed account of the storage being used by objects of different types can be obtained using kernelopts(memusage).

• 

The directory separator, as a string, used on the particular platform that Maple is running on, can be queried using kernelopts(dirsep).

• 

The limits on cpu time, data and stack sizes that can be set through the command line can now be queried using kernelopts(cpulimit), kernelopts(datalimit), and kernelopts(stacklimit) respectively.

User Interface

• 

The new interface(errorcursor) controls how errors are indicated in the TTY version of Maple

• 

The new interface(autoassign) variable controls whether the context-sensitive menus automatically generate an assignment for the results of a menu operation, and what variable name it uses if this feature is used.

• 

Command completion has been reenabled (see editing, and the lib/cmds file).

• 

Maple quits on reaching end of file. Use the -F option to recover the old behavior, which allows you to continue interactively after the end of the input file has been reached.

• 

Input files can now be specified as command line arguments of the maple command. It is no longer necessary to write maple < file, using shell redirection. (See the man page.)

• 

The help system in the TTY version now returns near-matches if an exact match was not found.

?evalfh

 No exact matches found, please try one of the following:

    eval

    evala

    evalapply

    evalb

    evalc

    evalf

    evalfint

    evalgf

    evalhf

    evalm

    evaln

    evalr

    evalrC

 >

• 

An alternate initialization file may be specified on the command line, using the new -i option.

  

For example, if you use the Korn shell, you can use the alias alias maplev5="maplev5 -i $HOME/.maplev5.init" to ensure that your new version of Maple uses the correct initialization file.

Performance

• 

Karatsuba's algorithm is used for multiplying large integers.

• 

Use of hardware floating point arrays (hfarrays) improves performance dramatically in some areas (such as plotting).

• 

Profiling of the kernel has been done, and significant performance improvements were implemented as a result of finding some bottlenecks.


Download Help Document