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

Online Help

All Products    Maple    MapleSim


Programming Facilities Changes in Maple 8

• 

Maple 8 includes the following changes to programming facilities.

 

System Changes

Higher Order Procedures

Verifications

Changes to the Type System

New and Improved Conversions

Packages with Programming Enhancements

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 ) } );

false

(1)

andmap( type, { seq( i, i = 2 .. 19 ) }, 'integer' );

true

(2)

ormap( isprime, { seq( i, i = 2 .. 19 ) } );

true

(3)

ormap( type, { seq( 2*i, i = 2 .. 19 ) }, 'odd' );

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');

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');

true

(7)

p;

4

(8)

membertype(fraction, [a, b, 1/2, 3], 'p');

true

(9)

p;

3

(10)

membertype(string, {a, b, 1/2, 3}, 'p');

false

(11)

maptype

• 

The maptype function is similar to the map command, but takes an additional first argument that specifies a type. The expression maptypeT,F,E is equivalent to mapF,E when typeE,T is true, and is equal to FE otherwise.

map( f, b*c );

fbfc

(12)

maptype( `+`, f, b*c );

fbc

(13)

map( f, a + b*c );

fbc+fa

(14)

maptype( `+`, f, a + b*c );

fbc+fa

(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))');

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 );

AddType,Exists,GetType,GetTypes,RemoveType,Type

(17)

AddType( 'oddprime', 'And( odd, prime )' );

type( 2, 'oddprime' );

false

(18)

type( 3, 'oddprime' );

true

(19)

type( 4, 'oddprime' );

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:=moduleoptionpackage&comma;load&equals;deftypes&semi;localdeftypes&semi;exportoddprime&comma;evenprime&semi;end module

(21)

with( m );

evenprime&comma;oddprime

(22)

GetTypes();

