Skip to content

Execution Time

Vector 7:4, page 25

The text of this article is not yet online. No complete scan of this issue has been found. The only copy found, on vector.org.uk, is damaged: its page images are lost, but the text machine-read from them survives, shown below (help find a scan).

Unedited OCR text, machine-read from a scan now lost: it contains errors, and its APL is wrong. Shown for searching.

VECTOR Vol.7 No.4

Execution Time

by Alan Sykes

of this short note is to discuss the execute  function # and to present some important ways it can be used with great effect.

What is ¢? Newcomers to programming sometimes have difficulty distinguishing between string variables’ and numeric variables’. For example in APL, the definitions

At'4 2 3! Bet 23

are quite distinct. To see this note that pB yields the answer 3 5. This is because A has allocated to it five characters-'4', ' ', t2', 't ', '3t; in fact the APL expression A+'i1',' ','2',!' ','3' is equivalent. Further differences arise if we try to execute the commands

1+B 234

At+A

A+Aé A

The statement with A can be rectified by executing  A first.

A+2A 234

showing that the string contents of A have been converted into their numeric equivalent.

The use of ¢ however is more far reaching than this. Let's take a slightly different example.

25

VECTOR Vol.7 No.4

Aw'Be1 2 39 4!

The string contents of A now contain an executable APL statement. So not surprisingly when A is executed, the statement in quotes is processed by the APL interpreter.

1234

At the very least this provides one with a mechanism for repeatedly executing a complicated APL statement without having to write an APL program - possibly an attractive proposition for teachers who would like their students to use programs as soon as possible but cannot afford the time to show them how to write programs in APL. (Of course direct definition is a much better approach in this situation.)

However there number of ways in which execute can be exploited with great effect, particularly in the area of making choices within a following sections demonstrate some ideas on this topic.

Incidentally, if we wish to allocate a string variable to B in the above example, then we must use a repeated quote:

AC'Be''1 2 a qere 4 Bea 2.3 48

Choices Suppose program, you have a variable can take the values 1, 2. Also suppose that if C=1, you wish to perform PASK1, whilst if C=2, you wish to perform TASK2. If TASK1 and TASK2 both require a right argument X say, then instead of branching on condition C, # may be used in the form:

a'TASK',(¥C},' X'

26

VECTOR Vol.7 No.4

This works because if C=4, then +¢ (format C) becomes the character 1  and so the argument of « is the string 'TASK1 X'. (Note the space to the left of xX  is crucial.)

Asecond possibility for choice in programming makes use of the fact that

1/'THIS IS A STRING! THIS IS A SIRING'

whereas

O/'THIS IS A STRING

What is happening here is that the Boolean reduction 1/'CAT" giving the string AT  ) is being used with a scalar argument (1 or 0) which is then effectively replicated to the same size as the string - hence 1/.... gives the whole string, whilst 0 /.... gives the null string.

Hence an alternative version of the previous choice of TASK1 and TASK2 can be written

2(C=1)/'TASKI X! £(C=2)/'TASK2 X'

This use of « is particularly useful in programming, conditionally to execute a statement or pass through to the next line, without the need to branch.

IE ... THEN ... ELSE This is a familiar construct in many programming languages, but not in APL. But if you want it, because you feel it helps you to read your programs, then you can have it, at the expense of writing three small programs. The idea is to construct IF, THEN, ELSE so that we could write an APL statement such as

IF Csi! THEN 'TASK1 X' ELSE TASK2 X'

First the program ELSE which is designed to combine the two executable statements into a two-row character matrix.

27

VECTOR Vol.7 No.4

9 R+LA ELSE RA;M [1] a RA is or scalar APL command (2) «® LA is string vector or scalar C3] a Ris a two row matrix containing both commands C4] M«(pLA+,LA)[pRA+,RA C5) R+(2,M)p(M+tLA) ,Mt+RA v

Re'X+1 2 3' THEN 'X+1 2 3 4! R xX+1 23 X14 234 eR 29

Now THEN uses as its right argument the two-row matrix constructed by ELSE, and together with its left argument which when executed tells it which row to select, returns the command to be executed.

VR+CONDITION THEN ACTIONMAT C1] R+ACTIONMAT[1+~s*CONDITION;] v

And finally, a syntactic sweetener’ IF which merely executes its right argument

