Interactive digital computing in undergraduate ... - ACS Publications

advantage of the availability of APL (A Programming. Language) which is a typewriter terminal oriented time sharing system implemented on a general pu...
0 downloads 0 Views 6MB Size
R. H. Herber a"d Y. H a z o n y ' Rutgers Univers~ty New Brunswick, New Jersey 08903

Interactive Digital Computing in Undergraduate Physical Chemistry

In the present paper we present the results of an educational experiment aimed at incorporating the use of online digital computing methods in the undergraduate chemistry curriculum. In this experiment we have taken advantage of the availability of APL (A Programming Language) which is a typewriter terminal oriented time sharing system implemented on a general purpose digital computer. Despite an initial appearance of complexity, APL is designed to lend itself readily to self-teaching and individual student-paced learning experiences. It can be used within a very wide range of sophistication, starting with the level of a simple desk calculator performing elementary arithmetic operations, up to highly complex manipulations of multidimensional arrays and tensor algebra. The neophyte student, having access to an appropriate terminal, learns a few simple ground rules related to the mechanics of establishing contact with the computer (via telephone connection) and then can start using the system for problem solving in such a way that the degree of sophistication increases with the experience of the user up to a level reflecting his personal inclinations, motivations, and needs. The ease with which students may be initiated to the use of APL makes it an outstanding tool for the introduction of methods of digital computation to large classes of users who otherwise may never make use of such tecbniques in their classroom or laboratory experience. In the present paper we shall describe some of the s~mplerfeatures of APL for the purpose of illustrating the application of this language in a typical undergraduate chemistry program. Rutgen undergraduate chemistry majors have for a number of years taken a combined physical-analytical laboratory course in partial fulfillment of the requirements for the bachelors degree in chemistry. This course, which consists of 1 hr of lecture and 5 hr of laboratory per week for three 14-wk semesters (the fourth semester is spent on a senior research problem under the guidance of a member of the faculty) combines traditional physical chemistry experiments with instrumental analysis and spectroscopy, and exposes the student to a wide range of techniques in these areas. Among the experiments undertaken during the first year are those listed in Table 1. Students carry out the laboratory work in pairs, and submit a written report within two weeks of finishing the experimental aspects of the assignment. For some time the Center for Computer and Information Services (CCIS) at Rutgers University has been offering a broad range of courses in computer programming techniques for scientific usage, including Fortran IV, PL/1, and Basic, and makes these available in a variety of formats and learning situations. Past experience has shown that with the exception of undergraduate chemistry majors who are doing their senior research in the area of X-ray diffraction studies or theoretical chemistry, there is only a very small incentive for students to become sufficiently conversant with programming techniques to make substantive use of the digital computer in their undergraduate studies. Consequently, only a very small number of graduating chemistry majors have, in the past few

Table 1. First Year Experiments in a Physical-Analytical Laboratory Course -. - . I I1 111 IV V