DGtransformation&comma;AtProcedure&comma;ExtendedProjectorKind&comma;TensorInternalRepresentation&comma;ac_symbol_local&comma;HermitianOperator&comma;&comma;AnnihilationCreationOperator&comma;PhysicsTensor&comma;NegativePower&comma;Covariant&comma;ProjectorCore&comma;c_var&comma;DGbiform&comma;DGform&comma;EntirelyNotNestedIntegral&comma;Physics:−Vectors:−`.`&comma;P_suffixed&comma;ProjectorSum&comma;su3matrixindex&comma;x_mu&comma;ExtendedDifferentialOperatorIndexed&comma;Physics:−Bra&comma;ProjectorKindStar&comma;DiracSpinorWithoutIndices&comma;EuclideanTensor&comma;TensorQuantumOperator&comma;LiteralSubscript&comma;PhysicsMatrix&comma;DGscalar&comma;Assumable&comma;FeynmanDiagramsTensors&comma;SpaceTimeVectorApplied&comma;DGalgebra&comma;VectorOperatorApplied&comma;HalfInteger&comma;DifferentialOperator&comma;p_P_indexed&comma;DGobject&comma;DGLiealgebraWithCoeff&comma;Tensor&comma;ExtendedTensor&comma;TensorWithoutIndices&comma;VectorDifferentialOperatorCreated&comma;nc_symbol&comma;DGinvmetric&comma;Name&comma;parameter&comma;ProjectorKind&comma;ExtendedBra&comma;TensorStructure&comma;p_indexed&comma;Procedure&comma;spinorindex&comma;DGdiffeq&comma;dg_dg&comma;ac_var&comma;InertSymbol&comma;Physics:−D_&comma;DGconnection&comma;Polynomial&comma;ExtendedKet&comma;FermionAnnihilationOperator&comma;PhysicsD_2&comma;Physics:−`.`&comma;DGmoving_frame&comma;ExtendedDifferentialOperator&comma;PhysicsMatrixWithMatrixIntegerIndices&comma;MinusTimes&comma;DGbftv&comma;ac_var_local&comma;tetradindex&comma;Physics:−Vectors:−`+`&comma;SumOfNegatives&comma;PhysicsD3_2&comma;X_mu&comma;oddprime&comma;NotNestedIntegral&comma;PhysicsVectors&comma;FermionCreationOperator&comma;Spinor&comma;FeynmanDiagramsTensorsIndexed&comma;c_symbol_local&comma;ExtendedQuantumOperator&comma;DiracSpinor&comma;UnitaryOperator&comma;SpinorWithoutIndices&comma;ExtendedMatrix&comma;DGmetric&comma;c_var_local&comma;FermionAnnihilationCreationOperator&comma;QuantumObject&comma;QuantumOperatorFunction&comma;LeviCivitaNonGalilean&comma;Physics:−`^`&comma;DGtensor&comma;BosonCreationOperator&comma;Physics:−Projector&comma;ExpandableProduct&comma;VectorOperator&comma;noncommutative&comma;EuclideanIndex&comma;ExtendedDifferentialOperatorSymbol&comma;Vectorial&comma;Physics:−Bracket&comma;commutative&comma;DGframemame&comma;DGinhomogeneousform&comma;evenprime&comma;Physics:−Vectors:−TripleProduct&comma;DifferentialOperatorSymbol&comma;NumericalIndex&comma;ac_symbol&comma;TensorAllowWithoutIndices&comma;PrettyPrintedBra&comma;su2matrixindex&comma;TensorWithNumericalIndices&comma;Physics:−`*`&comma;AnnihilationOperator&comma;spacetimeindex&comma;TypesettingStructureNeedsMfence&comma;p_suffixed&comma;ExtendedVectorDifferentialOperator&comma;anticommutative&comma;NonTensorFunction&comma;QuantumOperator&comma;ProjectorKindDot&comma;IdentityMatrix&comma;Physics:−d_&comma;LeviCivitaTensor&comma;DGrepresentation&comma;spaceindex&comma;IdenticalTo&comma;c_symbol&comma;Procedure&comma;su2index&comma;SpacetimeNumericalIndex&comma;TensorIndex&comma;AppliedQuantumOperator&comma;TensorVector&comma;DoublyIndexedPhysicsMatrix&comma;P_indexed&comma;nc_var&comma;Physics:−Ket&comma;LinearOperatorFunction&comma;QuantumNumber&comma;NonCommutativeProduct&comma;BosonAnnihilationCreationOperator&comma;VectorDifferentialOperator&comma;PhysicsFunction&comma;TensorWithIndices&comma;PhysicsKnownFunction&comma;TensorialExpression&comma;ContravariantGreek&comma;PrettyPrintedKet&comma;CommutativeMapping&comma;CreationOperator&comma;p_P_suffixed&comma;SpacetimeMetric&comma;SpaceNumericalIndex&comma;NeedsMfence&comma;DGLiealgebra&comma;AppliableProcedure&comma;ExtendedProjector&comma;ExtendedMatrixRequiringEval&comma;oddprime&comma;DGinhomogeneoustensor&comma;FullyCommutative&comma;DGvector&comma;DGmultivector&comma;TensorWithAbstractIndices&comma;SpaceTimeVectorComponentApplied&comma;Physicsd_2&comma;CompositeDifferentiationOperator&comma;ExtendedPhysicsMatrix&comma;PhysicsMatrixWithMatrixIndices&comma;ProjectorInt&comma;nc_symbol_local&comma;BosonAnnihilationOperator&comma;su3index&comma;DifferentialOperatorIndexed&comma;DiscardableAssumption&comma;TensorInCurrentCoordinates&comma;nc_var_local&comma;name&comma;genericindex&comma;SymbolicTensorIndex&comma;Contravariant&comma;MathematicalFunctions:−Region

(23)

type( 2, 'oddprime' );

local oddprime

false

(24)

type( 3, 'oddprime' );

local oddprime

true

(25)

type( 3, ':-oddprime' );

true

(26)

type( 4, 'oddprime' );

local oddprime

false

(27)

andmap( type, [ 2, 3, 5, 7 ], 'oddprime' );

local oddprime

false

(28)

ormap( type, [ 2, 3, 5, 7 ], 'evenprime' );

true

(29)

andmap( type, [ 3, 5, 7 ], 'oddprime' );

local oddprime

local oddprime

local oddprime

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');

true

(31)

type(f[x], 'assignable');

true

(32)

protect(f):

type(f[x], 'assignable');

false

(33)

unprotect(f):

type((f+g)[3], 'assignable');

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));

1.

(37)

convert([1, 2, exp(2)], 'compose', 'list', 'float'(4));

1.&comma;2.&comma;7.389

(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 pos&comma;expr, one for each expression 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);

1&comma;a&comma;2&comma;b&comma;3&comma;c&comma;4&comma;d&comma;5&comma;e&comma;6&comma;f

(41)

ListTools[Enumerate](L, 0);

0&comma;a&comma;1&comma;b&comma;2&comma;c&comma;3&comma;d&comma;4&comma;e&comma;5&comma;f

(42)

Subpackage for linear algebra mod m

• 

See updates/Maple8/packages