Partial Subscri qting: (Meta) NIKI Sl denotes the partial subscripting th of array M
..... In order to obtain an SF representation of an arbitrary select expression, we
...... SE6”ENl. (SEE. NE41 FIGULEI. E”A”PLE. 6-13s. DEGINN'ffi. OF SE'llENl.
YI7H ...... 285 156. 142 578. 571 209. 785 644. 25. 125. 275 221. 137 610. 062 5.
SLAC- 114 UC-32 (JJ=C)
AN APL MACHINE
PHILIP S. ABRAMS STANFORDLINEARACCELERATORCENTER STANFORD UNIVERSITY Stanford,
California
PREPARED FOR THE U.S. ATOMIC ENERGY COMMISSION UNDER CONTRACT NO. AT( 04-3)-515 l
February
1970
Reproduced in the USA. Available from the Clearinghouse and Technical Information, Springfield, Virginia 2215 1 0 Price: Full size copy $3.00; microfiche copy $ .65.
for Federal Scientific
ABSTRACT This dissertation propriate
proposes a design for a machine structure
for APL and which evaluates programs
which is ap-
in this language efficiently.
The approach taken is to study the semantics of APL operators structures
rigorously
and analytically.
We exhibit a compactly
standard form for select expressions, alter the size and ordering of transformations
In addition,
to include expressions
to derive the equivalent standard form for any are then extended
containing other APL operators.
By applying the standard form transformations for arrays,
which
we present a set
The standard form and transformations
select expression.
representable
which are composed of operators
of array structures.
sufficient
and data
select expressions
to storage access functions
in the machine can be evaluated without having
to manipulate array values; this process is called beating. second fundamental process which defers operations making possible simplifications leading to more efficient
of entire expressions
evaluations
Drag-along
is a
on array expressions, through beating and also
of array expressions
containing several
operations. The APL machine consists of two separate sub-machines memory and registers. simplified registers
programs
for the language.
arithmetic
The major machine
are ‘organized into logical
segments.
operations,
the factor of improvement
by
naive machine based upon presently-available
APL machine is the more efficient accesses,
then evaluates.
to defer
of the entire APL machine is evaluated analytically
it to a hypothetical
implementations
applies beating and drag-along
which the E-machine
are stacks, and programs
The performance comparing
The D-machine
sharing the same
For a variety
of problems
examined,
the
of the two in that it uses fewer memory and temporary
is proportional
_ ii -
stores; for some examples,
to the size of array operands.
ACKNOWLEDGEMENTS I wish to express my sincere thanks and deep gratitude advisor,
to my dissertation
Harold Stone, whose unselfish good counsel and understanding
essential to the successful completion reading committee, contributed
Bill Miller,
much appreciated
of this thesis.
Larry
and criticisms
of the material
of this work.
Bill McKeeman,
The other members of my
and Ed Davidson,
time and energy towards improving
have each the final form
Breed provided valuable help with his detailed readings in Chapter II.
My friend and fellow student
Sheldon Becker has been a kindred spirit during the vicissitudes student life.
have been
of graduate
Thanks to Ken Iverson and Adin Falkoff who over the years have
helped to imbue me with the “spirit
of APL, *I and to Ed McCluskey,
whose finan-
cial support enabled me to finish this work. I dedicate this thesis to Life and Living,
-
... 111 -
which begin anew each day,
TABLE
OF CONTENTS Page
Chapter I.
II.
INTRODUCTION.
. . . . . . . . . . . . . . . . . . . . . .
A.
A Programming
B.
The Problem.
C.
Historical
D.
Conclusion.
Language . . . . . o . D . D . 0 . . . .
1
. . . . . . . . D . . . . . . . . . . . .
2
. . . . . . . . . . . . . 0 . . .
3
. . . . . . . . o . . . . . 0 . . . . . . .
6
ANALYSIS OF APL OPERATORS
. 0 . . . .
7
. . . . . . . . . . . . . . . . . . .
7
Perspective
MATHEMATICAL A.
On Meta-Notation.
B.
Preliminary
C.
The Standard Form for Select Expressions
D.
The Relation Between Select Operators
E.
The General Dyadic Form - .2 Generalization
Definitions
. . . . . . . . . . . . . . . * . . . . . . . . .
8 17
.
25
D . . . . . . . . . . . . . . . . .
31
Conclusion a . . . . . . . . D . . . . . . . . . . . . .
37
and Outer Products. F.
1
and Reduction
.
.
of Inner
APPENDIX
A: SUMMARY OF APL
. . . . . . . . . . . . . . . . .
39
APPENDIX
B . . . . . . . . . . . . . . . . . . . o . . . 0 . . .
42
APPENDIX
C:
III.
. . . . . . 0 . o . . . . . .
63
STEPS TOWARD A MACHINE DESIGN m 0 . . . . o . . . . . .
64
IDENTITY
ELEMENTS
Drag-Along
B.
Beating and Array
C.
Summary
APPENDIX
Representation
A: TRANSFORMATIONS
THE MACHINE. A.
68
............
70
....................... ON STORAGE ACCESS FUNCTIONS
INDUCED BY SELECTION Iv.
65
and Beating .................
A.
OPERATORS
72 74
......................
Data Structures
........
and Other Objects - iv -
............
75
Page
Chapter B.
Value Stack (VS).
2.
Location Counter Stack (LS)
3.
Iteration
4.
Instruction
82
Buffer (QS) ................
82
D.
The D-Machine
83
....................
87
.....................
0.
A Guide to the Examples ...............
1.
Storage Management Instructions
2.
Control Instructions
The E-Machine
87 91
...........
94
.................
116
.....................
1.
Array Accessing
2.
Instruction
116
..................
120
Set ................... ENCODINGS AND TAGS
. .
137
DESCRIPTION OF THE E-MACHINE
. .
143
APPENDIX
A: SUMMARY OF REGISTERS,
APPENDIX
B: A FUNCTIONAL
APPENDIX
C: EXPANSION OF D-MACHINE
D: POWERS OF 2
OPERATORS 150
..................
FORE-MACHINE
V.
81
.............
Control Stack (IS) ..............
Machine Control
APPENDIX
81
..................
1.
C.
E.
79
...................
Machine Registers.
162
...................
EVALIJATION
........................
163
A.
Rationale.
.......................
163
B.
The Naive Machine
C.
Analysis
D.
Example - A Simple Subclass of Expressions
E.
Example -
F.
Example - Matrix
164
...................
of Drag-Along
167
and Beating ............
An APL One-Liner Inversion
-V-
.............. Programs
.......
173 176
..........
181
Page
Chapter Discussion.
. . . . . . . . . . . . . 0 . . . . . . . . .
189
CONCLUSIONS.
. . . . . 0 . . . e . 0 . . . . . o . . . , .
191
. . . . . , . . . 0 . . e e . . 0 0 . . 0 e m.
191
G. VI.
A.
Summary
B.
Future Research
C.
Concluding Remarks
REFERENCES
. . . 0 o D . . . . . 0 . 0 0 . . o . . .
195
. 0 D 0 ,, 0 . m . . . . . . . . . . .
197
. 0 . . o . . o o . , . . . . . . . . . . . . . . . .
198
- vi -
LIST OF TABLES Page Chapter IV l-1.
Storage Management and Control Instructions.
l-2.
Scalar Arithmetic
l-3.
Remaining Operators
2.
Interpretation
3.
E-Machine
Instruction
3-A.
E-Machine
- Simple Ins true tions . . . . . . . . . . . . . . 123
3-B.
E-Machine
- Control Instructions
3-c.
E-Machine
- Micro-Instructions
Operators
. . . . . . . D 88
. . . . . . e . . . . . . . . .
in D-Machine
89
. . . o . . . . . . . . .
of ASGN and ASGNV in the D-Machine
90
. . . . .
93
Set . . . . . . . . . . . . . . . . . 122
. . . . . . . . . . . . . 124 . . . . . . . . . . . . . . 125
Chapter V 1.
Steps in Evaluation of APL Operators
2-A.
Summary of Effort to Evaluate Operators
-NAIVE
2-B.
Summary of Effort to Evaluate Operators
- APL MACHINE
3.
Performance
4.
Operation Count for One Pass Through Main Loop, Program
Ratios for Primes
REC.
. . . . . . . . . . . . 168 MACHINE
. D . . . . . . . . . . 0 . . . . . . . . . 180
Total Operation Count for Main Loop, Program
6.
Machine Comparison
7.
Operation Count for One Pass Through Main Loop, RECl
. . 171
Problem as a Function of N . . 179
5.
Program
. 170
REC
. . . . . 181
Ratios For Main Loop of REC . . . . . . 183
. . . . . . . . . . . . . . . . . . . . . . 187
8.
Total Operation Counts for Main Loop, Program
9.
Machine Comparison Ratios for Main Loop of RECl . . D . . . 189
- vii -
RECl
. . . . 188
LIST OF FIGURES Page Chapter IV 1.
Structure
of M. ......................
2.
Maincycle routine
80
.....................
86
Chapter V 1.
State of the registers
before compress operator.
2.
Example program:
3.
‘Optimized’ example program:
-
... Vlll -
178 182
REC .................. RECl
.......
............
186
CHAPTER I INTRODUCTION an optimist is a guy that has never had much experience Don Marquis, The electronic
digital computer has progressed
esoteric curiosity, society.
archy and mehitabel
to its present pervasive
Over the years,
sophisticated. languages
importance
role in modern
have become increasingly
is the use of high-level
the use of problem-oriented
complex translation
programming
bridge between the highly-structured as ALGOL,
PL/I,
programming
languages requires
a
process in order to present them to machines.
Although this can be done automatically
In effect,
to an
which have made machines more accessible to problem-solvers.
In general, relatively
and indispensable
man’s uses of computers
Of particular
from being a dream,
by compilers,
there is a wide gap to
concepts in a programming
or APL and the relatively
language such
atomic regime of today’s computers.
there exists a mismatch between the kinds of tasks we want to present
to machines and the machines themselves. difference
is to investigate
One possible way to eliminate
ways of structuring
this
machines to bring them closer
to the kinds of problems people wish to solve with them. A.
A Programming A particular
programming
machines is especially (Iverson [1962]).
Language language in which this mismatch
obvious is APL,
APL is a concise,
expressions
based on the work of K. E. Iverson
highly mathematical
designed to deal with array-structured
with contemporary
data.
programming
APL programs
generally
with arrays as operands and which evaluate to arrays,
-l-
language contain
while most
other languages require
that array manipulations
To complement its use of arrays facilitate
its use of structured those of a classical
data
as operands, APL is rich in operators
Also, it is highly consistent internally
array calculations.
tically and semantically,
be expressed element-by-element.,
digital computer,
APL does not fit well onto ordinary have been written
ferent machines (Abrams
[1968]; Pakin [1968]).
[1966]; Berry
properties,
language rigorously
Because of
which are quite different
It is possible to do so, and interpreters
of its mathematical
both syntac-
and hence could be called l’mathematical”. and its set of primitives
which
from
machines.
for at least three difFinally,
because
it is possible to discuss the semantics of the
and to derive significant
formal
results about expressions
in
the language. B.
The Problem The problem considered in this dissertation
which is appropriate
“Machine structure”
to APL.
tional scheme and not a detailed logical design. of specifications
from which a circuit
but rather a superstructure
is to design a machine structure here means a general func-
The expected result is not a set
designer could produce a working device,
into which the features of the language fit cleanly.
Thus, this design must in some sense be natural for the language. the primitive addition,
operations and data structures
should include those of APL.
the machine should take advantage of all available information
to execute programs
as efficiently
as possible.
any particular
physical device.
ventional program
device or as a microprogram
For the purposes of this work,
it doesn’t really matter.
-2-
in order
and not necessarily
Such a machine could be implemented
or as a hardwired
In
We use the word llmachinell in
a very broad sense: what it really means here is lfalgorithmlf
system.
For example,
as a con-
in an appropriate
“APL” means any programming APL\360 of APL,
(Pakin [1968]).
We shall not be concerned with the particular
although this currently
appears to be the best way to represent
semantic ideas of the language. array-structured
language which includes the semantics of
In short,
the machine should be able to handle
of APL as basic primitives.
The approach taken is to invest a considerable of the mathematical
properties
of the operators
amount of effort in the analysis
and data structures
to exploit these results in the design of the machine. work will be dedicated to a rigorous,
mathematical
This study is contained in Chapter II.
II is related to the design of a machine, detail,
the
data with ease and should be able to evaluate functions on such
data using the operators
sions.
syntax
of APL and
Thus, a major part of this investigation
of APL expres-
In Chapter III, the work of Chapter
and the design goals are set forth in
Chapter IV discusses the proposed machine design, and Chapter V is an
evaluation of the machine with respect to the goals of Chapter III. It should be emphasized that the goal of designing an APL machine is a rather broad one.
Although there are clearly
practical
that is not the major focus of this work. this language and machine in detail,
applications
Rather,
we hope that by investigating
it will be possible to learn something about
the basic processes in computing and find ways of reflecting a machine structure. problems C.
The results
of such a design,
summarized
these processes in
in Chapter VI and the new research
suggested by this work indicate that this goal has been fulfilled.
Historical
Perspective
For the purposes of this dissertation, work in the area of language-directed
we are primarily
interested
machine design (McKeemank9671;
in previous Barton [1965]).
To some extent, all machine design can be considered to be language-directed, that one wishes to implement
some particular -3-
(machine) language in a piece of
in
hardware.
However,
let us consider only the class of machines which might that is, machines which are based
better be called “higher language inspired”;
in some way on languages capable of expressing concepts at a higher level than are normally The first of directly
associated with assembly code, such machine was reported
evaluating logical expressions
In addition,
(Burks,
Warren,
this machine used input in parenthesis-free
doubling its historical language-inspired high-level
interest.
and Wright [1954]).
(Polish) notation,
thus
The logic machine typifies one major class of
machine designs in that its machine language is identical
source language.
The other major class of language-inspired
is more concerned with the processing rather
in 1954, and was a relay device capable
to the
designs
of the semantics of the source language,
than direct acceptance of the exact language by the machine.
In fact, most
designs fall between the two extremes,
as even those which accept the source
language directly
transformations
intermediate
do some preliminary
on it to produce a simpler
language.
Other language-inspired
machines accepting source language directly
include
an ALGOL 60 machine (Anderson [1961]), two FORTRAN machines (Bashkow, Sasson and Kronfeld
[1967]; Melbourne and Pugmire
based on a special symbol-oriented
language (Mullery,
Meggitt [1964]), and a machine for EULER, [1967]).
Of these devices,
[1965]), the ADAM machine, Schauer
a generalization
some were to be implemented
of ALGOL (Weber
in hardware
Bashkow et al, ; Mullery --et alJ while others were implemented (Meggitt;
and Rice [1963];
(e. g, ,
in microprogram
Weber).
Machines which are more concerned with semantic processing that their machine languages are significantly language include the Burroughs
different
from a higher-level
I35000 (Barton [1961]; Burroughs -4-
to the extent
[1963]) which is
essentially
an ALGOL machine,
University
computer (Iliffe
a PL/I
Current work in this area includes
[1970]) and a micro-computer
processes easily (Lesser
Most of these efforts and are thus reported
machine (Sugimoto [1969]) and the Rice
and Jadeit [1962]).
machine (Wortman
high-level
a PL/I
[1969]).
are not directly
relevant to the work in this dissertation
here only for completeness.
The common aspect of all these
designs is that they are concerned with the processing information
and programs
type architectures. some modification
of descriptors, Warren,
are two machines based on lower-level
produced devices to do so
machine languages,
but intended to deal
[1968]) is based on extensive use
and data, while the other (Myamlin
Smirnov [1968]) is somewhat more closely oriented toward higher-level The latter,
in particular,
does run-time
evaluation of infix arithmetic
and languages,
expressions.
Aside from the work of Burks et al:, none of the designs in the literature to be derived from explicit except for simulations present satisfactory
analysis of their input languages.
or actual performance, evaluations
designs are not satisfactory: of computers
mathematical
to the contrary,
Further,
This is not to say that the
the success of the Burroughs
and the KDF9 show that language-inspired
preach to the development of new machines.
seem
none of the papers in the literature
of their designs.
family
designs are a viable ap-
On the other hand, nobody seems to
have established exactly how viable such designs really are. -5-
B5000.
Other related efforts not yet mentioned
One of these (Iliffe
logic for both programs
to use Polish
KDF9 (Davis [1960]) and the Burroughs
Both of these machines included stacks,
of descriptor
schemes using
and Wright machine was the first
apparently were the English Electric
primitives.
addressing
as well as at least one stack.
notation as a machine language, the first commercially
with high-level
of more highly organized
than are found in the conventional von Neumann
Most of them include generalized
Although the Burks,
capable of emulating
/
D.
Conclusion Having briefly
reviewed the developments of language-inspired
to date, they can now be left in the background.
The present approach is different
from those in the past in that it is based on a mathematical tics of the source language, and gives a clear comparison are, of course, program
similarities
analysis of the seman-
Also, the evaluation of the resulting
design is analytic,
of this APL machine to other similar to the designs of the past.
segments, data descriptors,
devices.
In particular,
and stacks is not novel in itself,
the machine developed here is substantially
different
last section. “The thing can be done, ” said the Butcher, “I think. The thing must be done, I am sure. The thing shall be done ! Bring me paper and ink, The best there is time to procure. ” L, Carroll,
machine design
The Hunting of the Snark
-6-
There
the use of although
from those mentioned in the
CHAPTER MATHEMATICAL
II
ANALYSIS OF APL OPERATORS
This chapter examines the mathematical operators.
Mathematical
definitions
of the operators
possible to deduce their properties. expressions
properties
to obtain it.
A similar
and that there is a complete set of
form which generalizes
products is introduced with transformations the relation
between these operators
APL.
of the operators
for this work,
in the drag-along
First,
in its own
and data-structures
in
it provides a strong mathematical
basis for the design of the machine to be discussed later. discussed here are reflected
Finally,
to obtain it.
for several reasons-
to the understanding
Second, and most important
appropriate
inner and outer
and others in APL is discussed.
This kind of analysis is important right it contributes
are given from which it is
We show that there is a standard form for
containing selection operators,
transformations
of some of the APL
In particular,
and beating processes,
the ideas which are
fundamental in the proposed machine design. A*
On Meta-Notation APL is a programming
processes, while mathematics rather than processes.
language,and as such is best suited for describing is primarily
concerned with discussing relations
Thus, in order to do mathematics
with APL,
sary to use some notations that are not available in the language itself. these meta-notations
definitions
Some of
are actually extensions of the language which might well be
included in APL to make it more powerful, analytic approach,
it is neces-
and do not reflect
while others are necessitated by the
shortcomings
of objects not in APL are clearly
-7-
in APL.
noted as such.
In the next section,
B.
Preliminary
Definitions
The definitions Hence
this
to follow are given partly in APL and partly in meta-notation.
and the remaining
knowledge” of APL.
Also recommended
are the APL\360
Reference Manual (Pakin [1968]).
that defining APL operators APL operators
“reading
The APL summary in Appendix A will be helpful to the reader
not fluent in this language. [1969])and APL\360
sections in this chapter assume a minimal
is elliptical.
At first,
in terms of other (intuitively
forms,
(Berry
it might appear
but not formally
In fact, there is no circularity
could be given in more primitive
Primer
defined)
since the definitions
but at the cost of less perspicuity.
Since
the goal here is not the development of a coherent theory of APL expressions rather the illumination explication
of the behavior of these expressions,
was chosen,
and no special or esoteric
the current
The use of %ndefinedlf APL operators applications
mode of
is made advisedly
of them are made in the following
The basic problem here is that of using a formalism
but
definitions.
to describe a formalism.
At some point it is necessary to assume a previous knowledge of something in order to avoid an infinite
regress.
“Nothing can be explained to a stone; the
reader must understand something beforehand. ” (McCarthy The definitions transformations to follow,
will be numbered Dn for easier reference.
will be numbered Tn and TRn, respectively.
the convention that unparenthesized
subexpressions
right will be used wherever this does not lead to confusion. be skipped in the first reading is enclosed in heavy brackets. this includes formal
statements in definitions
theorems and correctness understanding
of transformations,
the content of this chapter.
-8-
[1964], p. 7) Theorems
and
In APL expressions associate to the Material
which can
For the most part,
which are necessary for proving but which are not essential to
-DO.
Identity:
(Meta)
If.&’ and S’ are expressions,
then
d-t% means they have identical values. The sign h’
is used for identity because the more traditional
sign ‘= * is reserved for use as a dyadic scalar operator a.
Conditional Expression:
(Meta)
equality
in APL.
The conditonal expression
IF B EHg A ELSE C hasasitsvaluethevalueofA
ifB
++ 1,thevalueof
Cif B -
0,andis
undefined otherwise. McCarthy
[1963] discusses formal properties
of conditional
expressions,
some of which are used in the proofs in this chapter. Q3
Index Origin:
(Meta) The index origin is the lower bound on subscripts
APL expressions. In general,
It will be referred
to as I&?&.
this work attempts to show explicit
dependencies on index origin.
However, to do so throughout simply complicates Whenever it is unstated we use l-origin
insight. -D3.
Interval
Function:
If N is a non-negative
many expressions
without adding
indexing. integer scalar,
the interval
function of N,denoted by tN, is a vector of length N whose first Is,
element is
and whose successive elements increase by 1.
Formally, IN - LF N=O gga EMPTY VECTORELSE (dv-1),flt~R~-1. -[ Thus, one representation for the empty vector is 10. D4 -*
in
Odometer Function:
(Meta)
If R is a vector of non-negative
odometer function of R , denoted by tR, is a matrix
-9-
integers,
with dimension
1 the ( x/R), pR
whose rows are the mixed-radix consecutive integers, of APL,
representation
but is useful for discussing individual
13,2 -
Example:
-D5.
This extension is not a part
starting with m.
for each IE I x/R,
(zR)U;3
f-+ -IORGtRTI-=G.
That is, the relation
to one of the rows in the right operand matrix. E+g 13,2 -
(2,2)
Ea
subscript
-D7.
Ravel:
0
13,2 f-f 1 then the list of 4 denoted by ;lL , is a
If L is a vector,
list made up of the elements of L. ;/L
Example :
THEN v/RA.=L ELSE 0. ---
is true (has value 1) if and only if the left operand
(1,3)
List:(Meta)
1
defined as follows:
L ELT R f-f IF - (pL)=(pR)[21
-D6.
of an array.
ELT -- is a function whose left operand is a vector and
whose right operand is a matrix,
Example:
subscripts
1 1 12 21 22 31 32
ROW Membership:
vector is identical
to base R, of the ( x/pR)
MC;/151
-
-++ LCll;LC21;-.
That is,
. .;LCpLI.
MC1;2;3;4;51
The ravel of M, denoted by,M , is a vector containing the elements
of M in row-major
order.
The dimension is P,M
If M is a scalar,
-
X/PM
then ,M is a one-element
- lo-
vector.
kxipkf, Example :
-D8.
(,M)cIi
-
MC;/(I~M)~I;II
1
31 3 5 7 - 1,3,5,7,9,11 9 11 ,1,3,5 - 1,3,5 Let R be a vector of non-negative
Reshape :
Then the R reshape
integers.
of M , denoted by RpI$ is an array with dimension R, whose elements are taken from M (possibly with repetition) for each
(3,2)p16
4p1,2,3,4,5 (2,4)p13
-D9.
Partial
-
(,M)CImt(x/pM)
-
1 2 34 56
-
1,2,3,4
-
1 2 3 1 2312
Subscri qting:
(Meta)
NIKI
th of array M along the K - coordinate. MCCKI Sj -
(R.LL-I0RGl
Sl denotes the partial
In other words,
M[;...;S;...;I + + 1 K
+ PPM
Formally, ,MCCKI Sl -
((K-l>~pM),(pS),(K~pM)
%ndfor each
L EL2 IPMCCKI Sl,
if S is a vector,
then
(H[Kl
-
S3)C;lLl
and if S is a scalar, (MCCKI Sl)C;ILl
-
order.
L &LJ IR,
(RpM)C;ILI
Example :
in row-major
MC;l((K-l>~L),SCL[Kll,K~L] then MC;l((K-l)~L),S,(K-l)SLl - 11 -
.
subscripting
Subscripting:
DlO.
If M is a rank&
M[Sl;...;SKMl;SK1
-
array,
(... ((M[[ppMl
The above simply gives a formal
definition
then for any Sl ,S2, - . . ,SKM1,SK SKl)CC(ppM)-11
for array subscripting.
more complex than it really is because APL uses a different than for other operators.
If we write
SK &MI
value of the above expression can be rewritten
SHUlI)...)c~11
5'11
It looks
syntax for subscripting
Minstead of MC[KI Sl , then the as:
Sl &Cl3 . . . SKMl X_C(ppM)-ti SK _XCppMlM Dll.
Let LEN be a non-negative
J-Function:
Then J LEN,ORG,S is an interval is ORG;if s -
integer,
ORGan integer,
vector of length LEN whoseleast
o then successive elements increase
andSE0 ,l . element
by 1, else they decrease
by 1. Formally, J LEN,ORG,S ORGt(lLEN)-IORG ELSE (LENtORG-l)-((ILEN>-IsE). J-vectors
are a generalization
of the interval
are invariant
can have any origin,
function.
In particular,
under changes of m,
J-vectors
and can run forward
or backward. Example :
D12.
J, 4,2,0
-
J,
f--f 5,4,3,2
4,2,1
S&array: (PPM),~.
FC\M-
(&I&a)
2,3,4,5
and these relations
are true for any IORG.
Let M be any array and Fan array with dimension
Then the subarray selected byF , denoted FAM, is M[J_ F[l;];J_
F[2;1;
. . . ;J_FCppM;]l
where the elements of Fare assumed to be in the domain of the above expression.
- 12 -
A subarray
The subarray
selected by this function is compact.
used to provide a standard representation
for all the various
function will be
ways of selecting
compact subarrays. Example :
Let
pM -
and z then
lo,15
4 3 o 3 51
FAM -
NJ
D13.
mole
Array:
4,3,0
M[3,4,5,6
(Meta)
; J_ 3,5,11 ; 7,6,51
For any array
M , the whole array of M, denoted
by m, produces as a result the F such that FLU! AM -
Example :
IBG
Cross Section:
D14.
~(3,ppM>p(pM),((ppM)plORG),
If pM +-+ 6,10,32, and
(ppM),2
(i)
6 1 0 1 0 32 1 0
then AM tf
10
f--f 1 (Mete.)
Let M be any array,
F an array with dimension
FC;llcO,l
(ii)
(-FC;lI)/FC;21
(iii)
(FC;ll/FC;21)
-
(+I-FC;ll)pO
ELT ~F[;ll/pM
section of M, denoted by FAM, is:
and for each L ELT
IPFOM,
Cross section is used to formalize
(FaM>[;/Ll
-
the subscripting
column of F contains zeros for coordinates
requires
1
(PPM)PO
such that
Then the F cross
first
M.
that if FCJ;ll
Entries
indexed by scalars in the corresponding
(-FC ~11 )/PM
MC;I(xIF)+(-FC;lI)\LI of arrays
by scalars.
to be left intact.
Condition
The (ii)
0 . This is primarily
to make some
of 1 in FL ; l] correspond
to coordinates
+-+ 0 then FCJ; 21 -
of the theorems easier to prove.
PFAM -
element of FC ; 2 1 .
- 13 -
Example :
Let
pM -
4,7,13
F-12 0 0 1 10 then FL&V--D15.
Take:
MC2; ;lOl
If Mis any array and A is an integer vector with PA -
ppM and
( 1~)s~ , then A+M is an array of the same rank of M , as follows: IE IPPM, if A[I]zO
then include the first
AC11 elements along theI%
of M; otherwise if ACIl,(l~RG+(AC;1l,~a~>C;2l,~=~pp~
on the operator
1
is elided, it is taken to be ppM.
2 3 4 5 6 7 8 9
- 14 -
then,
(2,2)+M -
(2,-2)+M
1 2
-++ 2 3 56
45
(2,1)+M -
(-1,l)SM
8 9
-
2 3 56
4ClIM -
7 8 9 456 123
If M is any array and A is an integral
Transpose:
D18.
0)
PA -
(ii)
PPM
A/AE ~ppM i. e.,A contains only coordinate
(iii)
vector satisfying
A/( lr/A)cA
i.e.,
numbers of M
A is dense
then the transpose A4M of M byA is defined as follows: 1.
ppA4M -
1+-C I-IAbIORG --
2.
For each IelppAQM, (pA4M)CIl
-
L/(A=I)IpM
For each L Ea
3.
(A4M)C;/LI
A4M,
up
-
MC;/LCAII
In other words, A permutes the coordinates specify an arbitrary Example : I~G
-
(pRjC21
or
M
SUppOSe
1 we have ppR -
RCLCll;
L/(2
-
diagonal slice.
a matrix with PM -
iS
1+2-l
2,1)/5,6
LC211 -
Thus, R is the ordinary
-
2
Then if R -
5,6.
o Further,
5 andforeach
(pR)Cll
L Ea
(2,1 )QM , and L/(1=2,1)/596
-
RC;ILl
t6,5,
-
f-f 6
Mc;/( ,L)C2,111
MCLC21; LClll. matrix
transpose
of M .
Now suppose M is same as above and R So the result is avector.
of M. Transpose can alSO
Then(pR)Cll
- 15 -
f-f
( 1 ,l NM.
L/(1=1,1)/5,6
Then, ppR -
5.
Itl-1
-
1.
Then for each .&x5, we have RCLI -
MC;/( ,L)Cl ,111
-
MCL ; Ll
So R is the main diagonal of M. D19.
If x is any vector and U is a logical vector of the same
Compression: length,
then v/X is the result of suppressing from X all elements whose
corresponding
entry in U is 0.
For an arbitrary
array X, u/CII
X compresses
X along the I th - coordinate . Formally,
forvector
IF UCIl=l
X, pv/x -
~(uIx)c+IIwI
-
This is not a constructive formula VlCIl
D20.
+/v
and for each
xcz-1
formula
for (UlX)CIl
is too complex to be useful here. x -
Expansion:
XCCII
IEIPU,
;
however,
such a
For any arrayX ,
ulI(px)cI11.
If X is any vector and Uis a logical vector with t/U -
then U\X is a vector with
o
PX,
elements wherever u has, and whose other
elements are taken from X in order. The definition
of expansion is extended to higher-dimensional
the same way as for compression. pU \X -
Formally, (U\X)CIl
Example :
-
_
pU and for each IEIPU,
IF - UCII THEN XCtlIWl
(1,1,0,1,0)/1,2,3,4,5 ~1,1,0,1,0~\1,2,3
-
1,294
1,2,0,3,0
- 16 -
ED
0
I
arrays in
C.
The Standard Form for Select Expressions In this section the selection operators
transpose,
and subscripting
by scalars or _J-vectors.
among the selection operators, of selection operators terms of some simpler
considered are take, drop, reversal, Because of the similarity
we might expect that an expression
set of operators.
This expectation is fulfilled
to decide whether a particular
expression
in the
and
In the sequel we show that
every select expression has an equivalent standard form, which are sufficient
there must be a way
has a standard form representation
if so, there must be an effective method to obtain it.
arbitrary
in
to be discussed below.
If the existence of a standard form is to be at all useful,
transformations
only
applied to a single array could be expressed equivalently
standard form for select expressions,
formal
consisting
and exhibit a set of
to derive the standard form from an
expression.
It may at first operators,
seem strange to include subscripting
since its parameters
select operators.
are of a different
In the other select operators
in the set of selection
kind than those for the other
such as take or drop, the left
operand is a count, which is independent of ways of accessing the argument array. On the other hand, in subscripting For example,
the arguments act like maps rather than counts.
an expression like A+M has meaning out of context, as long as the
values of A andM are known.
Contrariwise
the expression MC1; 3 I cannot be
evaluated without knowledge of the index origin. follow,
the major complications
specifying Subscripting operators,
select operations,
In the theorems and proofs
to
often come from this dichotomy in the way of
rather than from the actual content of the material.
is included because its effect is similar
to the other selection
all of which change only the dimensions and orderings
- 17 -
of their operands.
D21.
Let 6 be any (well-formed)
Select Expression: Then gis consisting
as a select expression of an arbitrary
array-valued
on 8 if it is a well-formed
number (including
expression. expression
0) of the following
operators
applied to &: (i)
Take
(ii)
Drop
(iii)
Reversal
(iv)
Transpose
(v)
Subscripting
By extension,
by scalars of J-vectors
we will also include the subarray and cross section operators
in this class. Example:
Let M be a rank-3 array.
Then by D21,
(2,1,3>~(OC21(4,-6,3)~~)[;
is a select expression
; J6,2,11
on M, but -MC; ; 5,7,3,11
is not because it contains the scalar operator ’- 1 and the subscripting a scalar or J-vector. D22.
The definition
is not by
also admits M as a select expression
Equivalence Transformation:
An equivalence transformation
on M.
on expressions
is a rule of the form: -if set of assertions
then Q =>g
where 6’and gare
expressions,
If the set of assertions
is true, then expression
&may be replaced by expression lg, and the truth of the assertions
guarantees
that E=>ZZ
For example (if X is any vector 9
+@x=>X ) is an equivalence transformation,
since it is always true that if X is any vector,+$X
- 18 -
tt
X.
, i.
For any given transformation, equivalence-preserving. correct.
it is necessary to prove that it is indeed
If this is the case the transformation
is said to be
Note that the notions of expression and transformation
form used here are informal
ones.
to be acceptable to a logician,
It is possible to make them rigorous,
but that is irrelevant
to the current
only serve to obfuscate the important
mathematical
to explicate.
for each transformation
The correctness
“Proof
of TRn” .
D23.
Standard Form:
and standard
proof
A select expression
relationships
on an arrayM
so as
aims and would we are trying
will be called
is in standard form
as AQFAGnMwhere A ,F,G are all of the correct
(SF) if it is represented size and domain. In the remainder mations sufficient
of this section, we introduce a set of equivalence transfor-
to transform
most select expressions
the process we prove the correctness
THEOREM 1:
then &can be transformed
theorem:
If B is any select expression
into an equivalent expressiongin
In order to obtain an SF representation
of an arbitrary
must first be able to eliminate
the operators
The first four transformations
below do this.
TRl.
If M is any array and A is conformable WhereF
-
4’(3,ppM)p(
on an array M,
standard form. select expression,
take, drop, reversal
we
and subscripting.
to M for take, then A+M => FAM
1A>,(KR~t(Ax(pM>-iA),(ppM)pO .
- 19 -
In
The effect of this
of each transformation.
process is a proof of the following important COMPLETENESS
into standard form,
TR2.
If M is any array and A is conformable where
TR3.
F t-f Q(3,ppM)p((pM)-
to M for drop, then A+M => FAM
IA) ,(IORGtOrA),(ppM)pO.
If M is any array then @[KIM => FAM where
F tf
~(3,ppM>p(~)[;ll,(aM)C;2l,~=~ppM.
These three transformations the definitions
are obviously correct,
of the operators
as they follow directly
take, drop, and reversal.
from
Their proofs will thus
be omitted. TR4.
IfM is any array then MCCKI J_ LEN,ORG,S]
q
> FAM
where FCK;l t--, LEN,ORG,S and (K#~ppM)/[ll~ That the above is an equivalence transformation
f-f (K~IP~M)/[I]AM
requires
a small proof:
Proof of TR4: We must prove that for any array M, MCCKl J_ LEN,ORG,Sl where F is as given in TR4. quantities
FAM
In order to prove the identity,
have the same dimensions.
we show first that both
Then we show that corresponding
of each are identical. Let 1.
R -
MCCKI J LEN,ORG,SI.
By definition,
pR c-t ((Ii-l)+pM),(p
J LEN,ORG,SI,K+pM
+-+ ((K-l)+pM),LEN,K+pM and
PFAM -
FC;ll
f-f ((K-l)+(AM)[ -
;~I),LEN,K+(AM)[;~~
((K-~)+PM),LEN,K+~M
-2o-
elements
For each L EL2 I pR,
2.
RC ;/Ll
-
M[;/((K-1)4L),(J
LEN,ORG,S>CLCKll,K+Ll
and (FAM>C;/Ll
-
(MCJ_FCl;l
-
Mc(J FCl;I)CLClll;
; J FC2;l
; . . . ; J FCppM;IIC;/LI . . . ; (J FCppM;I)CLCMlll
(by L3 in Appendix B). But for each I#K,
(J FCI;I)CLCIII
-
(J (pM)CIl,~~,O>CLCIll
f-f LCII and(J_ FCK;I)CLCKll -
(FAM)C;/Ll LCKtll;
(by L4, Appendix B)
t-t (CL LEN,ORG,S)CLCKIl.
McLCll
Therefore,
; LC21 ; . . . ; LCK-11 ; (J, LEN,ORG,S)CLCKJl;
. . . ;LCppMll
-
K;;I((K-l)+L),(J
-
RC;/LI
The preceding
QED.
proof of TR4 is reasonably Although similar
the kind of proof required. transformations
LEN,ORG,S)CLCKll,K+Ll
are more complex.
simple, in style,
and is representative
of
the proofs of the remaining
Since they add little to the exposition,
they
are given in Appendix B. The following occurrances
transformation
makes it possible to reduce the number of
of adjacent subarray
operators
in an expression.
If M is any array and F and G are conformable
TR5.
for subarrays,
then
FAGAM => HAM
where pH where
J L,OR,S -
Transformations operators forming operators.
pF andfor
take, drop,
each I~lppM,
(J GCI;I)CJ
H[I;I
f-f L,OR,S
FE;11
TRl through TR4 are used to eliminate reversal,
them into equivalent
instances of the
and indexing from select expressions
expressions
involving
subarray
and cross section
TR5 shows how to coalesce two adjacent occurrances - 21-
by trans-
of subarray
into
one.
The remaining
transformations,
TR6 through TRlO are similar
and are used to permute the remaining
in spirit
operations into the order required
by the
standard form. TR6.
If Mis any array and Fand G are conformable, where
G’ -
then FAGAM => G'AF'@,
WC ;iI)/Cil~
and F’C;ll
-
FL;11
and F'C;21
c-f
F[;l]~(G[;2~t((-G[;3~)~F~;2~-~~)+(G[;3l~~GC;llt~~+-l-FC;2l~~~
TR7.
If M is any array and F and G are conformable
toM for cross section,
then FAGW => H&l -where HC;lI and TR8.
+-+ GC;~IV(-GC;~I)\FC;~~
HC;21 -
GC;21+(-GL-;ll)\FC;21
If M is any array and F,A are conformable respectively,
to M for subarray
and transpose,
then FAA@M=> AQFCA;IAM.
TR9.
If M is any array, (A@M)[[J]Q] where
TRlO.
Q a scalar,
=> E
A' -
JE I ppA@tMthen
l=ppAQM Tm
B@' Em
(A#J)/A-J C@M where
C -
A'&qB@l
BCAI.
- 22 -
for transpose,
then
Now that we have transformations
a proof
in Appendix B, we can outline note that for any array
M, M -
TRl through TRlO which are proved correct
Apply TRl,
theorem.
of the operators
on M which satisfies
we would have to prove a replacement
all instances
(In order to be absolutely
rigorous,
theorem which says that if in an expression
of a subexpression % is replaced by an equivalent subexpression
59 (i.e.,
a -
d’-AZ
. Call the result of this operation 6”.
subscript,
First
the hypotheses of the
TR2, and TR3 to 8 enough times to eliminate
take, drop, and reversal.
&, an occurrance
1.
(1ppM)Q(AM)A(((ppM),2)pO)&kf.
Let 8 be any select expression
1.
of Completeness Theorem
,9$ ’), then the resulting
A, and $ operations.
expression&
Clearly
is equivalent to 4
only
Note that 6” contains only
&‘l--
6’ because we have applied
only equivalence transformations. Now for each instance of an indexed quantity,
2.
expression
using partial
indexing,
as per definition
DlO.
IX notation mentioned there and apply TR4 to eliminate subscripts
and call the resulting
expression 8”.
substitute the equivalent Write this using the
all instances of J-vector
It should be obvious that &”
has the form Sl 81 S2 62 . . . SN 8N M, where the S quantities for the operators
8 and the 8 ‘s are A, Q and IX in arbitrary
substitute the expression subexpression,
call it PN, is in standard form.
and again note that TN3. .YK -
( IppM)Q(AM)A( ((ppM) ,2)pO)&V for
are left operands order.
M,and note that this
Call the resulting
algorithm:
at each step, the input is
Sl 81 ~2 82 . . . SK 8K PR, where gK is in standard form,
-
(a)
If K -
expression TN,
8.
Consider the following
?k
Finally
i,e.,
AKQFKAGKAM. 0 then the algorithm
is terminated.
Otherwise,
look at the operator
QK. Do step 1, 2, or 3 below depending on whether 6K is Q, A or IX, and return to step (a). - 23 -
respectively,
1.
8K is transpose, &J. Apply TRlO to the expressionSKG$
to get the equivalent 2.
QK@FKAGK&V, where QK tf
SKCAKI and call this YKml .
A . Apply transformations
OK is subarray,
t-f SKQAKQFKAGKM,
TR8 and TR5 to SKAL$ to
get SKAgK -++ SKAAKQFKAGK-&V => AK@SKCAK;lAFKAGK-&V => AKQFK’AGKM, where FK’ is obtained by TR5. 3. 8K is indexing by a scalar, IXC Jl . Apply transformations
TR9, TR6,
and TR7 to SK IXC JIPK, getting SK IXC Jl AKQFKAGK-&d=> AK’QBKAFKAGK-M => AK’@FK’ABK’&GK-@! => AK’QFK’AGK’-W. In each of steps 1, 2, 3 above, a set of transformations subexpression SK eKgK of TK. transformations
were equivalence transforms,
Let YHml be the resulting cQy-+
iQ*
the algorithm
Call the resulting
Finally
was applied to the
subexpression
,y;Cml. Since all
it is clear that SK @KYH-
PHel.
expression from plugging YRWl into *Y&e Clearly
observe that each PH is in standard form..
will terminate
Hence, in N steps,
with result “7, f-f Zl+-+ . . . +-+ “IN f-f &, and To f-f PO,
which is in standard form.
This is the desired result.
QED.
So far, we have defined a standard form for a subset of select expressions and exhibited a complete set of transformations representation
of an arbitrary
the completeness
in this class.
theorem gives an algorithm
Note that there are alternate an equivalent formulation represented
expression
for obtaining the standard form
the meta-notation
the proof of
for obtaining the SF of an expression.
ways of formulating
the standard form.
For instance,
says that an expression is in standard form if it is
as AQB+C+@CKlDm with B,C non-negative
so that the definition
Moreover,
and K a vector of indices
of +[K] extends in the obvious way.
formulations
The choice of using
was made for two major reasons.
- 24 -
First,
fewer
transformations
and therefore
Second, this formulation
fewer proofs are needed to establish completeness.
is closer to the way these results will be used in the
design of the machine. Another point to note is that the standard form could be made more general, by allowing more operators particular,
compression
candidate for inclusion, because rotations
expressions
and expansion might be included,
The general rotation operator
and catenation.
a simple way.
to be included in the set of selection operators.
but in fact does not fit in cleanly.
and perhaps extend operations
which do not compose in indexing of select
on select expressions
to operations
as in the case bVCS1 +-+ VC@‘l .
These results are important ships between APL-like
of the SF and completeness
in that they establish formally
operators
which informally
on his programs
results.
some of the relation-
may appear obvious.
not only provides a useful tool for the programmer,
This
who may make formal
trans-
without a second thought, but it also provides a formal
basis for automatic transformation property
This is primarily
extension would allow arbitrary
A final point concerns the significance
formations
as well as reshape
seems to be a possible
involve taking residues of subscripts,
A further
on their subscripts,
at first
In
of programs
and expressions.
is heavily used in the design of the APL machine.
that results such as we have described-aid which might be used in generalizing
Also important
in the understanding
them further
This second is
of array operators,
or in strengthening
the theoretical
foundation for operations on array data. D.
The Relation Between Select Operators
and Reduction
Obviously there is more to APL than just selection operators. of the previous section are to be generally relationships
between select operators
applicable,
If the results
we must look into the
and some of the other kinds of operators
- 25 -
One result that has been used implicitly
in an array language.
proofs in Section C is that selection operators scalar arithmetic -$v c-t $--v. arithmetic formally -Tl.
operators.
This property
operators
are distributive
For instance,
(A+B)CSl -
follows immediately
and the definitions
in some of the with respect to and
ACSl+BCSl
from the definition
of the select operators,
of scalar
and is stated
in the theorem Tl below: Let A and B be arrays
with the same dimensions and _Mand _Dbe monadic
and dyadic scalar arithmetic
operators
and j’a selection operator;
then
(i) if A _D B is defined, 2 (A Q B) (ii)
(2 A) Q (2: B)
if @ ’A is defined TMA-IJTA --
Tl contains the restriction with cases like
( ( 1,1,1) tl ,I, o ) [ 1,2]
but is defined after distributing general than as stated. compression, or reshape.
that A Q B and E A be defined, in order to deal in which the result is undefined as written
the indexing operator.
It should be clear that the operator
expansion (for some scalar operators) A similar
r can also be rotation,
or operators
such as ravel
result holds if one of A or B is a scalar.
One of the most important
constructions
dyadic scalar operator between allelements operator
This result is in fact more
in APL is reduction which applies a of avector.
Reduction is not an
in the sense we have been using, but is more like a functional.
be shown below, it is possible to change the order of select operators as well as to permute the coordinates
of the reducee.
these facts will have direct use in the APL machine. defines reduction formally, for expressions
As will and reductions
As in the previous The remainder
section,
of this section
and presents a set of equivalence transformations
involving reductions. - 26 -
D24.
Reduction:
If& is a dyadic scalar operator and Vis a vector,
reduction of V, written
P/V, is a scalar defined as follows:
Q/V -
VCll Q Vt21
IF (pV)>l
Tm
then theQ
Q . . . Q V[ppVl
ELSE IF (pV> = 1 THEa VCll --
EaE
(IDENTITY OF ii>
In the expression above, the operators Q associate to the right, The identities
of the scalar dyadic operators
as usual.
are listed in Appendix C.
If M is any array and Q is as above then the g reduction over theK th coordinate
of M is defined as follows: pDICK1 M -
((K-1
I pQ/CKI M
and for each L m
(DICK1 M)C ;/Ll
where FC ;ll
-
If the subscript
K*lppM AND FC ;2l f-f FC ;ll\L K is elided in the expression
the last coordinate
D25.
and ranking operators,
Membership: relation
DICK1 M, it is taken to be
of M, which is p pM in l-origin
In order to do some of the proofs required membership
Q/F@
-
and r/ 1ppMin general.
by this section,
so these operators
we will need to use the
are defined formally
If A is a scalar and B is any array,
first.
then the membership
AEB has value 1 if at least one of the elements of B is identical
to
A , otherwise the value is 0. -The dimension of the result is the same as that of A, and the definition is
AEB -
is extended element-by-element
V/ . . . V/Ao.=B. p-s
D26.
Ranking:
1
If B is a vector and A is a scalar,
of A in B, namely the least subscript [Formally,
B tA -
LI(A=B,A)I
- 27-
on A.
then B tA denotes the index
I of B such thatA f-f B[I] 11+pB.]
.
From the expression above, it is clear that if -A& then the result is i+rhpB
The operation is extended to arbitrary
o
arrays A element-by-
element. if A is any array, (BtA)C;/LI
An interesting
-
LI(AC;ILI
question about reductions
= B,AC;/Ll)Itl+pB.
is under what circumstances
coordinates
of the reducee be permuted,
coordinate,
and still have the result remain the same?
for example,
1
then for each L ELT ~PA3
with reduction carried
out on a different
It is intuitively
that +/Cl1 M f-f +/c 21 ( 2,l )QM, when M is a matrix,
the rows is the same as adding the columns of the transpose. that this kind of permuting
can be carried
can the
obvious,
since adding
Theorem T2 shows
out as long as the coordinates
that are
left after reduction are in the same order. Let Mbe any array,
-T2,
permutation
O_any scalar dyadic operator, K a scalar,
and P any .
of I PPM. Then, D_I[Kl M -
D_I[PCKII PQM
if and only if
Proof:
See Appendix B.
The complicated that permutation
condition in T2 is a formal
statement of the requirement
by P does not disturb the ordering
of the coordinates
in Mother
than rC Example :
Let M be a rank-4 array.
Then, by theorem T2, all of the following
are true: tlC21M -
+/cl]
(2,1,3,4)QM
-
t/C31
(1,3,2,4)QM
-
t/c41
(1,4,2,3)QM - 28 -
,
No other values of P satisfy the condition in T2. PC21 tf not
2and
PITPP -
3,2,4,1.
+-+ 3,4,1
So(2*1,2,3,4)/3,2,4,1
f-f 1,3,4.
(2~1,2,3,4)/1,2,3,4
For instance if P t-f 4,2 ,1,3, whichis
This theorem suggests the following trans-
formation: TRll.
If Mis any array and D_is a dyadic scalar operator, Ll/[Kl
then
M +-+ L?/[LASTI AtqM.
where LASTis the index of the last coordinate
of M ( PPMfor l-origin
and
r/lppM in general) and A f-f (OK-l>,LAST,((K-l)+~(ppM)-K) TRll
above and TR12, TR13, and TR14 to follow can be used to transform
select expression
on a reduction to a reduction along the last coordinate
a of a
select expression. TR12.
If M is any array and O_a dyadic scalar operator
then
AQQIM => Q/(A,l+r/A)QM. TR13.
If Mis any array,
O_a dyadic scalar operator,
then
GI1QIM => Q/G'@! where TR14.
G1 -
(paM)p(,G>,(-l~pM>,IoRG,O.
If M is any array, then
(DIM)CCJIQI
O_a dyadic scalar operator, => D_IMCCJIQI.
Proofs of TRll,
TR13, TR14:
Proof of TR12:
See Appendix B.
Transformation their operand array.
TRll
andQ a scalar,
Immediate from theorems T2, T3, T4.
forces all reductions
to be along the last coordinate
TR12, TR13, and TR14 permit
out” of select expressions.
- 29 -
reduction to be “factored
of
Given these transformations,
we can extend the completeness
result of the previous
section as follows: COMPLETENESS
If 8 is an expression
THEOREM 2:
only selection operators
then it can be transformed
and reductions,
D /g equivalent expression .gof the form_D1/Q2/. . .-K operators
it will be omitted.
-T3.
If M is any array,
to that for the first completeness
theorem,
of transformations
Q a dyadic scalar operator then -
LI/[K]G'AM
++ G AND G'[K;]
-
(M)[K;]
See Appendix B. For any array M and D a dyadic scalar operator, GU/M where
Proof:
are the reduction
through TR14, which follow from the theorems below:
where (K*~ppM)/[ll~~
-T4.
into an
is in standard form.
Such a proof depends on the correctness
GWCKIM
Proof:
! where the $
in the order they appeared in & and whereg’
Since the proof of this theorem is similar
TRll
on an array M containing
G1 -
Q/G'aM
((ppM),2)p(,G),O,O
See Appendix B.
The following
example takes an expression and derives the standard form of
Completeness Theorem 2. Example :
Let pM -
6,10,12,19
and consider the select expression With
reductions :
In each step, we note the transformations -3o-
applied.
1.
where
2.
(TRll,
~-(2,1)~+/1:31(3,1,2)~FAx/[4]M
CT-
F-3
where
G-3
0 0 0
1 71 4 9
1,2)Qx/C4
t/C31(2,1,3)@(3,
TRl)
GEM
(TR12, TR13)
1 71 4 9 19 1
3.
d“-
4.
cF+-+ t/C3lx/C41(3,2,1,4>QGAM
5.
df-
(TRlO)
+/[3](3,2,l)Qx/[4]GAM
(TR12)
t/C3lxl[41(3,2,1,4)QGAH&iV
where
by definition
H-00
of a
0 0 0 0 0 0 The above expression is in SF. E,
The General Dyadic Form - A Generalization
of Inner and Outer Products
In APL there are three ways of applying dyadic scalar operators operands.
The simplest,
the scalar product,
of a scalar operator to corresponding simplest is the outer product, operator
Finally,
product in linear algebra,
application The next
arrays.,
in which the result is obtained by applying the one from each operand array,
the inner product is a generalization except that arbitrary
pate as operands and any pair of operators us present the formal
is the element-by-element
elements of conformable
to all possible pairs of elements,
specified order.
to a pair of
definitions
(conformable)
may be used.
arrays
matrix
may partici-
Before proceeding,
of inner and outer products.
- 31-
of ordinary
in a
let
Outer Product:
D27.
operator,
arrays and Q is any dyadic Scalar
then the Q outer product of M and N, written M 0 .Q N, is defined PM o.~ N f-f (p~),pfl.
as follows:
D28.
If land N are arbitrary
M!i;/(ppM)fL]
Then for each L GL’
CM 0.0 N)C;/LI
-
Inner Product:
If M and N are any arrays
then the_D-z inner product of
M Q.c N, is defined as follows:
GC;ll
-
((-ltppM)pl),O
HC ;ll
-
O,(-l+ppN)pl
HL-;21 -
O,(l-ppN)+L
If one of M orN is a scalar,
N,
such that -1fpM f-f 1fpN and if
and for each L Ea IBM Q.z N, CM O_.g N)l;/LI where
0.D
Q NC;/(ppM)SLl.
Q and E are two dyadic scalar operators, M and N written
IPM
GC;21 -
pM Q.2 N -
(-l+pM) ,l+pN
f-f D_/(GAM) F_ HAN, U-l+ppM)fL),O
it is extended to a vector of the same length as
the reduction coordinate.
In the sequel, we assume that all operands of inner
product are array-shaped
(or have already been extended).
Example :
0.x 4,5 -
(1,2,3)
(1,2,3)
r.t
4,5,6
4 5 8 10 12 15
-
r/(1,2,3)+4,5,6
-9 If M and N are conformable
matrices, M t.x
is the ordinary
then N
matrix product of linear algebra.
Although these three product forms appear to be different also in their effect,
they are in fact intimately
as aspects of the same thing. scalar,
inner,
related,
syntactically
and can be considered
This section shows the close relationship
and outer products,
and introduces
- 32 -
and
between
a new (meta) form which
includes these as special cases, on this new construction
We also investigate
the effect of select operations
called the general dyadic form (GDF), and show that it,
like the standard form on select expressions,
is closed under application
of select
operations. The key to the relationship is the generalized
between these apparently
transpose operation.
diverse constructions
By applying a transpose to an outer product,
it is possible to write an expression which specifies a diagonal slice of the original For example,
outer product.
if I/ is a vector, M a matrix,
then the expression
1 1 2Qv” .+M describes the result of adding V to each of the columns of M. It would be desirable to understand this expression namely the result of adding the vector
to mean the result it describes,
V to the columns of M, rather than the process,
that is the transpose of the outer product of V and M. The difference Using the first interpretation
for two reasons.
must actually be evaluated, of the result to be computed.
as in a program,
Second, some information
For example,
the expression
requires
only the pertinent
important
when the operands are
is lost by ignoring the partial
and in transposes
the language renders expressions
Formally,
the definition
of
such as the one just mentioned undefined, yet My contention is that at worst this
kind of situation should be an ambiguous one, since it is essentially That is, the programmer of his program
in the evaluation of an irrelevant
sense
of outer products this is a serious problem,
this is really a matter of taste and style.
depend on the processor
results.
gives the value 1. Both in the case of
as it is in direct conflict with the semantics of APL.
of a side effect.
elements
( ( 1,~ ) t( 1, o ) ) [ 11 is undefined in the literal
but the apparent intended interpretation select expressions
in a situation where the expression
This is especially
large arrays.
is important
writing
an instance
such an expression
to indicate that a domain error
partial
result.
- 33 -
should not occurred
If that is what he wants, there
are direct ways of expressing it, such as writing
A-+(1,2 )t (1 ,O) , followed by ACI].
In any case, I have taken the view that what should be evaluated is the intent of an expression,
if this is perceivable,
rather than the literal
Except in cases which produce side effects,
expression itself.
both approaches compute identical
values. Theorems
T5 and T6 which follow, establish
the essential connections among
the product forms and the transpose. -T5,
If A and B are conformable operator
Proof: -T6.
then
A Q B -
for scalar product,
((1ppA1,1ppB)@A 0.Q B.
See Appendix B. If M and N are two arrays conformable dyadic scalar operators, where A f-t (I-ltppM),(2p
then
for inner product and Q and F are
M Q .z N -
(inl-origin
D_IAQM0 .E N,
LASTl),(-l+ppM)+~-1tppN
and LASTI is the index of second-to-last
Proof:
and if Q is a dyadic scalar
this is (ppM)t(ppN)-1
coordinates
in M 0 -E N
and r/l(ppM)t(ppN)-1
See Appendix B.
Example :
(T6) If A andB are matrices A t.x
B -
then t/(1,3,3,2)QA
0.x B.
We can see this as follows: (tl(1,3,3,2)QA
0.x B)CI;Jl -
t/((1,3,3,2)QA
-
t/ACI;
-
(A +.x B)CI;Jl
IxBC ;Jl
- 34 -
0.x BXI;J;I
in general).
In previous
sections we have looked into the effect of select operators
single arrays and scalar products. of the select operators answer,
form, D29.
A natural question then is, what is the effect
on inner and outer products.
it was necessary to discover an alternate
which facilitates
on
this kind of analysis.
In order to approach an formulation
Such an alternative
of these constructions,
is the general dyadic
defined below. General Dyadic Form:
An expression
with dyadic scalar operator
on two array operands R and S,
Q is in general dyadic form (GDF) if it is
expressed in the form: AQR' 0.Q S' and the following conditions are satisfied; (i) (ii)
R1 and S’ are the standard forms of select expressions A is a conformable
on R andS.
transpose vector for which each of (ppR’ )+A
and (ppR’ )+Aare in ascending order,
and each contains no duplicate
values. (iii)
CpAQR'o.Q S’>CAl
+-+ (PI?’ ),
~5”
The last condition guarantees that if A takes a diagonal slice of the outer product El’ 0.Q s’,
then the length of corresponding
This can always be done by performing
coordinates
in R' andS’ are the same.
a take operation affecting these coordinates
(see TR17). Example :
If Vis a vector,
M and N matrices,
(1,1,2)4V
then the following
0.0, M,
(1,3,2,3)4M
0.0 (2,1)4N,
(1,1)4((1,1)4M)
- 35 -
0.Q V
are in GDF:
but the following
are not in GDF because the conditions on A are not satisfied: (1,3,3,2)4M
0.D N
(1,1,1)4M From definitions
0.Q V
D27, D29 and Theorem
T5,
it is clear that the scalar product
and outer product of R and S by 0, are special cases of the GDF, obtained by taking A ++ ( ~PPR), lopSand A an inner product
I( ppR)tppS,
respectively;
can be expressed as a reduction of a GDF,
In discussing the effect of select operators of transformations, transformations,
IfW -
(ppR’)+A
in Appendix B.
and
of RTf -
G -
(ppR’)tA.
HCP;lAR' XG;lAS’
If wis as above and Q is a scalar, where UistheSF
B -
(J#A)/A-J B4U 0 .O_ V
a& R'CCFlJI
&I ELSE R'
S’CCGdl
&I ELSE S'
If W is as above then B4W => (F’ ,G’) 4U 0 .D v where
In the following
A4R' 0.0 S' is in GDF then HOW=> A4U 0.D- Vwhere
V is the SF of S” -
TR17.
we will present a series
let
U istheSF
TR16.
on GDF’s,
with proofs of their correctness
F -
TR15.
D28 and T6 indicate that
F' -
(MEBCFI)IM
G' -
(MEBCGI~IM
M f-f I(r/B)tl-IiL
U is the SF of
R" ++ (F’~BCFI)4(pB4W)CBCFII~R1
V/s the SF of
S"-
(G'tBCGI )4(pB4W)CBCGII+S’
-36-
TR18.
If M and N are conformable operators, where
for inner product and O_and E are dyadic scalar
then M O,.F_N => QIA4M' 0.F N'
A ++ (I-ltppM),
LASTl,(-l+ppM)t~ppN
M' is the SF of M N’ is the SF of (LASTN, ~-l+ppN)4N LAST1 is the index of the second-to-last ( (ppM)t(ppN)-1
in l-origin;
l-origin;
These transformations COMPLETENESS reductions
r/lppN
are sufficient
THEOREM 3:
and select operators
A and B respectively.
expression @of the form the reduction
operators
of N.
in general). to establish:
Let f9 be an expression
consisting
applied to a scalar product,
outer product of expressions &and on arrays
of M o SF N.
in general)
r/l(ppM)+(p~N)-l
LASTNis the index of the last coordinate ( ~~flin
coordinate
3,
only of
inner product,
or
where 4 and 9? are select expressions
Then &can be transformed
into an equivalent
D /.9’, where g’ is in GDF and the QI ‘s are LI,lQ,/ . . .-K appearing in &, in the same order.
expression E contained an inner product, QK is the first
If the original
operator
of the inner
product. Proof: F.
Similar
to Completeness Theorem 1.
Conclusion This chapter has discussed some of the formal
the operators
found in APL.
Of particular
interest
mathematical
of
are the completeness theorems,
which give conditions under which a subset of APL expressions standard form.
properties
can be put into
The general idea of the standard form is that sequences of selection
- 37 -
operators
on an expression can be transformed
tions on the same expression. are selection operators,
In other words,
inner,
outer,
sequence of opera-
if &is an expression
3 further
and 21,. . . ,sK and G such that
then there is a process for finding A, F, 21 22 *. . SK& -
Completeness Theorem
into a shorter
AQFAGn&
shows that, in essence, selection operations
or scalar products can be absorbed into the individual
Also by Completeness Theorems 2 and 3, reductions
on
operands.
can be factored out of select
expressions. Clearly,
the whole story has not been told at this point; indeed, the contents
of this chapter barely scratch the surface of the general problem of analysis of APL semantics.
Even so, the results discussed are a sufficient
design of the APL machine discussed in the next chapters. analysis here provides a formal
base for the
In particular,
basis for the beating and drag-along
processes,
which are the two foundations upon which the APL machine design rests.
- 38 -
the
APPENDIX
A
SUMMARY OF APL
Monadic form Definition or example tB
++
-B
+--c O-B
fB
Dyadic
f
AfB
Name
Name
OtB
form
Definition or example
Plus
t
Plus
2f3.2
c-f
5.2
Negative
-
Minus
2-3.2
4-t
-1.2
xB ++
(B>o)-(Bx(E\G'C;11)t10RG+-1-E\L
But
E\GrC;Kl
Making this substitution u tt
f-t EXG[;K]
f-f
(-FC;ll)xGC;K1forKe1,2,3.
and commuting krms,
((F[;1]t-F[;1])x(G[;21t((wG[
;3l)x-IORC)tGC
;31xGC;lhI&X&-l)
t((-G[;31)~(F[;11~~;21~t(-FC;ll~~(-F[:;l~~\L~ tG[ ;31x(F[ ;llx-FC;21>+(-F[;11)x-(-FC;1I)\L.
But F[ ;I] t-F[ ; 11 -
( pFC ;ll )pl
and does not contribute
- 45 -
to the product in the
first term.
Also, (-~[;ll)x(-FC;lI)\L
-
(-F[;l])\L.
u f-f G[;2]t((-G[;3l)x(x/F)t((-F[;ll)\L)+IORG) +~[;3]xG[;11+~~+-1-(~~/~~~~-~~;~~~\~~
-
S
QED.
Proof of TR7: 1.
~FLJG~ -
(-FL-;ll)IpGaM
-
(-F[;ll)l(-GC;ll)lpM
f--f ((-GC;ll)\-FC;ll)/pM pH@4 f-f
2.
(-HC;l])/pM
((-GC;ll)\-FC;ll)IpM
-
pF/JG-&V
L EL2
S -
where
T +j
II))/0
(by L8)
IPFAGIM,
(FLJG~JM)C;/LI -
(H&V)[;/L]
(-(GC; lIv(-GC;ll)\F[;
-
For each
where
-
(by LW
(GaM>C;l(xlF>+(-Fc;ll)\LI
-
MCi/s]
(xlG>t(-GC;ll)\(xlF)t(-~[;ll)\L MC;/(x/H)t(-Hc;ll)\Ll
-
MC;ITl
((C[;1lv(-GC;1l)\FC;l~)x(GC;21+(-G~;~l)\FC~21)) t(-(GC;l)v(-GC;lI)\FC;ll))\L
Expanding the products, G[;l]v(-G[;l])\F[;l]
and noting that -
GC;ll+(-GC;l~)\F~;l~,
we get T tt
(x/G)t(G[;1lx(-GC;11)\FC;23)+(G~;2lx(-~~;~l)\F~~~l) t(((-G[;11>\FC;al)x(-GC;ll)\FC;21)+((-G~;l~)\-F~~~~)~~.
- 46 -
Sowe must show thats order:
In simplifying
f-f T.
If U and V are logical vectors, Ux(-U)\X (U\X>x(U\Y) u\nx
-
(pU)pO
-
U\XxY
-
(U\V>\X
Also recall from the definition GC;I 1 does. T -
T, we use the following,
v-m
of A that CC;21 contains zeros wherever
Thus, we rewrite
T:
(~/G>t(GC;2l~(-GC;l1>\FC;ll)t((-GC;ll)\(x/F))t((~GC;l~~\~~C;l~~\L
But the second term goes away because of CC; 2 l’s 2’ -
zeros.
~~lG~+~~-GC;1l>\~~lF~~+(-GC;11~\~-FC;11~\L
-
~~lG~t~-GC;11~\~~~lF>+~-FC;ll~\L~
-
5’ QED.
Proof of TR8: Clearly the ranks of both expressions 1.
pFAAQM-
are identical.
F[;l]
Now, for each
(by L5) IEIPPAWCA
(pA4FCA;lAM)CII
;lM
-
LI(A=l)IpFCA;lAM
-
LIFC(A=I)/A;ll
-
(by LW
-M L/(t/A=l)pFCI;11 2.
For each
L ELB
~PJ’~(PM,
LI(A=I)IFCA;ll
-
FCI;ll
_
(FAA4M)C;ILl
-
(A4M)C;IQl
&CIl
-
(rl FCI;I)CLCIII
-
(FCA;IAM)C;ILCAII
-
(J_ ~~cA;I>c~;I~c~LcAI~c~ll
-
(J, FCACIl;I)CLCACIIIl
-
QCACIII
where
(A4FCA ;lAk’)C;/Ll SCII
where
Thus QCAI -
S.
-
QED., - 47 -
-
-
MC;/&CAll
-
(&CAl)CIl
MC;IS
(~FA~QM)CII
in
The case of ( PAQM) ++ 1 is trivial
Proof of TR9: 1.
pp(AQM>[[Jl&l
ppA’4B@4 -
-
and will be omitted. (in l-origin)
(l-/A)-1
(ppAQM)-1 -
r/A’ f-f r/(AtJ)/A-J -
of r .)
r/(J*ACL,E,GI)IACL,E,G3-J,~~pAC~l~p~~,~pACGl~p~~/~AC~l,A~~l,ACGl~ -((PACL,EI)PO),(PACGI)P~
If J f-f [/Athen
r/ACLI,(ACGI-1) ACGI -
-
(rIACLl)r(l-IACGI)-1
lOand the result is r/ALL]
A[G] is non-empty and rIACG1 -
r/A,
SO the result
f--f (r/A)-I. is still (r/AI-l
Thus the ranks of both expressions
exhausts I~A, by definition.
Otherwise, , since A
are identical.
We now show the dimensions to be indentical. For each IEl(r/A)-l, (pA’4B&‘f)CII
-
L/C (AtJ)lI=A-J\L (Q/G’-$)C;IL1
F'C;ll
-
F'[ ;21 -
-I+((-G[;ll),l)/~M
;ll)\Ll
-
&YFU’
(rI~PPM)#~pPM
Further, where
-
IPGQ/M,
(GAD/M)[;LI
F[;2]
(-GC;ll)I-I+PM
-
(x/G')+
-
D_/F’AG’aM -
(rl~ppG'aM)#~ppG'1IM
F'C;l]\L
and, by TR7, HI: ;lI H[;2]
f-t G'C;lIv(-G'L-;l])\F'[;l] -
G'C;21+(-G'C;ll)\F'[;21
- 55 -
FC;ll\(-GC;ll)\L Q/HIM
Now for each 1~ ~PPFIM, (F@f)[Il
-
MC;I(xIF)t(-F[;I)\II
tf
M[;/((x/G')tFC;ll\(-G~;l~)\L)t(-F~;~~~\~~
f-f M[ ;/( (x/G)t(-G[;lj)\L),Il
since FL;11 +-+ ((-ltppM)pl),O (-G'[;l])\F'[;11
and
-
((-GC;ll),l)\F'C;11
tf
((-G[;ll),l)\(-l+F'[;ll),-l+F'C;11
++ ((-G[;l])\(-ltppG'&V)pl),O so H[;l]
f--t G'[;l]v(-G[;l]),o
fl[;2]
and thus
-
(GC;ll,O)V(-G[;ll),O
f-t
(GC;2l,O)t((-G~;11,1>\F'~;2~
f-f
(G[ ;2],0)+(
(HLLM)[~I -
-
(-G[ ;I])\-l&F'[
;i!l),o
(-GC;ll),O -
-
(rl~ppM)#~ppM
(GC ;21+(-G[
;lI)\L)
90
MC;/(x/H)t(-HL-;ll)\Il
c-f M[ ;/(G[ ;2lt(-G[
;lJ)\L)
,I]
-
(FaM)Ul
and so HAM +-+ F-&V. Therefore
GAD/M f-t QlG'LM. QED. There are two main cases.
Proof of Theorem T5:
One of A or B is a scalar and is extended to the size of the other operand.
a.
Suppose A is scalar. (IPPA),IPPB
similarly
-
Then, A 0 .O_B f-t A O_B, by definition,
(10),1ppB
IPPB, which is the identity
-
1.
PP((IPPA),~PPB)~A
0.~ B f-t f-f
and for each
dimension.
Then
([/(lppA),lppB)tl-IJRJ (I-/lppA)tl-IJR0
-
PPA
IE xppA ,
(P((IPPA),~PPB)(PA
Thus,
transpose,
if B is a scalar.
A and B are arrays of identical
b.
and
pA o_ B -
0.~ B)[II
p((~ppA),
-
L/(I=(IPPA),IPPB)/(PA),~B
-
Ll(I=~ppA)lpA
1ppB)4A o.Q B. - 56 -
-
(pA)C.U
and
For each
2.
L g
1pA Q B,
0.Q B)C;/LI
(((zppA),lppB)QA
-
(A 0.2 B)C;/L,LI
-
(A Q B)C;ILI
AC;/LI
-
Q BC;ILI QED.
Proof of Theorem T6: 1.
ppA&JM0.F N -
(r/Ah-l-m?G
f-f
rh(ppM)+(ppN)-1
-
l+ppM g.g
N
For each IclpAQM 0.F N, (pAQM 0.g N)CII
L/(I=A)/pM
-
IJ- I&-1tppM m
So, PALM 0.c N -
andtherefore
For each
L/(I=A)I(pM),pN (pM)CII
ELSE IF Id-l+ppM)+l-1tppN --
ELSE L/C-lCpM),l+pN.
(-l+pM),(l+pN),-1fpM
pQ/AQM
L ELT
m
(pN)C2tI-ppM1
0.F
N -
-l+pAQM
2.
0.F N -
-
IPM
0-F
0.F
(-lbpM),lSpN
N -
pM Q.F_ N
fl,
(M 0.F N)C;ILl
Q/(G&kO E HAN
-
whereG and H are asinD28.
Also, (QIA4M 0.F N)C ;/Ll
-
where
0.F
N)pl),O
EC;11 -
and EC;21 -
CC-1tppAW
EC;ll\L
To complete the proof, Clearly
-
N)pl),O
((PPM
o,.E
L,O
we must show that the two reducees above are identical,
both have the same dimension,
Then for each
-
Q/E&4QM 0.F N
namely -l+pM.
IEIP-~+PM,
((CAM) E HarV>CIl -
(E&4QM o.F_ N)CIl
(G&WC11 F_ (H@)CIl
-
MC;I( (-l+ppM)+L),Il
-
(AQM 0.E N)C;IL,II
-
CM 0.F N)C;l((-ltppM>tL>,I,I,(--ltppNj+Ll
-
MC;lU-ltppM)+L),Il
-
((GM)
E HAN)CII
- 57 -
z NC;II,(--1tppN)cLl -
CM 0.E N)C;I(L,I)CAII
E NC;II,(--ltppN)+Ll
Thus, (G@) g HAN identical.
E&AQM 0 .E N, and so the_D reductions
of each are
QED.
Proof of TR15: 1.
The ranks of both expressions does not affect ranks.
PU
0.Q V)CIl
0.g V -
2.
therefore
PAQU
For each L ZC
L/(I=A)IpU
0.0, V.
0.Q H[G;lAS'-
-
(PHCF;IAR~>,PHCG;IAS~
-
HCF;ll,HCG;ll
-
0-Q
-
HCF,G;ll
L/(I=A)/HL-A;11 V c-t
HC;ll
tf
-
-
HCA;ll
L/HC(I=A)/A;ll
-
HCI;ll
PHAW-
~PHAW,
(HAW>C;/Ll -
CAQR' 0.Q S')C;IPl
-
R’C;IPCFll
-
CR' 0.Q S')C;/PCAll
Q S'lI;/PCGII
P +-+ H[;2It((~HC;3l>xL-~)tHC;1I+IOR&t-l-L
where
(AW 0.0, V>C;lLl
where
Then
-
(H[F;lAR')
Thus, ( PAQU 0.Q V)CIl and
operator
So for each Ic~ppW,
(PAW
But
are the same since the subarray
T -
-
(R"
0.Q S'OI:;IL[AII
-
(HCF;lAR')C;/LCFII
-
R'C;/!Z'l
Q (HCG;lAS')C;ILCGII
Q S'C;/T'l
H~F;21t((-H~F;3~)~L[FI-IORG)+HCP;3lxHCF;3~~H~F;l~t~~t~l-L~F~
-
PCFI
T' -
PCGI
and sinklarly,
(AQU 0.Q V)C;/Ll
-
R'C;IPCFll
0, S’C;IPCGII
-
(HAW)C;lLl.
Finally,
the result is in GDF since u and v are in SF and the value of A still
satisfies
the required
conditions.
QED.
- 58 -
Proof of TR16: 1.
PwCCJI &I f-t
To determine
(J#IPPW)/PW.
PBQU 0.Q V we must first
pu 0.Q v. pU -
pR”-
IF JEF TaN
&I E’LSE pR’
~R’CCFIJI
There are two cases: a.
JEF. Then, pR” -
&I -
pR’CCFtJ1
((FxJ)t~ppR’)/pR’
-
((F~J>#~ppR’>l(pW>CFl
-
(PW)C((FIJ)*IPF)/‘FI
-
(pW)C (F#J)IFI
-
(((J-~)~PW),(PW>CJI,J~P~)C(F~J)/FI
-
(((J-l)~pW),J~pW>C(FtJ)/F-JCIl -
LI(I=F’,G’)IPV
-
O.i? v
L/(I=F’ ,G’ )l(pR”)
,pS”
So we must findpI?” and PS”. p(F’zBCFl)4(pB4W)CBCE’11+Rf
pR”ppR”-
([/F'tB[Fl)tl-Im
(rIipF’)tl-IORG
-
-
PF’
Then, for each JE IPPR”, (pR”)[JI
Hence
-
L/(J=F’
-
L/(J=F’\BCFl)l(pB4W)CBCF11
-
L/(pB4W)C(J=Ff~BCFI)/BCFll
-
L/(pB4W)C(F’CJI=BCFl)/B[Fl1
-
(pB4W)CF’CJII
pR” -
and similarly,
~BCFl)/p(pB4W)CBCF11~Rf
(pBQW)CF’I
-
~5”’ +-+ (pB4W)CG’ 1,
‘and thus (p(F’ ,G’ )4u 0.~ v>CIl
andtherefore
p(F’,G’)4U
-
LI~~=~‘,G’~I~PB~W~C~‘,G’~
-
L/(pB4W)CU=F’,G’)IF’,G’l
-
(pB4W)CIl
0.0, V -
- 61 -
PB~W-
2.
For each L ELp 1pB4w, (B4W)C ;/Ll
((F’,G’)QU
-
(R’ 0.0 S’ )C;ILL-BL-AI11
-
R’C ;I(PPR’ )+LCBCAIIl
-
R’C;/LCBCFlII
0.Q
V)C;lLl
0, S’C;l(ppR’
)+LCBCAlII
Q S’C;/LCBCGIIl
-
(R” 0.Q S”)C ;/LCF’ ,G’ll
-
R”C;/LCF’II
Q S”C;lLCG’ll
So we must calculate the R” and St1 terms above. ~“C;lLCF’ll
since
L m
implies
(U”~BCFl>4(pB4W>CBCFll~R’)C;/LCF’ll
-
((PB~W>CBL-F~~+R’>C;/LCF’C?“~BCF~~~~
-
((PB~WCBCFII+R’
-
R’C;/LCBCFll3
&J
S1’C;/LCG1ll
I (pB4W)CBCFII -
SIC;/LCBCGlll
((F’ ,G’ >4U 0.Q V>C;/L,3 -
Finally,
observe
)C;ILCBCFll
1pB4W
LCBCFII
Similarly, Thus,
-
R’C;ILCBCFIII (B4W)C ;/Ll
that the result is in GDF since U and V are in SF and F’ and
G’ are in order and contain no duplications Proof of TR18: Immediate from
Q S’C;/LCBCGIIl
T6.
- 62 -
by construction.
QED.
APPENDMC IDENTITYELEMENTS
Dyadic Function Times Plus Divide Minus Power Logarithm Maximum Minimum Residue Circle out of Or And Nor
Nand Equal Not equal Greater Not less Less Not greater
Identity Element x + i * 8 r
1 0 1 0
L L
R R R R R None
1 -7.237
. ..E75 . ..E75
i 07-237
0
! v h Y * = f > 2 < s
1 0 1
1 0 0 1
0 1t
LeftRight
ApPlY for logical arguments only
L
R
L R L None L L R L R None None L R L R R R L L
Identity Elements of Primitive Scalar Dyadic Functions
- 63 -
CHAPTER III STEPS TOWARD A MACHINE DESIGN
I
Never do today what you can Put off till tomorrow. William
Brighty Rands
procrastination is the art of keeping up with yesterday Don Marquis,
archy and mehitabel
As demonstrated consistency
in Chapter II, there is a high degree of power and internal
in the APL operators
write simple expressions
and data structures.
This makes it possible to
which have the same semantic content as several state,
ments in comparable
programming
languages.
This chapter discusses how to
exploit these features in the design of an APL machine. In general,
APL programs
contain less detail than corresponding
in languages like ALGOL 60, FORTRAN, value in a vector,
or PL/I.
For instance,
programs
the maximum
V , of data can be expressed as r/V in APL while ALGOL requires
the following: MAX:=smallestnumberinmachine; -for:=1
step1 --untilN
While this aspect of APL often makes programs say, ALGOL programs, than one for ALGOL,
it also requires especially
do
shorter
and less intricate
than,
that an evaluator of APL be more complex
if such expressions
are to be evaluated efficiently.
On the other hand, a machine doing APL has greater freedom since its behavior is specified less explicitly. of their results
In effect,
APL programs
can be considered
rather than as recipes for obtaining them.
- 64 -
Further,
as descriptions the language
renders
many of these descriptions
machine,
as in the case of r/V,
that the original
obvious, both to the human reader and to a
while other languages encode them so intricately
intention of the programmer
is hidden.
In the example above,
an APL machine can choose any method it pleases to find the maximum value while an ALGOL machine doesn’t know what result is expected. This feature of APL also has some drawbacks in that some expressions results
require unnecessary computations
instance,
the expression
For
as written,
3+(2X-v) specifies a result which is the first 3 elements
of twice the negative of v[/. Presumably However,
three elements.
if calculated literally
for
the programmer
the literal
interpretation
is only interested
in these
of this expression proceeds
as follows: 1.
Negate I/ (and store it somewhere).
2.
Multiply
3.
Take the first 3 elements of the last result.
the previous result by 2 (and store it).
In case V is large,
this process is grossly inefficient.
The negation requires
fetches and stores as well as (pV> spaces for the value to be stored. plication
requires
another( pV) fetches,
stores,
and multiplies,
( pV>
The multi-
In fact, the
desired result could have been found simply by negating the first three elements of I/’and multiplying
by 2.
evaluate such programs A.
Drag-Along
Clearly,
efficiently!
_
and Beating
One approach to efficient exploit the mathematical the machine,
we would like the APL machine to be able to
and natural evaluation of APL expressions
properties
of the language to simplify
is to
calculations,,
this approach is embodied in two fundamental new processes:
along and beating.
- 65 -
In drag-
Drag-along
is the process of deferring
as long as possible. simplify
By examining a deferred
it in ways which are impossible
are available.
evaluation of operands and operators
In effect, drag-along
expression it may be possible to
when only small parts of the expression
makes the machine context-sensitive,
while
most machines are context-free. Consider the drag-along assume a stack machine, 1.
LOAD
2.
NEGATE
3.
LOAD
4.
MULTIPLY
5.
TAKE
evaluation of the example in the last section.
the machine code for this expression
2
3
execution of this sequence was already shown.
we temporarily
defer instructions
LOAD
the buffer contains
V
2, we have
LOAD
V 1
NEGATE
where the pointer connects the negation with it-s deferred instruction
Suppose now that
in a buffer instead of executing them as they
After the first instruction,
After instruction
might be
V
The immediate
appear.
If we
operand, V.
After
4, the buffer contains LOAD
V
NEGATE LOAD
31 2
MULTIPLY
3
>
The evaluation of the TAKE is different selection operator.
from the previous
operators
since it is a
TAKE can examine the contents of the buffer and change them, - 66 -
as below.
Note that the deferred
expression
is equivalent to the original
expression.
The process of making the changes in the buffer is called beating. (Note change in this instruction)
3+v
LOAD
3
NEGATE 2
LOAD
3 3
MULTIPLY
When values must finally be computed,
only the desired elements will be accessed
and used.
beating.
Thus, drag-along
facilitates
The other aspect of drag-along results
is that it eliminates
with consequent savings of stores,
such as AtBtCtD
the literal
fetches,
intermediate
and space.
array-shaped
In an expression
execution proceeds in three steps:
Tl+CtD T2+BtTl T3+AtT2
If the variables temporary
A,B,C,D are vectors,
each step above requires
store and the last two steps require
as operands.
With drag-along,
evaluated element- by-element -for
a vector-sized
fetches to get the previous
the entire expression
is deferred
finally
results to be
as : I+1
step 1 until p.4 &
T3C~l~AC~~t~C~1tCC~1tDC~l
This requires
no extra fetches,
stores,
or temporary
space to obtain the desired
result, In the machine,
drag-along
will be applied to all array operands E and Sand
to all monadic and dyadic operators (MOPG)C;ILI
MOP and DOPfor which -
~O~(Fle,c;/Ll
and (~DO~L~VC;/LI
-
(FlQ)C;ILl - 67 -
Dop' (F2g)C;/Ll
where Fl and F2 are simple functions of arrays and Mop’- and DOP’ are similar MOP andDoP . An example of a function which is not dragged-along is grade-up which is essentially
to
by the machine
Grade-up obviously does
a sort of its operand.
not fit into the above scheme since Fl also becomes a sorting function which is not simple as required. B.
Beating and Array
Representation
Beating is the machine equivalent of calculating pressions
standard forms of select ex-
If the effort to do beating followed by an evaluation of a standard form
is less than that to evaluate an expression
directly,
then the process is worthwhile.
We will see in the following chapters that this is in fact the case. In order to apply beating we must specify a representation form.
One possibility
expression
of the standard
is to maintain the A, F, and G values for each array in an
to allow calculation
of the standard form AQFnG-M
as defined in Chapter II. .-and it is desirable
However,
to find a more compact representation.
If we choose to represent resentation
these arrays contain redundant information
arrays in row-major
order we can utilize the rep-
of the storage access function as the representation
In this way, beating will consist of applying the kansformations
of s”kndard forms. of Chapter If to
the mapping functions for arrays. In the following index origin is zero. subtracting IaG
discussion we can assume without loss of generality Situations where it is different
from all subscripts.
reduce to the zero case by
Let A be a rank4
that each element in A is to occupy one word in memory,
array.
- 68 -
Then, assuming
the element AC ; lL1 will be
located at VBASE+(pA)lL
that the
(*)
where VBASE is the address of AC0 ;O; . . . ; 01. Thus, subscripts in row-major
order are representations
system (Knuth [1968] p. 297).
of numbers in a mixed-radix
This representation
in APL because APL arrays are rectangular, this representation
of arrays
is especially
number
suitable for arrays
dense, and homogeneous.
does not favor any array coordinate
stored
Further,
over another which is
essential in APL. We can generalize
the access function slightly
by writing
VBASEtABASEtt/DELxL where ABASE is an additive constant,
it in the form:
(**I
in this case zero, andDEL is the weighting
vector used to calculate the base value in (*) above.
DEL is computed by
DEL[N]+l DEL[lh-DEL[ltljx( Example:
pA)CItlI
Let M be a matrix with dimension 2,3.
for each IE d-1. Then DEL-3,l
and we set ABASE-O.
The layout of M in memory is VBASE + McO;Ol
t1
t2
t3
t4
t5
MCO;ll
MC0;21
MCl;Ol
MCl;ll
MC1;21
Given this formulation transformABASE
of the storage access function,
it is only necessary to
and DELin order to obtain the effect of evaluating selection opera-
tions on an array. Example : IfM is the matrix in the previous example,
then the mapping function
for ( 2,1> (PMhas the same VBASE. For the transpose we use ABASE'*0 and DEL I-1,3. Note that the change in DEL corresponds
to permuting
uses the same values that were stored forM, the transpose
( 2 ,l )(PM. To verify
it by 2 ,I.
This new function
but accesses them as if they were
this, note that the address for ( ( 2 ,l )QM)CI;JI
- 69 -
is VBASEtABASE'tt/DEL'xI,J
which is the location of MCJ;Il
VBASEtABASE'tClxI)t(
-
VBASEtABASEt(3xJ)t( 1xI)
-
VBASEtABASEtt/DELxJ,I
f-f ((2,1)QM)CI;Jl.
This can be done for any selection operator to those in Chapter II.
taining reductions,
by using transformations
Appendix A shows the beating transformations In the machine,
functions for arrays.
3xJ)
-
analogous on access
beating is also applied to expressions
scalar operators,
con-
and inner and outer products, based on the
results in Chapter II. C.
Summary At this point we have outlined the framework
of a machine for APL.
pleasing to know that it will work since it is justified developed earlier.
The remainder
by theoretical
of this dissertation
results
discusses the structural
details of a machine based on the beating and drag-along evaluation of its effectiveness.
It is
processes and gives an
Let us outline some goals that such a design should
satisfy: 1.
The machine language should be close to APL.
all primitives
in the language and in a similar
to design a machine to accept APL directly doing so.
We are primarily
language, not its syntax.
form.
That is, it should contain While it is well-known
there is no particular
concerned with processing
freeing the machine from the particular
- 70-
in letting the machine
This has the further
external
advantage to
the semantics of the
Thus there is no loss of generality
language be a Polish string version of APL.
how
syntax of APL.
advantage of
2.
The machine should be general and flexible.
not be so deeply committed 3.
In particular,
it should
to evaluating APL as to be useless for other purposes.
The machine should do as much as possible automatically.
storage management,
control,
and simplification
should not have to be aware of the structure
of expressions.
and internal
This includes The programmer
functioning
of the machine
at a level much beyond that specified in an APL program. 4.
The machine should do simple things simply and complex tasks in pro-
portion to their complexity.
In other words,
to execute a program
or expression
way to the program’s
complexity.
5,
Of course,
technology; at present, is use of memory. porary 6.
for the machine
should be related in some straightforward
The machine should be efficient.
focus of this work.
the work required
This is perhaps the most important
the question of efficiency
is related to the current
a major bottleneck in evaluating array-valued
Thus we concentrate
expressions
on reducing memory accessing and tem-
storage space in the evaluation of APL programs. The machine design should be elegant, clean, and perspicuous.
- 71-
APPENDIX TRANSFORMATIONS
A
ON STORAGE ACCESS FUNCTIONS INDUCED BY SELECTION OPERATORS
1.
The storage access function for an array M contains the following RANK
-
PPM
RVEC
-
PM
VBASE
location of first
ABASE
constant term of access polynomial
DEL
vector of coefficients
Then, the element
MC; /Ll
information:
element of ,M
of access polynomial
is located at
VBASEtABASEttIDELxL 2.
This section lists the transformations
used to effect beating of selection operators. as program
segments written
to the various a,
on storage access functions which are These transformations
in index origin zero*
selection operators
are conformable
!2iJ ABASE + ABASEtDELt.x(QO)x 1s RVEC + RVEC- 1Q
ABASE +- ABASEtDELCJlx(RVECcJ3-1) DELCJ] + -DELCJI
- 72 -
are given
It is assumed that the parameters and in the proper domain.
R +- RVEC D + DEL RANK + lt(r/A) I+0 DEL + RANK+DEL RVEC + RANK+RVEC RANK REPEAT BEGIN -RVECCII + LI(I=A)/R DELLI] + tl(I=A)lD I f It1 m
e.
Mr r JlSCALARl
ABASE + ABASEtDELCJl xSCALAR DEL + (JtlRANKjIDEL RVEC + ( Jz tRANK>IRVEC RANK +- RANK-l f.
M[[Kld
LEN,ORG,Sl ABASE +- ABASEtDEL[KlxORG+(LEN-l > RVEC[Kl + LEN E S=l Tm DELCKI + -DELCKI
- 73 -
CHAPTER IV THE MACHINE This chapter contains a functional
description
of a machine designed to process
the semantic content of APL programs. In general, descriptions be written
the description
will be given in English,
will be used as necessary to provide clarifications. in the style of a programming
and rationales
The section will
manual, with the addition of explanations
as required.
The APL machine (APLM) is conceptually
composed of two separate machines,
each with its own language, sharing the same registers D-machine
although algorithmic
(DM) accepts APL-like
does some simplification
of incoming expressions
does all the actual computations
The current
(EM), and in the process
using drag-along
and beating.
of values in the system.
a stacking location counter based on the organization the overall control
By using
of machine code into segments,
scheme for the machine is quite simple.
chapter consists of five sections which present the APLM in a
logical sequent e . Section A discusses the data structures objects in the machine,
and other manipulable
and explains how they. are managed in the machine’s
memory.
Section B continues by explaining the stacks and other registers
machine,
followed by a discussion of the overall machine control,
Finally,
The
machine code and does all the necessary analysis
The DM produces code for the E-machine
on expressions.
The E-machine
and data structures.
the details of the D-machine
D and E, respectively.
and the E-machine
Examples are used liberally
tional details of the APL machine.
- 74 -
in the
in Section C.
are set forth in Sections
throughout,
to clarify
opera-
Data Structures
and Other Objects
The manipulable
objects in the machine fall into three main classes:
A.
values,
descriptors
and program
segments,
This section will describe these
three kinds of objects and how they are represented Scalars are the simplest kind of data. rank- 0.
In practice,
in the machine.
In APL,
a scalar is a different
data
a scalar is an array of
kind of object than an array,
and is
so treated in the machine.
Although arrays are stored in the memory,
M, of the
machine,
They appear only in the machine registers,
in particular
scalars are not.
the value stack, and as immediate scalars would have an attribute
operands in a code string,
of &oe, determining
use for encoding and decoding them. handled automatically,
In this work,
In a real machine,
the kind of representation
to
we will assume that this is
and that all scalar data are the size of a single machine
word. The most important
data structure
in the APLM is the array.
tation of an array is divided into two parts. a row-major is a descriptor
order linearization
array (DA) for an array,
DA’s, not necessarily
makes beating possible.
is the value array which is
of the elements of the array.
storage mapping function for the array. multiple
The first
The represen-
The second part
which contains the rank, dimension,
and
This separation makes it possible to have
identical,
In this chapter,
referring
to the same value array,
descriptor
which
arrays will be shown in the
form: @ARR 101 +02 $03 i-04
RC=Z VB=VARR RANK=2 R( 1)=003 R(Z)=002
LEN=05 AR=000 D( 1)=02 D(2)=01
@ARR is the address in memory of the first word of the descriptor array named ARR, which is shown above.
- 75 -
The first
array for the
word contains a reference
count (RC) and a length (LEN) field, in the APLM.
as explained in the discussion
on memory
The rank of the array is recorded in the third word of the DA;
words after that contain the elements of the dimension vector, in this case, PARR is 3, 2.
Thus
labeled R(I).
The second word in the DA encodes the base address
of the value part of the array (labelled VB for VBASE) and the constant term in the storage mapping function (here labelled AB for ABASE). contains the coefficients here).
of the storage mapping polynomial,
Recall that for an array ARR, the element ARR[;/L] VBASE + ABASE + +/DEL
This formula
the DA
DEL (labelled D(I) is located at
x (L - IORG);
is the storage mapping function for any array.
In addition to array descriptors, J-vectors.
the machine contains descriptors
Recall from Chapter II that a J-vector
assume that these three quantities function JCODE(length,
origin,
and a direction
can be encoded into a descriptor
direction)
for
is a vector of consecutive
integers which can be specified by a length, an origin,
functions.
Finally,
bit.
We
by the
and that there are appropriate
decoding
(See Appendix A. )
Finally, segments.
programs A program
and is referenced
in the machine are represented
internally
as program
segment is any sequence of machine commands and operands,
by a segment descriptor.
Segment descriptors
encoding of the beginning address of a segment- (relative function they are a part of) and the length of the segment.
contain an
to the beginning of the There is also a bit
which indicates the execution mode for the segment (see Section C). Each defined function (program) function may also be represented to activate and de-activate of organizing
programs
is a segment, and logical subparts of the
as segments.
As will be seen later,
segments in the APL machine.
Briefly,
it is easy
the advantages
in segments is that these are the logical units of a program,
- 76 -
while other organizations,
such as paging, do not allow this kind of natural cor-
respondence of form and function (pardon the pun!). APLM instructions
property
of
is that they contain no absolute addresses except for references All internal
to NT, which remain constant in any compilation. other parts of a program
are relative.
Thus, all programs
Each function has a corresponding a DA.
An important
A function descriptor
function descriptor,
contains the following
references
to
are relocatable. which is similar
to
information:
FVBASE
location in M of beginning of function segment
FLEN
length of function segment
FIORG
index origin for this function
FISR
logical variable -1
FPARS
number of parameters
FLCL
total number of local names
In addition,
the rest of the function descriptor
in the function, (if any).
in the order:
from functions,
contains a list of all local names
result (if any), parameters
The function descriptor
if function has a result
(if any), local variables
for a function is used in calling and returning
as will be discussed in Section D,
Main memory in the machine is a linear array of words named M. objects which reside in M are arrays,
DA’s,
and program
objects are stored in the machine’s registers. NT, the Nametable, which is an abbreviated
segments.
symbol table.
Every identifier
either an actual value or a pointer to where it can be found in M. descriptors
are stored directly
in NT.
and functions in the machine go through the NT. dynamic allocation
and relocation
All other
In addition to M, there is an array
active workspace has an entry in NT, which contains descriptive
J-vector
The only
information
to variables
allows for
of space in M, without having to alter any
- 77 -
and
Scalars and
Thus, all references This organization
in the
program
The operation of NT is described more fully in the next
references.
section under machine registers. stored as part of the program of the function,
Constant array values within a function are
segment; they are addressed relative
.
to the beginning
and so, too, remain relocatable.
Within M, two different and array values,
allocation
mechanisms are used, one for functions
and one for descriptor
because of drag-along
and beating,DA’s
than functions or array values,
arrays.
are expected to have a shorter
Further,
is likely that DA’s will be of similar
The reasons for this are that,
in a given function,
sizes.
lifetime
locally at least, it
Thus, it is feasible to keep an
available space list for DA’s, with the hope that erased spaces can be reused intact.
We would therefore
expect more efficient
use of M by DA’s than by array
values. The free memory space (M) is arranged as follows:
functions and array
values are allocated from the lowest address (BOTM) towards the top of M and DA’s are allocated from the top (TOPM) down. The space in the middle is the POOL, with boundaries BOTP and TOPP. an encoding of a reference a filler
count.
is allocated.
Each entry in M has a header word containing
count (see Collins [1965]), the length of the entry,
The latter field is used when space slightly larger Each time a reference
count field is adjusted.
than necessary
to an entry is added or deleted,
Wnen a reference
count goes to zero,
and
the reference
meaning that there
are no uses of the entry anywhere in the sy’stem, the entry is made available in one of two ways.
If it is adjacent to the POOL, it is merged with POOL.
wise, it is added to the appropriate
availability
list,
Other-
of which there are two, one
for DA’s and one for functions and array values. The availability similar
lists are doubly linked,
to those for active entries.
and each entry contains a header
Wnen space is needed, the appropriate
- 78 -
availability
list is searched using the first-fit
a fit is found, the space is allocated and the availability space is taken from the POOL.
If
method (Knuth [1968] 436, ff). list adjusted.
Otherwise,
If a request for M-space is made which cannot
be honored because there is not enough contiguous space available, The two halves of M are garbage-collected
a garbage
collection
is made.
collecting
array space, all the DA’s are scanned and a linked list is set up which
ties together all DA’s pointing to the same entry.
Then arrays
separately.
In
are compacted
towards BOTM, with the links used to adjust the VBASE fields in the referent If enough space is still not available, similar
algorithm.
location algorithm, B.
the DA’s are also compacted,
DA’s.
using a
Some coalescing of available space is also done by the alGETSPACE.
Figure 1 illustrates
how M is structured.
Machine Registers This section describes the registers The present description
machine.
these registers
and register-like
in the APL
covers only the logical functions performed
by
and does not make any demands on how they are actually to be
implemented.
Although most of the registers
programmer,
thorough knowledge of their use is important
functioning
structures
are not directly
accessible to the
to understanding
the
of the machine.
There are several registers The most important
related to memory accessing and allocation.
of these is the Nametable,
NT.
NT is an associatively
dressed stack, each entry of which contains a name field,
ad-
a tag, and a value.
The name field of an entry contains an index for the identifier
associated with the
entry.
JT, for encoded
Permissible
J-vectors,
tags in NT are ST, for scalar quantities,
UT, for undefined identifiers,
DT, for arrays,
and FT for functions.
ST and JT entries contain the actual value in their value field, entries have descriptor
addresses in their value fields.
- 79 -
while DT and FT
ARRAVAIL Array atillbilitp forward link0
reference
list
Array avaihbility backward linkk
N
-
count
BOTP
POOL
#
B. PLUS MINUS SGN RECIP ABS FLOOR CEIL EXP LOGE PI RAND FAC NOT
Add Subtract Multiply Divide Modulus Minimum Maximum Power Logarithm Circular functions Random deal Binomial coefficient or beta function Logical and Logical or Logical nand Logical nor Less than Less than or equal Equal Greater than or equal Greater than Not equal
Monadic t X . 7 I
L r * @ 0 ? t.
Plus Minus Signum Reciprocal Absolute value -Floor Ceiling Exponential (base e) Logarithm (base e) Pi times Random number Factorial or gamma function Logic al not
- 89 -
TABLE
l-3
Remaining Operators Operator __-_----_-------------
Definition APL ______--__--------------
m-m---- ---m- _---m-e --w-w- ------
Selection
A. TAKE
+ 4,
DROP REV K
Take Drop Reverse along Kg coordinate
axI
TRANS INX
in D-Machine
Generalized
Q
K
transpose
Index on Kg coordinate
CCKI Evaluated Immediately
B. BASE
1
Base value (Decode)
REP
T
Representation
GDU
4
Grade up
GDD
T
Grade down
CAT K
9
Catenate (top K on VS)
RAV
,
Ravel
URHO
P
Dimension
DRBO
P
Restructure
UIOTA
I
Interval
(Encode)
Deferrable
C. ROT K
Rotate on Kfi coordinate
OCKI E
EPS DIOTA
Membership Rank
I
CMPRS K
/CKl
Compress on Kg coordinate
EXPND
\Clil
Expand on Kg coordinate
SUBS D.
K
C
K
Subscript with K expressions
in VS
Reduce along Kg coordinate
by OP
Compound
RED
K OP
GDF
OP
OPICKI ---
General dyadic form with OP
-9o-
are encoded, we have chosen, for purposes of illustration, two word quantities,
depending on whether or not they have operands.
addresses are shown symbolically strut ture.
In the register
headings are summarized Descriptor
arrow. form
@A, for variable
dumps, most of the material in Appendix A.
is self-explanatory,,
which are pointers
to the memory,
A, and value addresses in M are of the form VA.
for examples.
Field
The top of each stack is indicated by an
the real machine, these would in fact be numerical form is much clearer
All operand
and comments are used to explain the program
array addresses,
Segment descriptors
to show them as one or
addresses,
are in the Again, in
but the symbolic
Fields in DA’s are labelled mnemonically.
in VS or QS are shown in the form SCODE(SEG.X, m), where
m is 0 or 1 depending on whether the segment is a DM or an EM segment, and X is the segment symbolic name (arbitrary). along the right side of the QS display, starts here and segment Y ends here. and is interpreted interpreted
EM segments are delimited
in the format XY, meaning that segment X The LINK field of QS contains relative
according to the opcode.
as a logical vector,
by “bracketsf
pointers
The contents of the AUX field is to be
although in fact it may be encoded differently
in an
actual APLM. 1.
Storage Management Instructions This class includes all instructions
fetching of data.
concerned primarily
Each of the load instructions
Of these, four have immediate
pushes a value to the value stack.
operands; LDS, LDSEG, LDJ, and LDN push their
operands to VS with tags ST, SGT, JT, and NPT respectively. scalar the current from the top of IS. current DT (i.e.,
value of the CNT field of the iteration LDNF N refers to variable
value of the variable arrays),
with the storing and
LDIS K loads as a
stack element K entries
N in the nametable,
and enters the
(from NT) into VS. In the case of NT entries with tag
the reference
count of the DA is increased
- 91-
by 1 when it is
entered into VS, and the VS tag is set to FDT.
The LDCON K instruction
is used
Its operand K is a pointer
to access a constant array stored in a function segment. relative
to the function origin pointing to the beginning of the DA for the constant
value.
This DA is copied to the DA area of M, its VBASE is set to the beginning
of the function (FBASE),
The DA pointer is pushed to
and its ABASE is set to K.
VS with tag FDT. Although all the load instructions values do not always remain there.
just described push a value to VS, such At the beginning of each D-machine
top of VS is examined for tags FDT, DT, and JT (see Fig. 2). present,
If one of these is
then the entry is deferred in QS, because it is array-valued.
done by pushing an E-machine
instruction OP
cycle, the
This is
to QS of the form @ARR
0
MASK.
OP is IFA, IA, or IJ, depending on whether the VS tag was FDT, DT., or JT; @ARR is the DA pointer that was in the VS value field, mask.
and MASK is an access
The access mask in this case is a logical vector whose last K bits are 1
when ARR is a rank-K array, in accessing this array.
It will be used by the DM in beating and by the EM
The LINK field in E-machine
unused, and thus is shown as 0 above.
instructions
of this type is
The VS entry is then replaced by a segment
descriptor
with tag SGT pointing to the one-word QS segment containing the deferred
operand.
In general,
the load instructions deferral
this entire process is invisible
in the examples below, and
which generate array values can be thought of as doing the
themselves.
Although ASGN and ASGNV are operators, management instructions be stored,
they are included as storage
because they have the side-effect
These instructions
of causing values to
expect the top of VS to contain a destination,
as a name (tag NPT) or as a QS descriptor
- 92 -
either
pointing to a segment containing only
TABLE Interpretation
2
of ASGN and ASGNV in the D-Machine
Top of VS
(Top-l)
a.
tag=NPT or tag= SGT and deferred expression has one element
tag=sT
Do immediate assignment. That is, store the scalar value in NT or in M, as appropriate.
b.
tag=NPT
tag= SGT and deferred segment is a J-vector
Do immediate
assignment.
C.
tag= NPT
tag= SGT and deferred segment is a single DA with reference count of 1 and value also has reference count of 1
Do immediate
assignment.
d.
tag=NPT
tag= SGT and deferred segment is any arbitrary array expression
Allocate space for a DA and value of the size necessary to store the result. Defer the assignment in QS, as for scalar arithmetic operators.
e.
tag=SGT and deferred segment consists of a QS entry with opcode IA
tag= 9GT and deferred segment is any arbitrary array expression
Check ranks and dimensions for conformability. If the lhs variable is a J-vector, it must first be explicitly evaluated. If the rhs expression contains instances of the lhs variable with different permutations, then the rhs expression is evaluated to temporary space. Finally, the assignment is deferred as above.
Action
of VS
- 93 -
/ /
an IA instruction;
the second entry in VS is the right-hand
side of the assignment.
There are several possible actions taken by the DM in interpreting depending on the VS contents.
assignments,
These cases are explained in Table 2,
We have
assumed that l’evil” side effects do not appear in the code; their treatment straightforward, strategies
is
Also, it should be noted that although the
but uninteresting.
outlined in Table 2 could,be modified to alter the machine’s performance,
the case analysis remains the same. The final storage management instructions are left further only (serial) 0 mdC1 2.
unspecified.
strings,
are INPUT and OUTPUT,
These could be conceived of as read-only
which are used as primitives
for writing
which and write-
functions such as
e
Control Instructions The control instructions
flow of control
of the APLM are all concerned with directing
among statements at the source-language
level,
the
and are all evaluated
by the D-machine. The three jump instructions,
JlKl?, JMPO, and JMPl are used to alter the Since no jumps are allowed out-
flow of control among statements in a function. side of a function,
there is little difficulty
in specifying this operation.
is necessary is to change the value of the relative on LS.
pointer in the current
CYCLE is a special case of JMP, which sets the relative
causing the current
(D-mode) segment to be repeated.
IS, if the segment is involved in an iteration. in returning
segment
pointer to 0,
LEAVE pops LS and also
RETURN performs
In addition,
from a call on a function.
All that
it automatically
similarly erases the
locals for the current function from NT. The interpretation
of the DO instruction
depends on the top value on VS. If
the top of VS is a scalar then the DO acts as a no-op.
- 94 -
If the tag is SGT, then the
segment described on VS is activated by pushing the segment descriptor with VS being popped. and if the tag is FT, paragraph;
In case thetag is NPT, the corresponding then the named function is activated,
all other cases are no-ops.
is similar
except that if the top is VS and has tag NPT, the value referenced
the segment is evaluated.
NT tag is examined,
as described in the next
The DO1 instruction
space, while if the tag is SGT, temporary
to LS,
to DO
is copied to new
space is allocated for the result and
Thus, after executing a DOI, the top of VS contains an
entry with tag ST, JT, or FDT. When a DO instruction
encounters a function name on top of VS, the following
actions take place: 1. fetched.
The function descriptor,
referenced
It is expected that all parameters
by the NT entry for the function,
is
to the function have been evaluated
and placed on top of VS, so that the topmost value is the leftmost parameter. parameter
count, FPAR, in the function descriptor
is fetched,
checked to see that there are that many values already there. signaled.
Otherwise,
function descriptor,
and the top of VS If not, an error
the machine goes through the list of local variables making an entry in NT for each one.
set to UT, for undefined, unless it corresponds
The
is
in the
Each new tag in NT is
to a parameter.
Parameter
values
are placed in NT and popped from the value stack in order. 2.
A function mark entry is pushed to VS, with tag FMT containing an
encoding of the current values of FREG, IORG, and the name of the function being activated. 3.
IORG is set to the value in the function descriptor,
and FREG is set to
the VS index of the function mark. 4.
An entry is pushed into LS for the segment described by FVBASE and
FLEN in the function descriptor.
FBASE is initialized
is completed. - 95 -
to FVBASE,
and the process
The segment just activated contains all the code for the function. is executed within this function,
the following
When a RETURN
occurs:
1.
LS is popped, thereby de-activating
2.
The function name, encoded in the function mark onVS, is used to access
the function descriptor
If there is a result,
and then popped.
to VS, and its NT entry erased.
the function.
the value is pushed
All other NT entries for locals in the function,
together with their values, are also erased. 3.
FREG and IORG are restored from the values in the function mark on VS.
The function mark is deleted and the result, 4.
Finally,
if any, is moved into its place.
FBASE is set to point to the current
accessing its function descriptor
active function (if any) by
through its name in the newly-exposed
function
mark. 3.
Operator
Instructions
The operator
instructions
correspond
to the primitive
They can be considered in four groupings, set tion.
(Table l-3A); immediately
of the selection
Scalar arithmetic
(Table l-2); part b
which are evaluated by beating which are generally
and part d covers remaining
well as the compound operators a.
operators
operators
part c describes those operators (Table l-3B);
in APL.
and are so discussed in the rest of this
Part a discusses the scalar arithmetic
contains a description
operators
deferrable
executed operators
(Table l-3C, B).
operators
If the top of VS contains two scalar values (or one if the operator then the operation is done immediately, operand(s).
This process is illustrated
pushed to QS and the E-machine this micro-process
as
is invisible
is monadic)
leaving a result in VS and popping the in Example 1. In fact, the operation is
is activated to perform to the user0
- 96 -
the actual evaluation,
but
The other possible cases occur when the top two elements of VS are segment descriptors
for deferred code in QS or when one is a segment descriptor
other is a scalar.
If one of the operands is a scalar,
VS entry is replaced by an appropriate case of two segment descriptors
and the
it is entered into QS and its
segment descriptor,
reducing it to the
in VS.
The D-machine compares the ranks and dimensions of the two operands for conformability is deferred
and signals an error by drag-along
if they don’t match.
Otherwise,
the operation
in QS and the top of VS adjusted so that it contains a
segment descriptor
pointing to the entire deferred
the stack discipline
in the machine,
expression in QS. Because of
the deferred code for both operands will
always be contiguous in QS. The link field of the QS entry for the operator opcode OP) is a relative the deferred
backwards pointer to the earliest
subexpression.
(with
deferred operand in
The AUX field is the same as the AUX field of the
two operands (see Example 2). Selection Operators
b.
The selection operators of performing
are evaluated in the D-machine
a selection operation on an array-valued
the storage mapping functions of its constituent analysis of Chapter II legitimizes formations
this approach,
used in beating produce the correct
us define what it means for an array-valued An array-valued
expression
array
deferred
expression by changing operands.
(ii)
The mathematical
and guarantees that the transBefore proceeding,
results.
let
expression to be beatable. in QS is beatable if any of the following
conditions apply: (i)
by beating, the process
It is a single QS entry with opcode IFA or IJ. It is a consecutive pair of QS entries of the form S
scalar
0
0
IRD
ptr
0
R,
- 97 -
---
tx.*PLE L - S‘ALIR lJPEYA,cu, SCILIR OPERANDS _-______--_______-________I_____________-----------------------------------------
EXAMPLE 1 - SCALAR OPERATUR, S‘ILAH OPERANDS ,_________---______-_________________I__-------------------------------------REGlSTER NEY‘T -
REti‘SIER DUllP YEW11 = 0
D”“P ,DH‘
0
-
0
I.*:
LEN REL ORG t-----+-----*-----,---*--t---,---*---*,
-->
I I
010
I
000
EFFECTrYE
I
.ODR
D/E
LOG
-
FYEG
I
=
IS
0
I
0210
0
FN I
I
IN
FbASC
OOCCO NM, I
3
=
30200
RL‘
PP I
00
,ORG
L*:
l -----.-----*-----*---,----*---+----*----*
-->
I I I
I
OIL 001
I I
000 000
-->
I
I
I sr IS1 I
I I
I
l ----
l
EXfCUTikG
ADD
*T
_---
0 I
I I
c Q
= 000,
OOOOC
I I
hhT
L 0
I I
0 0
Ct\4SE
=
oo2co
OP
I “0 I I
0’)
lh
OS
+
us:*
OP
l --__------__------
I I
EXl”P‘E
1((210) -
_-_____---
-
-----
I
VALUE
----
+ -----
LINK -
----------
I 288
lCRG
--,
011 OGO
I I
COO 000
I I
F”EC
= 0
I I I
O/E
LOO 001
I I
=
0000
-
IS
0 I
I I
0 0
OOCOO
FN I I
1 0
hhl I I
0 0
FBI!& 0“
I I
00 00
-
1-3:
RFGISTER NENIT -
OOZOC
ADDR
lh
lURG
REL
’ I I
I 1 2:;
EXECUrlON
OF
lDDi
QS
SECMCNI
EXHAUSTED
OR‘
L*:
l -----*-----+-----.--,---.---,---*----,
-->
I I
011
I
000
= 0
F(IEG
LEN I
DIE
LOO
I
-
0211
.“DP.
0
IS I
0
=
00000
FN
NWT
I
IN
I
I
0
FBASE
-
OOZ(IC
UP I
00
I
n
OS L,NK
“lL”E OP OS:*----,---------------*---*-------*
“lL”t ------------------,
E-MACHIkE
1 -“;
1 OP
I
I
*Do
“*:
.“X I
I
VALUE
.-----
l ---
I.. I ST
I I
OP
--------------
268
l
I I
-**
a*:*
-->
-_--
L,NK
VALUE l ------------------
l ----
I
-->I
*-I
I EXA”PLE
EXAWLE
I
UUMP 0
T&C
,“t IN0 THE
l
I
-**
AFlEY
EFFECTIVE EFFECTIVE
--z
I”X
l ----.------
________--_____-_-__-------------------------------------------------------------
- ----------------I-
D”“P 0
L*:
I.. ( :;
I I
FN
YALUE
I.. I sr
-------------------------
LEN “EL ORG ,-----*-----,----+---,-lt--*---C----~---*
T&G
ICO 031
*“OR
TAG
I
BEFORE -
“*;+----+
I I
iS
A”X + __-___
I --’ I
**-
FREG DIE
-->I
I-,:
REGISTER hELlI -
L,NI(
VALUE
.-----,------------------
“*;*-
256 32
._______________
z
p*;
l ------------------,
I..
EXINP‘E
“P
VALUE
____-
0
N EFFtCllVE
TAG \**+
= ‘EN
ORG
ADD ,NSIR”C,,‘N OEFEHRED IN ‘IS. DEFERRED SEGMEhl 1-2:
AFTEII
41 IrfZlOI HAS BEEN FtTCHEU. DECCDEO, SINCE BOTH “PERlh”S .RE SCALARS, IS ACTIVATED IMHEDIAIELY. (NOTE LSI
DECODING
ADD;
“PERArlDN
UEFERRED
IN
OS
1-4:
AFIER
RErURN
TC
D-PACHIhE.
AESULr
UF
100
IS
UN
YS
AUX l ------,
EXAMPLE 2 - SCALAR OPERATOR, -----------------------------------------------------------------------------. REGISTER NEWIT =
ARRAY
DUMP 0
IORC
Ls:
REL +--me-
ORC +-em---*
I 010 1
I 000
-->
EfFtCTlVE
=
0
LEN ----
I
AODR
1co
=
FREG
=
00000
O/E IS FN +---+---+---+---+----*
NkT
OP
I 0
I 00
I 0
I
0
0210
I
IN
-->
;;T SGT
I 1
1
00
01
I
SC0DEi;~G.A.l)
1
I
SCODEISEG.i3,1)
I
AKttAVS WITH DA’S NEXT INSTRUCTION EXAMPLE
2-l:
OP -----
as:+
I
I
1
BEFORE
1000
AT IS
ADC
EXECUTING
FBASt
=
00200
I
M
TAG VALUE vs:+-----+------------------+
I
OPFRANOS
1
VALUE + ------------------
-->
IFA 1 IFA I
1 dA I iIB
AND Al
1010 ARt Mt210,
CF
&ANK
3
(NOTE
LINK + ----
AUX + ------
+
I
I 0111 I 0111
I AA 1 Bd
;;iS
AUX
FIELDS).
AOD
---------------------------------------------------------------------------REG I STER WIMP hEkIT = 0 REL
IORG
OKG
=
0
FREG
LEN
O/E
Ls:
+--a--
+ -----
l -----+--e-*--e+
-->
1 011
I 000
I 100
EFFECTIVE
-->
Fhr
NkT
FBASE
I 0 I Li I 1 I 0 I 00
+
QS:
+-----+----
I
I
1
001
1 ;dT
I
1
01
tFA(3A 1 IFA I 1 OP I
0211
UP
1
1
EXAFIPLE
02
--> 2-2:
AF 1ER
002OC
LIP
VALUE + -----------------S‘0DE;;;G.W
=
----+----+-----+
M
TAti -----
=
OOCOO
IN
vs:+
ADOR
IS
=
DEFERRING
I
ADD
- 99 -
l
VALUE --------------
LINK
AUX
+ _---
+ -----_
l
I L,
d8
f
I 0111 I 0111
ADD
I 02
I 3111
I ,c
I
(iii)
It is a QS segment consisting
of a scalar monadic operator
on a beatable sub-segment.
I
That is, it is of form:
code for operand
OP optype (iv)
operating
1
R
It is a QS segment consisting
of a pair of beatable operands combined
by a dyadic scalar operator.
One of these operands can optionally
be a scalar value.
The form is:
I . 0.
code for right
opnd I
I ... code for left opnd . . . . . .
(v)
It is a pair of beatable operands combined by GDF. similar
(vi)
to case (iv) above.
It is a reduction of a beatable operand, in the form: BRED for I code . 0.
k
0
0
reducee
I ..0 OP reduce-op SGV SEG.A k: S -length ITM
- 100 -
-A
The form is
(vii)
Inadditionto(i)
through (vi) above, a single QS entry with opcode IA
is beatable, although it does not enter into the recursive When a selection operation is interpreted operand is first checked for conformability.
if a DA to be transformed
it is a local temporary count is greater
result,
the array-valued
If the operand is beatable, then it
is beaten, according to the transformations this process,
by the D-machine,
definition.
shown in Chapter III, Appendix A,, In
has a reference
count of 1, indicating
then the DA can be modified directly.
that
If the reference
than 1, then a copy must be made, and the copy is beaten.
If the
result of a beating operation is a scalar value, then the segment is turned over to the E-machine,
which evaluates it and leaves the scalar result on the top of VS.
When the operand of a selection operation is not beatable, there are two possible strategies
to follow:
In the case of the TRANS operation,
choice: the operand must be evaluated by the E-machine stored,
which is then beaten as above.
Otherwise,
be treated as a special case of subscripting, E-machine
instructions
of subscripting.)
is dragged-along
illustrates
and a temporary
the selection operation can
in which case a.n appropriate
is a second-order
and drag-along
Note that the vector
2,-2
translation
of the
is a constant and is
This approach avoids having to keep array-
valued constants in the memory with other array quantities; having an entry in NT for each such constant, management functions.
Example 3
of scalar operators.
The DM code shown for the statement is a straightforward
‘%ompiled” into the function segment.
set of
design decision,
since either approach is viable,
both beating of selection operators
APL statement into Polish.
value
in QS, (See Section d. for an explanation
The choice of strategies
and need not be made at this time,
there is no
to do so would require
and would complicate
the storage
In Examples 3-l and 3-2, the state of the machine before
executing the sample code is shown; the values of the variables
- 101 -
M and N are not
EXAMPLE
DRAG-ALONG
3:
AND BEATING IN THE D-MACHINE
Consider the APL expression ~~(2,l)~(~cllM)+(2,-2)~N
At the time this is to be evaluated, has no current starting
value.
. Assume that R
andp N-3,4
The machine code for this statement is shown as follows,
at location 250 in memory. Comments
Operand
op
Addr
N
250
LDNF
252
LDCON
254
TAKE
255
LDNF
257
REV
259
ADD
260
LDJ
262
TRANS
263
LDN
265
ASGN
266
. 0.
. 0* 000 290
RC=l
LEN=4
291
vB=o
AB=94
90 M 0 JCODE(2, 1,l)
Refers to constant
294
R(w RC=l
295 296
2 -2
2 ,-2 with DA at 290
(RecaII O-base in all machine code) This is the vector 2 ,l
R Assign (and discard vdlue)
DA header DA for constant vector 2 ,-2. See Section A for description of format.
RANK=1
292 293
PM++2,2
D(l)=1 LEN=3
1 Header for value array Value
- 102 -
given, as they are irrelevant D-machine
for this example.
LS contains a descriptor
for a
segment of length 100, which is the main segment of the function F.
The effective address is the sum of the REL field of LS and FBASE, the beginning of the value part of function F.
VS contains a function mark for F which was
placed there when F was called. In 3-3 and 3-4, the LDNF and LDCON instructions that each caused the deferral of an IFA instruction in QS. Also, for each deferred instruction, to VS.
The LDCON instruction
have been executed.
Note
(fetch array element in the E-machine)
a QS segment descriptor
was pushed
allocated space and made a copy of the descriptor
array for the constant which was in the function segment; the new DA is named Tl. The VBASE for the constant is 200, the same as the FBASE of the function. The TAKE operation (3-5,6) descriptor
is evaluated by the DM using beating.
array T2 was created for the result,
N by the transformations
been erased.
and was derived from the DA for
listed in Chapter III, Appendix A.
this DA is in fact the correct
one.
It is easy to see that
Also note that Tl is no longer needed, and has
At this point, VS contains a segment descriptor
QS segment describing
The
which points to the
the result of the computation to data, which is the evaluation
of the subexpression ( 2 ,- 2 ) +N . Examples 3-7 through 3-9 show the next LDNF instruction
The process in this case is similar
of the reversal
operation by beating.
for the TAKE.
The ADD operation is deferred
were array values. 2 elements earlier subexpression
and the evaluation
in 3-10
because both of its operands
The LINK field of the ADD in QS is 2, referring in QS. The top of VS now contains a descriptor
in QS which has been evaluated at this point.
(3-11) is executed similarly
to that
to the operand for the entire
The LDJ instruction
to LDNF and LDCON in that it defers a value in QS.
- 103 -
The TRANS instruction
takes the transpose of the entire expression which
has been dragged along so far.
In this case, since its operand is a sum, the
transpose is applied to both terms. has not been altered (3-12), LDN R instruction
the DA’s which it references
have been (3-13).
The
pushes a value with tag NPT to VS (3-14) as the next instruction
is an ASGN (3-15). Example 3-l)
Notice that although the deferred code in QS
This instruction
notes that R was undefined (see NT, in
and allocates space for its DA and its value array.
The space is
allocated based on the knowledge of the size of the result deferred 3-15, we see the deferral
of the assignment.
in QS. In
The POP instruction
of the value after it has been assigned (in deferring
in QS disposes
ASGNV, no POPS are used).
In 3-16, the state of memory shows the new DA for R; also note that the address of the DA for R (@R) has been entered in NT by the ASGN evaluation. co
Other Operators
The “other operators” deferred
conveniently,
(Executed Directly) include all those APL primitives
or which are evaluated immediately
BASE is in this class because it has a scalar result, included because they require operands simultaneously,
URHO is easily done by the D-machine, which produces a J-vector is a direction
as result.
in the D-machine.
while REP, GDU, GDD are
rather complex calculations
which are impossible
which cannot be
involving
or difficult
their entire
to do element-by-element.
and so is not deferred, The catenation operator,
as is UIOTA, with operand K,
to catenate the top K elements of VS to form a vector.
done immediately of the operators
(with the result being put in temporary in this class are dealt with differently,
of their operands.
- 104-
space).
This is
The remainder
depending on the values
EXAMPLE 3 - OR&-AL‘h‘ INO BEATING ---------___----____----------------------------------------------------------PEW*” OWP AODR CONtENIS ----c-----------------a* NC-1 l 01 “0-v” l 02 RANK-2 .03 R,*,=c‘2 l 0* RIZI-002
EXA”PLE 3 - DRIG-ALONG ___________ - ________________-__ PEPOR”
.ocu (;“NTENTS ---,---------------iN at- I l o, “O=“N RINK-L +I)2 .o, Fz,*,=oo3 to+ a121-001
LEN-C5 .o-OCc 0l11.02 0~21-01
NT: IAG COhtENtS ---t---~----------------F ,-T rF I) 0, 9” N “I dh II UT 0
LEN*OS L*=oco c,,,=o, “,*,-oL
AOOR CONIENIS ----,----------------a*
3-1:
IIEMIIRV
BEFORE
EXECUllkG
EXAMPLE
FO”
LEN-05 10-000
N NW
,OYG
-
L
tX*(IPLE
bOEi
Ls:
REL l -----
ORG l -----
LEN DIE l ----*---*---*
I I
I 000
I
-->
EFFECTIVE
3-4:
I
ICO
LOOR
I
0
‘S I
0
= 0250
-
00000
FN ---,---
hht
I
IN
VALUE l --_-----------
FNt
I
l 01 +0.? ro3 l 0.
“AS
Ilt”OY”
1
I
0
FbASt
-
co200
REG,SrFrl hEb.11 -
UP + ----,
WtF‘O
OF
2.
t,
LEN-05 .a-000 01ll*0* 0,2,-o* IS
.
‘UP”
Uf
THE
0.
FOR
LEN-O+ 10-094 OIlI-01
AFTER
t”E
VECIOR
2.-I
LO‘GN
I
00
I
0”“P 0
LORG
Lc&:
I(EL +----
0°C +-----,--I
-->
I I
05,
oco
.FN
UP VALUE “S:*-----,--l---------------*----r--*------, --> I
--•
RIY&
FO*
F*
I
Ltk
I
L
FREG
O/E --,---.---
I@0
I
IS
5
I
-
FN l ---c
0
I
I
FUSE
1)OOOO NUT --,---I
0
I
.,P
=
00200
l
GC
I
* EFFECTIVE
TI‘ -----
vs:,
RC*2 VB=VN YANK-L R,,,‘O‘3 *,2,=001
a
0,1,-02 0,2,-‘JL
ACOR CONtENtS ----.----------------NC- 1 4t1 l 0* YB=ZOO AlNG1 l 02 R~ll.002 t03
CCNT EktS _________---___-
________________________---------------------------------------------------------
REGISTER OWP hEtilt = 0
I
----------------------------------*
WOE
.---------___-_--___----------------------------------------------------------------
C5J
BEATING ----------------
AOOR ---*--
NC.1 VtJ-VN i(lNK-* NIlI-CO2 R‘Z,-OOZ
ro L r02 +03 ro+
DA EXAMPLE
AN0 -
“VW
LINK
.“OR
= 0255
,*
II
l
UP OS;.----,------
A”X ,IG _---_
vs:* I I
YI‘“k +------
F”t SGt
I I
-----------
*FN MAYI FUR SCOOE,SEG.L,ll
F.
I I
00 -->
I I
,FA
VALVE I
-----------
412
LINK + ----.------,
AUX
I
DO,,
I
I
.A
-->I EXAMPLE
3-2:
REClSlERS
BEFOkE
tXECUtlhG
EXAHPLE
CODE tHE
HEGISTEU ht*It -
D”“P
ExAHPLE
0
lORG
=
I
FREG
=
00000
FOASE
*
tAl(t 3-5:
n.3 UEGISIEHS
lL,EREO
tHE
lFtEL
“A
TAKE
FOR
h,
CREAIING
A NtY
COP”.
OPfRAtUR
00200 ______________________--_____-________----_---__-___----_--_--_-_---------------
Ls:
RE‘ l -----
ONG LEN Oft l -----*-----*---~---*---*---C---t I
-->
I I
c>c
coo
EFFEClIVE
I
A”W.
IuC
I
J
IS I
= 0254
kN
cl I
Ih
n
l I
00
TAG vuut vs:+-----+----------------+
--,
1 F”, I SGt I SGt ,
l I I
LONF LOCON EXAMPLE
3-3:
.FttR
I
OS,Oi, USllil LONF
F.
0;
AN0 *NO
VS,,;, VSi.?:I
AN”
LDCON
0
UP -----
us:,
.FN “AR% FOR SCUOEISEG.L.11 SCOOElSEG.8,11
P”>“EO PUSHED
1
kht
I 1
IF& IF*
tP I
“EIIOY”
‘0
I
VALUE + ____--____-___ l I
*N dtl
.“OR -___.
---
-,---I
IINK
I”“. + ----__
l
I I
I I
0011 0001
1” l 0* l 02 l 03 t04 A. ad
““MP COktENlS ---------Is‘= 1 VWv* PINl(*Z R,,,-oOZ Rl21-002
LOO.4 CONtEN,S _--+ _____________-
- ------LEN=05 .a-000
H l 0, .02 +03 t04
0~1i-02 o,z,=o,
W-1 VO-VN RAN?.=2 *,*,*oo~ 1,2,-001
---LCN=OS lO*ClO “,1,-o* 0,2,-o,
AO”R CONtEktS -___ l ---_ - _-----_-----at2 .o* +02 l 03 .“l
xc- 1 V%VN MINI=2 NIlI-002 R~2~=002
LEN-05 1*=002 01 II=01 0l2l-01
THE NE* “4 A, Pt2 ‘OAtIINS THE StORIGE ICCE,S FUNCTION FW t”E TWsE ,,PER,t,“N ON N, tdti“” *AS PRCOUCEU B” BtAtlNG. NOTE IN PAYIICULAI w&t THE VBASE Of t2 IS VN. YH,CH POINrS rU TIlL “lL”t ARYAI 66 Nt ti ,HAt t”E DIMENSION OF , LS SPECIFIED B” 1”E t&U OPERATOR. t2 IS 2.2 t”t l,!lSE HIS CHAN‘EO FROM 0 TO 2 t t0 LC‘OUIlt FUR tHE -2 ELCMEht IN THE PAR,“EtE(I (I.E. tAltE FRC” THE C&D,. NOTE ,klt THE VALUE “F DLL FINALLVI IN ,2 IS tHE S.“(t AS IMAt FOY N. FXIllPLE
,-6:
MEMORV
AftEM
TAKE
OPERATOR
EXIMPLE
3
-
Ok&G-ALOh
=
REL DUG LEN *-----~-----*-----*---t----,---*---t
-->
I IYE
TAG
-->
FREl
I O/E
*
IS
AOOR
= 0256
OOCCC
FN 1
LIkt I
I I I
FlbPPLE
*Fk M.&I( FOR F* SCOUE1SEG.A. II SCOOE,SEG.B,lI
3-t:
I
CO
*FtER
LOhF
I
l
US:*----t-------------------.--*--*------,
0, -->
I I
VALUE
IFA
I
LlN* I I
dll
REL
l”RG UL‘
0‘11 “O,,
I I
____-
l ------*
050
I
000
CFFECt,“E TAG VS:
--_--
F”, SGT SC,
=
F*tG
I
____
OlE
Fh
I”0
*“OR
*
I
3
C2,Ll
I
0
,h
I
I
I
413 *01 .02 l 03 l c.
c
OP
l __---_----_----__-
+
l Fh YARK F”* SCU”E,SEb.P,I, SCCOE,SEG.B,1)
-->
F*
I I I
3-8:
AFTER
REV
0,*,*01 0l2~*01
ltc-l Vo*“*
LEN-05 ~0-002 YANF.=Z “,*I-002 “, ,1*-z RLZ,-OCZ “~2,*0,
=
t”b.r,PLt
OOLCO
3-9:
lF,tk
REV
VP I
00
uFG,StFR OU’IP VEklT = 0
I
IURG
=
I
FrlEG
dDOP
= 0259
Ih
=
FLllSE
OCCCC
= 0020‘
VILUE
LINX
AUX
US:.-----.------------------*----r-------*
GO 0, -->
I I I
IFA lFA
1 at2 1 *I3
I I
I I
oo,, 001,
I I
EFFtClIVb
Ipi t)b
TAG
VAL”L --__---__
vs:.-----+ , ,
EXAMPLE
‘EN-05 AB=OO2
*
“ILUt I I I
FOISE
k*t
-t---*---*---*---*----t
I
0,11-04 oIzl=“l
.U”17 CLNtENtS ----.-----------------NC=, at2 vLI=VN +(?A **NV.=* +02 to3 R,,I=OoZ l 04 Y,21*002
, b,n,C” ‘“NIP~INS t”t ALLtSS F”NCt,UN FOR THE hOT,CE THE ht.z EA. it 3 THE PIRIb wick nbvt CHANGEU FROH wt DA At a” ARE RtVtaSAl UN * . THESE k!i,C” IS NUh 2, LNO O~LI,,, hH,‘H IS -2 INStEAD CF 2. A04St. n , ANALciGOUSL” 1” tI?E Y&t THE DA CHAhlGtS ACCOUNI FOP THE REYERSAL GF P“O”NlS i-OR ttlt IME OPtP41IuN ON N . IT dT2 = o‘co‘
IS
OlI,=O2 0,2,=01
LtY-05 cl0=00”
PA an
M
LEN
AOOR CGNt ENt 5 ----+-----------------RC= L FIN +01 W=VN Y&h*=2 .c 2 *,,,=*o, +03 +c4 K,*,*Oo+
LEN-05 *0*00~
b”I I /
___________-________----------------------------------------------------------------REGlSltR "VW hEba,t = 0
r)““P
00200 lC”R CONtthtS ----*-----------------dP RC- 1 “O-VM +01 RINK*2 l 32 R,lI=302 +03 R,Z,=OCZ +cIt
II
I
=
OP
UP
t ------------------
FMt SGt SGt
0
FBASE
IN
VlL”t
-----
I I I I
ExA”PLE 1 - DRAG-ALONG AN0 bEAtlNG ________________________________________-----------------------------------------
t)EAt,NG
I 056 I JO0 I 100 I 0 I 0 I
*s:+
I
IOvG
Ls:
EFFECT
CL
PN”
NEllDRY
REGISTER ““MP NEhIt = 0
FNt SC1
I I
l Fh MAKR SC,dEISkG.‘,II
“P ---_FOh
-4,
tl4”PLE
3-10:
AFtER
*
A””
----, k*
us:+-
, I
00 0, 02 -->
I I I I
YALUE
Llkl(
AVI
__--
l -__-------_-------
t ----
+ -----
Ifl IF& OP
I I I
I I I 02
I I I
dt7 ,t3 &DO
0011 co,, GO,,
-+
I cI I -C
EIAMPLE 3 ____-______________---_____ REGtSrER hE,,IT *
DRAG-ILO”‘
AND -
ME”011” 1DRG
0
*
LEN REL ORG .-----*-----.-----*---,--*--.--.----t
--,
I I
061
I
000
EFFECTIVE
I
ADDL
FArA
1
‘s:
O/E
ICC
I
*
0261
0
I
0
l I I I
SC1 SGr
I SCODEISEG.C.,11 1 SCUDE~SEG.D.Ll
-->I
I $
EIAMCLE
3-L,,
AFlEP
oocoo
FN I
IN
I F”, I rFn “ARK FORF. I l
=
IS
IAG VALUE ----,-----------------
“f:,
EXAMPLE 3 - DRAG-ACChG AND bEAlING ___--_____-_-____--_-____---_-----_______-___-_---_____--_--___---______
BEAlINC ---- __________-_________I___-_____-____-_
DUNP
1
FBASE
NbT I
0
*
ADDR CONlENIS ----c-----------------all UC-1 VB- VII t01 RANK’2 402 l 03 R,,I*002 +04 RlZl-002
JC I
00
I
N LINK
OP VALUE pSt*----*------------------*---,------, 00 01 02 03 -->
I l l I I
IFA IFA DP IJ
I I I I
dl2 dl3 100 J0300~2.1.11
I I
O2
I
‘*:
OOII 0011
I I
DIl,=OZ OIZI-01
.OD‘l ----,----
nc- 1 v0*VN RANK-2 Rlll-003 R(21*001
LEN-OS A**000 OILI-04 OIZI-01
I
0001 0°”
I -c DO THE THE Olll NOY EXAMPLE
CCNIENTS ----nc= I vll-VN RANK-Z Rill-002 A12~=002
LEN-05 *0=002
a13 .OI to2 ro3 l 0*
nc- 1 va-VL RAW-2 AIll-002 R(21=002
LEh-05 At)=002
EFFECT OF WE 1RANSPUSE MIS TO ALTER TWz DA’S Al C”AN‘E IN BOTH CASES dAS 10 INIERCHANGE A,,, .ITH YITH lJ,z,. IT SHOULD 8E INTUIllVELY CLEAR WAT ACCESS 1Ht 1YANSPDSES W THEIR PREVIOUS VALUES. 3-13X
IIEWORV
AFlCR
TRAMS
IORG
1
FREG
INOTE
ALTtRED
---_----
dl2 .Ol .02 l 03 l 04
al2 11,2,, THESE
Dlll-01 ol2)*0+
uc1,*01 0~2l*-2 AND AN” DA’S
II). MILL
DA’S1
DUMP IOR&
0
=
FRE6
1
OIIG l -----
LEN D/E IS l ~~~-,---~~-~,~--,~~-*----*
I
I
I
062
EFFEClIYE
000
ADDR
1oc
I
0
I
J
IN
= 0262
VALUE 1AG “Sr*----,---------------, I FM I .FN #A”,, FOR --,; SC1 I SCOOElSEG.C.lI
*
00600
FN
NhT
I
1
I I
0
*
00200 REGISrEN DUMP hEYI = 0
UP I
00
I
N
ps: F*
I
FBASE
00 01 02 --,
OP +---, I IFA 1 IFA I DC I
VALUE ---_-___---I I I
dl2 Or3 ADD
LIW ----*------,
----+ I I
02
I I I
‘S* -->
I I
3-121
REGISlERS
AFTER
064
I
EFFtCTlVE
AUX OOLL 0011 0011
I cI I -c
*
OR6 REL LEN .-----*-----*-----.---,--,-~-.---+----,
TAG -----
ys**
--> EXAN,LE
im +01 +02 +03 .01
c-
LDJ
REL + -_---
--, i
AOOR COk,EN,S ---,----------------LEN-05 An*000
AUX I I
____________________------------------------------------------------------REGlSlER AfaIl *
OUNP
00200
I I I I
FM1 SC1 NPT
000
I
AODR
16C
WE I
0
= 0264
l FN NAttIC For( SCUOElSEG.C,ll R
3-16:
AFTER
LON
C
l F*
TRANS EXAMPLE
I
Ih
VALUE l ___--______---___I I I
IS
Y
I I I
*
00000
FN l
1
FBASE
Nbl I
0
*
OOZGO
DP I
00
I
* OP VALUE “s;*-----,------------------*----*-----* 00 ‘)I 02 -->
I I I I
IFA IFA “P
l l l
912 al3 A00
LINK I I I
02
AUK 1 ;“,::
I
L
I
I
-c
0011
AN0 BEATING EXAMPLE 3 - DRAG-ALCNG --------------------------------------------------------------------------_____ RFC I STER DUMP hEYIT = 0 IORG = I FREG = RkL
ORG
LEN
D/E
IS
FN
Ls:
+ -----
l -----
I C O O 1 1CO 1 5 1 3 1 I
-->
1 065 1
+ -----
EFFECTIVE TAG
ADDR
khl
+ ---,---+---+----*
= 0265
IIt
n
I I
0s: 00 02 01
VALUE
1 0
I *FN HARK FOR 1 SCOUE(SEC.E,l)
F*
03 04 J!i -->
3-15:
REGISTERS
AFTER
IFA IFA OP IFA OP POP
=
00200
i/P ---_
+
I 00
I
+’ -----,--I-------
-->
EXAMPLE
FBASE
OP
v-5: •-----+------------------~ t FWT ‘I SGT
00000
I I i 1 I I
VALUE
LINK ----
-----+
AUX + -----_ I
dT2
dT3 ADD dR ASGN il
0011
I 0011
f I 02
I
0011
I 02
f
Kx
I
I 0011
ASGN
------^----------------------------------------------------------------------------MEMORY ADDR ----•+
ah! +01
DUMP
CONTEluTS ------- ---------uc=: LEN=05
+02 +03 404 av
+01 402 +03 +04 am
+01 402
+03 434
EXAMPLE
ve=vn
AOUK CONTENTS ----+-----e--------a12
AB-000
401
RANK=2 R~lI=OOZ Dfl~=OZ R(Zl=OOZ D(Z)=01
402 +03 +04
RC= 1 W=VN RANK=2 R(l)=003 R(Z)=004
LEN=CS AB=OOO
WC= 1
LEN=05 AB=OOZ VB=VN RANU=Z H(lJ=OOZ UL lJ=Ol R(Z)=002 D(Z)=04
l 01
RC= 1 vl3=vn
462 +03 +04
RANK=2 R( l)=OOZ D( l)=Ol Rt2)=002 D(Z)=-2
i)T3
D(l)=04 D(Zl=Ol
NT: TAG ---*e-e+-
CUNTtNrS ---------------_
F
Fl
ilF
M N I(
01 UT DT
iw ON dR
LEN=05 At)=002
RC- 1 LEN=04 A0=003 VB=VR RANK=2 R(lJ=OOZ O(l)=02 R(Z)=002 D(Z)=01
3-16:
MEMORY
AFTER
ASGN
I
.~.
-+ I E1 I -t
RAV and DRHO are difficult calculations
to defer in general because of the complex
necessary to access an arbitrary
element of the result.
there are special cases which are easy to defer, (i)
However,
as follows:
The right operand is a scalar or single-element
quantity.
of such a value is a J-vector
or at worst is an
explicit
one-element
is deferred
in QS
as
if it is an integer, Similarly,
vector.
IRD
the DRHO of such a value
follows: value
S
The RAV
Tl
0
0
0
R
where @Tl is a DA for the result and R is the encoding of the rank. The IRD instruction
is essentially
a note to the D-machine
that the
result has dimension described in Tl. (ii)
The right operand B is an expression
deferred
in the form of (i) above.
In this case, all that has to be done is change the descriptor
array
@ Tl. (iii)
The right operand is of the form IFA
@W
0
R
and @ W points to a DA which has not been altered by any select operations which upset the ordering
of the value part.
That is, if
W is the array specified by @ W and D is the vector containing the value part, then WC; /LlttD[
( pc)~L]
for all appropriate
In this case, RAV is evaluated by providing dimension x / p W . DRHO can be deferred left operand of the IkHO, providing
a new DA with rank 1 and if
X/PA , where A is the
is less than or equal to X/PC
a new DA with dimension
values of L.
also by
A.
If none of the above apply,. then IUV and DRHO are evaluated immediately creating temporary
values in ML - 109 -
by
Other Operators
d.
The D-machine
and Compound Operators
(Deferrable)
evaluates this subclass of operator instructions
by deferring
code in QS. The expansions are detailed in Appendix C and should be
E-machine
easy to understand with a knowledge of the way the E-machine here discuss only the SUBS instruction
works.
and the compound operators,
We will as their
behavior is somewhat more complex. The SUBS K operation corresponds
to the symbol C in an APL program.
When decoded, it expects the top of VS to contain a QS segment descriptor rank-K
for a
quantity and the next K entries on VS to be either scalars or QS segment
descriptors
for the subscript
by the LDSEG instruction
An empty subscript position is created
expressions.
with its operand a segment descriptor
SCODE(0, 0,O) of
length 0, There are two important (i)
cases to consider:
If the subscriptee
is beatable, then the subscript
examined in turn,
starting from the rightmost
find scalars or J-vectors. the equivalent of INX
If found
for,
expressions
(deepest in VS) to th say, the I- coordinate,
I with that operand is performed
on the sub-
scriptee by beating, causing new DA’s to be created for it. entry for this subscript a J-vector,
are
is then deleted if it was a scalar.
The VS If it was
then the VS entry is-changed to the empty segment and
the QS entry is deleted by moving all of QS down 1 to fill in the space (with appropriate
adjustments
to descriptors).,
If, after all subscripts
have been examined it is found that the remaining are either empty or non-existent, standard form, descriptors
stacked subscripts
then the result already exists,
in QS. In this case, the remaining
in
empty segment
are removed from VS and the result is the QS descriptor
- 110 -
at the top of VS.
Otherwise,
the remaining
subscripts
are treated
as in the second case, described in the next paragraph. (ii)
If there are explicit
non-scalar
and/or the subscriptee
or non-J-vector
is not beatable,
subscript
then the subscripts
dragged along in QS, This is done by creating temporary cumulators
(opcode XT) in QS and generating E-machine
activate the necessary subscript the subscriptee
is a reduction,
transformation
(OP/A) [LY] --)
as above.
evaluations
OP/A@
Appendix C.
Example 4 illustrates
must be index accode to
at the right times.
QS is transformed
The details of the subscript
expressions
If
according to the
3 and evaluation continues
expansion are shown in
the process which has just been
described. In evaluating a GDF, the machine first deferred
operators,
then they are evaluated to temporary
done to avoid unnecessary recalculation a GDF.
of subexpressions
It also guarantees the possibility
pressions
by beating.
examines the operands. space first.
If they contain This is
necessary to compute
of applying SF transforms
to GDF ex-
Then all that is necessary is to alter the access masks in
the AUK fields of the deferred left operand in QS to provide the proper access method for the E-machine.
This is illustrated
reduces to a simple case, e.g., pression
if one of the operands is a scalar,
is treated as a normal scalar operator
Efficient E-machine)
evaluation of reductions depend on transformation
tation of the reduction coordinate
in Example 5 below.
If the GDF then the ex-
expression (see part a above).
along coordinate K of the reducee R (in the TRll
(see Chapter II) which allows permu-
by transposing
REDUCE along coordinate K the reducee is first
- 111 -
the reducee.
In evaluating a
checked to see if it fits into one
of the special cases of reduction: (i)
Empty reduction coordinate. ( (KZ~~~R)/~R)~IZ)ENT where
The result is then an array with value R is the reducee and IDENT is the
identity element for the reduction operator. (ii)
of length 1. The result is then R[ [K] m
Reduction coordinate If reducee is a scalar,
(iii)
In this case, the reduction is activated im-
Reducee is a vector. mediately
the result is R.
in the E-machine,
If none of the special cases is satisfied, the transpose of TRll
if necessary,
since the result is a scalar. the reduction is deferred
and generating the deferred
by first
doing
code in QS as
shown in Appendix C. EXAMPLE
4: SUBSCRIPTING IN D-MACHINE
Consider the APL expression p&-+5,4,6,3
and
w-+3,2,1,2
,
for evaluating this expression
A[ t4 ; ; 2; VI where A is a rank-4 array with with the index origin
IORG +-+ 1. The D-machine
is
250
LDNF
V
Vector V
252
LDS
2
Scalar 2
254
LDSEG
256
LDS
258
UIOTA
259
LDNF
A
Array
261
SUBS
4
Do the subscript,
263
...
The following
SCODE(0, 0,O) 4
Empty subscript Scalar 4 Gives ~4 -
memory and register
A expected operand rank is 4
dumps show the steps the D-machine goes through
to evaluate this expression.
- 112 -
EX4MPLE
EXIWLE 4 - SUc9SCR‘PllNG IN O-*ACHINE ____________________-----------------------------------------------------------“ElWi”
u)OI ____
AOOR CONTENTS ----,-----------------aA +01 .02 t03 .Ol +05 .06
RC-I “I-“‘
LEN-07 *B=oco
RINK-, R,‘,=M)* 11,21=00. 1,31=00t. *,,,*003
OIL‘=72 Dlzl-18 0I31=03 D,~I=o‘
NT: T&G CL;klEN‘S ---*---,----------------A DT I. ” “7 d”
CCNlENlS l ____ -_-
---------^LEN-O, IN,= 1 .B=Joo “8-v” Y.NK=, RI,,=004 OIlI-01
-
SUBSCRIP7‘NG
4” l c L +02 l ,,
4-L:
*E”oR”
‘ORG
EXEC”7,NG
E”IMPLE
FlEG
Ls;
LEN l ----
DIE ,---.---
I I
I
I
I
-->
063
000
TAG -----
0
IS I
= 0263
“lI.“E + -----------------_
I.. I SC1
CODE
LOC
ADDR
D-IIKHINE
I
O&G l -----
EFFEC7‘“E
BEFDRE
=
‘h
BE‘. l -----
v,;,
ExIWLE
‘
OEGISlER 0”W hEYI = 0
D”“P
I I
. . . SCOOElSEG.O.Il
3
‘ORG
=
Ls: -->
I I
06‘
I
EFFtCI‘VE I& ___-_ I.. 1 :;I 1 SG, SGT I SGI I
I
-->
coo
I
AUOR
FYEG
I
IOC
DIE I
0
= 026‘
I
I
I
=
IS I
0
‘h
I
I
FBISt
OOCOO
FN
NUT
I
I
I
6
I
FIJISE
ot
OOZOJ
I
+
“P VALUE gs:*-----*-----------------*----*----,
I I
=
PP
*
I
0
=
00 0, c2 03
l I I I
JIIP IFA ‘CA Xl
I I I I
0 iv .r1 KODEI0.3.Il
06 07 08
i I I
IllL KS IIL
I I I I
XC0DEI0.2.11 0 0 c
I
00
1tNK
09 10 I IIIXS I2 I 13 I --, I
n A”I
LINK
f I
I I I
oooi 000, 1‘11
I I I
AA 80 cc
Af,ER
.,A.
B”7
W&SCR‘PIS Ah” SUBSCRIPlLt. THE” ‘FID‘CA‘E IHAI PS. I YANK-. ARK.“. 1HE
S”0S
“Pt*lroR
01
I I I
03
I I
01
Y
k”Tlz ‘HE ACCfSS *ho T”t .I-VEcrw.
NISLS Ant
xs ‘SC S‘ 100
I 0SCUDElStG.E,lI to I SCJDtISEG.Fr‘, l =r2
I I
05 06
I I
0001
1 I
f
O9
’I 0111
I
“S AND OS HAVE MEN IRALSFUR~EO 8” 1HE SUBS “IERb,‘ON. SUBSCU‘Pl REDUCED 1HE RlNK OF 1 &I I, AND THE IhlERYAL SHORTtNED THE FIRS, COOlO‘NI7E (SEE “A &7 a,,‘. THE UtS7 C‘OE GtNERAlED IN US IS FOR CALCVLA~ING EXYl‘CIl SUISCRIPI YH‘CH ARE &LPI IN IHE II tNlklES. THESE EWIYIES COhSllrUTt PStUO’J-ITERAIION STICK. ISZE SEC7‘UN EI EllYPLE
S-2:
A”X
I
I I 000‘ I 011‘ I I I i 0‘00 I IOOIOI
I I
:z FF
I i
I
I
SCOOEISEG.N‘L,Ol SI.UOEISEG.B.‘I SCOD~ISEG.CIII
0020E
GjP
“P “PLI)E yS:r-----r------------------,----r--------* l I 00 I IF4 I d” I 0‘ I IJ I JCUDEl+rl,Ol IFA I d4 I 02 I --> l l I
VALUE l - ___________-----. . . I 1 ~ODEISEG.A.‘l
“S CONTEhTS WE THE IN ,nt A”X F‘EL” OF ,s VECTORS, AND L El4”Pt.E
Nb, ---,----.
D”“P 0
LtN DRG PtL l ----*-----*-----1---*---*---,----*----*
“SC.
OOCOO
IN
-->I WE‘ISTER hEb#,I =
= FN l ---.
r-3:
REG‘SItRS
AFTtl
,“E SCALU VtCtUR M 7HE VALUES, A
SUBS
________________________________________--------------------------------------“EN”*”
DUN)
b”OR CONTtNrS ----+-----------------d. +01 l 02 +03 to1 to5 l ot.
EXIMPLE
IDOY CONIENIS ---l _---------------
K-1 “6-V‘
LEN-07 *Et=oc 0
RANK-‘ RI,‘=005 RIZI-005 noI=006 Fl,+,=003
6-b:
Olll-72 D12I=IO 0(31=01 0,4,-O‘
IIE”6R”
a” +01 .02 l o, .I
AFTER
I l 01 .Q2 .03 l OS .C5
S6BS
--
RC.2 “0-v”
LEN-O, AB-OOG
Fllkl-I R‘*l=004
0,*1=0,
AC- I “0-Y. RANK-, RI“-001 RIZI=(IOI R(3)=003
LEN-06 18-003 OI‘l-72 D,ZI=18 6‘3,=0‘
*DDR CChTENrS ----.-----------------dT2 l o* .02 l 03 .0* .OS
RC- I “(IRANK==, Rlll=OOl aIzl=001 Rl3~=00*
LEN-06 *a=000 “ll~=lb OIZl=04 0131-01
-Cl
EXAMPLE
5: GDF IN D-MACHINE MO. xN , both M and N are matrices
In the example expression, and fl++-~3,2.
D-machine
code for this expression
250
LDNF
N
252
LDNF
M
254
GDF
MUL
256
0.0
with
pMct4,3
is
Do GDF
Examples 5-1,2 show the machine state before evaluating this code.
In 5-3, the
GDF operation has been deferred in QS. Notice that the access mask of M The IRD entry,
in the AUX field of QS has been changed. the dimension of the result, EM to use a 4-level
contains 1111 in its AUX field,
iteration
M says that M-indices
whose operand DA gives which instructs
stack to evaluate the expression.
come from the two highest iterations,
the
The 1100 AUX for while the 0011 AUX
for N indicates that N is to use the two lowest. An equivalent formulation
of the contents of QS at this point is that it represents
the GDF in the form: step 1 until 3 do -for I := 0 ---for J := 0 step 1 until 2 do for K := 0 step 1 until 2 d_o -for L := 0 9
1*
-
1*
RESULT [I;J;K;LJ
:= M[I;J] XN[K;L];
- 114-
EXAYLE 5 - GDF IN D-MACnlNE _______-_______-______I_________________-----------------------------REGlSlCll MEY‘:
‘OAG
0
l
=
Ls*
l -----*-----,----,--~--*--*---*----*
--,
I
I
05‘
I
EFFECTIVE
-->
I
ICC
ADO‘!
DIE I
0
I.. I SC1 I SC1 I
5-L*
YEGISlERS
=
IS I
0
‘h
= 0254
VALUE -----__---------. . . I I SC00E1SEG.L.11 I SC00t~SEG.B,1l
IbG
EK.WlE
000
F”EG
I
LEN
ORG
REI.
vs:,----+
-----OOGOO
FM I
I
NM7 I
0
FGISE
00
-
--_--
MEllOW
--em-
I )
‘FA IF1
I I
a* ))I
+01 602 .03 .Db
fl.“PLE
5-2:
IlJRG
0%
I
,lG
000
I I
14 Ga
I
1
LOO
IOm
F#EG WE I
0
IS I
= 0256
GEFORE
0
IN
VALUE ------------------,
vs**---*-• OO‘I 0011
=
I I
MIX I I
O-•U~lME
I.. I SC1
I I
. . . SCOOE‘SEG.Crll
I I
*
00000
FN
NY1
I
I
I
0
FYASE
-
00200
PP ----. I
00
I
” OP VALUE US*,---.---------------.-----+ 00 I ‘FA I aN 01 I ‘FA I W 02 I top I cut 03 I ‘(IO I ill --, I
LINK
AUI ;
y;
;
I I
‘111 1111
I I A
GDF 5-31
ACrEll
GDF
-
lllrE
CWNGEO
UIX
FIELOS
111 PS
__-_-____--_--------------------_--------_--_-_-__-----_--____“Elm” ,001 CONIEWS ---c----------------I‘C’ I 2R
LEN=05 Am-000 OIlI-03 Dlzl-01
llEMmV
GEFmE
l 01
VI-VW
LEN=05 Au-000
002 .03 *aI
llANl=Z 1111~=003 Rl21=002
Of a)-02 Dlzl=Ol
DUW
bOOI CONIENIS ---.---------------ill +01 .02 ro3 +01
RC=2 va.VII RAM.2 llllI=ODI 1)12~=003
AODl CUNlENlS ---.--------------i#a nc=z
LEN=05 .a=000 OIlI-03 0‘2~=01
l 01
ve-VN
+02 +03
“ANK=* IllI.003 Rl2l=002
l 01
COF drl UAS 7HE lESU1 SIGNIFIES EXtCUTED. EIAWLE
I-+‘
&O&M CONTENIS ----,---------m-eLEN=05
AD.000 Dill-02 0l2l’0l
dll
l 01
v&w
LE”-07 *B-O00
.02 +03 .OI +05 +ob
nc-
ww-$ 1111-001 Rl21=003 ROl=003 111+1=002
I
O(l,.,G DIZI-06 013)=02 0‘4~-01
CREAlEO SIWLT 10 RECORD WE (Iu* AND Dl)lthSlDN OF WING WE WIEI cIDD”C1. Icy o?coDf IPD 1H11 ITS OlERMD 01 IS OESCllCTlVt, AND IS NO1 IN 1HE E-MCI)INE, IRD IS ICWOREO. “C”DI”
AFIEI
GDF
cm
f
______________^_________-__________-____-------1-_---
D”lC
Ilc-1 va-VII nwl-2 111t=Do* 1)12~=003
0
EFFECTIVE LINK
IN
---,I
.DDl CDWIENlS ----+---------------a*
GDF
1s*
EXAWPLE --__
DUW
--> N
I 00 ‘I 0;
5
ORG REL LEN .-----,-----*~~~~~*---*---*--~,--~+
I
0, VALUE US*.-----*----------------*---,------+
-.
= 00200
UC I
E”..IICCE bEG‘S7ER NEY‘I -
DUO?
VKIOR OF IIN PSl3I~l TO GE
E.
The E-Machine The E-machine
is a simple stack-oriented
valued expressions
by iterating
EM takes its instructions
element-by-element
from the instruction
over their index sets.
are used in the same way as in the DM.
The central task of the EM is to access individual array-valued
As most of the complexity
expressions.
array elements in computing of the E-machine
to this task, we first discuss the accessing mechanisms it is a simple matter to explain the instruction 1.
The
buffer (QS), where they were put
Other machine registers
by the D-machine.
computer which evaluates array-
is related
Given this,
in the EM.
set of the machine.
Array Accessing a.
Indexing Environment
Array
reference
instructions IFA
are entered in QS in the form @AR
0
MASK
where @WAR is the address of a DA in M, and MASK is a logical access mask. When such an instruction
is first entered in QS by the D-machine, The E-machine
regard to its context in the input expression. evaluate it, determine
The indexing environment
of an instruction
by how the segment containing the instruction
turn relates to the form of the original (i)
must, in order to
its context, which takes the form of an indexing environment
for an array reference. determined
it is done without
expression
in QS is
was activated,
which in
input to the &machine.
If the QP field of the top of LS is zero, then the environment
is simple,
and array references
on the
iteration explicit
stack.
within this segment are based directly
A simple environment
subscripting
not affected by
or which are not operands in expressions
expansions to be made by the DM. all variables
arises in variables
For example,
have simple environment.
- 116 -
which cause
in the statement A+B+C,
(ii)
If the QP field of LS is non-zero, array references
then the environment
in this segment are controlled
is complex,
and
by a pseudo-iteration
stack,, In the statement A-++CC V;Wl , A and B will have simple environments, but C will be complex as the reference segment resulting
from the expansion of the subscript
that this concept is recursive. environment
operator.
Note
For example, we can also say that the
of the subexpression
allows arbitrary
to C is embedded in a
levels of subscript
CCI/‘;WI is simple.
This recursiveness
nesting to be handled by the drag-
along scheme of the D-machine. The segment containing the IFA @C instruction EM by an SG instruction
referring
is activated in the
to a sequence of entries in QS of the
form: XT
XCODE(a,
ml,
XT
XCODE(b,
m2, c2) e
cl)
Here, a and b are indices for C calculated from the subscripts by the expanded subscript
code in QS. These quantities
computed from the current permissible flags.
values in IS.
fields of the iteration
are, in turn,
ml and m2 are the maximum
values of a and b derived frompC,
Thus, these XT entries correspond
V and W
and cl and c2 are change
to the CNT, MAX, and CH,
stack, and are therefore
called a pseudo-iterw
stack (pseudo-IS). b.
Initialization
of Access Instructions
Each array accessing instruction when first
executed.
must be bound to its indexing environment
This process is described below for IFA instructions
is analogous for IA and IJ.
- 117 -
and
(i)
Determine
index sources
The encoded access mask in the AUX field of an instruction to determine
its indexing environment.
For example,
is used
if the environment
is simple and the bit pattern in AUX is 0101 and the IS is four deep, then the index sources are determined 1,3.
by (0, 1, 0,1)/O, 1,2,3 which is the vector
Had the QP field of LS indicated a complex
Call this vector INX,
then INX would have been based on the length of the
indexing environment,
pseudo-IS rather than on the length of IS, (ii)
Set up iteration An iteration
control block control block (ICB) is established
containing the coefficients
at the top of QS,
of the storage mapping function from the DA
for the array (DEL) and the INX vector, one word for each coordinate
An ICB contains
calculated above,
of the array being accessed, as shown below,
The fields marked Ql and Q2 are both encoded into the VALUE field of QS using the function QCODE (see Appendix A).
The contents of the Ith
ICB entry are: field
contents
OP
if simple environment
LINK
INwl
AUX
0
Q2
DEL [I]
Ql
if simple environment
t&
NT e&
then DEL [I]
QT
X
(MAX field of IS
entry selected by LINK field) else 0 In addition,
the last entry in an ICB is given opcode NLT or QLT,
on its environment,
- 118 -
depending
(iii)
Initialize
QS entry
The Ql fields of the ICB just established are added to the ABASE found in the array’s
descriptor
array to produce the sum S. VBASE is
also fetched from the DA, and the DA is “erased” from QS by subtracting 1 from its reference FA
count.
The original
IFA entry is then replaced by
QCODE(VBASE, S)
IPTR
0
where IPTR is a pointer to the beginning of the ICB for this array. This completes the initialization
of array references.
been done is to replace the context-independent by information
which binds the reference
contains all information C.
reference
what has
created by the D-machine,
to its indexing environment,
and which
necessary to access the array (in the ICB).
The Index Unit
The index unit (IU) is invoked by the E-machine array-access
instruction
Using the information
differently,
that has been initialized
every time it executes an
as above (i.e.,
FA, A, J).
its ICB,and IS or a pseudo-IS,
in the instruction,
accesses the appropriate
(i)
In effect,
array element and pushes it to VS.
the IU
The IU functions
depending on the indexing environment: Simple environment In this case, we know a priori be accessed in a simple order, information
that the elements of the array will
determined
can be used to minimize
by the way IS is cycled,
the re-computation
mapping function for each element of the array. iteration
stack entries for this array (specified
the right-most but not recycled,
coordinate.
and this
of the storage
The IU looks at the in the ICB),
starting
at
If the IS entry has changed (noted by CH bit)
then the IS adds the DEL component from the ICB to S;
if there was a change and a recycle,
- 119 -
the Ql field is subtracted from S.
This process continues
The new S value is stored back in the instruction.
until an IS entry with no changes is found, in which case higher IS entries contain changes either.
If the iteration
as in a reduce, then addition and subtraction (ii)
none of the is going backwards,
are interchanged,
Complex environment In the complex case, there is no way of predicting indices will proceed and each change requires part of the mapping function.
in advance how the
an explicit
This is done similarly
by examining the pseudo-IS for each coordinate
evaluation of
to the simple case,
of the array.
If a change
is recorded (in the X3 part of the XT entry) then the new index (Xl part) is multiplied
by DEL,
This result is added to S and the Ql field of the ICB is
subtracted from S with the new S stored back in QS. Finally, just found is stored in the Ql part of the ICB. partial
2.
thus records
values of the mapping polynomial.
The behavior of the machine in array accessing, illustrated
This.field
the product
as described above, is
in Example 6.
Instruction Instructions
Set in the E-machine
a.
Simple instructions
b,
Control instructions
CO
Micro-instructions,
In addition,
can be considered in three groups:
used primarily
as seen in the previous
section,
for maintaining
pseudo-iteration
the instructions
buffer contains entries
for pseudo-iteration
stacks (opcode XT) and iteration
Table 3 summarizes
the E-machine
algorithmic
description
repertoire,
of the E-machine’s
discusses these instructions
- 120-
control blocks (NT, QT, NLT, QLT).
and Appendix B contains a detailed
behavior.
in both functional
stacks.
The remainder
and “programming”
of this section
terms.
a.
Simple instructions
The S instruction,
Load Scalar, pushes its value to VS with tag ST. IFA
fetches an array element according to its operand DA and the indexing environment, and pushes it to VS with tag ST; similarly,
IJ pushes an element of a J-vector
VS, while IA pushes an address of an array element (tag AT). can be considered simply at the programming
level,
These instructions
as just described,
the mechanism which they invoke is much more complex,
to
although
as was seen in the previous
section. The instructions
OP and GOP have as operands the names of arithmetic
functions in the EM (monadic or dyadic). named function, the result, No-op,
which operates on the top of VS, deleting the operands and pushing
with tag ST.
(This process is illustrated
and does nothing.
first
in Example 1. ) NIL is a
Recall from Section D and Appendix C that IRD and IRP
are generated by the D-machine drag-along.
Executing an OP or GOP invokes the
to keep track of intermediate
As they have no use in the E-machine,
results in doing
they are changed to NIL when
executed. b.
Control instructions
The main control instructions segment descriptors.
are SGV and SG, whose operands are QS
SGV pushes this descriptor
analogous to LDSEG in the DM. entry to LS; in this instruction, the indexing environment.
9G activates the named segment by pushing an the LINK field is significant,
JMP, JO, Jl,
within QS; RED is also a relative
to VS (with tag SGT) and is thus
in that it can change
JNO, and JNl are simply relative
jump, but in addition,
with tag RT, to be used as an accumulator
for a reduction,
the DM only in conjunction with reductions. )
- 121-
it pushes to VS
jumps
an entry
(RED is generated by
MIT is used primarily
to activate reduction
segments.
from the top of VS and uses them to push new iterations
It takes ST entries
to IS.
When the MIT
execution reaches an SCT entry on the top of VS, the referenced by pushing the descriptor of how reduction c.
information
(See Appendix C for a description
segments are deferred in QS. )
Micro-instructions
The set of micro-instructions iteration
to LS.
segment is activated
are used by the E-machine
stacks in QS. They result from D-machine
and related operations.
The micro-instructions
E-Machine
expansions of subscripting
are fully explained in Table 3-C,
and the DM expansions in Appendix C illustrate
TABLE
to maintain pseudo-
their use.
3
Instruction
Set
Notes: a.
Each instruction
is in the form OP
In the discussion, b.
VALUE
LINK
K is the address of the instruction
Instructions
starting with the letter
instructions
without the leading 7” when first
- 122 -
in QS.
“I” are Wninitialized.
have not yet been bound to their indexing environments. similar
AUK 0
” That is, they
They are changed to executed.
TABLE E-Machine Operation
3-A
- Simple Ins true tions
Name
Definition
S
Load Scalar
Push VALUE to VS, with tag ST,,
IFA FA
Load Array Element
IFA causes initialization,
as described in
Section E. 1. B., and the instruction FA.
becomes
FA fetches an array element determined
by the indexing environment
and pushes the
value to VS with tag SC. IA A
Load Array Address
IA causes initialization becomes A.
and the instruction
A is similar
to FA except that
the (encoded) address of the selected element is pushed to VS with tag AT. IJ J
Load J-Vector Element
IJ is similar
to IFA,
initialization. descriptor
and becomes J after
The VALUE field is an encoded of a J-vector,
the correct
element
of which is computed and pushed to VS with tag ST. OP GOP
Scalar Operator
The VALUE field is the name of a scalar arithmetic
operator.
This is invoked and
takes its operands from the top of VS, leaving a result there after deleting the operands. NIL
No Operation
No operation.
IRD IRP
Result Dimension
These instructions
are used by the D-machine
and are left in QS when a segment is turned over to the E-machine.
Since they are of no
use to the EM, they are changed to NIL the first time encountered. - 123 -
TABLE E-Machine Operation SCV
I
3-B
- Control Instructions Definition
Name Load Segment Descriptor
The VALUE field is a QS segment descriptor, addresses relative
to K.
Make these addresses ab-
solute and push the descriptor SG
Activate Segment
with
to VS with tag SGT.
The VALUE field is as in SCV, and LINK, zero, points to a pseudo-iteration
if non-
stack in QS.
Activate the segment by pushing an entry to LS, using the LINK information
to alter the QP field of
LS if necessary. JMP JO Jl JNO JNl
Jump Jump if 0 Jumpifl Jump if 0 nondestructive Jump if 1 nondestructive
Potential
jump destination is K+LINK,
is considered
as a signed number.
where LINK
JMP is uncondi-
tional. The others are conditional
on the value on top of
VS. JO and Jl also pop VS. RED
Begin Reduction
Push an element with tag RT to VS to act as a reduction accumulator,
MIT
Mark and Iterate
and jump to K+LINK.
Scalar values on top of VS are used to start a new iteration
nest in IS.
The absolute value of the VS
value, less 1, is the MAX field in IS; the .iterat.ion direction
(DIR) is forward (0) if VS is positive,
otherwise
backward (1).
initialized
to 0 or MAX, depending on whether DIR
is 0 or 1. Moreover,
The CNT field of IS is
the first
entry in IS has its
MRK bit set to 1; all others are 0. Each VS value is popped,
Finally,
when an SCT entry is found it is
popped and the named segment is activated in LS. - 124 -
TABLE E-Machine Operation POP
3-C
- Micro-Instructions
Name
Definition Pop top element of VS.
DUP
Pop Duplicate
ORG
Load IORG
Push current
CY
Cycle
Step IS and repeat the current overflowed.
LVE
Leave
De-activate IS entries.
RPT
Repeat
Repeat current
CAS
Case
If top of VS is not an integer scalar, then error else if the value is N, then pop VS and execute the instruction at K+N and resume execution at K+LINK.
Exchange
Interchange top two entries on VS.
Load from Pseudo-IS
LINK fields are relative pointers to XT entries. (or X2) field of referenced entry to VS, tag ST.
Store in Pseudo-IS
Store top (ST) entry on VS in Xl (or X2) field of referenced XT entry. Pop VS.
Index load
ML is initialized to give XL, in which the LINK field points to IS or a pseudo-IS element. XL gets the current iteration value, adds IORG, and pushes the result to VS with tag ST.
xs
Index Store
Subtract IORGfrom ST entry on top of VS; store in Xl field of XT entry at K-LINK in QS; if the value just stored is negative or greater than the X2 field of the same word, signal an error. Set the X3 field (change bit) to 1, and pop vs.
xc
Index Change Set the change bit (X3 field) of the referenced XT entry to 1, ISC is initialized to SC in same way as ML. The VALUE Activate Segment field of the instruction is a QS segment descriptor. If the Conditional change bit in the referenced IS or pseudo-IS entry is 1, then the segment is activated. Otherwise, the change bit of the XT entry referenced by the following instruction is set to 0, and this instruction is shipped.
ISC SC
Fetch the VS entry, LINK elements from top of VS, and push it to VS, (Does not disturb original copy. ) value of IORG register
the current
to VS (tag ST).
segment if IS hasn’t
segment, erasing any associated
segment from beginning.
- 125 -
(Does not affect IS. )
Push Xl
EXAMPLE
6:
This example illustrates
typical behavior of the E-machine.
Consider the
APL statement E[l;]+EP>I-lt(t/(l
2 2 QPTo.-PZ'[I;l)*2)*0.5
and suppose it is encountered by the machine when the variables EP is 0.0001 I is 2 PT is 0
0
0
1
1 1 The D-machine
EisO
1
1
0
1
0
0
1
0
0
0
0
0
1
0
0
0
0
code for this statement is as follows:
- 126-
are as below:
D-Machine
Code for Statement in Example 6: Comments
Addr
Op
Operand
200
LDS
202
LDS
0.5 2
204
LDSEG
SCODE(0, 0, 0)
206
LDNF
I
208
LDNF
PT
210
SUBS
2
212
LDNF
PT
214
GDF
SUB
PTo. -PT[I;j
216
LDCON
50
218
TRANS
Constant vector 1,2,2 1 2 2 QPTo.-PTCI;]
219 220
PWR
(1 2 2 4PTo.-PTCI;1)*2
223
PWR
224
LDS
226 227
ADD
-1tR
MOD
I-1tR
228
LDNF
230 231
GT LDSEG
SCODE(O,O, 0)
233
LDNF
I
235
LDN
E
237
SUBS
2
239 240
ASGN
250 251
RED
DO0 RC=l
1 ADD
Empty subscript
Result is PTCI; 1
+/cl
2 2 QPTo.-PT[I;I)*2
(t/(1
2 2 QPTo. -PT[1;1)*2)*0.5
(CdlthisR)
-1
EP EP> I-1tR Empty subscript
ELI; 1 .EtI;l+EPs
LEN=4
252
AB=54 vB=o RANK=1
253
R( 1)=3
D(l)=1
254
RC=l
LEN=4
255
1
256
2
257
3
I-1tR
Header for DA of constant
1,2,2
Rest of DA -
Header for value of constant Value array
- 127 -
1,s) 2
Example 6-l shows the instruction evaluate the sample statement.
buffer containing the deferred
code to
The transpose operation was evaluated in the D-
machine using beating, and its results are manifested in the access masks (AUX field) in the instructions Four temporary
at locations 3 and 4.
descriptor
arrays were created by the DM as follows:
PT[2;1
e (Recall that I is 2 in this example. )
@Tl
DAfor
@ ‘33
DA containing dimension of the result of the GOP operation, in this case 4,2.
@T3
DA containing dimension of the reduction result,
@T4
DA for EC2;l
in this case 4.
The deferred code is equivalent to the following: -forJ
r-Ostepluntil3& begin REDUCE := 0; for K := 1 step -1 --until 0 do REDUCE := REDUCE t- (PT[J;K] -PT[2 ;K])*2; E[2;J] := O.OOOl$-l+(REDUCE*0.5); end
The remainder
of the example shows the D-machine’s
progress
through the code
in QS, and contains comments which explain-the machine’s actions at each step.
- 128 -
EX.“PLE 6 -E-HICHINE __________________________________I_____------------------------------------------rwNOR”
Ls:
LEN REL ORG l -----.-----*-----*---*---*---,----*----*
-->
I I I
osc 000
I I
coo 000
EFFEC,l”E
“5;. -->
TAG ----I FWI I
I I
075 022
A”08
C/t I
0
IS I
0
FN I
1
NW‘ I
3
I 1 I I I 0 I 3
= DO00
“hut l -----------------I FCUUEI-I.O*FI
lh
OS
+ I
ps:
UP I I
UP ,-----
00 I s Cl I RED 021s 03 I ‘FA 02 I IFA 05 I CUP 06 I IRD C7IOP 01) I UP 09 I SC” ‘015 ‘I I N‘l 12 I IRO 13IW ISIS ::I:: ‘IIS IBIOP 19 I 2c I 21 I --> I
IA OP POP
CD 30
I I
*s:
CIR + ----
NAX DIR cn + -----,--*---*---*
I I
1 co3
-->
ccc
I
I
L‘NK
VALUE l -----------------t----.------. I 3.5 I 9 I 2 I ,r, I .P, I >“B I rrz I PM” I u3” I SCObEIStG.A,II I -2 I 3 I 413 I P*R I -1 IOD I N‘C I C.003‘ I Cl I a14 I LSGN I 0
c
I I
NIIK 1
I I I
02
I
05
t
f I I i I I I
O’
13 02
1
I
A”* I I I I O”0‘ I 0011 I 0011
08
I
I i i I I I I
z:: OoL’
0001 0001 OUOI 3001
I
I
I I I I
A-
I -* I I i I I I I
I ; I I
02 02
1I 0001 3001 I OOC‘ I
b-l
:
S,A,E
OF
lkt
REGISIERS
BEFORE
ElECU,,ON
YE to1 l 02 l 03 l c4 l OS .C6 +07 l oa 10‘7 .*c l ,* t:r( 113 l ,c +I5 l Lb
P.c=z 0 ‘ L 0 1 0 0 I 0 0 0 0 0 ‘3 0 0
---___
-_--
LEN-09
LEN=17
AOCN ----, PP, .OI l 02 l 03 +0*
CCNltkTS ----_ ---
__---___
RC-2 “L-YP, I .NK-2 R‘ll-004 1i21=002
LtN-05 *t)=ooo
i!E +01 to2 .c3 +G4
RCI‘ “B-Yt
LEN-05 .~*ooo
RlNL=2 Rlll=004 RlZl=004
“‘1,-o+ oI7,=0*
01‘ *cl to2 l 03
P.c*, “B-VP, ll1*ll= alLI=
a12 l o* +i).? l 03 +C4
NC-L ve-
‘tN=uS *L1-000
RlNK=Z ill,,-004 Rlzl-002
o‘,,*oz o‘L,-O,
RC=1 Ye=
LEN=04 be=030
RINI-L NIlI-004
olll=OI
Yc=, “W”E
LEN*04 1tl=ooe
RANK“ R‘,I-C04
“,L,-O,
d13 l c, l 02 +03 a14 l 0* l 02 +03
I I I
NO EIECUlIDN ,“E D-~AW‘NE’ ,,.S ,“S, PASSED COhTR”‘ ,U TtiE E-NACd‘hE. ,PE F”NC,‘ON MAl1K “N “S “AS PLACto 1HERE 8” “A!, ,AF.Elv PLACE “ET. ,HE COh,EN,S L)F THE “.,,I IRE ,hE PLtY‘OUS ACllVAllNG FUNCTION F. AND IHE NI”E OF THE FUNC,lON IFI. “AL”ES OF FREG ,-,I AND 10°C 101, SEG”EN, A Y‘,“‘,, QS EVbLUAlES ,nt RtO”C,,GN FO”hD IN THt SOURCE ,HE “tRA,ION STACK IS SE, UP ,O D” ,“E EUU‘VILtNl OF THE CODE. IltRAI‘IIN. ‘@FOR , :* 0 S,EP 1 UNTIL 3. EXAMPLE
DUMP
.“OR CCN,EN,S ___- *-------“P, w-2 .01 0 l o* 0 .33 0 tc4 L l 05 L .06 3 r07 I l oe I
0,,,=01 ulzl-01
EX.“PLE
CON‘ENIS ----_ - ---------.F 3 OPT OE 0.0001
LEN-O+ *a-004 1 oIl~*Ol
:;7Ea:HA, SF
N,: l&G ---*-es+ F F, I ST P‘ Cl E OT tP 51
IN ,Ht NANETACLE. rHE tNrRI FOB IHt ‘DEkT1FItR THE TAG OF ,“E EN,“” IOENIIF‘tS l, 15 A F”,,C“ON . IS ,t(t .“DRESS OF 7HE F”N‘,lON UCSCRIPIOR FOR F. YHICH
b-2:
S,A,t
OF
“EMCR”
BEFORE
EXEC”,‘“H
F PUINlS NI”E. IS NOT
SHOhN.
EXAMPLE 6 -E-MACHINE ----------------_-_-------~----------------------------------------------------REG‘SlER DOW kEYI = L ‘ORG * c FREG REL
OllG
LEN
DIE
IS
EXAMPLE 6 -E-“LCHIhE ________________________________________-----------------------------------------= 00‘00 FN
FBASE
kb7
UP
I OIO 1 001
I I
000 000
I I
015 022
I I
0 I
I I
0 1
I I
L 0
I 1
3 3
I I
ac2cc
‘Swc
ClR
l -----,-----.-----.---•---,---c--,----,
Ls:
-
00 00
I I
,s*
l -----,-----
-->
I I
11.x
-
DIR
cn
Nan
l ---.---
000
I
003
I
REG‘S7ER hEnI -
CG
LsI
l ---,
0
I
1
I
I
1
-->
DUMP 1ORG
I
0% I(EL .-----*-----t-----.---*---*---.---, I 040 I coo I I 0‘2 I 000 I I 000 I 002 I
--, i EfFECl‘VE
A”DR
-
000,
IN
VlLUE
FM7 ST
l I
OP
-_ u,i*
“S:*-----+----------------+
I I
FCOOEI-l,O,FI 0.5
VALUE
-----
LINK
l ------------------
5
1HE
I 0
-I
6-3:
I I
REGIS7E" NE",7 *
L
INSlRUCl‘Ch IFlER
***as
l ..-----,
LS:
-->
I I I
-.
SCILLRI
060 OLL
I I
000 OOJ
I I
F1EG ME
or5 322
I I
0 I
=
IS I I
PUSr)EO
occoo
FN
0 I
00000 Nhl
I I I
u I I
I I I
J I 1
I I I
1 0 0
‘IS
"PERANC
I I
FUSE
Wl
, 0
I I
3 3
-
PP I I
(0.5,
00200 ClR
00 00
I I
,j*
.-----
--->
I I
,,,
‘SMK NIX
l ----
O"0
AOO”
= 0002
IN
FBASE
I I I
3 3 1
I 00 I 00 I 00
I I I
-
002‘0
Cl& .----I 000 I 001 I
C,P
--a
ISRK
“1” .* -----.--.---
*
0‘1
100310I I0011
0, C”
“(II ,--.
LII 111
II
-* I
OS
VS.
I
-
D‘ll I
0
-.
I
I
LINK
*ux
l ------------------.----
***as
l I I
.-----*
UNCHANGED***
R,r "SE0 7"E SCALIII -2 CN 1OP OF VS 10 STAR1 I Ntbi IlEklllUN. 1nE LENClH JF 1HE IlEdAl‘D~ IS 2, AND 1WS lnt MAX FIELD IN IHE IiERAllON VS EkWV SIGNIFIED lHA7 1HC s,*c* IS SF1 70 L. 1HE WtGAllVE SIGN OF 1HE MNCE ClR S,&RlS Al L ,N,lEAO “F 0. ,IEl.llON IS 7D RUN LllCKllROS ID‘R-II; IN OS. 1”E NEXT VS ENlRV WAS A SEGMENl DtSCRlPlUU FOR SEG*ENl I I BY PUSHIM? A NEW tNlMV 70 LS. USEu IHIS 10 ACllvllE 1HE SEWEN MI1 311 IS Li 1nlS YIS 1”E PREVIOUS Y”7E 7H.l IN 1”E hEY LS ENIRI, 7”E N.7 YlLUt OF NEhIl. NEIlI IS NOW 1 I)ECA,,SP A NE* IlERlllON H&S BEEN SlARlEO.
“RK
- .---,---.--
003
I FCOOtl-I,O,Fl I 0.5 IO
.-----
-->I
00 cn
V*L”t
UP Jj:
I F”, I 51 IaT
(LOAD
= 0
FN
*s; 075 022 007
“s1*----*-----------------.
"*CH.NGto*..
"""P IO*6
IS
YALUE
1AG
S
“EL OR6 Lth +-----.-----.-----*---,---*---.---.----*
FREG WE
AUK
l ----
-->I
EXARPLE
9
us EFFECl‘VE
1.G
LEN
I
I
I EIA”PLE
6-5:
LFlEY
,471
________________________________________-------------------------------------------EFFECl‘Vt 14ti “s;*
-----
I F", I ST IRl I SC1 I ST
lU"R
= CO‘,
IN
REGISIEN N&,1 =
rlS
VALUE l ----------
l I I') I I
OP -
------
l
FCOUEI-‘,O,F, c.5
I I
SLOOEISEG.A.II -2
I I
VALUE
ys:*----*
----------------
-~
l **r)S
LINK -
.----
0U”P L
IWG
-
0
FREG
-
00000
FN
NW1
= 00200
FdASE
ISNK
-
01
*UK l __-___
l
"NC"lNGED.*.
LSI
OYC LEh YEL .-----*-----*-----t---~---*---,----*----~
-->
I I I I
040 Ok2 001
I I I
000 009 oc2
I I I
D/E
075 922 007
I I I
0 1 L
-
COO3
IS I I I
0 I L
I I I
I 0 0
I I I
3 3 L
OP I I I
00 00 00
CII
ClR I I I
,s:
l -----,-----
-->
I I I
GO0 001
OIR
‘I(
win
l ---,---*
I I
CO3 co1
I I
0 1
---,
I I
I I
I I
I 1
I I
5
.
-->I EFFELllVE 1Ht (IEO OPERAICY Pk,S”tC 1HE Rl tNlRV. FOY 1HE REWCl‘ON. AN0 JWPED 1U QSlPil. PUSHE ‘IS OPERAND IlHt OtSCR‘PlOR FOR THE 5 lWSlR”CllON IAT 13, PUSHED 1”E lI%SE TYO ENlIIES *ILL I)E ,,SE” 8” THE 7”E REDUC, ‘Ok SEG*EIYl. EIAlPLE
6-.X
AFlEI
"ED,
SGV,
.NO
S
dt “SE0 AS IN ACC”““LAlOR WE SW IhSrR”Cl‘LlN ,A1 SEGMtkl II 10 VS. -2 VALUE 1‘ VS. MI1 ‘NSl~UCl‘JN 10 ACl‘VA7E
AODR
Ih
cs
10
9, ys;.
-----
, F”, I 51 Ial IS1
OP
VALUE
146
YILUE
LINK
A”I
,SEG.A, 10 VS.
IS
as*.-----,------------------,-----*------.
l ------------------,
I FCODtl-lrO,Fl I 0.5 IO I7
.**QS
I
"N‘".NGtO*.*
I I
-->I 1”E F,“,l Al OSlZil. EXIPPLE
6-6:
,NSlRWl‘DN OF IHE 1”‘s INSlRUCllON OFFER
5
4~1
asiz;b
hEuLV-AClIVLlED PUSHED 115 7
SEWEN, “PER&NO I21
EXAMPLE 6 -E-MACHINE __-___-___-_____-__------------------------------------------------------------
EXAWLE b -E-NA‘HINE _______________________________-____---_-_______---__--------__---------------‘IEG‘SIER NE”,, a
---
,
IORG
AEL
-
OllG
LEN
000 000 002
I 0?5 I 012 I oc7
,
L-71
AFTER
IF1
.-----.-----
-->
I I I I
DIlG
950 0,2 002
I I I
L‘hl(
VALUE
14G
.“I.
RED
If4 GOP
I I I I I
SGV 5 MI1 ‘RD UP :P
t I I I I
tp OP ‘A “P POP
t
NLr
0.5 3
i
iKUE~VPl.4l APT sue 112 Pd. 40D ~CODElSE6.A.ll -2 0 Al3 PI4 -1 400 WO 3. coo 1 Gl .I4 AS‘N 0 PCDDEll.lI
000 000 002
-
I I I
6A
I I I
I
i A._ I I I
lq 02
I I
JO11 0011
I 05 I 07 I
I I I
t::: 0011
i
1
f I
I I I I I
0001 0001
I I I
3O”l 000,
! I
t
0001
I
! I
13
I I
c2
f I
02
I
02
/
I
0,
I
I I I
--,
t FRl I Sl I41 IS1 IS1 I
FYtG 0,E
l ----
+---•--
I 075 I 012 I 007
I I I
4004
-
VALUE
CCOI
0 1 I
-
00000
FN
N.1
I I I 0 I 0
I 3 I 3 I 1
IS -...--.
I I I
0 1 1
IN
-A
I
-
I 00 1 00 I 00
00200 Cl4
I I I
,SI
.-----
-->
I I I
000 co1
‘SMK
..I
-
11.X DIR .----.--.---*---* 003 I 00,1IILllI
01 cn
0
I
)(LI I
I
I
I
US “P
“I
I I I I I I
:x
:,,
I
I
s lltD
I I
I oc I I 01 I I 02 IS IO3lfA I 04 I 05 I Ob I OlIO? 08 I
,FA GOP Ill0
:: t ::: ‘3l”P 141s ‘SIOP 161°C ,715 ‘aluP 19 I ‘A 20 I “P 2‘ I POP 22 I NLl --> I
I
FBASt P*
---*----.
.y,I.----*
I FC”OE,-,,O.F, I 0.5 IO I2 IO
i
::::
0
LEN
,5,*-----.-----------------.
L”C,Al,ON 3 IN US, NHlC” CREY,““S‘I CONIAINPI) AN IF4 INSlR”C7lDN. UAS WE VALVE F,ELO NM C”Nl4lkS VP, , THE b4St BEEN INll‘AL‘ZEO 10 f4. AL,“~ESS wEFERENCED IN IHE “A 41 all, AN” 7nE ABASE (=%I FROM lHA1 04. IN AOD,llON, 1”E L‘NK FIELD OF 05131, IS N”. A ‘IELAllVE POINIER 1” QS,22;,, MH‘C” IS 7,,E ,,ERAll”N CONTRUL BLWI F”” lH,S AYRA”. THE SECOND ,,.E. WE 92 FIELD‘ IS THE DLL FOY 1HtS ANdAY. ‘zLEMENI OF 1”E ICL) ENIYV ,SEE EIA”PLE 6-2 FOR CONlfNlS OF 11,. IHE F‘llSl ELfl)tNl 74IEN FRuN PI‘. IS DEL TINES 1”E MAX VALUE IN 1HE 1”P ENlRV ON IS. ,P, FIELD, LS “AS NO1 C,,ANGED “El BtCAUSE IHE NE,,LV-CREAIE” FA lNSl4UClION HAS IHE !N‘l,4L,L4l,ON PROCESS ALSO ERASE” THE OA ND, “El L)EtN CXECWED. Sl44,‘NG Al 111, Y”,C” IS NO LONGER AtFERENCEO 4NVuHERE IN THE MACHINE. ElAWLE
Lj,
I I
cS*,----,------------------,-----*----,
‘I)
,“RG
Rt‘
NW
-.---
I I
D”“P I
EFFECltVE
I IRO I I ::
I
I I I --a
‘Sk&
OS
001s 01 I 021s 03lFA I I “b 01 00 39 I 10 I II I l.? I 13 I *4 ,5 I
I FCOOEI-l,O,F, I 0.5 IO I2
OOLCC Cl4
co 06 00
OP l
.
“P 1s;
---_--____--__--
I FM1 I Sl I41 IS1 I
FAE6
0
VALUE
IAG
_--
REGISIER NEhll =
DUMP
I
I I I I I I I I I I
“4L”E -----_____-_--J.5 0 2 amEtvP7.5t dP7 SUB a12 PII AC0 SCOOEiSEG.A.1, -2 c A13 PNR -1 AU0 O.JOOl Cl I14 ASGN 3 PCOOEll~II
L - -*-
i
i
I
00
I I
I I
I I I I
19 02
II I I I I
I
05 01
I I I
i
A._
f I I I I -A
i
i 0001 i 13
1 02 I I I I I I
0011 0011 OOI‘ OOI‘ 0011
I I I
000‘ 3001
I I I
I Oool ’I
02 02 /21
i 0001 i I I I I
r)OO‘ 0001
I I 1
7HE AODIESS IN PS,siI H4S BEEh UPOAIEO 6” ,“E INDEX UN‘1 At‘” IHE VA‘Ut 11 REFERS 10 HAS BEEN PLWED IL VS. 1WS 1nE VALUE IO1 ON 1°C OF VS Al l”,S POINI IS PllZill. IIIECALL lMA1 IN EFFECIIVE ADDRESS “F AN ARRA” ELtNENl REFCIENCEC IN AN FA ‘NSlR”Cl‘ON IS 1HE SW OF ‘IS C”DE” PAILlS, PLUS 1 II” CONPENSAIE FLW. 1”E yI44V HEADCL MC”“, ,. ENAMPLE
6-1:
AFIER
F4
EIIIIPLE 6 -E-MACHINE -_____________-_____________I___________------------------------------------P.EGlSlE4 hEYI =
1
IORG
= 0
LS*
LEN REL ORG *-----*-----.-----.--~--.---C-C---+
-->
I I I I
040 012 003
I I I
000 000 002
EFFECIIVE
I I I
ADD.?
075 022 007
F4EG DIE
=
IS
OOCOO
FN
NY1
1 :;l
;
I RI IS1
I 0. I2
i::
E I
= 0005
0 I I
I I I
0 1 I
IN
I I I
I 0 0
I I I
ryl-l,O,Fl i
1:
i
11 ‘2 ‘3 :: lb 17 II I9 20 21 22 23 24 -->
I 00 I 00 I 90
00X0
ISelK
MAI ClR t-----*-----C-,---,---,
I I I --,
1000100310I‘I‘I I 001 I 001 I
=
DIR
I
VALUE
4FlE4
OS,481
I
5 AED 5 FA F4 GOP ‘AD UP OP SGV 5 11‘1 ‘II0 UP 5 OP OP 5 OP ‘A O? POP NLl hl NLl
0.5
.‘NK
1
“4,‘
I
1
, ‘N‘l‘4L‘.?AlION
-E-“ACH‘NE ---------------
1
IORG “4%
i UC”OElVPl.5l ocmatvrr;,, SW 412 PYR ADO SCWElStG.4,ll -2 0 iI3 PII -1 A”0 Mar) 0.000‘ Cl 014 ASGN 0 ikOOE,l,ll GCrnEl6.2‘ aCmE~l.lI
‘9 19 02 05 07
I I I I I I I
TAG
I
0011 00“ 00“ 0011
I
13 02
i 02 02 01 01
i I I I I I I
4-
ADDR
=
IS
-
0007
0 1 1
300‘ 000‘ 000‘ 000‘ 0001
EKECUIIUNI
YP
I 0 0
I3 I 3 I 1
IO0 I 00 I 00
IN
OP
l ---------------
--•
I FCU”t,-l,O,Fl I a.5 IO I2 IO
as*+
I I I I I
-----
001s 0‘ I 021s 93 I 04lFA 05 I 06 I
-->I
I I I I I I I I I
1
REO c. GOP NIL
EIAllPLE
b-10:
4FlE4
SUB,‘R”
I 000 I 1001100‘1‘I I
VALUE I I f I I I
09 I SGV 101s II I Ill ‘2 I Ill0 ‘3lOP 141s 15I"P ‘6I"P IT I 5 18 I UC ‘9IIA 20 I OP 2‘ I POP
I I I I
:: 24
I' I
I I I
2:' WLl
IHE WI HAS DEEN DONE. (IN THE IME ‘40 “PtRAl‘ON DECREASES THE ‘ISELF Bv NIL. THE W-UP, BECAUSE NO1 8V 1”E E-MACHINE.
,
00200
ISMK
CIA *4x .----*----t--*---.--*
+ -------------___.
I I I I I I I I
I
b-7, AND lnt VS ARE N”u IOP “F US
I I I -->
=
co3
=
01
DIR I
CH
3
I
I I 1111
1(11& 1
I
I I
4-
45
VALUE
--,
AN“
FUASE
kbl
I I I
i 0001 0001
00000
FN
‘S, I I I
I
i
I I I I I
-----
I Fill I Sl IAl IS1 IS1
I I I I I -4
IO I 1 I 1
--,
000 000 002
FllEG
I015 I 022 I 007
IO40 I 012 I 005 I
4”X
________________________________________-------
0 DIE
l -----*-----,-----*---,--*---,---,----*
I I I
LEN
Lst
I
-
O”*P
REL
“S*+
Al OSl4il WI MEN CWNGEO 1” F4 , AS IN El4”PLE THE IOP 1W ELEMENIS ON BEEN EXECUILO, AS IN 6-B. ALSO MlE WE 1W NEh ENIR‘ES Oh II‘& AN0 PllO3‘l. 4”E It&E IC8 FO” 1HE F4 Al PS,4;l.
6-9X
01 C”
1
6 -
EFFECllVf UP ---_
‘FA
Y”,C” EXAMPLE
3 3 1
=
EXA”PLE AEGISIER hEYI =
PS
--,I
1HE ;AH;;
FI(4SE ‘ZIP ‘Sl
I I I
Illi VALUE vsr+----.--------------*
I
--------------
OUllP
0.5 0 2 “CmE,vPl,5‘ QC"UElVPl.Il SUB 0 P”Y 400 SCWElSEG.A.ll -2 0 ill
l UR
LINK
-+..---,-e--e, 08 19 1‘4 02
4”I
I I
05 07
t I I I I t I
I
13
1 000‘ I 000‘
I I
02
I
0001
I
f I I I I I I I
ooo‘ 000‘ 000‘ 0001
I I I I I
0011
0011 0011
-1
0.000‘ GT 414 4sGN 0 UCOOEIl,lI ‘XmE,6rZl &00E11.11
02 02 0‘ 0‘
I I I I I -4
I
! I
E-MACHINE, GOP IS ll(E4lED S4”t AS OP., REFC” “F ‘IS OPtRAND 8, 1 AND REPLACES l4D IS USE0 8” WE 0-“4C”‘NE ,“I
EAA@PLE *______-------RE‘ lSlEl LEbIl
--
4
---=
REL LSr
E-MACHINE _________________________________--------_----------------
1 DUMP
1oRG
= 0
F"EG
LEN
UP6
O/E
=
IS
00000
FN
FBASE
Nbl
-->
I 000 I
I 0 I I
075 I022 I 007
coo 002
EFFECIIVE
ADOR
=
'I I
I I
0 1 1
I I IO I 0
IN
0004
I 3 I3 I I
tslw “4X
Cl4 ‘SI
I I
= 00200
‘IP
l -----,-----•----*---.--*---•---t
I 040 IO12 I 001 I
EXAMPLE 6 -E-“4C”‘NE __--____--__________________-_______________________________________________I__-
I 00 ICD I 00
I I I
=
o,*
REGISIER NEY,, =
01 cn
--a
I
1
I
1
I
I
l -----+-----,----+--~--*---,----,
-->
I I I I
I
I
OR‘
Ls*
040 OL2 wo
I I I
EFFECIIVE
QS LINK
“P VALUE aSrr-----,--------------.r----*------,
146 VALUE vs*.----.----------------, I F”1 I FCOOEt-l.O,FI
‘“RG
AEL
mu
l -----,-----*--,---.---,
1000100310111‘1 I 001 I 00‘
DU”P 0
***OS
000 000 002
= 0
FREC
LEN I I I
ADDR
075 022 007
DIE I I I
0 1 1
= 0002
I I I
0 1 ,
IN
VALUE IA‘ vSI+-----,------------------.
AUX
I
UNCHAffiEU***
F”1
I
=
IS
00000
FN I I I
I 0 0
FbASE
N#l I I I
3 3 ,
=
OP I I I
00 00 00
00200
I I I
‘SNI “41
cm ,s*
.----,-----,--.--,--,
-->
1000100310I‘I I 000 I 001 I
=
DIR
I
1
01 C”
I
1
‘WI I I
I
CS UP as;*
VALUE
-----.---
FCOOEI-1,O.F‘
LINK
-------
***as
-----
+--,
A”X ------
l
WCHANGEO...
I I :: IS1
I
I F’ IO
-->I
I
-->I ,A, QS,T~ll YIS APPLltO PYA 7HESE OPERANDS 0 AN0 2: tJ HAS BEtN PUSHED 1” VS.
I
E I
E,A”PLE
b-118
4FlER
-->
lb‘ -_--
ON THE V4L”E IlESUCl OF 1”E
AD”R
FlEG
= 0 “,E I I I
0 I 1
= CO09
I
FCODEt-l,O,Fl
I
::
I
“,*’
OOCOO
FN
a I 1
IN
I I I
I 0 3
NUT I I I
3 3 1
1°C SECCNO PASS IWOUGH 7nE RELWCllon SEGtiEN7 PROCEEDS S‘N‘LARLV I” 1”E FIRSI. EICEPI I”41 110 FUlltHFl ,N,l‘AL‘ZAl‘UNS NEED SE DONE. 41 ‘HE END OF IHIS ‘7ER4llUN. &EL-LEN IN LS ANO, 4.5 BEFOOE, IHL ‘1E441‘0N SlACA MILL 8E SIEPPEO. HO”EVER, IH‘S 1,ME 11 “VERFLObS, SO ExOlH LS AND IS ARE POPPED, REIVRNING 1HE MACHINE 1” 1”E “4,N SE6”ENl. (SEE NE41 FIGULEI
1s:
l -----
l -----
l ---.---
I I
I I
--a
I I I
“AX
000 00‘
DIY
003 001
0 I
LINK
VALUE .**QS
------
“NC”AWGED.*.
1”E ADO UPEI,l,“N, SEE‘& lH41 ‘IS SEWN0 “PERAWU IIAS IAG IHIS GIVES AS ‘IS RESULI IHE FIRS1 “PEAAND. d‘lH IAG 57. ACCo(ID,NG 1” 1”E OEF,II,l,ON OF REJUClI”N. ADD
MA* l ---*
I 1
I I
1 1
4”X
--*---.
*-----.---------------
i
AFTER
‘H I I
I I E”A”PLE
-->I
A-128
01
as
ps:
---*
OOZOC
=
=
ClR I I I
,s#w
FBASt UP
I 00 I $0 I 00
UP
l _______-e____
F”,
=
IS I I I
VALUE
I
EIAIPLE
IN l,,E LAS1 Flbllt, 1”E SEMEN1 “AS C”*PLEIEO, S‘hCE ‘15 4ELAllVE ADDRESS WAS IHE SAME AS 115 LENGIW. ““YEVER, SINCE IHE IS lur YAS SE1 FOR lb‘41 SEG”ENlr IHE 345 SIEPPEO WI UION’I OVERCLOY. IS 1”“s. LS YAS RE-‘NIlIAL,2EO,~ ‘~~,~~f’“‘“‘ OF THE SEGMENI, 1” BE AtPEAlED N‘l” lI+E NEY . NOlE lH41 hEllI No* IS 0. 41 THIS PO‘NI, THE EWIVALWl OF 7HE 4LWLiC -REDUCE := lkDUCE l . ..= "AS BEEN DDNE FLX J-0 440 4-l.
SlUKr “PE44llJN
____________________------------------------------------‘OR‘
EFFECl‘VE
yj;*
ELL”tN,S AN0 IHE
DWP I
LEN OR‘ REL +__--*-----*-----.---*--*---*---*----. I 040 I 000 I 575 I 012 I 000 I 022 I 007 I 002 I 307 I
Ls:
2
PYR
____________________-----AEGISlEA hECl1 =
10 1°C ,OP WERE DELEIED l 2 = 0,
Il. IS
l
6-13s
DEGINN‘ffi
OF
SE‘llENl
YI7H
SIEPPED
IS
I I
EXIWLE 4 -E-KACHINC ________________-_-__-___________----_____-_--_-________-----_---_----------
EKAWLE 6 -P-NACIIINE .-___________-__________---________-_-_---__---------_-_-----------------KEGlSrER NthIT Ls*
-->
I
IORG
-
TAG
4004
-
FAEC
0
LEN KEL OAG l -----+-----+-----~---*--*---*---.----* I OIO I 000 I 075 1 OL2 I 000 I 022 I EFFECTIVE
“S,
DIE I I
0 1
0012
IS I I
0 1
IN
-
ooaoo
FN
NbT
I I
1 0
l -----------------.
I FNt I ST IS1
I FCOOEt-lrO.Fl I 0.5 II
I t
-->I
:: 20 21 22 23 24
--, Kcoucc SCGNEWI Nt,,E T”47 NEYlt
,-,,I
I 00 I 00
4FTE4
REtURN
70 F”Ol
ISUK
,s: -->
I I
000
I
-
DIR
003
I
00 CH
0
1
1
nKK I
I
7HF:
DUMP l
IOKG
REL LSI
l -----*-----.----*---+----.---.---*----,
--,
I I I
I
010 020
I 000 I 000
-------*---.------. 1 04
I I I
I I
OF O?
I I
:“’ Ml1
I
lip””
I :* I OF I 5 I OP
TAG
.“K
2 QCOOElVClr4l 9COOEtVP7rOb
t
i i
;;
1 02
IY
I I I
PM ADO SCOOElSEG.4.II
1 I I I I I I
o2 413 CUR -1 400 NOD 0.0001
;
OS.1
I I
O7
I
f I
13
I I I
I
-----
--,
I FNl IS7 I AT I
A-
i
I
vs,*
I
0011
I
0011
I
0°”
I -’
0001 0001
t I I
02
t
0001
I
t I
02
t I
OQO’ 0001
I I
I
02
I
tE:
1
t
01
t
t
I
I I
-
0
FREG
LEN
ORG
EFFtC7lVE LINK
VALUE ---------
I I
O/E
075 022
I I
-
0020
4004
0 I
IS I I
I I I
4EO”CtlW
0 L
IN
I I
1 0
I
01
OF
IO? OF COWED.
THE
-FOR
I I
3 3
--,
I FCOUEI-l,O,Fl I1 I PCOOClVE,4I
QSI.
I
I
OP I I
00200
I I
,s;
l -----.-----
-->
IO00 I
‘SNK *4x
CIA
co GO
-
0,A
00 cn
NmK
l ---*---*---*
I
003
IO
VLLUE
OP
l __---___----_--
00
1021s I O’ 03 0. OS 06 07 OU 09 10 II 12 13 ii 15 ‘6 17 II 20 21 22 23 24 25
--, IS ON LS YAS
FBASE
Mb1
I
I
I
I
I
PS
IV
OCOOEll,ll acooEl4r2l ‘XUOE~l.1~
COMPLEtlON
= 00000 FN
VALUE
1’ 24 ! ii I CO? I NLl I N7 I NL7 I
4ESU7 ,,I TO 1 l”EN
Its IS DONE. “IS lltS,OKEO
COKKESPONM
I I
00200
“AK Cl4 ,-----*-----.--.---,---,
OF
ils:*----*--00 01 02 03
:: lb I7
StAGE
3 3
*
OS
04 05 06 01 04 09 LO 11 12. 13
t”,S
I I
FUASE
OI
V4LUE
l _____
EKAWLE
REGISIEK NEYlI -
DUMP
-----
IS
LINK
l _-----_----_____--
l ----
I
0.5
I I I l I
I I I
RED Fb F4
t I I
: YCOOEIVPI.~~ OCOOt,VC7.0,
I I I
OP OP SGV
I I I
PY4 400 SCOOElSEG.A.lI
I I f
:,7 NIL oc
I I I
0’ 0 FYI
i
g;
1
i;
I 5 I oc I 4 I OP I PO? I NL7 I Nl I NLT I NLT I
I O.OOOl I Cl 1 PCOOflVE.4t I ASGN I 0 I PCoMtl,lI l PCOOE16.2l I 9CWE41.1~ I OCOOCl3r1l
AU4 l -----,
I 04
t
19 I9
1 I
I O2 I 05
I I
0°” 0011
I I
I O’ 1 I
I
Ool’
! -4 I
I
L3
I
0001
f I
I
02
i
y;
1
I I I
02 04
i I
0001
i
O2 01
I I
ooo’
I
01
t I
t I I I I
I
A-
I
I
I I
VS.
I-
LOO?
Yl7M
OS112101 THKWGN QStl9;t NAS 144NSFMNEO 10 4 ‘A,’ ON lo? OF vs. TAG
J-0. EXAlPLE
4-151
4EFOKE
4SCN
HAVE 4LEN EXECUlEO. AWD tn47 ITS RESULT
W7E IS tNt
IWT 1HE I4 Al COOED ADDRESS
OSlL90 WITH
EIAMPLE .______________
4
REGlStER hEYIt -
--
E-MICH‘NE - _________----
---
,OKG
,
-
Ls:
-->
I I I
010 II22
I I
000 000
EFFEC,,VE t4G yS;*-----+ I FM,
I I
DIE
015 022
AUOR
-
FREG
0
LEN ORG REL l -----*-----,-----*---,----*---t----*----*
-->i
------_-____-
-
-----------
--------_-
EXAMPLE .____------__
------__
I I
0 1
IS I I
IN
‘ 0
FUASE
W, I I
OP
3 3
I I
00 00
I I
-
‘S”K
00200
,s:
“AX CTK l -----t-----*--,---,---*
-->
I I
000
I
-
DIR
003
I
0
00 cn
I
NKK 1
I
‘
--
0
VALUE l ------------___ ***OS UNCHANGED***
I
LINK l ----,------,
4°K
E-MACHINE ------_---‘URG
-->
I I I
040 022
14G -----
vs:+
-_.>I
I
FM1
---
I I
000 OCO
I I
I I
-
0022
AD”4
VALUE *-- --------_ I
“,E
075 022
0 L
g
EKA”PLE
b-,61
4,
EN”
OF
MAIN
SEUIEhl.
FIRS,
1lME
1HRO”GH
OWP
I
ADOR CONtEktS ---*------------------
4PT +01 ro2 l 03 l Oh
RC- 1 VB-VP1 RANK-2 R,,,-Oo. R,2,-002
iE to, l 02 +03 +04
RC- I vu=vt RANK-2 11, L,‘OO. 4l2l=oo4
VP, .o* l 02 .C3 .o* l 05 .C6 r07 l ou
LEN=05 AI)-OCO 01 ,I=02 0121-0‘ LEN-OS AB-000
Kc-‘ 0 0 0 I 1 0 ‘ 1
b-17:
LEN-09
“1 II.01 ol2l-01
EN,R,ES FOY 4,,,...,4,4 NOW HAVE , 4L,HWGH ‘INKED 4VAILABIL’,V LtSt THE ENTRV IN ,tiE VALUE ARRAV FO” CHANGED TO ‘ 4” 1HE 45611 OPER4,‘ON. ElA”PLE
ADD4 ----*
S,A,E
OF
II
4F,E4
F‘4St
YE .O‘ .02 l 03 .o* to5 rob +07 l ou l 09 r,o .‘I ...L‘ .‘3 .‘4 r15 l lb
CCNlENlS _______----__ IX-1 0 1 1 0 ‘ 0 0 ‘ 1 0 0 ^ ” 0 0 0 0
---LEN-17
REFCOS OF 0 , ANU HAVE BEEN ADDED 10 ,HlS IS W7 SHObN HERE. IN I(E”OR”, “AS BEEN E . 4, VE,9 TH‘S tNlRV IS ElZiOb. ,‘ME
,H(I”“W
,Ht
SEGMENt
THE FOR AllU ,“‘S THE
EXlllPLE
-
-
-----------------
COO00
FII I I
1 0
-
FBASE
NY, I I
3 3
QP I I
00 CO
I I
=
-^--------
0020c
-___--
REGlStERS
AFIt
*
,s:
CTR l -----
“AX l ----
OIK .--,---,
I
I
-->
I i
003
OP -----
00 IS 0‘ I 02 I 03 I o+ I 05 I 06 I 07 I 08 I 09 I ‘0 i 1‘ I I2 I 13 I I+ I 15 I lb I I? I 11) I ‘9 I 20 I 21 I 22 I 23 I 26 I 25 I --> I
RED 5 FL FA GOP NIL OP UP 5 n,r NIL OP 5 OP UP 5 OP 4 OP POP NLT NT NLI NLT
VALUE l -----I I
003
00 CH
0
I
I
NEXT
WREF
LINK +----*-----*
- -------
0.5 0 2 *CODE,“Pr,C# WOOE,YP,r6, SUB 0 **Ia IOU SCUlJElSEG.4.1) -2 0 0 PY” -1 ADD
l”4O”W
ou
I I I
O2 05 07
19 19
I
I II
1
“KK ---, I
‘
I
I I i
A._
I i I I I I I I I
i OO“ 00‘1 ml‘
i
I I I -4 I I Ii
I
1 02
S.&k HAVE HAS J-.
A”4
‘‘33 II 000‘ 000‘ ff
I I 02 I 06 I 02 I I 0‘ I I 0‘ I
1
PASSES
I I I I
i
0.000‘ Cl 1CODEIVE,“1 AS‘N
NA‘N SEGNENT atAS 4EPEIlED 3 W4E ,‘,tES IN ,Ht t”E F‘RSr PASS. At lH1S PCIN,. 3 NURE VALUES tHE IS ENIR” CO44ESPONOlNG ,O THIS SE‘r)EN, PU‘Nl COYRESPGNDS 10 IHE CCWLET‘UN Ok -F”I b-,4:
‘5°K
GS
“s:, I
cn ADD4 CONTENIS ----*-----------------
0 1
------•
FCOOEI-‘,O,Fl
,___________________--------------------------------------------------------------llEM0RV
IS I I
‘h
THE VALUE CN VS HA> BEEN SlOREO 4, VE*l+U IN I(EIIURI. ,F,ER ,SGN 4NO VPOP. “ILL 4t SIEPPEO AN0 SINCE ,“E SEGMENT HAS BEEN COMPLEIEU, ,Ht IS LS ,,,,.L BE RESE, TO THE BEG‘NN‘N‘ SINCE 7HERE ‘S NO OVERFLOW. ,H‘S S,AGE CURYESPONOS TO CNE PASS ,r(ROUGH IHE ‘FOR J” RANGE. ltTM J-O.
I
-_----FREG
= 0
RtL ORG L&N .-----*-----t-----.---1----*---,----+----~
EFFtCl‘VE OP -_--
-
D”“P
Ls: I
OS
us:*
----t
00000
FN
0 I ‘ I
0022
VALUE -----------‘ FCODEI-L.O.FI
-
6
DEG‘S,ER NE”‘, -
DUMP
f I
000‘ JO01
I I
I I I
000‘
I
0001
I I I
CA” 4s StN,dN 4EtN S,OYED BEEN EXHA”S,t”.
SEGMEN,
I f I I I
EXAMPLE ----------------
6
-E-MACHtNE ------------------------
REC 1 STEH DUMP hEWIT = 3
IOWG
Ls:
REL ORG +-----+-----+-----*---*---+
-->
I
I
c40
I
coo
EFFtCTIVE “St+ -->
TAG ----I FHT I
=
0
LEN I
FRtC D/E
IS
=
OCCOO
FN NkT ----+---+----+
= 0240
VALUE + ------ ----------I FCODEt-l,O,Fl
IN
n
+
OS:+
I
VALUE
-----
LINK
+ ------------------
l ----
6-19:
REGISlEHS
AT
AUX + ------
+
I
THE LAST FIGURE WAS THE END OF THE SEGMENT. STEPPED. SINCE IT OVERFLOWED, IS AND DE-ACTIVATING THAT SEGMENT CHANGtO CONTROL AN0 THEREFORE 01 kAS RESET TO THE BEGINNINti JUST COMPLETED. EXAMPLE
= 00200
UP
UP
I -->
- ---------------
FBASE
I c I 0 I 1 I 3 I 00
075
ADLIR
--------------------------
CCMPLETICN
OF
THUS, IS MA5 LS WERE POPPED. FROH THE E- TO THE OF THE SEGMENT
k-MACHLNE
D-MACHINE
EVALUATION.
I
w’ Q, I
MEMORY
DUMP AOOH CONTENTS ---+ -----------------VP1 RC-1 +01 c +02 0 +03 0 404 I
AOOR CONTENTS --- - +-e-e 1------------3PT RC= 1 LEN=05 VB=VPT AB=OOO +01 RANK=2 +02 +03 R(l)=004 U( 1)=02 +04 R(Z)=OG2 0(2)=cll
+os 406 407 +ce
RC= 1 LEN-05 VB=VE AB=300 RANK=2 R(I)=004 O(l)=04 R(Z)=004 Dt2)=01
aE
+01 402 +03 +04
LEN=09
AUDR e--e+ Vii
CUNTENlS ------------------
+01 +a2 +03
+04 +05
1 0 1 1
+otl *or
EXAMPLE
6-20:
THAT THE CORRESPOND MEMORY
VALUES AT TO E( 2;). AT
COMPLETION
VE+9rlO~llrA2 THE ENTIRE OF
ROY
E-MACHINE
HAVE OF
7
1
1 0 0
408
1 1
+10 +11
0 0 1 0 0 c 0
+I3 +14 +15 +16
LEN=1
1 0
+09
+12
NOTICE THESE
RC=l 0
CiiANGElJ FROM EXAMPLE E TO BE CALCULATED.
EVALUATION
6-2.
APPENDIX SUMMARY OF REGISTERS, This appendix summarizes fields in the various stacks,
A ENCODINGS AND TAGS
the uses of all machine registers In addition,
functions in the design description
and details the
the several encodings used as parametric
are outlined.
Because of the parametric
nature
of the design, not much will he said about field sizes except to indicate the range of the contents of a particular incarnation
of such a machine,
field or register.,
all the fields are “big enough” to contain their
In the detailed algorithms
contents.
We assume that in any particular
of Appendix B, the registers
are construed
as arrays of scalars with some kind of encoding imposed upon the contents, While not completely
necessary.
rigorous,
machine works without having to explicitly registers
if
this approach serves to show how the encode and decode all references
to
at each step.
A.
Registers
1,
LS (Location
Counter StaCli)
Field Name
Column Index
REL
0
Relative location in segment. instruction to be fetched.
ORG
1
Segment origin. For D-machine segments, this is relative to FBASE. In the EGmachine, the effective address is t/LSCLI-l;o,lI and in the D-machine it is FBASEtt/LSCLI-1 ;O ,ll.
LEN
2
Length of segment. For D-machine segments, this is in words, and for the E-machine, this is the number of QS entries for the segment.
D/E
3
Segment mode. This field is 0 for the D-machine machine segments.
IS
4
Iteration mark. Has value 1 if this segment is associated with an iteration in IS; otherwise it is 0.
Contents
- 137 -
Generally
points to the next
and 1 for E-
FN
5
Function mark. Has value 1 (else 0) if this is the main segment of an active function.
NWT
6
NEWIT value, stacked when a new iteration
QP
7
Used by index unit for e,xpression indexed from QS pointer. QS rather than IS. (See Section E. )
2.
IS (Iteration
is activated.
Control Stack)
Field Name
Column Index
CTR
0
Current iteration count. This value is always non-negative and varies between 0 and the value in the MAX field, in the direction indicated by the DIR field.
1
Maximum iteration
DIR
2
Direction of count. (0 for positive, 1 for negative. ) If positive, then CTR is initialized to &otherwise it is initialized to MAX.
CH
3
Change. Used by STEPIS routine in main control cycle to mark all IS entries which have changed since the last cycle.
MRK
4
Mark. Has value 1 for the outermost iteration of each nest. Otherwise, it is 0. (See ISMK register, below. )
3.
Contents
VS (Value Stack)
Field Name
Column Index
TAG
0
Tag field.
VALUE
1
Value.
4.
count.
QS (Instruction
Field Name
Column Index
Contents Identifies
kind of entry in value field.
Buffer) Contents code. The QS contains instructions deferred later execution by the E-machine. Occascontain a tag, such as XT, for an entry value for the EM rather than an executable
OP
0
E-machine operation by the D-machine for sionally this field will which is a temporary instruction,
VALUE
1
Value. Contains the value in immediate operand for others.
- 138 -
instructions
and the
LINK
2
Link. This is a signed integer used to reference other instructions and entries in QS. It is taken relative to the QS index of the entry in which it is found. By keeping links and segment origins relative in QS, all deferred code is relocatable.
AUX
3
Access mask. Contains an encoding (MCODE) of the iteration indices to use in accessing an array expression.
5.
NT (Nametable)
Field Name
column Index
TAG CONTENTS
6.
Contents
0
the value of Symbol index, Since NT is content-addressable, INX must be carried with each entry. These indices (or names) may be assigned in any arbitrary way. There is no built-in restriction on their use.
1
Tag.
2
Value.
Same as tag field in VS. Same as in VS.
M( Memory) In the APL machine, M is considered to be a vector of length MLENGTH
which can be addressed between BOTM and TOPM. in M are not specified except as necessary, the M-entry
e.g.,
The particular in instructions
containing the operand is in SCODE encoding.
encodings used such as LDSEG,
Otherwise,
value is assumed to take up one machine word, as is each instruction. clearly
inefficient
implementation kinds of values.
in space utilization,
of words
each scalar This is
and it would be expected that any real
would specify more reasonable and detailed encodings for various Nothing in the machine design is based on the word as the primary
unit of memory in the machine,
so there should be no problem in making such
modifications.
- 139 -
7.
Other Scalar-Valued
Registers
Register Name
Contents
LI
LS index. (All stack indices point to the next available entry in the stack. )
II
IS index,
VI
VS index.
&I
QS index.
NI
NT index.
BOTP TOPP
POOL pointers for M allocation.
ARRAVAIL DAAVAIL
Pointers
to beginning of availability
chains for M allocation.
FREG
VS index of innermost active function mark. When a function is activated, the previous values of FREG and IORG are stacked in VS in the function mark, and restored on return.
IORG
Index origin for innermost
FBASE
Function origin in. M. Points to beginning of the segment containing the innermost active function, Upon exit from a function, FBASE is restored to point to the correct base from information in the stacked function mark.
NEWIT
Iteration tag. Set to 1 at the beginning of a new nest of iterations, NEWIT is and used by the index unit to keep indexing straight. stacked in LS and restored from there each time a new iteration nest is activated.
ISMK
IS index of the marked entry closest to the top of the iteration stack. Used by IU.
B.
active function.
Encodings The APL machine makes use of a few specific encoding functions.
These are
used for encodings which could be expected to fit within a single machine word. Although this bias is built into the design, it is inessential in the design, and could be changed if necessary.
- 140-
to the basic ideas used
-
1.
. This is the encoding of a segment descriptor.
SCODE org, len, m
m is 0 or 1 depending on whether this segment is for the D-machine org is the beginning address and len is the length of the segment. (decoding) functions are SORG, SLEN, and SMODE, respectively. a segment descriptor
is in QS, org is relative
The inverse functions are JLEN,
Generally,
their inverses.
be signed. 5.
respectively.
implementation
c is always a single
of the APL machine,
The inverse functions for XCODE are Xl,
QCODE a,b
executions.
descriptor.
It is conceivable that the functions SCODE, JCODE, and XCODE
might be identical in a particular
4.
to its QWndex.
JORG, JS.
a and b are an index and its limit,
bit quantity.
In the EM, if
e Encoding used for various purposes in the E-machine.
XCODE a, b, c
3.
The inverse
. This is the encoding for a J-vector
JCODE len, org, s
2.
or the E-machine.
X2, and X3, respectively.
. This encoding is used in constructing
Each field is potentially
as might
ICBls during EM
as large as the machine’s memory and might
The decoding functions are Ql and Q2.
MCODE mask
. This is the encoding function which takes a logical
vector which is an access mask for an array and encodes it for storage in the AUX field of QS. The inverse function is MXl. 6. on VS.
FCODE freg,
iorg,
The inverses are Fl,
name
. This is the encoding used in function marks
F2, F3.
- 141 -
C.
Tags This section summarizes
the tags which can be used in VS and NT entries.
Meaning
Tag
VS
UT
1
Undefined value,
ST
1
Scalar value.
JT
1
Such entries are moved to QS from VS almost J-vector, immediately.
DT
1
Descriptor array pointer. In VS means this is a result to be assigned to, while in NT, a.II array values have this tag,, As with JT, DT entries will be deferred to QS as soon as they are noticed.
FDT
1
Similar to DT, except the array is to be fetched. note applies.
FT
0
Function descriptor
SGT
1
Segment descriptor.
NPT
1
Name pointer.
FMT
1
Function mark.
RT
1
Unused (so far) reduction accumulator.
AT
1
Encoded M-address.
NT
pointer.
This is an NT index.
- 142 -
Same
APPENDIX A FUNCTIONAL The functional informal controlling
statements.
easily understood,
DE SCRIPTION OF THE E-MACHINE
description
dialect of APL.
of the E-machine
It differs
which follows is written
from “standard”
Instead of using branches,
constructions
are utilized,
1.
BEGIN o . o END delimits
2.
Likewise,
conditional IF
are as in ALGOL.
in an
APL only in its sequencemore sophisticated,
These are summarized
a compound statement,
statements and expressions
and more briefly
below:
as in ALGOL. of the form
condition THEN a . a ELSE 0 D . However,
in this description,
evaluates to 1 or 0, corresponding 3.
B
the condition part
to TRUE or FALSE in ALGOL.
The case construction, CASE n OF -BEGIN
^
Sl s2 .00 Sk END th chooses and executes the n- statement in the sequence.
This description
has omitted some BEGIN’s and END’s in compound statements within the CASE statement and substituted typographical not syntactically 4.
rigorous,
grouping.
it renders the description
The REPEAT statement repeats its range indefinitely. statement,
Although this is
more readable. Within a repeated
the CYCLE statement is used to resume the main (compound)
statement from the beginning,
and LEAVE aborts the innermost
- 143 -
REPEAT.
THE E-MACHINE
A
--
A FUNCTIONAL
DESCRIPTION
A MAIN CYCLE ROUTINE REPEAT --w--w BE!xN A THIS IS THE CONTROL ROUTINE IN FIGURE 2, HOWEVER, R ONLY THOSE PARTS RELATED TO THE E-MACHINE ARE SHOWN, LE -CASTOG THEN BEGIN -------v IE LSCLI-l;OllLScLI-1;21 THEN w-wBEGIN A TOP SEGMENT ON LS HAS O.VERFLOWRD --w-m LE LSCLI-l;41=1 THEN -v-M BEGIN CI ITERATION MAY RECYCLE LSCLI-l;O1+0 STEPIS NEWIT + 0 /g STEPTOG THEN -w-s CYCLE END e-m 19 DEACTIVATE TOP SEGMENT AND TRY AGAIN LPOP CYCLE END W-B
K f +/LscLT-1;0,11 ;TE -Qi'CK;O1di,iFA,IJ,ISC,IXL LSCLI-1;Ol + LscLI-1;01+1
THEI
END --CASTOG + 0
A IF ACTIVE SEGMENT IS FOR D-MACHINE THEN ACTIVATE ---LF LSCLI-1;31=0 THEN DMACHINE ELSE w--w A GOES TO LABELS BELOW CASE DECODE QSCK;O1 GE -vBEGLN 19 DELIMITS RANGE OF CA_SE_ STATEMENT w-v n
S) IA
IFA)
'LABELS'
BELOW NAME E-MACHIWE
INTERPRETATION
1 D + QSCK;ll
INX f GINX K QSCK;2,01 f &I, re r+s+o T 4 LE LSCLI-1;71=0 (oINX) REPEAT -----A +GETDEL S 4 StR+LF
D,I
QSCK;Ol=IA
TH_'g A &Sg
FA
THEE NT,NL-T FLSE QT,QLT A,-, IDA
= DELrI1
FOR THIS
T[Ol=NT THEN AxISCINXCIl;ll -v-e QPUSH TCI=-ltpINXl,(QCODE R,A),INXCII,O---I 4 I+1
END e-w QS[K;l1
4
QCODE (GETVBASE
l?),StGETABASE
ERASE D FA)
RULES
VPUSH ST,QSCK;ll
BEGIN -m-e-
A)
DM
IU K VPVSH LE QS[K;OI=A _THgg AT,QSCK;ll g,S ST,FETCH QSCK;ll
- 144 -
D
ARRAY ELSE
0
J)
IV1
K
UP)
EXECUTE
RED)
VPVSH RT,Q LSCLI-l;Q]
QS[K;l]
R QSLK;l]
ENCODES A SCALAR
UP
+ KtQSCK;23
DVP)
IF
K>VI
THEN ERROR E&SE w-w-
VPVSH
VXC)
LF
VI