the maple computer algebra system: a review

9
JOURNAL OF APPLIED ECONOMETRICS, VOL. 10,329-337 (1995) THE MAPLE COMPUTER ALGEBRA SYSTEM: A REVIEW JOHN HUTTON Department of Economics, University of York, Heslington, York, YO1 5DD JAMES HUTTON Department of Mathematics, University of Essex, UK SUMMARY We set out the main features of Maple V, Release 3, and discuss its potential value to econometricians. Computer algebra systems, of which Maple is a leading example, have developed with the increased power of modern computers, but require skill and patience to use. It seems likely they will find a place in the econometrician’s toolkit for work at the interface between analytic and numerical work, where they should prove valuable. However, although Maple has many of the features of conventional statistical/econometric/numerical software, it should not be seen as a substitute. 1. COMPUTER ALGEBRA AND ECONOMETRICS Maple is a computer algebra (CA) system, and so, in essence, is software for evaluation and manipulation of algebraic expressions according to the usual rules. It therefore has obvious possibilities for econometricians. An immediate consequence of its design is the capacity for exact and arbitrary precision arithmetic simply by performing numerical calculations algebraically. A modem CA system offers much more than this, however, with sophisticated graphical, numerical/statistical and other packages, and, indeed, Maple as supplied consists of a library of such packages, built around a relatively small ‘kernel’ which performs the key functions. The basic characteristics of Maple are described succinctly in the Maple V Lmguuge Reference Manual (Char et al. 1991): Maple’s basic features (e.g. elementary data structures, input/output, arithmetic with numbers and elementary simplification) are coded in a systems programming language for efficiency. For users, there is a high-level language with a modern syntax more suitable for describing algebraic algorithms. An important property of Maple is that most of the language facilities in the system are implemented using the high-level user language. The basic system, or kernel, is sufficiently compact and efficient to be practical for use in a shared environment or on personal computers with as little as two megabytes of main memory. Library functions are CCC 0883-72521951030329-09 0 1995 by John Wiley & Sons, Ltd. Received February 1995

Upload: john-hutton

Post on 08-Aug-2016

225 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: The Maple computer algebra system: A review

JOURNAL OF APPLIED ECONOMETRICS, VOL. 10,329-337 (1995)

THE MAPLE COMPUTER ALGEBRA SYSTEM: A REVIEW

JOHN HUTTON Department of Economics, University of York, Heslington, York, YO1 5DD

JAMES HUTTON Department of Mathematics, University of Essex, U K

SUMMARY

We set out the main features of Maple V, Release 3, and discuss its potential value to econometricians. Computer algebra systems, of which Maple is a leading example, have developed with the increased power of modern computers, but require skill and patience to use. It seems likely they will find a place in the econometrician’s toolkit for work at the interface between analytic and numerical work, where they should prove valuable. However, although Maple has many of the features of conventional statistical/econometric/numerical software, it should not be seen as a substitute.

1. COMPUTER ALGEBRA AND ECONOMETRICS

Maple is a computer algebra (CA) system, and so, in essence, is software for evaluation and manipulation of algebraic expressions according to the usual rules. It therefore has obvious possibilities for econometricians. An immediate consequence of its design is the capacity for exact and arbitrary precision arithmetic simply by performing numerical calculations algebraically. A modem CA system offers much more than this, however, with sophisticated graphical, numerical/statistical and other packages, and, indeed, Maple as supplied consists of a library of such packages, built around a relatively small ‘kernel’ which performs the key functions. The basic characteristics of Maple are described succinctly in the Maple V Lmguuge Reference Manual (Char et al. 1991):

Maple’s basic features (e.g. elementary data structures, input/output, arithmetic with numbers and elementary simplification) are coded in a systems programming language for efficiency. For users, there is a high-level language with a modern syntax more suitable for describing algebraic algorithms. An important property of Maple is that most of the language facilities in the system are implemented using the high-level user language. The basic system, or kernel, is sufficiently compact and efficient to be practical for use in a shared environment or on personal computers with as little as two megabytes of main memory. Library functions are