Vibrational (HCl) and Electronic (Id Speetmsmpy volumetric Calibration Grevimetrie Determination of Lead Molar Refraction Salubility of CaSO. VI ~ ~ t i vcoemcient i t ~ of HCI and its ~ e ~ p e ~~ e~ pt e ~~ dl ee ~ e e VII Onsager's Equation and Condvetivity VIII Calorimetry I X Potentiornetric Titrations X Gas and Liquid Phase Kinetics X I D i ~ Moments k of Pure Liquids XI1 Magnetic Susceptibility by the Gouy Method e of Visermity XI11 V i r o a i t y of Mixtures and T e m ~ a t u r Dependence XIV spectroscopy of Iz&ewis Base Complexes X V Redox'ritrations

years, achieved a fluency in programming which is developed to a useful point at the time a t which they are ready to enter upon graduate study or an industrial job experience and are potentially ready to apply these techniques in the pursuit of their research problems. In an effort to overcome the understandable reluctance of the typical undergraduate chemistry major to learn c o v u t e r programming, a new approach to this problem has:been sought for some time. The requirements for this new approach are that the time needed to become articulate in the programming language be minimal, that the computational results be available at an early stage of data processing (i.e., rapid "turnaround" time), that the method of learning the programming techniques be largely one of self-teaching so that different students could pace themselves according to their abilities and interests, and finally, that the data input and output -could be performed uia a remote terminal readily accessible to the students, and useable in small time segments. The development of a new programming language, called APL, appeared to meet essentially all of these demands, and an introduction to the use of this language was incorporated on an experimental basis into the second semester (junior year) of the physical-analytical laboratory course referred to above. APL/360

APL (standing for A Programming Language) was originally developed by 1verson2 and is fully described by Falkov and Iverson3 and in a number of user-oriented manu'Also affiliated with the Computer Center, Princeton University, Princeton, New Jersey. 21verson, K. E., "A Programming Language," John Wiley and Sons, New York, 1962: Iversan, K. E., "The Use of APL in Statistics and Statistical Computation," Academic Press, New York, 1969.

3Falkov, A. D., and Ivenon, K. E., "APL/360 Users' Manual," 2nd Ed., T. J. Watson Research Center, I.B.M. Yorkt m Heights, N. Y., 1968 (GH20-0683). 4See for example: "APL/360 Primer," (Editor: Berry, Paul) IBM, Yorktown Heights, N. Y., 1971 (GH 20-0689-2);Berry, P., "APL/360 Primer, Student Text,'' IBM, Yorktown Heights, N. Y., 1969 IC 20-1702-01; Gilman, Leonard and Rose, "APL/360, An Interactive Approach," John Wiley and Sons, New York, 1970. (It should be noted that a bibliography of nearly 100 titles can be accessed from the "Public Library" (see tent) by executing the command )LOAD I APLBIB.) Volume 51. Number 4, April 1974 / 245

'

als.4 The version which has been in use in the presently described course is called APL/360 and uses the Rutgers IBM 360/67 computer. There are several input/output devices, of which the IBM 1050 or 2741 keyboards, the Tektronix Model 4013 or University Computing Co. UCC Model 1035 Terminal or the Datel Model 30 are typical examples. These keyboard terminals are coupled to the central computer h j a dial-up telephone connection using an acoustic coupler such as a Western Electric 103-A2 Dataset or a UCC Model 90 coupler. A special APL character set typing element is used in conjunction with the keyboard terminal. The character set consists of 26 upper case letters, the ten digits, and 52 special characters as shown in Figure 1. In typewriter ter-

(user enters) (computer response)

A name can also he assigned to a vector which is an ordered sequence of numbers, which can then he operated upon. For example, defining the vector V as the first five 1 2 3 4 5 (or more integers, can he done by typing V simply V- r5) Each element in the array can he accessed by using the square bracket notation, so that the first element of V is V [I] ( = I ) and the fifth is V [5] ( = 5). The sum of the elements can he ohtained by typing +/V, which elicits the response 15. The number of elements in the vector is ohtained by typing pV, so that the average value of the elements in the vector is ohtained by typing (+/V t pV. Two vectors (of equal length) can he combined in a sequence of normal arithmetic operations. For example, if

-

(user enters) (user enters)

(computer response)

Figure 1 . The APL character set for the keyboard terminal

(user enters)

(computer risponse)

minals, both input (user commands) and output (computer responses) appear on paper, giving the user a "hard c o ~ v "record of the whole terminal session. This feature is es&cially useful during program writing and "debugging" sessions and is of particular use to students. Interactive display terminals dhich do not produce "hard copy" will he discussed below. The four most common arithmetic operations are denoted by the usual symbols "+ - x c," while exponentiation is represented by the symbol "*." Data, whether consisting of a single numher, an ordered sequence of numbers, or the result of a previous calculation, can be represented by a letter, a word, or a string of letters and/or digits beginning with a letter. Literal input is identified by being enclosed in quote marks. Mathematical expressions are evaluated from right to left within parentheses, and therefore do not obey the normal arithmetic hierarchical rules. Square brackets are used to denote subscripts or elements of an ordered array. Some Simple Examples of Operations

Mathematical expressions entered will be executed by pressing the carriage return key, and will immediately he printed out, while named expressions can be called on demand. For example, typing 3 X 4 and pressing the carriage return will cause the output device to respond with 3 results in the re12. Similarly, typing (3 x 4) + 2 sponse 2.4 (note that execution proceeds from right to left; that is, 3 is added to 2, and that result is the divisor for 12. Typing ((3 x 4) + 2) 3 results in the response 9. If data are assigned a name (by use of the backward arrow symbol), the numerical result can he ohtained by manipu3 x 4 and B lating the names. For example, typing A 1 + 2 assigns to A and B the values 12 and 3, respectively, and stores this information subject to recall. To obtain a printout of those values the user types A (or B) and presses carriage return. The actual sequence is

+

+

-

+

(user types A and presses carriage return) (computer response)

4

A*B

(A to the power of B)

1728

The same results would be ohtained if the user types in the actual numbers, instead of A and B 246

/ Journal of Chemical Education

from which it is seen that each element in one vector is appropriately operated on by the corresponding element in the second vector. In the preceding examples, it should he noted that the user input is indented six spaces while the computer response appears at the beginning of the line. This distinction is performed by the computer which indents the line prior to unlocking the keyboard in anticipation of user input. As is seen from the foregoing where use has been made of the symbols +/ and p, one of the most powerful and convenient aspects of APL is the representation of a complex mathematical operation or series of operations by a sinale character or small moup of characters (sometimes generated by a combination of hack-spacing i d overtypi n d . Thus the characters + / V sum all of the elements in the vector V and the symhdl p counts the number of elements in the vector which follows this symhol. Similarly, the symhol 0 unlocks the typewriter to accept numerical input and the symhol which is achieved by typing n followed by a backspace and a ' unlocks the typewriter to accept literal (alphabetic) input. I t is this convenient representation of a complex set of logical and/or arithmetic steps by a single character or set of characters which makes programming in APL such a readily learned skill, even for those students who have no prior knowledge of programming logic, flow diagrams, or control statements. The Function Definition Mode

One of the most useful aspects of APL/360 is the utilization of the function definition mode which is entered by typing the APL symbol v ("DEL") followed by the function name. In this mode, variables can be defined and operations on them may be specified in a logical sequence of steps which are executed by the computer in turn when the program is called for by name. As an example, cousider a simple program which will calculate the volume of a sphere of given radius. Such a program may appear (in its simplest fonn) as follows v VOLUME (entered by user) [ll (computer response) At this point the user enters the content of the first line which instructs the computer to ask for an input which will correspond to the variable R. The first line will read [I] R-o with the character 0 signifying a request for input. After

pressing the carriage return the computer responds with the next line number, which in the present example will be (21. The program when completed may read as follows (11 R-0 [2] V-(4+3)~3,142XR*3 [3] 'THE VOLUME OFA SPHERE OFRADIUS ';R;' IS:';V v

While the second line contains the actual computation, the third line is an instruction for mixed output producing a printout of the statement THE VOLUME OF A SPHERE OF RADIUS "R" is "V' where " R and ''V'denote the corresponding numerical values for these variables. Line [3] also contains the symbol v used to close the function and return from definition mode to execution mode. Once the above function has been defined the student may call for its execution by typing (entered b y user) VOLUME 0: (computer response) (a numerical value entered 1 THE VOLUME OFA SPHERE OF RADIUS 1 IS : 4.1893

of any dimensionality as well as on the results of an operation of another function, this being in fact a function of a function. Functions may operate on each other or he linked to each other in a very simple and powerful way, the details of which are beyond the scope of the present discussion. However, from the preceding simple examples, some of the versatility and power of the APL language in permitting the user to catenate a sequence of calculational steps into a larger program, should be evident. An example of a somewhat more complex program, useful for carrying out a least-squares linear regression calculation and for plotting the data, is shown below.

by the student)

The function SPHERE may he expanded to

,-, '.

(21 [3] [4] [5]

-

V-(4+3Jx3.1416xR*3 'THE VOLUME OFASPHERE OFRADIUS ';R;'IS :';V S-4x3.1416xRY2 'THE SURFACE AREA OF A SPHERE OF RADIUS ';R;' IS :';S [6] RATIO-S+V [ I ] 'THE SURFACE TO VOLUME RATIO OF A SPHERE OF RADIUS ' ; R [a] 'IS :';RAT I 0 v

By typing SPHERE the student calls for the execution of the above function. The computer responds by returning "a:" at which point the student may enter a numerical value for R, or he may decide to use the function SPHERE to study the functional relationship between the different variables involved over a certain range of values for R. To do so he may proceed as follows SPHERE 0: -

13 THE VOLUME OF A SPHERE OF RADIUS 1 2 3 IS :4.189 33.51 113.1 THE SURFACE AREA OF A SPHERE OF RADIUS 1 2 3 IS :12.51 50.21 113.1 THE S T O V RATIO OF A SPHERE OF RADIUS 1 2 3 IS :3 1.5 1

iiij

TJO YOU WISH A PLOT OF x VERSUS Y? TYPE YES OR NO'

There is an extensive literature related to more complex and sophisticated programming techniques using APL, lying outside the intent of the present discussion, to which

-

The computer returns with results for each member of the 1 2 3. These results are stored under the vecvector R tor names R, V, S, and RATIO. The student may now choose to display the functional relationship of these variables by plotting them against each other. For example he may type 20 20 PLOT V AND S VS R and the computer responds by providing the plot shown in Figure 2. (It should he noted that the functions PLOT AND and VS are accessible from a "public library" collection of functions. For more detailed information on the use of such libraries, the reader is referred to footnote 4. A program may easily he modified or edited from the terminal. Simple procedures are available for insertion of new lines, deletion of lines, or editing the content of a specific line. The name of the function may be redefined in such a way that the function will operate on data already existing in the "work space" utilized by the user in the memory of the computer. A function may he defined to operate on number arrays

Figure 2. Computer plot of volume and surface of a sphere versus its radius.

Volume 51. Number 4. April 1974

/

247

the interested reader is referred. The mastery of such techniques by advanced students is facilitated by the dialogue-type of interaction between the user and the computer, which is one. of the characteristic ( b u t n o t unique) features of this laneuage. - - This characteristic, in turn, makes feasible a trial-and-error approach to the learning of nromammine methods which reinforces student interest anh ogginalityvin solving programming problems in an individual way. Introduction of Students to APL There are several features of APL which make the introduction of this language into an experimental physical analytical chemistry course rapid, and compatible with a variety of course formats. Among these are (a) the high syntactical content of the language which permits the ready combination of literal text, common arithmetic symbols and notations; (b) the."forgiving nature" of the APL system which causes the computer to reply to a programming mistake with an "error message" which gives the user the immediate chance to "try again;" and (c) the rapid response to an input command (request for execution) which is characteristic of time sharing systems and which is particularly advantageous in a self-teaching environment. With these factors in mind it is easy to see why the introduction of this material into an undergraduate physical chemistry course is straightforward, and demandine of verv little in the way of formal class time. Most of the ultimate student's proficiency derives frnm the self-teachine: and self-paring character~sticsof the APL/ 360 approacTh already referred to. During the . past year, APL was introduced into a junior year chekistry course by giving the students two one hour lectures which covered the following topics I. First Hour A) General comments about digital computers and their role in solving calculatianal problems B) A general description of APL-time sharing versus batch pr&essingof data C) Directions for unlocking.the keyboard and accessing the computer D) Simple keyboard procedures E) The functiondefinition mode and its use 11. Second Hour A) Some sample programs and explanation of literal input and ~

--

o,,tn,,t -..

H I Editme and de-bugging a pruvam (', 1)pfinitlonuf workcpnrer and their mnnngement D IThe saving of programs and etfirienr urc uf availnhle w m k -

space

E) Accessing public library material and the copying of programsfrom one workspace to another F) Workspace security and control At the end of this second lecture, each student pair was assigned an individual account number which permits access to the system (log-on procedure) and were instructed to proceed on their own. The computer terminal in the School of Chemistry is located near the physical chemistry laboratory and is available to undergraduates during the normal hours during which the building is open. APL is accessible on the central computer facility from 9 AM to 12 PM on weekdays and from 9 AM to 3 PM on Saturdays. Students are free at any time during these hours to make use of the terminal for self-teaching, programming, and data reduction. In connection with the physical-analytical laboratory course described briefly in the introduction, the students were given the following "gmund rules" (a) there is complete flexibility with respect to how much or how little use is made of digital computer methods in conjunction with in the course; (b) students are the experiments not charged for computer time and hence can spend as much time on the terminal as they wish; (c) there is no formal examination in the course with respect to knowl248

/ Journal of Chemical Education

edge and understanding of APL/360 programming techniques; (d) computer calculations-provided as hard copy output from the terminal-is acceptable as part of the experimental writeup if supported by a description and sample calculation to permit adequate checking by the instructor; (e) each student pair is required to submit prior to the end of the semester one original, non-trivial program appropriate to data reduction of one of the laboratory experiments, together with a sample calculation obtained by executing the program. Student Response As might be expected, student response to APL has spanned a very wide range, although in general the students considered the material introduced in conjunction with programming to be among the most interesting and useful in the course. One measure of this response is provided by the user statistics supplied by CCIS and summarized in part in Table 2, which pertains to one 4-wk time period during the middle of the Spring semester. Table 2. Student Pair 1 2 3 4

5

6 7 8 9 10 11 Average

User Statistics for One Four-Week Period Connect Time (mh) 380 1334 632 182 225 5119 160 159 85 8.5

417 372

CPU Time (-) 64.5 716 402 2.2 52.1 287 21.8

67.4 69.6 0.74 121 164

Connect Time CPU Time (-1 353 112 94.2 496 259 106 442 142 82.1 692 207 271

-

*The average ehould not be mistaken for the weighted mean of user statistics. since thia does not differentiate between the heavy and the light user, see teat.

From this compilation it is evident that terminal use ranged all the way from 1334 min (by a student pair who were so fascinated by the possibilities offered by digital computer programming that they became-to use the common parlance in the field-"computer freaks") to a miniscule 8.54 min (by a student pair, one of whom had developed an advanced knowledge of Fortran IV programming techniques, and preferred this language over APL). The average connect terminal time for 11 student pairs was 372 min. The average CPU (Central Processor Unit used in carrying out user instructions and actual arithmetic data processing) time was 164 sec. The average ratio of connect time to CPU time was 271; that is, the actual computer time used was approximately 13 sec for every hour of terminal use. These numbers are somewhat misleading, however, since they give equal weight to the T,/T, ratio for the heavy and the light user. A more realistic estimate is obtained from the ratio of the sum of T, and T, for the whole class and this calculation leads to the relationship T, 130 T,; that is, the typical learning undergraduate user requires about 1 sec of CPU time for every 2 rnin of terminal connect time. Current charges at the Rutgers University C.C.I.S. are $3.60/hr of connect time and $216/hr of CPU time, so that the average cost per student during the sample month was $22.32 for connect time and $9.84 for CPU time, for a total of $32.16 per student pair. (This figure can he compared to approximately 3-4 hr of a teaching assistant's time per student pair per mouth a t present compensation rates for teaching assistants in U. S. Universities.) Pedagogical Assessment

-

The teaching value of the introduction of undergraduate students to APL/360 programming can be considered from a number of different, but interrelated, viewpoints. First, the student has learned a new technique of data

organization and reduction, comparable to the use of the slide rule, a desk calculator, or a drafting set. By itself, this technique will not enhance his knowledge of chemistry or his understanding of nature. But, in conjunction with the other skills learned in the laboratory or the lecture hall, it will provide him with an enhanced ability to carry out his activities as a scientist. In this context it should he remembered that most undergraduate (and many graduate) students are "afraid" of computers, just as they were once (or still are) afraid of mathematics. Since the introduction of APL/360 to the point where the student is put on his own is very brief, and he can thereafter he left to a self-paced program in which he proceeds a t a speed governed by his own motivation and comprehension, be rapidly surmounts the fear of computer methods in data analysis. The fact that programming errors are susceptible to self-correction by the student probably contributes to this ready student acceptance. In this context it should, however, be pointed out that in no sense does the APLJ360 system satisfy all digital computation needs. Clearly there are many calculational problems in chemistry (for example those which require very extensive data files such as X-ray diffraction data reduction or wave function calculations, to name only two ohvious cases) which are not amenable to solution by presently available APL methods or are more efficiently executed by other programming methods. The solution of such problems clearly requires the students' learning of other programming languages, such as Fortran IV. Present experience sunnests verv stronelv that students, who have heen introduc'eb to digkal computer programming via the APL aproach outlined in the present discussion, master a second computer "language7' much more readily than those whose initial experience is based on Fortran programming. Moreover, mastery of both languages is advantageous in a wide variety of situations in which a sub-routine or initial data reduction can he executed by means of an APL program, thus furnishing refined data input to a more extensive (and time and money consuming) calculation processed by use of Fortran-based programs. Secondly, in terms of the use of APL in conjunction with the undergraduate physical-analytical chemistry course referred to in the introduction, it is clear that students carry out a much more detailed data analysis of the results of their laboratory experience. Clearly this permits both the student and the instructor to focus attention on the fundamental chemical and physical principles involved in the experiment, rather than to force the student to carry out the same calculation repeatedly for a large number of related data sets. To cite a simple example: Once a student has written for himself (or has copied from the public library) a leastsquares fitting and linear correlation program, he is very much more likely to use such programs to carry out a regression analysis of his data and to decide whether, in fact two parameters correlate with each other, (and if so, how well) than if he had to hand calculate such a relationship. Programs of this type are readily stored in the individual users' library, and can be called into the active workspace by a simple command message. The ready accessibility of such "utility" programs to the student facilitates the meaningful treatment of experimental data and the estimation of systematic and random errors associated with the data derived from experiment. In this connection it should he noted that since the link to the central computer is uia telephone line, the typewriter keyboard terminal can he set up in a location that is close to the laboratory facility in which the student carries out his experimental work. Such proximity and convenience again knhances student use of computational methods in data reduction, often while the experiment is in progress. The advantages of this feature-and its relationship to "on-line" type data reduction-are substan-

tial, and can be utilized to provide an introduction to the student of "real time" processing of experimental results. Future Prospects As experience is gained with the present hardware and software capabilities of the APLl360 system, a variety of new and innovative uses of digital computing techniques can he exploited by the instructor. Most promising of these is an interactive display terminal in which the input and output characters are displayed on an oscilloscope screen rather than giving paper "hard copy." In conjunction with fast plotting routines which are available commercially, it will be possible for the instructor to vary one (or several) parameters in an equation and obtain from the computer a family of curves which illustrate the effect of this variational treatment. When this computer response is plotted on the oscilloscope the instr;ctor can readily call the attention of the class to the salient point which is demonstrated. Examples of such use which come readily to mind include (a) The effect of temperature or atomic (or molecular) weight on the shape of the Maxwell-Boltzmann distribution curve; (h) The effect of changing the ratio of parent to daughter half-lives in a sequential nuclear decay process thus illustrating the concept of transient and secular equilibrium; (c) The effect of concentration of a complexing agent in the spectral analysis of two and three component equilibrium systems; etc. It should also be noted that the interactive display terminal capability lends itself ideally to a discussion of the statistical analysis of experimental data (via histogram and bar graph plotting of the data, among others) and to a discussion of appropriate plotting techniques for the display of experimental results. The potentialities for imaginative exploitation of such a peripheral display unit are almost limitless. Finally, it should he noted that the use of an interactive display terminal does not necessarily require sacrificing "hard copy" output of the computer executed results, since a device is already available which-with the push of a single button-will provide a copy of whatever information is displayed on the terminal at the moment of execution. This feature lends itself very readily to the generation of a data set which can then be copied and distributed to the class participants for further consideration. It is also possible with presently available systems to reproduce t h e interactive-display terminal scope face via closed circuit television on any number of TV receivers strategically placed around a large class room or auditorium. he use of such a system for teaching and demonstrating to large classes is, of course, ohvious. Summary and Conclusions In the present discussion the use of APL as a programming language in conjunction with high speed digital computer usage in an undergraduate experimental chemistry course has been presented. The major advantages of this language and the APLJ360 system lie in the selfteaching (and self-pacing) character of the approach and the early utilization by the student of the results of his programming skill. The incorporation of APL programming techniques into a typical undergraduate physicalanalvtical lahoratorv course has been described and the extehsion of such methods to further use of computational methods in the undermaduate and maduate chemistw curriculum has been inbicated. The very substantial stident interest in the mastery of this computer language has been amply verified by actual classroom use with junior level chemistry majors. The authors are indebted to Mrs. D. Dickenson for numerous helpful discussions and the Computer Center of Rutgers University for partial financial support of this program. Voiume 51. Number 4, April 1974

/

249