VIF STRING [a3 sSPRING v

Hence piecing these together we can write, for example:

C+t IF 'C=1' THEN 'X+1 2 3' ELSE 'X+1 &! x 123 c+2 IF '@=1' THEN 'X*1 2 3' ELSE 'X+1 u! x 1234

28

VECTOR Vol.7 No.4

A MENU Program

this article, we use # to construct a MENU program which activates a set of different functions by the careful an appropriate key.

First we define the keys to be used; for example assume that there are four tasks denoted by the keys A,B,C,D.

Secondly, we wish to explain on the screen what the options are that are selected by these keys. So we might use the BOX program of a previous issue to construct a matrix called EXPLAIN.

EXPLAIN*BOX Option 1/Option 2/Option 3/Option 4/' EXPLAIN Option 1 Option 2 Option 4 Option 4

Thirdly we list in matrix form the action programs that require execution. (Each line of ACTION could be a complicated APL expression which requires execution when selected.)

ACTION+BOX 'ACTION1/ACTION2/ACTION3/ACTIONG/MENU/'

Then a MENU program might look something like the following.

VMENU [13 Choose one of the following using only the keys ',KEYS [23 KEYS,‘-',' ',EXPLAIN [33 *, ACTIONCKEYS11403] v

Some readers may not be familiar with the use of the 1 symbol in this way (usually referred to as the dyadic iota’ construct). It is basically a vector look-up table function. For example

342 Gel

29

VECTOR VoL7 No.4

as the first occurrence side is in position 2. Similarly

'BACD'1'A'

However, note what happens when there is no occurrence.

"BACD'1'X!

What is returned is 1 more than the length of the look-up table.

Hence in our application, KEYS: 1+] returns the value 3 4 according to the first key pressed equalling A,B,C,D and if the first key pressed is not in KEYS. To cater for this case we have appended MEWU to the end of the action list so that if an incorrect key is pressed, the menu is repeated.

(Note also the reason for the comma after the execute symbol. This is because the argument must be scalar or vector. As the code is written, 1+1] returns a vector of length 1 and hence the indexing of ACTION uses hence a one line matrix is created.)

As you can basic MENU program is very concise, and a good demonstration of the usefulness of the execute function.

30

VECTOR Vol.7 No.4

British APL Association Monthly Meetings

From February 1991, we have decided to change the venue of our monthly meetings in London. Meetings are now be held at the Institute of Electrical Engineers, Savoy Place, London (nearest tube outlets: Temple or Embankment). The committee believe that this move will greatly enhance the quality of our monthly meetings - but they are still free, and of course non-members are still most welcome. Come along and see if we’ve made the right decision.

Date Venue Event

26 April IEE London BAA Meeting: Vendor Forum

7 June IEE London AGM and BAA Mesting: Modern Productivity Aids for APL

20 September IEE London BAA Meeting

25 October iEE London BAA Meeting

22 November IEE London BAA Meeting

, 42D er i Slog SNE an c XY

WATERLOG

a Renaissance Data Systems

Enlightenment Thru Information Processing

ALL APL BOOKS IN PRINT

Catalog excerpts as of September 1, 1990

ACCOUNTING STRUCTURED IN APL. ljiri, 1984, 491p. $10.00 The basic principles of accounting with numerous APL

COMPUTING IN STATISTICAL SCIENCE THRU APL, Anscombe. 1981, 426p. Lots of statistics and APL. His workspaces are available from Yale University. ci

MATHEMATICAL EXPERIMENTS ON THE COMPUTER, Grenander. 1982, 525p. Case studies using APL in a number of fields, including statistics, linear algebra, geomet networks, invariant description and analysis of APL. functions in all topics discussed.

PROBABILITY IN APL, Alvord. 1984, 142p. A delighttul, yet seflous development of 3 ; mutations, geometric distributions, and the World Series. Friendly examples. No previous APL required. DISKETTE FOR ABOVE containing functions covered in book.

APL WITH A MATHEMATICAL ACCENT, Jones, Reiter. 1990, 200p. $41.95 Specialty written for use in advanced of college math course:

APL - THE LANGUAGE AND ITS ACTUARIAL APPLICATIONS, de Kerf, 1987, 223p. Introduction to teserves, credibility, probability, numerical analysis, forecasting, with APL functions.

COMPUTATION FOR THE ANALYSIS OF DESIGNED EXPERIMENTS, Meiberger, 1989, 683p Analysis of the construction of ANOVA programs using least squares techniques, including ighich a language specification is intexpreted, Emphasizes the neoraty as well as the algebra of the methodology. All programs in the are included on 5 1/4" diskettes in APL, BASIC, C, and FORTRAN.

APL2 AT A GLANCE, Brown, Pakin, Polivka. 1988, 444 p. Solid, unintimidating, introduction to APL2. Clear lilustrations,

LEARNING APL: AN ARRAY PROCESSING LANGUAGE, Mason, Emphasis on arrays, naturally. A readable, with thorough exal

APL - ADVANCED TECHNIQUES AND UTILITIES, Bergquist. 1986, 450p. Good discussion of altemative approaches to range of programming 8 documentation, fila design, boolean techniques. Assumes knowledge of the basics. Many idioms worka| DISKETTE FOR ABOVE. Contains all func ext. Formatted tor APL*PLUS/PC, uploadable to VS/APL, APL2.

APL AS A TOOL OF THOUGHT, PROFESSIONAL DEVELOPMENT SEMINARS, NY/SIGAPL; The first 5 years. A.wide range of topics in education and business, Logic, insurance, statistics, A. I, accounting, fractals,teachers toclbox, computer science, biology, graphics, engineering, data bases, and much more, 1989 - 1987, approximately 342.00

317.50