CCC 0883-72521951030329-09 0 1995 by John Wiley & Sons, Ltd.

Received February 1995

Page 2: The Maple computer algebra system: A review

330 J. HUTTON AND J. HUTTON

loaded into the system as required, adding to the system facilities such as polynomial factorisation, equation solving, indefinite integration, and matrix manipulation functions.

The majority of the available library functions have the useful feature that their code may be inspected. The applications include student calculus, linear algebra, plots, statistics, simplex linear optimization, Grobner basis, combinatorial functions, permutation and finitely presented groups, Boolean logic, number theory, differential forms, Lie symmetry, Newman-Penrose formalism, Euclidean geometry, projective geometry, orthononnal polynomials, formal power series, and total ordering of names. Also supplied is a selection from the ‘share library’ of packages and functions contributed by users. The complete share library (which is in a standard form and includes help files,) is available directly through e-mail or ftp addresses supplied with the package but with no assumption of responsibility for reliability. There are many such user- supplied functions, though inspection revealed none which appeared to have come from the economics/econometrics coimmunity.

Maple is one of a number of sometimes closely competing substitutes: Reduce, Derive, Mathematica, Macsyma and Axiom all offer somewhat similar features, but this review cannot provide a buyer’s guide to the market. For a slightly dated feature-by-feature comparison of systems, see Harper et al. (1991), in which Maple tended to come out in front in terms of both numbers of features and by crude function-count; there was also evidence that Maple tended to be faster than most of its main rivals. All of these products, however, are subject to continuous development, and published comparisons are quickly out of date.

Mathematica is probably the best known CA system to economists and econometricians, largely due to the efforts of Hal Varian (see Varian, 1993). Most applications he presents consist of demonstrations of the solution of mathematical problems in economic theory, but he includes chapters on what could narrowly be deemed econometrics: an econometrics estimation package, an application of Bayesian econometrics, and an ARIMA package. It is, however, not entirely clear that CA systems are the most sensible media for developing many of these applications, since the special feature of computer algebra is its capacity for analytical as distinct from rapid or large-scale numerical investigation. Several applications in Varian (1 993). however, illustrate a marriage between Mathemdtica and GAUSS: the former is used to derive analytical Jacobians and Hessians which are then supplied to numerical optimization routines in GAUSS. Maple can be used in exactly the same way. The Maple kernel is also incorporated into other packages, such as PV-Wave, Matlab and Scientific Works.

Of the CA systems available, Maple and Mathematica are probably the most widely adopted both by researchers and by teachers. The teaching of introductory calculus courses, in particular, quite commonly uses computer algebra. Heck (1993) provides an interesting and balanced discussion of the pros and cons of computer algebra, though clearly himself a convert.

2. MAPLE IN DETAIL

2.1. The Interface and Sahme Practical Details

The major computer algebra packages all now provide the user with a similar interface. In Maple’s case, the screen displays a ‘worksheet’, which is similar to a technical wordprocessor document, in that symbolls and text both appear and graphs can be pasted in freely. The difference is that commands following the > prompt, typically in a different font, are live. A return on the command line sends the command to the processor, and the result appears on the next line. An outstanding feature of the current version of Maple is that the results are properly

Page 3: The Maple computer algebra system: A review

MAPLE COMPUTER ALGEBRA SYSTEM 33 1

Table I. Basic data

Distributors In UK: Clecom plc The Research Park Vincent Drive Edgbaston Birmingham B E 2SQ

In US and Canada: Waterloo Maple Software Inc 450 Phillip Street Waterloo Ontario Canada N2L, 552

Operating systems Documentation

Versions available for all main operating systems. ( i ) Language Reference Manual; (ii) Library Reference Manual; (iii) First Leaves: A Tutorial Introduction (see Char et al., 1992); installation guides. Local distributors via e-mail Supplied with distribution disks, and contributed libraries available by e-mail.

Technical support Libraries

Table II. Student and full versions of Maple

