Algebraic programming languages: A scientific tool for chemists

R. M.. "Science ConfmnCl the Creationist Issue." Chern. &Ens. NOW. D. 12 . . (January 18.1982). ... availability and utility of algebraic programming ...
0 downloads 0 Views 3MB Size
do not tell the wholestory. They lackstatistical treatment of the data and do not get into the models that physical scientists huild for the ohenomena with which thev deal. These could be the basis fbr future work. Both simulations are available on flonnv disk. Annle II DOS 3.3, along with supporting handouts. A'iherk for'$10.00 (for earh simulationl should be made oavable to theauthor at the above address. &

-

Acknowledgment The author would like to thank Richard Vercb for his helpful suggestions during the formulation of these simulations. Literature Cited (1) k o t t , L. W. et al., 'Chemical Investigation8 for Changing Tima,-' 3rd ed., Burg-, Minneapolis, 1980. 12) . . Baum. R.M.. "Science ConfmnCl the Creationist Issue." Chern. &Ens. NOW.D. 12 (January 18.1982). (3) Penguin Software, 8304th Avenue, Geneva, IL80134. (4) An example is PmnfoDOS, Beagle Bros, 1315 Sierra Vista, Ssn Diego, CA 92103. (5) Bailey, M., US. Fish and Wildlife Servive, personal mmmunicatinn, 1980. ( 6 ) Thomas. L.."An Epidemic of Apprchcnsion,"Diseouer. 78 (November 1983).

Algebraic Programming Languages: A Scientific Tool for Chemists Thomas E. Raidy University of South Cmlina Columbia. SC 29208 Surely most chemists are familiar with the use of computers to perform extensive numerical calculations or to collect and analyze large quantities of experimental data. However, most chemists are &t aware of algebraic or symbol manipulating programs and languages. These languages have been developed over the last 30 years by computer scientists interested in artificial intelligence and by physicists working in astrophysics, general relativity, and quantum electrodynamics. I t should be emphasized that symbol manipulating languages nerform aleebraic calculations usine svmbols with no numerical value. Mathematical operatiois ranging from addition and multi~licationto inteeration and differentiation nroduce algebraic or analytical expressions as opposed to numbers. For example, the product

-

(X

+ 2 ) * ( ~+ 1)

would yield the result x2+3*x+2

Reports of applications of symbol manipulating.languages - . to problems in-chemistry are i n f r e q ~ e n t . ~ ~ o w e vase rearly , as 1956, Boys et al. (1) used a computer to perform algebraic operations heeded in quantum chemical calculations: More recently Maricq and Waugh (2) emploved the svmbolic (3) i n t h e moment analysis computer program MACSY-k4 of NMR lineshapes. Raidy (4) and Raidy and McCourt (5) applied the polynomial handling capabilities of ALTRAN (6) t o check and then generalize DWBA collision cross section expressions given by Moraal(7). Santry and Raidy (8)utilized the REDUCE (9) language to derive analytical expessions for eaussian dinole moment inteerals necessarv to their numerical calculations of dipole polarkabilities (16). I t is not the intention of this author to present an exhaustive listing of all chemical applications of algebraic languages. Rather, it is hoped that this paper and others (11,12)will help to make the availability and utility of algebraic programming languages more widely known throughout the chemical community. T o 'This mav not indicate a lack of use bv chemists but rather a lack of cmng such &.The a W has wed lh& languages for over a aecade whale only once (51c m g theu use

this end, this paper is divided into three main sections. In the firat, salient references and a brief discussion of languages, of language availability, and of programming problems will be given. In the second, a simple example will be presented in full detail. In the third. the future of aleehraic oroeramminelan" guages in chemical research and Gemical education 411 be briefly discussed.

.

