Programming - Maple Help

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

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

(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