$89.00

$59.95

$35.00

$21.50

$44.95

». $15.00

APL&9 - STATISTICS TUTORIAL, Alvord, Traberman, et al, 72p. A.unique collection of papers on statistics and its exposition in API $10.00

pee meee EE "

| Name: Date: Payment in check or money order payable | in $U, S. must accompany order. Send to: reat: enaissance Data lems: Street: Renal: Data Syst P.O, Box 20023 Park West Finance Station | New York, New York 10025-1510 | Oty: State: Postal Coda: (212)864-3078

| Country Telephone

| We regret that we cannot accept purchase orders or credit cards,

| Title Price Quantity ___ Total

| Title Priea Quantity ___ Total

| Tite Price Quantity Total

i Subtotal: Postage and handling - US, and Canada ($2.50 minimum: $2.50 each item over $25.00}: + International {surface mail add 15%, airmail add 40%): |

Total:

Thank You For Your Order!

Please send complete CATALOG of APL books and software a | Nae ee ee ae ~~ a

VECTOR Vol.7 No.4

THE

RANDOM

VECTOR

The Newsletter of the APL Statistics Library Editor David Eastwood

April 1991

Contents Editorial David Eastwood 34 The Third ASL Conference 35 The Genesis of ASL (2) Tony O’Hagan 36 The Regression Shelf Alan Sykes 41 Sterling’s Function: a Case Study in APL David Appleton 47

33

VECTOR Vol.7 No.4

Editorial

In this second issue of Random Vector’ Tony O'Hagan continues to explore the genesis of the ASL project, seeking to prove that if no one present at a meeting can remember what was said, he who writes something down creates the history! During the period in question (late 1988 to date) I have been a member of both the BAA Committee and the ASL Management Committee and so J can add some comments regarding the feelings of the BAA Committee when we were first officially approached for funding. I think it is fair to say that there was an immediate and enthusiastic acceptance of the ASL project within the BAA - we felt that ASL combined a number of themes dear to our hearts:

+ ASL represents a means of demonstrating the appeal of APL in a key area of current usage.

+ Within that area, ASL offers a route to enhance APL’s level of acceptance by supplying the basic, tested, algorithms that new users have a right to expect.

+ The proposal seemed unlikely to receive any commercial funding.

+ The project proposals seemed to be realistic and not over ambitious

The initial queries raised by the BAA were largely concerned with points of detail within the various proposals put forward by the ASL team.

In the first issue of Random Vector we gave a brief overview of the contents of the Bottom Shelf’ ASL functions. By the time this issue is delivered the official launch of ASL will have taken place at the March 1991 meeting of the BAA. In the run-up to this launch, a meeting was held on February 12 1991 at University College Swansea. Maurice Jordan and Jake Ansell braved the uncertainties of British Rail and its snow. Norman Thomson was unable to be present but communicated by telephone. Also present were Alan Hawkes, Alan Mayer and Alan Sykes from University College.

A profitable day was spent reviewing the mountain of paper produced by Maurice’s APL test bed’ as applied to the functions on the bottom shelf. This largely automatic approach to APL code testing was discussed by Maurice at the second ASL conference at Swansea in September 1990. Also discussed were the comments that had been received from testers who had attended that September meeting. Alan Mayer presented his work on producing accurate tail probabilities and quantiles for Normal, t, F and Chi-Square, which have subsequently been tested by Maurice.

VECTOR Vol.7 No.4

Norman Thomson has been maintaining the specification document for the Bottom Shelf and has been incorporating the results of discussions such as this in the document. I shall publish as much of Norman’s document as space permits in a future issue of Random Vector.

This issue, however, takes a look at the Regression Shelf in some detail. We reproduce some notes written by Alan Sykes which were issued with the first test versions of the Regression Shelf. Although, as Alan says in his article, these notes are now being revised, they do offer an insight into the scope of the Regression Shelf.

The last article included is not so directly related to the ASL theme, but David Appleton does offer an interesting view into the way in which the APL representation mathematical formula can be progressively refined. As with any article which dares to introduce the theme of coding techniques and style, I expect a lively reaction from readers, so, having lit the blue touch paper, I shall retire and await the postbag with interest.

The 3rd ASL Conference I would like to conclude this introduction by making a preliminary announcement about the third ASL conference. This will be held at:

The University of Wales Conference Centre at Gregynog from Monday 30 September 1991 till Wednesday 2 October 1991

As with previous ASL conferences, this is an invitational conference and the only costs for delegates are their travel costs. We are hoping to review the ASL and to chart out the next phase of development for the project. In particular we are hoping to attract more volunteers to work on the project!! The ASL team will be delighted to hear from anyone who would like to attend - we to continue the mix of Statisticians from Higher Education and the state or private well as theoretically professional APL programmers. If you would like to find out more about the next conference, why not contact one of the ASL Management Committee who are:

Chairman: Tony O'Hagan, Department of Mathematics, University of Nottingham, University Park, Nottingham NG7 2RD. Telephone: 0602-484848 x2800

35