Maple V Release 3 Student version Full version

Maximum memory usage (MB) 4 Maximum number of floating point digits Maximum array dimensions 3 Total array size 5000 items Amount of disk space required 13 MB Maximum size of expressions 8000 items Price for single copy (academic/government) $99 (US and Canada)

€74.50 (UK)

100 No limit 500,000 No limit No limit 17 MB 64,000 items $595 (US and Canada) €495 (UK)

formatted and arranged, with properly sized integral, summation and differentiation signs, complete with subscripts, limits and brackets. A printer will show the same quality of output. It is possible to paste these images, via the Windows Clipboard, into a wordprocessor. One may also translate any Maple expression into (optionally optimized) FORTRAN or C for pasting into code, or LATEX for subsequent typesetting. The quality of the graphical plots is excellent, both two- and three-dimensional, with many display options and intelligent defaults.

The error messages are fairly terse, and can give little clue to the real problem (e.g. ‘error in arguments’), but the ‘information level’ may be increased to show intermediate steps and assist debugging. The syntax can also be mysterious at first, with important distinctions between ‘ , ” , ” ”, and ’. Nevertheless, the feel of the worksheet still retains a close affinity to that of working

with paper and pencil, with natural names for the various procedures. Thus diff(f (x, y), x) will partially differentiate f(.) with respect to x ; and the function itself can be readily defined by f+(x,y) +x A2+y *2, for example. If preferred, the differential operator D can be used, as in D(f’g) = (Df)*g + f’(Dg). Care must be taken to avoid inflation of expressions-the wrong command may produce many pages of output and consume RAM unnecessarily-but this can be mitigated and speed increased by suppressing output to the screen by the simple expedient of terminating a command with a colon instead of a semi-colon.

Arithmetic speed is not Maple’s (or any CA system’s) strong point, if the alternative is, for example, GAUSS or MATLAB, and the task is essentially numerical, i.e. uses floating point operations. The Manual points out that compiled FORTRAN will be about fifty times faster for identical operations; but GAUSS 386i took 0.65 seconds to generate a (300 x 300) matrix of random numbers from a uniform distribution, while Maple took 806 seconds on the same

Page 4: The Maple computer algebra system: A review

332 J. HUTTON AND J. HUTTON

33 Mhz PC with 8MB RAM; running on a SGI Unix machine reduced the time to 426 seconds (see Rust, 1993). An attempt to invert the same matrix using Maple on the PC was abandoned after several hours. Speed of calculation depends critically on available RAM: if the calculation generates more intermediate results than can be held in RAM, the hard disk takes over and speed drops off sharply.

Maple is a large system, and many features cannot be mentioned. Econometricians may be interested in the data-handling facilities, though it should be clear by now that this is not the package’s main strength. Nevertheless, there is a largish Statistics Package with a variety of standard distributions provided, and this has been greatly extended and improved for Release 3, exploiting the graphical power available. This will be adequate for smallish statistical analyses, given the comments on numerical speed above. The Linear Algebra Package is also of obvious interest and is very comprehensive, although indefinite arrays are not permitted and Cholesky decomposition is omitted. Asymptotic expansions and limits are other features of interest. The building blocks are present for the development of, for example, time-series applications, but await development into a package or set of library routines. For example, operators can readily be defined by a number of alternative routes: (the difference and lag operators are defined as exercises in the tutorials); and there are solution algorithms for recurrences (mainly linear difference equations).

2.2. Documentation and Help

The Maple package includes three hardback volumes (see Table I) , one of which, the Library Reference Manual, is essentially a hard-copy of the on-line help system. There are also booklets updating the manuals for the latest features, instructions on installing for DOS and Windows, and the regular newsletter Mapletech. The on-line help system works well, with a tree-structured browse facility, and a quick route activated by ?command (e.g. ?plot;). Windows allows easy cut-and-paste of examples from the help system into one’s own worksheet, for subsequent editing. The Language Reference Manual is a useful overview of the whole package, and essential reading before attempting any programming. First Leaves is a well-written tutorial manual and there is an on-line tutorial. As well as the ‘official’ documentation, Heck (1993) comes from the same stable but is noticeably more critical at points, and has the advanta,ge of providing more extended examples. Finally, a large number of independent guides and introductions have emerged, mostly from academic mathematicians for teaching purposes (e.g. Harper and Chalabi, 1992). User groups, conferences, etc. provide further support.

