Programming - Maple Help

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 ) } );
 ${\mathrm{false}}$ (1)
 > andmap( type, { seq( i, i = 2 .. 19 ) }, 'integer' );
 ${\mathrm{true}}$ (2)
 > ormap( isprime, { seq( i, i = 2 .. 19 ) } );
 ${\mathrm{true}}$ (3)
 > ormap( type, { seq( 2*i, i = 2 .. 19 ) }, 'odd' );
 ${\mathrm{false}}$ (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');
 ${\mathrm{true}}$ (5)
 > p;
 ${2}$ (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');
 ${\mathrm{true}}$ (7)
 > p;
 ${4}$ (8)
 > membertype(fraction, [a, b, 1/2, 3], 'p');
 ${\mathrm{true}}$ (9)
 > p;
 ${3}$ (10)
 > membertype(string, {a, b, 1/2, 3}, 'p');
 ${\mathrm{false}}$ (11)

maptype

 • The maptype function is similar to the map command, but takes an additional first argument that specifies a type. The expression $\mathrm{maptype}\left(T,F,E\right)$ is equivalent to $\mathrm{map}\left(F,E\right)$ when $\mathrm{type}\left(E,T\right)$ is true, and is equal to $F\left(E\right)$ otherwise.
 > map( f, b*c );
 ${f}{}\left({b}\right){}{f}{}\left({c}\right)$ (12)
 > maptype( +, f, b*c );
 ${f}{}\left({b}{}{c}\right)$ (13)
 > map( f, a + b*c );
 ${f}{}\left({b}{}{c}\right){+}{f}{}\left({a}\right)$ (14)
 > maptype( +, f, a + b*c );
 ${f}{}\left({b}{}{c}\right){+}{f}{}\left({a}\right)$ (15)

evalindets

 • The new evalindets procedure is similar to subsindets, but uses the two-argument form of eval (evaluation at a point) in place of subs.

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))');
 ${\mathrm{false}}$ (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.
 > with( TypeTools );
 $\left[{\mathrm{AddType}}{,}{\mathrm{Exists}}{,}{\mathrm{GetType}}{,}{\mathrm{GetTypes}}{,}{\mathrm{RemoveType}}{,}{\mathrm{Type}}\right]$ (17)
 > AddType( 'oddprime', 'And( odd, prime )' );
 > type( 2, 'oddprime' );
 ${\mathrm{false}}$ (18)
 > type( 3, 'oddprime' );
 ${\mathrm{true}}$ (19)
 > type( 4, 'oddprime' );
 ${\mathrm{false}}$ (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;
 ${m}{:=}{\mathbf{module}}\left({}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{option}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{package}}{,}{\mathrm{load}}{=}{\mathrm{deftypes}}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{local}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{deftypes}}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{export}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{oddprime}}{,}{\mathrm{evenprime}}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end module}}$ (21)
 > with( m );
 $\left[{\mathrm{evenprime}}{,}{\mathrm{oddprime}}\right]$ (22)
 > GetTypes();
 $\left[{\mathrm{ExtendedKet}}{,}{\mathrm{TensorWithNumericalIndices}}{,}{\mathrm{X_mu}}{,}{\mathrm{DGscalar}}{,}{\mathrm{DGinhomogeneoustensor}}{,}{\mathrm{ExpandableProduct}}{,}{\mathrm{noncommutative}}{,}{\mathrm{AppliedQuantumOperator}}{,}{\mathrm{PhysicsD_2}}{,}{\mathrm{SpaceIndexValue}}{,}{\mathrm{BosonCreationOperator}}{,}{\mathrm{PhysicsKnownFunction}}{,}{\mathrm{FeynmanDiagramsTensors}}{,}{\mathrm{oddprime}}{,}{\mathrm{FermionAnnihilationOperator}}{,}{\mathrm{FermionAnnihilationCreationOperator}}{,}{\mathrm{TensorWithoutIndices}}{,}{\mathrm{ac_var_local}}{,}{\mathrm{NonCommutativeProduct}}{,}{\mathrm{PhysicsFunction}}{,}{\mathrm{ExtendedDifferentialOperator}}{,}{\mathrm{DGalgebra}}{,}{\mathrm{ExtendedTensor}}{,}{\mathrm{nc_symbol_local}}{,}{\mathrm{ExtendedProjector}}{,}{\mathrm{ExtendedVectorDifferentialOperator}}{,}{\mathrm{ac_symbol_local}}{,}{\mathrm{c_symbol_local}}{,}{\mathrm{DGinvmetric}}{,}{\mathrm{oddprime}}{,}{\mathrm{System}}{,}{\mathrm{Physics}}{:-}{\mathrm{Bracket}}{,}{\mathrm{Physics}}{:-}{\mathrm{Vectors}}{:-}{\mathrm{+}}{,}{\mathrm{spinorindex}}{,}{\mathrm{ProjectorInt}}{,}{\mathrm{QuantumObject}}{,}{\mathrm{ProjectorKindDot}}{,}{\mathrm{anticommutative}}{,}{\mathrm{TensorWithAbstractIndices}}{,}{\mathrm{DGvector}}{,}{\mathrm{x_mu}}{,}{\mathrm{ExtendedBra}}{,}{\mathrm{UnitaryOperator}}{,}{\mathrm{TypesettingStructureNeedsMfence}}{,}{\mathrm{DGinhomogeneousform}}{,}{\mathrm{TensorStructure}}{,}{\mathrm{Physics}}{:-}{\mathrm{D_}}{,}{\mathrm{VectorDifferentialOperatorCreated}}{,}{\mathrm{nc_symbol}}{,}{\mathrm{SubSystem}}{,}{\mathrm{DGform}}{,}{\mathrm{FeynmanDiagramsTensorsIndexed}}{,}{\mathrm{c_var_local}}{,}{\mathrm{spaceindex}}{,}{\mathrm{Physics}}{:-}{\mathrm{*}}{,}{\mathrm{DGobject}}{,}{\mathrm{DifferentialOperatorSymbol}}{,}{\mathrm{Physics}}{:-}{\mathrm{^}}{,}{\mathrm{su3matrixindex}}{,}{\mathrm{NotNestedIntegral}}{,}{\mathrm{AppliableProcedure}}{,}{\mathrm{Procedure}}{,}{\mathrm{Covariant}}{,}{\mathrm{HalfInteger}}{,}{\mathrm{Name}}{,}{\mathrm{DGtransformation}}{,}{\mathrm{nc_var_local}}{,}{\mathrm{FullyCommutative}}{,}{\mathrm{DGconnection}}{,}{\mathrm{HermitianOperator}}{,}{\mathrm{DiracSpinor}}{,}{\mathrm{ExtendedDifferentialOperatorIndexed}}{,}{\mathrm{ac_var}}{,}{\mathrm{DGmultivector}}{,}{\mathrm{Physics}}{:-}{\mathrm{Ket}}{,}{\mathrm{TensorQuantumOperator}}{,}{\mathrm{PhysicsTensor}}{,}{\mathrm{SumOfNegatives}}{,}{\mathrm{VectorOperator}}{,}{\mathrm{Physics}}{:-}{\mathrm{Bra}}{,}{\mathrm{TensorInternalRepresentation}}{,}{\mathrm{DGtensor}}{,}{\mathrm{DGmoving_frame}}{,}{\mathrm{BosonAnnihilationCreationOperator}}{,}{\mathrm{Contravariant}}{,}{\mathrm{commutative}}{,}{\mathrm{su2index}}{,}{\mathrm{QuantumNumber}}{,}{\mathrm{Physics}}{:-}{\mathrm{d_}}{,}{\mathrm{DGbftv}}{,}{\mathrm{ProjectorSum}}{,}{\mathrm{TensorIndex}}{,}{\mathrm{tetradindex}}{,}{\mathrm{Tensor}}{,}{\mathrm{ProjectorCore}}{,}{\mathrm{DGframemame}}{,}{\mathrm{InertSymbol}}{,}{\mathrm{Polynomial}}{,}{\mathrm{VectorOperatorApplied}}{,}{\mathrm{QuantumOperatorFunction}}{,}{\mathrm{su2matrixindex}}{,}{\mathrm{c_symbol}}{,}{\mathrm{QuantumOperator}}{,}{\mathrm{TensorInCurrentCoordinates}}{,}{\mathrm{ExtendedMatrix}}{,}{ℂ}{,}{\mathrm{ProjectorKind}}{,}{\mathrm{PrettyPrintedBra}}{,}{\mathrm{PhysicsMatrixWithMatrixIndices}}{,}{\mathrm{LinearOperatorFunction}}{,}{\mathrm{dg_dg}}{,}{\mathrm{c_var}}{,}{\mathrm{PhysicsD3_2}}{,}{\mathrm{SpacetimeMetric}}{,}{\mathrm{DGmetric}}{,}{\mathrm{IdentityMatrix}}{,}{\mathrm{DifferentialOperatorIndexed}}{,}{\mathrm{BosonAnnihilationOperator}}{,}{\mathrm{SpaceTimeVectorApplied}}{,}{\mathrm{ExtendedProjectorKind}}{,}{\mathrm{GenericMatrix}}{,}{\mathrm{ExtendedMatrixRequiringEval}}{,}{\mathrm{CreationOperator}}{,}{\mathrm{CommutativeMapping}}{,}{\mathrm{EntirelyNotNestedIntegral}}{,}{\mathrm{ProjectorKindStar}}{,}{\mathrm{NumericalIndex}}{,}{\mathrm{ExtendedDifferentialOperatorSymbol}}{,}{\mathrm{TensorAllowWithoutIndices}}{,}{\mathrm{LeviCivitaTensor}}{,}{\mathrm{EuclideanIndex}}{,}{\mathrm{Physics}}{:-}{\mathrm{.}}{,}{\mathrm{Physics}}{:-}{\mathrm{Vectors}}{:-}{\mathrm{.`}}{,}{\mathrm{PrettyPrintedKet}}{,}{\mathrm{Physics}}{:-}{\mathrm{Projector}}{,}{\mathrm{su3index}}{,}{\mathrm{LiteralSubscript}}{,}{\mathrm{VectorDifferentialOperator}}{,}{\mathrm{parameter}}{,}{\mathrm{TensorWithIndices}}{,}{\mathrm{AtProcedure}}{,}{\mathrm{FermionCreationOperator}}{,}{\mathrm{DGbiform}}{,}{\mathrm{Vectorial}}{,}{\mathrm{AnnihilationOperator}}{,}{\mathrm{AnnihilationCreationOperator}}{,}{\mathrm{Physicsd_2}}{,}{\mathrm{NegativePower}}{,}{\mathrm{Procedure}}{,}{\mathrm{ExtendedQuantumOperator}}{,}{\mathrm{ac_symbol}}{,}{\mathrm{nc_var}}{,}{\mathrm{evenprime}}{,}{\mathrm{DGLiealgebraWithCoeff}}{,}{\mathrm{gaugeindex}}{,}{\mathrm{DifferentialOperator}}{,}{\mathrm{name}}{,}{\mathrm{CompositeDifferentiationOperator}}{,}{\mathrm{DGdiffeq}}{,}{\mathrm{DGLiealgebra}}{,}{\mathrm{MinusTimes}}{,}{\mathrm{spacetimeindex}}{,}{\mathrm{ContravariantGreek}}{,}{\mathrm{NeedsMfence}}{,}{\mathrm{TensorVector}}{,}{\mathrm{SpacetimeIndexValue}}{,}{\mathrm{DGrepresentation}}{,}{\mathrm{PhysicsVectors}}\right]$ (23)
 > type( 2, 'oddprime' );
 ${"local oddprime"}$
 ${\mathrm{false}}$ (24)
 > type( 3, 'oddprime' );
 ${"local oddprime"}$
 ${\mathrm{true}}$ (25)
 > type( 3, ':-oddprime' );
 ${\mathrm{true}}$ (26)
 > type( 4, 'oddprime' );
 ${"local oddprime"}$
 ${\mathrm{false}}$ (27)
 > andmap( type, [ 2, 3, 5, 7 ], 'oddprime' );
 ${"local oddprime"}$
 ${\mathrm{false}}$ (28)
 > ormap( type, [ 2, 3, 5, 7 ], 'evenprime' );
 ${\mathrm{true}}$ (29)
 > andmap( type, [ 3, 5, 7 ], 'oddprime' );
 ${"local oddprime"}$
 ${"local oddprime"}$
 ${"local oddprime"}$
 ${\mathrm{true}}$ (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');
 ${\mathrm{true}}$ (31)
 > type(f[x], 'assignable');
 ${\mathrm{true}}$ (32)
 > protect(f):
 > type(f[x], 'assignable');
 ${\mathrm{false}}$ (33)
 > unprotect(f):
 > type((f+g)[3], 'assignable');
 ${\mathrm{false}}$ (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.
 > convert(Pi, 'float');
 ${3.141592654}$ (35)
 > convert(Pi, 'float', 3);
 ${3.14}$ (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));
 $\left[{1.}\right]$ (37)
 > convert([1, 2, exp(2)], 'compose', 'list', 'float'(4));
 $\left[{1.}{,}{2.}{,}{7.389}\right]$ (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.
 > convert(114, iupac);
 ${"ununquadium"}$ (39)
 > convert(114, iupac, symbol);
 ${"Uuq"}$ (40)

parfrac,fullparfrac

 • See updates/Maple8/efficiency and convert/fullparfrac for information on efficiency improvements made in these conversions.

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 $\left[\mathrm{pos},\mathrm{expr}\right]$, one for each expression $\mathrm{expr}$ 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);
 $\left[\left[{1}{,}{a}\right]{,}\left[{2}{,}{b}\right]{,}\left[{3}{,}{c}\right]{,}\left[{4}{,}{d}\right]{,}\left[{5}{,}{e}\right]{,}\left[{6}{,}{f}\right]\right]$ (41)
 > ListTools[Enumerate](L, 0);
 $\left[\left[{0}{,}{a}\right]{,}\left[{1}{,}{b}\right]{,}\left[{2}{,}{c}\right]{,}\left[{3}{,}{d}\right]{,}\left[{4}{,}{e}\right]{,}\left[{5}{,}{f}\right]\right]$ (42)

Subpackage for linear algebra mod m

 •