Algebraic Programmlng Languages Four reviews, Barton and Fitch (13), Cohen et al. (14), Brown and Hearn (IS), and Pavelle et al. (16),present agood overview and historical perspective of the development and amlication of svmbolic oromammine - laneuaees. Barton and ~ i i c hgive example piog'ams written in the languages SCRATCHPAD (17), IAM (I@, REDUCE, ALTRAN, CAMAL (19), SAC-1 (20), and CLAM (21). Several other languages are also discussed. Cohen et al. compared and contrasted six algebraic languages; ALTRAN, FORMAC (22). LAM (23),REDUCE, SAC-l.and SYMBOL (24).l'wosample cnlculations from physi*, were tested and timed with each language. These problems have become a standard for testina new symbol manipulating languages (25). Interestingly, another standard is the reproduction of the lunar theory of Delaunay (26).While Delaunay spent about 20 years on his calculations of lunar coordinates, current algebraic languages nerfonn the calculations in a matter of hours or dam . (16). , ,The more recent review of Brown and Hearn provides a general survev of the andications of aleebraic laneuaees and of hvbrid algebraic-numeric computat~ons.~ h i l k&ere are a iarge number of references to paners emolovine laneuaees. - - aleebraic no example programs &e included in the text. The ~ c r i n z f i c American article of Pavelle e t al. is an excellent "informed layman's" introduction to the history and development of algebraic systems. Taken as a whole the four reviews provide a solid introduction to algebraic programming. In choosing which of these lanauages to use, the first auestion would have to be the one ofbro&m availability. ~ y p i cally, most university computing centers have one or more algebraic languages available on line, in either batch or interactive modes. Often several others may be stored on tape, but implementation and debugging of off-line programs are usually the responsibilitity of the user. Occasionally, the lack of local maintenance and consulting expertise can be frustrating for both on-line and tape versions of algebraic languages. On the other hand, recent advances in algebraic programming languages and the proliferation of Motorola 68000 micro~rocessorhased "suner" microcomnuters mav have elimiiated the availability problem. The powerful languages MACSYMA, SMP (27), and Maple (28) will run or are currently running on 68000 based microcomputers (28,29). I t should also be noted that there is a t least one symbolic computer language, muMATH (30,31,32),available for use on several microcom~utersincluding- the TRS-80, IBM PC. and Apple I1 (33). Another important consideration in the use of symbolic languages has to be the ease of programming. Although there are some exceptions, the majority of algebraic programming languages are written in Fortran, in LISP, and more recently in C. For most applications the grammar and syntax used are relatively simple and straightforward. Often the syntax is Fortran- or Algol-like or corresponds closely to standard algebraic convention and usage. Any chemist familiar with Fortran or Basic shouid experience little difficulty withproerammine in aleebraic laneuaees. As well. the interactive " nature ofihese languages (even on many mainframes) greatly facilitates their use and masterv as turn around is ranid and mistakes are immediately apparent. The lanauaues Al.'l'ltAN. ItKI)UCK MACSYMA. SMP. and ~ a ~ l e aprobably re the most appropriate for chemical research a~plications.Of these. MACSYMA. SMP, and Maple are the cl& favorites because of their power andgenerality.

- -

Volume 61

Number 7 July 1984

629

While REDUCE is widely available it lacks many of the features (such as integration) possessed by MACSYMA, SMP, or Maple. ALTRAN, a Fortran-based language, is limited to the mani~ulationof oolvnomials of inteeer order. Elementaw functions (i.e., cos o; sin) require definition by the progra&mer. As a number of algebraic programming languages have been designed to maximize the efficiency of certain classes of mathematical manipulations, considerable efficiencies may be gained by matching problem and programming language. For example, REDUCE possesses special facilities for calculations in quantum electrodynamics. For applications in chemical education MACSYMA, SMP, Maple, and interactive versions of REDUCE could all be of value, particularly as these languages are ported to (super) microcomputers. For immediate use, one may wish to consider the microcomputer package, muMATH. This language apDears to be rather versatile-it is canable of svmbolic integration-and is run in interactive mode. However, storage is alwavs with aleebraic laneuaees and even s i m ~ l e . a oroblem . programs written in &MATH can quickly exceed the memory of many microcomputers. An Example Program