2.3. New for Release 3 and Problems

Release 3 came out in the course of writing this review, and seems mostly to be a significant improvement. Not all of the claims made have been tested, but certainly some of the bugs and difficulties we found in Release 2 were fixed. For example, there is better, but still limited, pasting into word processors and the facility to write the entire worksheet in LATEX code, a button to execute a whole worksheet (rather than hit return for each command, as in Release 2), genuine multitasking and the (new) facility to interrupt long calculations, a better data file- reading utility and an extended statistical package. Release 3 also copes better with the summation operator: it now knows that C ( x + y ) = E x + Cy. Finally, several example worksheets are now supplied, demonstrating the use of various packages.

Page 5: The Maple computer algebra system: A review

MAPLE COMPUTER ALGEBRA SYSTEM 333

We experienced a few problems in the course of experimentation, perhaps due to misunderstanding. The ‘Execute worksheet’ command can produce errors: Example 3 below requires manual entering of each command on all the computers we experimented on. It is possible to paste a worksheet, via the Windows Clipboard, into the text, but only if there are no text sections in the worksheet. An irritating feature, which may just reflect our poor programming, is that use of expressions of the form sum(x[i], i=1..10) often must be preceded or followed by the curious command i := ‘i’ to avoid an error message indicating that i = 1 1 and refusing to sum as requested. A rather more serious problem, which arose from the options example below, is that although this example was initially written and run on Release 2, Release 3 is unable to evaluate the functions P or C, despite advertised claims that Release 3 has improved integration routines. As the example shows, the user must sometimes show ingenuity in reformulating the problem until Maple will take over. The reason for this change is to avoid errors, but there is still some way to go before the system can distinguish straightforward from difficult integrals: it does seem strange that Maple can integrate exp( - x 2 ) and exp(x)*exp( - x 2 ) , but cannot integrate (1 - exp(x))*exp( - x2) .