The following program illustrates the general algebraic and algebraic matrix manipulating capabilities of the REDUCE language. The example problem han its nsns in the theory of NMR linesha~esin solids and is a modification of an example presented b y ~ e h r i n g(34). In the analysis of NMR lineshapes, the free induction decay or the NMR spectrum is expressed in terms of a relaxation matrix A (34,35). Calculations based on these expressions are greatly simplified if the matrix A is diagonalized. The QR transform method (36,37) employs a transformation matrix S a n d its inverse S-1 to form the diagonal, eigenvalue matrix E as

E = S-'AS Following the 2 X 2 matrix example given by Mebring, the complex elements of the matrices A &dS are defined in terms of i(i2 = -1) and the three algebraic variables X , Y, and Z. With these variables, Mehring's matrices are

level. This fall, K. 0.Geddes (38) of the University of Wae an inteeral Dart of his first-vear terloo ~ l a nto s use M a ~ l as calcul& course. ~hemi'caleducationkillbe forced to respond to these advances. Just as hand-held calculators trivialized many previously difficult or tedious computational tasks and expanded the mathematical horizons of homework and exam problems, the availability of algebraic systems, possibly even on hand-held calculators (391, opens new vistas in algebraic or hybrid algebraic-numeric computations. has sueeested several a. ~.~ l i c a t i o of n salStoutemver . (40) . gebraic languages in educaiion. For example, imagine a calculator that displays both numeric and dimensional results of a computation. In chemistry several areas of application instantly come to mind. Balancing chemical equations, deriving rate laws from reaction mechanisms, and the factorlabel approach to stoichiometry are just a few. Consider the pedagogical advantage of obtaining the "exact"solution of an equilibrium concentration expression to illustrate the "chemistrv" involved in neelectine hieher-order or smalldifferenceterms in the equigbrium constant expression. Without a doubt. the ootential of aleebraic svstems or merely the elimination of 'tedious and le&hy algibraic mani~ulationsmakes it well worth the effort of learnine or teaching the syntax and grammar of another programming laneuaee. Clearlv. as stated bv Brown and Hearn. aleebraic or s b 6 o l i c computing, either alone or combined with numeric computations, has a brilliant future;

- -

-

Literature Cited (11 Boys, S. F., Cwk. G. B.. Rcevea. C. M.. and Shavitt. I.. Nofure. London. 178. 1207 (1956). (2) Maricq, M. M., and Waugh, J. S.,J Cham. Phys.. 70.33W (1979). (3) Bogen, R.. et al., MACSYMA Reference Manual. Pmjeet MAC. M.I.T., Cambridge, MA, 1974. (4) Rsidy,T. E., Ph.D.Thesis, UniversifyofWste.lw. 1976. (5) Raidy,T. E., and McCourt. F. R., Chem Phys. Left., 38.3W (1976). i 4NJ (6) B m m , W. S.,"ALTRAN User's Manual," 4thed., Bell LaborsLorie, Munay H

.".., ,077

(7) Morsal, H.,Z Naturforsch, 28a.824 (1973):Physico. 68.64 (1973). (8) Santry,D.P..andRaidy,T.E., Theor Chim. Ado,53,121(1979). (9) Hesrn, A. C., "REDUCE User'8 Manual," 2nd ed.. Univusity of Utah. 1973. (10) Raidy,T. E., and Santry, D. P.. Chem. Phw. Lett.. 63,568 (1978). (11) Rsidy,T. E..in preparation. 112) Raidy,T E.. 34th Southeast Regional ACS Meeting (1982). (131 Barton, D.,and Fitch, J. P.,Rep. Progr. Phys.. 35,235 (1972). (141 Cohen, H. I., Leringe, 0 , and Sundblad, Y., Gen. Relotiuity Onmitotion, 1. 269 ,,.,"a \.",",.

+

where s = (i(X - Y) (Z2- ( X - Y)2)1/2)/Z. In the program, the MATRIX statement is used to declare and dimension the matrices A, S, S-I (SI in program), and E. The individual elements of A and S are assigned with the MAT statement. The normal algebraic operators "*", "/",and "*+" take on s ~ e c i ameanings l in exoressions involvine variables declared'as MATRIX REDUCE. The inverse matrix SI is obtained by appropriate application of the "/"operator as SI:=lIS.The transformations of A to E is obtained as E: =SI*A*S. where "*"is the ooerator for matrix multi~lication. The matrices SI and E are calculated and printed in the REDUCE program reproduced helow. Discussion Considering the power of algebraic programminglanguages, it is unfortunate that they are not more widely employed as research or educational tools. This neglect will not last long considering the growing interest in and use of these techniques. In particular, the educational use of these languages, possibly accelerated by the advent of powerful microcomputers, is already expanding rapidly, even a t the undergraduate

630

Journal of Chemical Education

Brown, W. S. and Heam, A. C., Compt. Phyr. Cornm., 11,207 (1979). Pavelle, R., Rothstein, M., andritch, J.,Sci. A m ? . 245,136 (1981). Griesmcr. J. H.. and J e n b , R. D., "Proe. 2nd Symp. on Symbolic and Algebraic Manipulation, ACM,"N- York, 1911,p 42. Christensen, C.,and Ksrr.M., "Proe.ZndSymp.onSymbolieandAlgebraicMsnipulation, ACM," New York, 1971. p. 115. Fitch, J. P., "CAMAL U3cm Manua1,"Compt. Lab., Csmbridge.UK, 1916. Collins. G. E.. "Pme. 2nd Sm. on Svmbolicand Ahbraic Manidation. ACM."NYO&, 1 ~ 1 1 , 144. ~. D'lnuemo, R. A,, and Russell-Clark, R. A , "CLAM Pmgrsmmer's Manual," King'# College. London, 1971. Tobey, R. G., et al.. "SHARE Contributed Pragrsm Library," No. 360, D-0.3.3.M 1969. D'lnverno, R. A,, CompulorJ.. 12,124 (1969). Engeli, M..ACM SIGSAMBuN., 21 (1975). Krssinski, A,. and Perkowski. M.. CompL Phys. C o r n . . 22,269, (1981). Delaunay, C., Mim. Acad. Sci, 28,883 ILffiO). Inference Corp., Computer Mathematics Group, 53W West Century Boulevsrd. La Angeks. CA XO4B Char, B. W.. Geddes, K. O..Oentleman, W. M..and Gonnet, G. H.,Leetvre Notes in Cornpuler Science, 162,101 (1983). Fitch. J.. Lecture Notea in Computer Science. 162,128 (1983). "muMATH," Microsoft Consumer Produc*i.Bellevue. WA. Williams, G., RYTE. 5,824 (1980). Wi1f.H. S.,Arnsr. Moth. Monthly,89.4(19821. "Suurcebwk I, Supplement," Information Sources, Inc., Glen%ew. IL, 1983. Mehring. M., "NMR Baaie Principle and Progres," Vol. 11, Springer-Verlsg. New

..

.

.

.

" . L ,O"U .".n,A".".

(35) Abrsgam, A., "TheP.mipk

0fNuelcarMagnrtlsm." Orford U " i ~ ~ i t y P r a 9London. . 1961. (36) Gordon. R. G., and McGinnk, R.P.. J . Cham. Phys., 49.2455 (1968). (37) Wilkinwn. J. H.. '"The Algebraic Eigenvalue Problem," Oxford Univemity Press. London. 1965. (381 Goddes, K. 0..privstemmmunicstim. (39) Stoutemyer, D. R., SIGSAMBullofin, 14.5 (1980). (40) StouYmyer, D. R..Arnsr J . Phys., 49.85 (19811.