Another serious issue is that Maple is unable to do indefinite matrix algebra: this is restrictive, and means that one cannot even derive the OLS estimator without specifying the numerical dimensions of all matrices. For example, although Maple will correctly invert the 8 x 8 symbolic matrix [p’ ’ -” 1, it cannot differentiate ( y - Xp)’ (y - Xp), where X is n x k, y is n x 1 and /3 is k x 1. Maplesoft tell us that they are working on this for future releases.

3. EXAMPLES

The following examples comprise a single worksheet.

Example 1: Present Values

This example shows some nice general features of the presentation of calculus, and the surprising difficulty of some apparently simple manipulations. Equation e l defines the zero net wealth condition; this is differentiated in e2, and it is obvious that this derivative can be simplified to give the conventional intertemporal wealth constraint, by substituting r*u( t ) into e2. We could not persuade Maple to solve el and e2, however, and various attempts failed with Maple’s refusal to allow division of e2 by r to isolate a(t). Instead, the result is merely stated as e3. Notice the use of the ‘inert’ form of differentiating before defining e2, to display the required operation before execution.

>restart:el=int(s(u)‘exp(-r’(u -t)),u =t..infinity)+a(t)=O;

The ‘restart’ command clears the memory before each example.

>Diff(e,t)=diff(e,t);

= (~~ms(u)re (-411 - 0) du - s(t) + (& a(t)) = 0)

Page 6: The Maple computer algebra system: A review

334 J. HUTTON AND J. HUTTON

The two equations, e l and e2, solve to give e3, the intertemporal wealth constraint

>e2+diff (e,t):

a at

e3 + ra(t) + s(t) = - a(t)

Example 2: Likelihood Function Manipulation

In this example we show how to define a density function, the effect of converting the resulting expression into Fortran, the formulation of the log-likelihood, and the results of differentiating once and twice. The Weibull function is illustrated. The relevance of the Fortran conversion is that output in this form may be read directly into other programs in which Fortran-like syntax is used.

>restart;

>f=(phi,x(i)) +phi'x(i)A(phi-l)'exp(-x(i)Aphi);#note that phi is positive

f b ($, x ( i ) ) -+ @x(i)(#-')e(-x(i)+)

readlib(fortran ):fortran (f (phi,x(i) 1); tO=ghi'x (i) * * ( p h i - 1 ) 'exp (-x (i) "phi)

>LL(phi)esum (log(f (phi,x(i) )),i= 1 ..n);

>s(phi)=diff (",phi);

This expression is clearly positive for small values of phi, and negative for large values, indicating the existence of a.t least one root.

>diff (s(phi),phi);

This expression is clearly negative for all values of phi: therefore one root exists.

>fortran (LL(ph i 1); E r r o r , ( i n f o r t r a n ) u n a b l e t o t r a n s l a t e , 1 . . n

This line shows that human intervention is necessary at this point to write a Fortran expression.

>solve(s(phi),phi);

E r r o r , ( i n solve/r;umint) canno t s o l v e f o r v a r i a b l e s used i n uneva lua ted sumlints

Page 7: The Maple computer algebra system: A review

MAPLE COMPUTER ALGEBRA SYSTEM 335

This final command, producing the error message above, shows that Maple cannot find the root unaided. This example was suggested by an example in McCabe and Tremayne (1993).

Example 3: Pricing European-style Options

>restart:

We now consider the standard problem of pricing European stock options (see Hull, 1993, for further details). A 'European put' option, with exercise price K and maturity date T , pays to the holder, at the maturity date and when stock price S r ) is x, the amount max(K-x,O).

The equivalent 'call' option pays max(x - K, 0). We model stock price by a geometric Brownian motion for r in [0, T I , with drift r (the riskless rate) and volatility sigma. So the conditional density of log(Sr)( S (t) = x) is the normal density below, defined as a Maple function.

>f=(x,t,xi) + (l/(sqrt(Z*Pi"sigma 12'(T-t))))'exp(-(xi-log(x)-(r-sigma A2'2(2)' (T-t)) -2 I (2"sigma -2*(T-t 1) 1;

sqrt(2zu2(T - t))

The value of a European stock option is the expectation, conditional on the current stock price, of the payoff at time T discounted at the risk-free rate back to the current time. So we write Maple functions for put and call values as

>P=(x,t) + exp(-r'(T-t))'lnt(max(K-exp(xi),O)'f (x,t,xi ),xi = -infinity..infinity);

P = (x, t) + e(-'T-')) 1" max(K - e', Oy(x, t , 6) dE - >Ce (x,t) -+ exp(-r" (T-t))'lnt (max (exp(xi)-K,O) 'f (x,t,xi ),xi = -infinity..infinity 1;

C + (x, t ) -+ e(-r(T-')) jm max(e' - K, Oy(x, t , 6) d5

Maple V3 has problems evaluating these integrals unless we provide some help. First, split the integrals at log(K) to limit the range; second, use the 'assume' command to restrict the range of certain variables and so ensure convergence.

>xiO=log (K);

(0 + In (K) >assume (t>O);assu me (t<T);assu me (sigma>O);

Now use the 'frontend' and 'expand' commands to break up and simplify the expression to be integrated.

>Pa=exp (-re (T-t))'int (f rontend (expand, [ (K-exp (xi) )Of (x,t,xi ) I ),xi = -infinity..xiO):

>Ca+exp(-r* (T-t) )'int(f rontend (expand, [ (exp (xi )-K)'f (x,t,xi) 1 ),xi =xiO..infinity ):

Now substitute example numerical values (notice the tildes, indicating variables restricted by 'assume'), and evaluate the Put and Call values. The time in seconds to evaluate the 'Put' is shown below the value.

Page 8: The Maple computer algebra system: A review

336 J. HUTTON AND J. HUTTON

>myvais={r =.1 ,sigma =.I ,T'= 1 ,K= 1);

m.yvals=(K= 1, a-=.l, T - = 1, r = . 1 )

>MyPa+subs(myvals, Pa):lblyCa*subs(myvals, Ca 1: >start=time( ):Put = evalf (subs(x=l ,t=O,MyPa));time( )-start;

Put = 0.0079 1892725 1 1 a000

Call = 0.1030815091

The Put-Call Parity expression defined below should be identically zero: again we use the expanded form below to simplify and hence confirm the Parity value.

>paritytCa + K"exp(-r'fT-tli )-Pa-x:

>s i m pi i f y ( " );

>Call = evaif (subs(x=l ,t=O,MyCa));

0

We may also plot P and C: for ranges of x > O or t < T. Both curves display the features predicted by theory. For example, below is a plot of P near maturity-the value should be close to the payoff function (K - A:) +. This plot was quite fast: the time taken in seconds is given by 'time( )-start'.

>sta rt=ti me ( ):plot (su bs (t :=0.95, My Pa ),x =O.. 1.5);time ( )-start;

3.000 >

02 0 4 06 08 1 1 2 1 4

Figure 1 The Put near maturity

0

4. CONCLUSIONS

In general, CA systems, including Maple, are not 'good' at algebra-they will probably not find a solution to a problem that one could not find unaided. Especially if one is not dealing with very long expressions, it may be better to use paper and pencil, to avoid the frustration of having to

Page 9: The Maple computer algebra system: A review

MAPLE COMPUTER ALGEBRA SYSTEM 337

push the software into the appropriate manipulation and get to a recognizable or interpretable expression. However, if one is manipulating large or complicated expressions, computer algebra is quick and rarely makes mistakes, and, as with any complex system, skill pays dividends. More importantly, one may combine the ability to deal with abstract quantities with some of the more usual computer abilities to do rapid numerical calculations, plot the results and run programs.

As a CA system, Maple has most of the features one expects, has a long pedigree, is developing rapidly and is probably one of the best available. There is a large community of users, supplying various publications and contributions to the share library, it appears on many platforms and other software packages contain its kernel. It also has excellent graphical abilities. The student version, which omits the libraries and restricts the scope of certain operations, will be the choice of many and is particularly good value for money.

ACKNOWLEDGEMENTS

We are indebted to John Robinson of the University of York Computing Service for help with this review.

REFERENCES

Char, B. W., K. 0. Geddes, G. H. Gonnet, B. L. Leong, M. B. Monagan and S. M. Watt (1992), First

Char, B. W., K. 0. Geddes, G. H. Gonnet, B. L. Leong, M. B. Monagan and S. M. Watt (1991), Maple V

Harper, D. and R. Chalabi (1992), An Introduction to Maple, Computer Algebra Support Project, Queen

Harper, D., C. Wooff and D. Hodgkinson (1991), A Guide to Computer Algebra Systems, Wiley,

Heck, A. (1993), An Introduction to Maple, Springer-Verlag, New York Hull, J. C. (1993), Options, Futures and Other Derivative Securities, 2nd edition, Prentice Hall,

McCabe, B., and A. R. Tremayne (1993), Elernents of Modern Asymptotic Theory with Statistical

Merton, R. C. (1990), Continuous Time Finance, Basil Blackwell, Oxford. Rust, J. (1993), ‘GAUSS and MATLAB: a comparison’, Journal of Applied Econometrics, 8,307-324. Varian, H. (ed.) (1993), Economic and Financial Modeling with Mathematica, Springer-Verlag, New

Leaves: A Tutorial Introduction to Maple V , Springer-Verlag, New York.

Library Reference Manual, Springer-Verlag, New York.

Mary and Westfield College, London.

Chichester.

Englewood Cliffs, NJ.

Applications, Manchester University Press.

York.