home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
teach.zip
/
TEACH7A.ATF
< prev
next >
Wrap
Text File
|
1997-09-18
|
74KB
|
908 lines
XNÉIO 0 1 °
XNÉCT 0 1E²13 °
XCÉFC 1 6 .,*0_² °
XNÉRL 0 16807 °
XCÉPR 1 1 °
XCÉLX 1 5 TEACH °
XAC╜(1)(2)(Γ3 4)(5 6) °
*(1997 9 14 12 30 44 504) °
XFDISCLAIMER ÉFX 'DISCLAIMER' 'Σ Copyright statement' 'disclaimer' °
*(1996 4 6 16 3 9 216) °
FDISPLAY ÉFX 'D╜S DISPLAY A;ÉIO;R;C;HL;HC;HT;HB;VL;VB;V;W;N;B' °
'Σ DISPLAY A GENERAL ARRAY IN PICTORIAL FORM' °
'Σ NORMAL CALL IS MONADIC. DYADIC CALL USED ONLY IN' °
'Σ RECURSION TO SPECIFY DISPLAY RANK, SHAPE, AND DEPTH.' 'ÉIO╜0' °
'»(0=ÉNC ''S'')/''S╜µA''' 'R╜╞µ,S Σ PSEUDO RANK.' °
'C╜''┐┌└┘'' Σ UR, UL, LL, AND LR CORNERS.' °
'HL╜''─'' Σ HORIZONTAL LINE.' °
'HC╜HL,''Θ╕'',HL,''~+ε'' Σ HORIZONTAL BORDERS.' °
'HT╜HC[(0<R)⌡1+0<╞²1╞,S]' 'ΣW╜,0╧■╞0µΓ(1⌐µA)╞A' °
'HB╜HC[3+3╛(''2⌡~A╧«A'' ÉEA ''1+╞ε0⌡(1⌐⌡/µA)╞,A'')+3⌡1<µµS]' °
'VL╜''│'' Σ VERTICAL LINE.' °
'VB╜VL,''Φ╟'' Σ VERTICAL BORDER.' °
'V╜VB[(1<R)⌡1+0<²1╞²1╟,S]' °
'»(0εµA)/''A╜(1⌐µA)µΓ╞A'' Σ SHOW PROTOTYPE OF EMPTIES.' °
'╕(1<╧A)/GEN' '╕(2<µµA)/D3' °
'D╜«A Σ SIMPLE ARRAYS.' 'W╜1╞µD╜(²2╞1 1,µD)µD' °
'N╜²1+1╟µD' '╕(0=µµA)/SS' °
'D╜(C[1],V,((W-1)µVL),C[2]),((HT,NµHL),[0]D,[0]HB,NµHL),C[0],(WµVL),C[ °
3]' '╕0' 'SS:HB╜((0 '' '')=╞0µΓA)/'' -''' °
'D╜'' '',('' '',[0]D,[0]HB,Nµ'' ''),'' ''' '╕0' °
'GEN:D╜«DISPLAY■A Σ ENCLOSED ...' 'N╜Dδ.⌠'' ''' °
'D╜(Nδ~1ΦN)≡D' 'D╜(δ≡~'' ''╤D)/D' 'D╜((1,µS)µS)DISPLAY D' °
'╕(2≥µ,S)╟D3E,0' 'D3:D╜0 ²1╟0 1╟«ΓA Σ MULT-DIMENSIONAL ...' °
'W╜1╞µD' 'N╜²1+1╟µD' °
'D╜(C[1],V,((W-1)µVL),C[2]),((HT,NµHL),[0]D,[0]HB,NµHL),C[0],(WµVL),C[ °
3]' 'D3E:N╜²2+µ,S' °
X 'V╜C[Nµ1],[0]VB[1+0<²2╟,S],[0](((²3+╞µD),N)µVL),[0]C[Nµ2]' 'D╜V,D' °
*(1996 4 6 16 3 9 216) °
FEXIT ÉFX 'EXIT' 'Σ Exit from function' '''To log off type: )OFF''' °
X '╕' °
*(1996 4 6 16 3 9 216) °
FGO ÉFX 'GO;T;E;B' 'Σ Expression driver' 'L0:B╜E╜''''' 'æ╜'' ''' °
'T╜æ' '╕(^/'' ''=T)/L0' '╕((^/'')OFF ''=5╞6╟T)doif ''EXIT'')/0' °
'╕(('':''εT)doif ''B╜evaldd (+/^\'''' ''''=T)╟T'')/L0' °
'''E╜ÉEM'' ÉEA T' '╕(0=µ,E)/L0' '╕B/L0' °
'''This is not a valid APL2 expression''' 'æ╜''*''' °
X '╕(''?''⌠╞1╟æ)/L0' 'E' '╕L0' °
*(1997 8 15 11 56 12 476) °
FHELP ÉFX 'HELP;N;I;T' 'Σ Help to student' '''WHAT TO DO'',r' °
''' ° To get out of the lesson''' ''' ENTER: EXIT''' °
''' ° To log off APL2''' °
''' FIRST, ENTER: EXIT THEN ENTER: )OFF''' °
''' ° To get help''' ''' ENTER: HELP''' °
''' ° When you see the prompt on a blank line''' °
''' ENTER AN APL2 EXPRESSION - OR JUST PRESS: ENTER''' 'do' °
''' ° If you get this line'',r' °
'''This is not a valid APL2 expression'',r,''*'',r' °
''' YOU CAN EITHER''' ''' A. PRESS: ENTER''' °
''' B. PRESS: ? and then ENTER to see what was incorrect''' °
''' in your expression causing that response'',r' 'do' °
'''HINTS'',r' °
'''This lesson is made up of '',(«N╜7),'' components named TEACHx, whe °
re''' '''the x stands for a digit:'',r' 'I╜0' °
'L0:T╜''TEACH'',(«I╜I+1)' 'T,'' '',1╟notb(ÉCR T)[2;]' '╕(N>I)/L0' °
'do' °
'''You may review either of these components separately. To do that,'' °
' °
'''first enter EXIT (and RETURN), then enter the name of the lesson.'' °
' '''component (e.g. TEACH4).'',r' °
'''To re-start the lesson, just enter TEACH'',r' °
'''When the screen fills up, it is a good idea to move the cursor to'' °
' '''the start of a convenient paragraph, and press ENTER'',r' °
'''You may also wish to press PAGE UP to review the prevous pages.''' °
'do' '''RESOURCES'',r' °
'''You may also enter ONE of the following words at a time'',r' °
X '''REVIEW To review the contents of the previous lesson''' 'endd' °
XANULL╜0µ0 °
XCPHRASE 1 34 Once upon a time there was an elf. °
*(1997 5 29 12 6 2 284) °
FREVIEW ÉFX 'REVIEW' 'Σ Review of lesson 6' °
'''APL2 supports a variety of data structures. So far we have learned °
that''' °
'''elements of data can be organized in multi-dimensional box like arr °
ays.''' °
'''Such arrays can be described by specifying their dimensions. For''' °
'''example, a vector has only one dimension, namely a length. A table' °
'' °
'''can be described by the number of rows and columns. A list of table °
s''' '''is a table that is repeated in a third dimension.'',r' °
'''One can readily calculate the total number of scalar (rank 0 array) °
''' '''components in such tabular data with the expression "⌡/µ"'',r' °
'show ''A╜3 4 5µ∞6'' ''⌡/µA''' °
'''The number of axes of an APL2 data object is called its RANK. This' °
'' °
'''number of dimensions, however, must not be confused with another''' °
'''type of DIMENSION, namely that of data. For example a vector of len °
gth''' '''N may be thought of as a point in N dimensional space.''' °
'do' °
'''While a scalar has no dimensions (rank 0), a vector may have zero'' °
' °
'''length (null vector). The rank of a null vector is one because it'' °
' °
'''is a vector. In general, the rank of any APL2 object can be any''' °
'''positive integer or zero. (There is an upper limit to this number). °
''' °
'''The shape of any APL2 object is a vector whose components can be an °
y''' °
'''positive number or zero. (Here too there is a practical upper limit °
.)''' 'do' °
'''Reduction and scan of arrays is applied to the last axis. However, °
there''' °
'''are ways to modify reduction and scan. The symbols ≡ and ± force re °
duction''' °
'''and scan to apply to the FIRST axis. There is also a bracket notati °
on''' °
'''to force these two operators to be applied to intermediate axes.''' °
X 'endd' °
*(1997 5 31 11 59 20 572) °
FRULE ÉFX 'V RULE W' 'Σ Display rules' '╕(2=ÉNC ''V'')/L0' °
X '2 rule W ╪ ╕0' 'L0:V rule W' °
*(1997 7 4 11 46 51 544) °
FTEACH ÉFX 'TEACH' 'Σ Start seventh lesson in APL2 by Zdenek V JIZBA' °
'exit ''TEACH''' 'initialize' 'TEACH1 Σ Nested arrays and depth' °
'TEACH2 Σ APL2 syntax' 'TEACH3 Σ Rank and depth; the pick function' °
'TEACH4 Σ Using pick on nested arrays' °
'TEACH5 Σ The enclose with axis' 'TEACH6 Σ Rank tansformations' °
X 'TEACH7 Σ Partition' 'problems' °
*(1997 6 2 12 24 59 480) °
FTEACH1 ÉFX 'TEACH1' 'Σ Introduction to nesting' 'exit ''TEACH1''' °
'''In the previous lesson we studied about ARRAYS OF RANK 2. You will' °
'' °
'''recall that arrays of rank 2 are tables defined by rows and columns °
.'',r' °
'''In this lesson we will study yet another aspect of data, called DEP °
TH.''' °
'''before you proceed, you may wish to refresh your memory about array °
s''' '''by entering REVIEW.''' 'do' °
'''We have already hinted at the existence of depth several times. For °
''' °
'''example, when discussing reduction, we formed the following express °
ion'',r' 'show ''µ/8 5 3''' °
'''The result has to be a scalar because reduction reduces rank by one °
,''' '''and 8 5 3 is a vector.'',r' °
'show ''µµ/8 5 3'' ''µ(µµ/8 5 3)''' °
'''Yet when displayed, we see a numeric vector of length 8. There woul °
d appear''' °
'''to be a contradiction here. The object generated by µ/8 5 3 is inde °
ed a''' °
'''rank 0 object. We can use the DISPLAY function to see the structure °
of''' '''that result'',r' 'show ''DISPLAY µ/8 5 3''' °
'''The diagram shows two boxes. The outer box is that of a rank 0 arra °
y (no''' °
'''arrows), and the inner box is a vector. In APL2 terminology, the ve °
ctor''' °
'''has been ENCLOSED. As a result of this enclosure, the object has th °
e''' °
'''properties of a "scalar". Its shape is null, and its rank is zero.' °
',r' °
'''The process of placing a box around data is called NESTING, and the °
''' '''results are called NESTED ARRAYS.''' 'do' °
'''The number of boxes that one has to penetrate to reach a simple sca °
lar''' °
'''is a property of data called DEPTH. Indeed, APL2 supplies a special °
''' '''primitive monadic function called DEPTH. The symbol is ╧.''' °
'do' '''We can test the result of µ compression'',r' °
'show ''╧µ/8 5 3''' °
'''Since there are two boxes, depth is clearly 2. Some APL2 arrays may °
''' '''contain data at different depths'',r' °
'show ''DISPLAY (1 2) 3''' °
'''In the above example, (1 2) are at depth 2, while the 3 is at depth °
1''' '''We define depth with the following rule:'',r' '0 RULE 20' °
'''Given this rule, what would be the depth of a simple scalar?'',r' °
'show ''DISPLAY 2'' ''╧2'' ''DISPLAY ''''A'''''' ''╧''''A''''''' °
'''Since no box encloses a simple scalar, its depth is clearly ZERO.'' °
' '''Furthermore, we have'',r' 'show ''DISPLAY +/∞5'' ''╧+/∞5''' °
'''Which gives us the following rule'',r' '0 RULE 21' °
'''Before we discuss depth of APL2 objects any further, it will be use °
ful''' °
'''to introduce yet another primitive monadic APL2 function. The symbo °
l''' °
'''Γ when used monadically, is called ENCLOSE. It converts the right'' °
' '''argument to a rank 0 array, by increasing its depth by one'',r' °
'show ''DISPLAY 1 2'' ''DISPLAY Γ1 2'' ''DISPLAY ΓΓ1 2''' °
'''Note that a vector AUTOMATICALLY has a depth of ONE. Also, by rule °
21''' °
'''the enclose of a scalar should return that scalar unchanged.'',r' °
X 'show ''DISPLAY 2'' ''DISPLAY Γ2'' ''DISPLAY ΓΓΓΓΓ2''' 'endd' °
*(1997 5 25 12 42 17 472) °
FTEACH2 ÉFX 'TEACH2;A;B;q' 'Σ Strand notation' 'exit ''TEACH2''' °
'''Before we proceed any futher, we must pause, and digress about APL2 °
''' °
'''SYNTAX. When we first introduced numeric vectors, we merely entered °
''' °
'''a sequence of numbers separated by blanks. The number of blanks in' °
'' '''fact seems immaterial'',r' 'show ''2 4 6 7''' °
'''Then on another occasion (lesson 4), we introduced an APL2 primitiv °
e''' '''function called CATENATE'',r' 'show ''2,4,6, 7''' °
'''As you can see the effect on simple numeric scalars is the same whe °
ther''' °
'''we use a blamk or a comma, or both. The comma is indeed a primitive °
''' °
'''APL2 function, but the blank is not. It is part of APL2 SYNTAX.''' °
'do' °
'''The usage of blanks to separate data is a special technique, called °
''' °
'''STRAND notation. This notation can be used with characters as well °
as''' '''with blanks. Here is an example'',r' °
'show ''DISPLAY ''''A'''' ''''B'''' ''''C'''''' ''DISPLAY ''''ABC''''' °
'' °
'''The vector ''''ABC'''' was defined using strand notation, as well a °
s in the''' °
'''regular way. When we deal with simple scalars, strand notation can °
be''' '''thought as equivalent to catenation'',r' °
'show ''DISPLAY ''''A'''',''''B'''',''''C'''''' ''DISPLAY 1 2 3'' ''DI °
SPLAY 1,2,3''' °
'''When we begin to consider nested arrays, we see a clear distinction °
X''' '''between strand notation and catenation.''' 'endd' °
*(1997 6 2 12 29 8 296) °
FTEACH3 ÉFX 'TEACH3;A;B' 'Σ Rank and depth' 'exit ''TEACH3''' °
''' RANK AND DEPTH'',r' °
'''Using strand notation we can create objects of arbitrary depth in'' °
' '''a simple way'',r' °
'show ''(1 2) (3 4)'' ''DISPLAY (1 2)(3 4)'' ''╧(1 2)(3 4)''' °
'''In the above example we used parentheses to generate a vector whose °
''' °
'''components are vectors. The resulting object is called a NESTED''' °
'''vector. We can also create nested vectors of characters'',r' °
'show ''''''Nested'''' ''''vector'''''' ''DISPLAY ''''Nested'''' ''''v °
ector''''''' °
'''Nested vector can be a mix of characters and numbers'',r' °
'show ''DISPLAY ''''AGE'''' 24''' °
'''In this last example, one might ask why do we get a nested vector'' °
' °
'''instead of a simple vector containing the salars ''''A'''',''''G''' °
',''''E'''',and''' °
'''24? (It is nested because ''''AGE'''' IS already a vector.) To get °
a''' °
'''depth 1 vector, we would have to catenate the two elements'',r' °
'show ''DISPLAY ''''AGE'''',24''' °
'''Another way to generate a mixed vector without nesting would be'',r °
' 'show ''DISPLAY ''''A'''' ''''G'''' ''''E'''' 24''' °
'''The mere fact that a character STRING is placed in quotes defines i °
t''' °
'''to be a vector. This is why parentheses are not required to identif °
y''' '''character strings as components of nested vectors.''' 'do' °
'''We have shown that a simple vector has a depth of one. What precise °
ly''' '''do we mean by the expression "simple vector"?'',r' °
'show ''DISPLAY ∞4'' ''DISPLAY (1 2) 3 4''' °
'''The first example is a simple vector, because all of its components °
''' °
'''are simple scalars. Since we must make a distinction between depth' °
'' '''and rank, the question of depth of a vector is not trivial.''' °
'do' °
'''Recall that to access an element of a vector, we have to use an''' °
'''expression that permits INDEXING of its components. Operationally'' °
' '''therefore we can propose the following rule'',r' °
''' RULE 22. Depth can also be defined as the number of simple steps °
''' °
''' to reach the innermost simple scalar in an array.'',r' °
'''This rule is vague so let us see if we can improve on it.''' 'do' °
'''Since we can access a simple scalar in a simple array using bracket °
''' '''indexing, simple arrays should also have depth of one'',r' °
'show ''DISPLAY 2 2µ''''ABCD'''''' ''DISPLAY 2 3µ∞6''' °
'''One would think that to reach a simple scalar in a nested array, al °
l''' '''we need is to apply indexing twice'',r' °
'show ''A╜(1 2) (3 4 5)'' ''DISPLAY A'' ''DISPLAY A[1]''' °
'''But as we can see this does not work! The expression A[1] returns a °
''' °
'''rank 0 array, as it SHOULD. The result still has the same depth as °
the''' °
'''nested array. We need a way to reach the inner contents of a "non-z °
ero''' '''depth rank zero array".''' 'do' °
'''We could try the indexing function (squad), but it too poduces a ra °
nk''' '''zero array'',r' 'show ''DISPLAY 1╙A''' °
''' THE PICK FUNCTION'',r' °
'''We define an APL function called PICK. It is a dyadic function usin °
g''' °
'''the symbol π. It is SOMEWHAT similar to squad but it differs in tha °
t''' °
'''it extracts the contents of nested arrays. Let us see how pick work °
s''' '''in a simple case'',r' 'show ''DISPLAY 1πA'' ''DISPLAY 2πA''' °
'''So far so good, but let us now add some more depth to A'',r' °
'show ''B╜A'' ''B[1]╜ΓA'' ''DISPLAY B''' °
'''Since B[1] is a rank 0 array, and A is a vector, we had to enclose °
A,''' °
'''before we could assign it to B[1]. The vector B has depth 3. To acc °
ess''' °
'''the first element of B and obtain the contents of whatever this sca °
lar''' '''encloses, we use pick'',r' 'show ''DISPLAY 1πB'' ''µ1πB''' °
'''To reach the second element of 1πB we merely write'',r' °
'show ''DISPLAY 1 2πB''' °
'''and to reach the third component of that vector'',r' °
'show ''1 2 3πB''' °
'''The left argument vector has a special name. It is called the ACCES °
XS''' '''VECTOR. Now we can rephrase rule 22'',r' '0 RULE 22' 'endd' °
*(1997 6 2 12 30 19 344) °
FTEACH4 ÉFX 'TEACH4;A;B' 'Σ More on depth' 'exit ''TEACH4''' °
''' USING PICK ON NESTED ARRAYS'',r' 'A╜(1 2)(3 4)' °
'B╜((1 2)(3 4))(3 4)' °
'''Rule 22 may still have a flaw. Recall that there is a way to use th °
e''' '''indexing function on a scalar'',r' 'show ''(∞0)╙5''' °
'''In a similar way it is possible to pick from a scalar'',r' °
'show ''(∞0)π5''' °
'''Therefore we could generate an arbitrarily long access vector by''' °
'''catenating NULL vectors as rank 0 arrays'',r' °
'show ''DISPLAY B'' ''NULL╜∞0'' ''(1 2 2,NULL,NULL,NULL)πB''' °
'''However since the null vector has no components, it has no effect'' °
' '''on the length of the access vector.'',r' °
'show ''DISPLAY 1 2 2,NULL,NULL,NULL''' °
'''So why do we bother with all this trivia?''' °
'''Because the NULL vector DOES HAVE a function in the access vector!' °
'' 'do' °
'''Let us explore this seeming paradox. First we generate C'',r' °
'show ''C╜1 2,(Γ3 4) (5 6)'' ''DISPLAY C''' °
'''The third element of C is a RANK 0 ARRAY containing the vector 3 4. °
When''' '''we pick this element'',r' 'show ''DISPLAY 3πC''' °
'''we get the rank 0 array. Now the question is how do we reach the co °
mponents''' °
'''of the enclosed vector? The answer, of course is to pick that array °
with''' '''a NULL vector'',r' °
'show ''DISPLAY (3,Γ∞0)πC'' ''(3,(Γ∞0),1)πC''' °
'''The NULL in the acces vector serves the role of a can opener for wh °
atever''' '''is inside the rank 0 array.''' 'do' °
'''We can summarize these features in the following rule'',r' °
'0 RULE 23' °
'''So far we have been using pick to access elements of nested vectors °
.''' °
'''How will pick work with nested arrays of rank greater than 1? Let u °
s form''' '''a depth 2 nested array'',r' °
'show ''A╜2 2µ(1 2) (3 4) 5 6'' ''DISPLAY A''' °
'''This array has depth 2 since the first row components are nested'', °
r' 'show ''DISPLAY A[1;2]''' °
'''Clearly indexing extracts the component, but retains depth.'',r' °
'''We can also try the index function. (The length of the left argumen °
t''' '''must be equal to the rank of the array)'',r' °
'show ''DISPLAY 1 2╙A'' ''2 1╙A''' °
'''Here too, depth is retained on nested elements of the array (to kee °
p''' '''them as rank 0 arrays).''' 'do' '''What about using PICK?''' °
'''If we were to use pick in the same way as INDEX (1 2πA), it would f °
ail,''' °
'''because the first element of the access vector (1) is NOT a valid'' °
' '''argument for accessing an element of A (a rank 2 array).''' °
'''To reach the second element in the first row, we would have to use °
1 2,''' '''but as a rank 0 array.'',r' °
'''By rule 23 we can reach row 1 column 2 of A by'',r' °
'show ''DISPLAY (Γ1 2)πA''' °
'''To reach the second element of the vector in row 1 column 2, we hav °
Xe''' 'show ''(1 2) 2πA''' 'endd' °
*(1997 8 28 13 7 13 344) °
FTEACH5 ÉFX 'TEACH5;A;B' 'Σ Enclose with axis' 'exit ''TEACH5''' °
''' THE ENCLOSE WITH AXIS'',r' °
'''Monadic enclose need not always produce a rank 0 array. What enclos °
e''' '''does is to increase depth. Consider the following array'',r' °
'show ''A╜2 2µ∞4'' ''DISPLAY A'' ''DISPLAY ΓA''' °
'''By simply enclosing A, we convert it to a rank 0 array. This is bec °
ause we''' °
'''treat A as a single object. However, suppose that we think of A not °
as''' °
'''an array, but as a list of two vectors. The first row A[1;] is the °
first''' °
'''vector, and the second row A[2;] is the second vector. Can we conve °
rt''' '''the array A into a nested list of vectors?'',r' °
'show ''DISPLAY (1 2) (3 4)''' °
'''Basically, what we want to do is to enclose the rows of A. This can °
''' '''indeed be done'',r' 'show ''DISPLAY Γ[2]A''' °
'''The enclose together with axis specification allows us to form''' °
'''equivalent data structures. If we think of array A as a collection' °
'' '''of column vectors, we can also enclose columns'',r' °
'show ''DISPLAY Γ[1]A''' °
'''Let us see how this concept can be generalized. First we form an ar °
ray''' '''of rank 3'',r' 'show ''B╜2 3 4µ∞24'' ''DISPLAY B''' °
'''We could think of B as a single unit, as a vector of arrays, or as °
an''' °
'''array of vectors. Each of these data structures is distinctive, but °
''' '''equivalent to B'',r' 'show ''DISPLAY Γ[3]B''' °
'''In this form we see that we can convert B into an array of rank 2 w °
ith''' °
'''vector components of length 4. If we think of the first two axes as °
''' '''defining arrays'',r' 'show ''DISPLAY Γ[1 2]B''' °
'''we generate a vector whose components are arrays. By selecting othe °
r''' '''axes, we can convert B into other data structures'',r' °
'show ''DISPLAY Γ[2 3]B''' °
'''When two or more axes are specified, these need not be in increasin °
g''' '''sequence'',r' 'show ''DISPLAY Γ[3 2]B''' °
'''The arrays in this last example are the TRANSPOSE of the arrays in' °
'' °
'''the previous examples. As a matter of fact, APL2 has a special''' °
'''transpose primitive function, φ'',r' °
'show ''DISPLAY φA'' ''DISPLAY Γ[2 1]A''' °
'''We will study this function in more detail in a later lesson.''' °
X 'endd' °
*(1997 8 28 13 10 25 404) °
FTEACH6 ÉFX 'TEACH6;A;B' 'Σ Disclose of nested arrays' °
'exit ''TEACH6''' ''' RANK TRANSFORMATIONS'',r' °
'''We used the phrase "equivalent data structures". What do we mean''' °
'''by that? Such structures are equivalent, because we can readily''' °
'''transform one into the other. What can be enclosed, can also be''' °
'''disclosed. The monadic disclose gives us that facility'',r' °
'show ''DISPLAY π(1 2) (3 4)''' °
'''Using the disclose, we transformed a depth 2 nested vector (rank 1 °
array)''' °
'''to a depth 1 rank 2 array. In this example there is no loss of info °
rmation,''' '''and the two forms are duals.''' 'do' °
'''The disclose can also be applied with an axis specification. When s °
o used,''' °
'''the axis in brackets specifies the placement in the resulting array °
.''' °
'''Default is the last axis, namely, a vector is transformed into an a °
rray''' °
'''of vectors. Specifying the first axis would transform into an array °
of''' °
'''vector components (which is equivalent to the TRANSPOSE of the arra °
y).'',r' 'show ''DISPLAY π[2](1 2) (3 4)''' °
'show ''DISPLAY π[1](1 2) (3 4)''' °
'''Disclosure of a scalar merely reveals the contents of that scalar'' °
,r' 'show ''DISPLAY π5'' ''DISPLAY Γ∞5'' ''DISPLAY πΓ∞5''' °
'''we have the following rules'',r' '0 RULE 24' '0 RULE 25' °
'''The meaning of the last sentence in rule 25 is illustrated in the'' °
' '''following examples'',r' °
'show ''DISPLAY π(1 2 3) (4 5) 6'' ''DISPLAY π''''ONE'''' ''''PHRASE'' °
''''' °
'''We will study FILL elements in more detail later, but for now, the' °
'' °
'''fill element for a numeric scalar is 0 and for a character scalar i °
s''' '''the blank character.''' 'do' °
'''When we talk of equivalent forms, we talk of homogeneous forms. By' °
'' °
'''homogeneous, we mean forms containing as many rank 0 arrays as ther °
e''' '''are in the equivalent form of depth 1.'',r' °
'''Can the disclose with axes be applied to more general arrays? Yes,' °
'' '''and no. The axis specification must be valid'',r' °
'show ''DISPLAY A╜(2 3µ∞6) (2 3µ''''ONETWO'''')''' °
'''We can treat this as a vector with two arrays, as two arrays in a'' °
' °
'''vector, or as three four element vectors in an array repeated twice °
or''' °
'''in many other ways. Here are some examples of valid transformations °
'',r' 'show ''DISPLAY πA'' ''DISPLAY π[1 2]A'' ''DISPLAY π[2 3]A''' °
'''Consider now the following nested array'',r' °
'show ''DISPLAY B╜(2 2µ∞4) (5 6)''' °
'''The components of this array have different ranks. Therefore neithe °
r''' °
'''π[1] nor π[1 2] will work as you will find out if you try. The''' °
'''expression π[1]B will not work because the first component of B''' °
'''is an array, and requires an axis specification of the form [1 2]'' °
' °
'''or [2 1]. The expression π[1 2] will also not work, because the''' °
'''second component of B is a vector. It requires an axis specificatio °
n''' '''of the form π[1].''' 'do' °
'''We have therefore the following rules'',r' '0 RULE 26' '0 RULE 27' °
'''By rule 26, rank 0 arrays are allowed. Here are some examples'',r' °
'show ''B[2]╜5'' ''DISPLAY πB'' ''B[2]╜ΓΓ(5 6)'' ''DISPLAY B'' ''DISPL °
AY πB''' °
'''How about ππB? Would this be a valid transformation, and if so what °
X''' '''would be its shape?''' 'endd' °
*(1997 6 2 12 34 53 496) °
FTEACH7 ÉFX 'TEACH7' 'Σ Dyadic enclose or partition' 'exit ''TEACH7''' °
''' PARTITION'',r' °
'''We have studied the monadic disclose with and without axis specific °
ation''' °
'''and the monadic enclose with and without axis specification. We als °
o''' °
'''studied the dyadic form of the disclose. It was called pick. What'' °
' °
'''about a dyadic enclose. There is such a primitive function, and it' °
'' °
'''is called PARTITION. Let us see what it looks like, and how it work °
s.''' 'do' °
'''Suppose we have a character vector that has been entered at the''' °
'''terminal'',r' °
'show ''PHRASE╜''''Once upon a time there was an elf.''''''' °
'''If we are to process text, it might be useful to break up a string' °
'' °
'''into its component words. In APL2 this can readily be done with the °
''' '''partition function'',r' °
'show ''DISPLAY (PHRASE⌠'''' '''')ΓPHRASE''' °
'''Before we investigate precisely how this works, notice that the las °
t''' °
'''period is included in the word ''''elf.''''. Let us remove this per °
iod.'',r' 'show ''DISPLAY (~PHRASEε'''' .'''')ΓPHRASE''' °
'''And since we do not want to lose any punctuation, we should also''' °
'''enter'',r' 'show ''DISPLAY (PHRASEε'''' .'''')ΓPHRASE''' °
'''These two expressions produce nested arrays that are equivalent to °
the''' °
'''original phrase. (We will see how to reconstruct the original phras °
e''' '''from these two nested vectors in the next lesson.)''' 'do' °
'''Right now, let us see how partition works. The expression'',r' °
'show ''PHRASE⌠'''' ''''''' °
'''returns a vector. The fact that this vector is boolean is irrelevan °
t'',r' 'show ''DISPLAY (5⌡PHRASE⌠'''' '''')ΓPHRASE''' °
'''What does matter is the presence of zeros, AND the position in the' °
'' °
'''vector where the value increases. Let us call the left argument the °
''' '''partition vector. We have the following rules'',r' '0 RULE 28' °
'0 RULE 29' °
'''Let us see how this works. For illustration, we will use numeric''' °
'''vectors'',r' 'show ''DISPLAY (∞6)Γ∞6''' °
'''since the partition vector increases at every step, the result is'' °
' '''a partition into six component vectors.''' 'do' °
'''In the next example, the partition vector never increases''' °
'show ''DISPLAY (6µ5)Γ∞6'' ''DISPLAY 1Γ∞6''' °
'''Since a scalar is always replicated to match the shape of the other °
''' '''argument, it too generates no partition.''' 'do' °
'''Now let us see how we can partition the vector in other ways'',r' °
'show ''2|∞6'' ''DISPLAY (2|∞6)Γ∞6'' ''1+2|∞6'' ''DISPLAY (1+2|∞6)Γ∞6' °
'' °
'''In the first example the even numbers have been removed because''' °
'''their residue (modulo 2) is zero. In the second example, the''' °
'''partition is the same, but the even numbers are included because''' °
X '''the partition vector does not contain any zeros.''' 'endd' °
*(1997 7 13 12 28 49 504) °
Faddquote ÉFX 'u╜addquote w' °
'Σ Put quotes around a string, and double existing quotes' °
X 'u╜ÉAV[40],((1+w=ÉAV[40])/w),ÉAV[40]' °
*(1997 7 24 13 20 38 476) °
Fav ÉFX 'av;A;N;I;ÉIO' 'Σ Display characters in ÉAV' 'ÉIO╜0' °
'A╜22 78µ'' ''' 'N╜3 0«φ12 22µ1+∞356' 'A[;,(6⌡∞12)°.+2 3 4]╜N' °
'A[;6+6⌡∞12]╜φ12 22µÉAV' 'ΣA[8 10 13;6]╜'' ''' 'A[13;6]╜'' ''' °
X 'A[14+∞8;68 69 70 72]╜'' ''' 'A' °
*(1991 11 11 8 25 13 316) °
Fdate ÉFX 'u╜date w' 'Σ Format date and time of day' 'u╜«6╞w' °
X 'u╜('' ''⌠u)Γu' 'u╜εu,■''-- .. ''' °
XCdig 1 10 1234567890 °
*(1997 9 9 13 0 45 372) °
Fdisclaimer ÉFX 'disclaimer' 'Σ Copyright statement' °
'(10µ'' ''),''Copyright, Z. V. Jizba, 1995,1996,1997'',r' °
''' This and subsequent workspaces labelled TEACHxx are made available °
''' °
'''at no cost to anyone who desires to learn how to use effectively''' °
'''the IBM/OS2 version of APL2.'',r' °
'''This software is provided "AS IS" with no WARRANTY of any kind, eit °
her''' °
'''express or implied. Any risk in its use resides with you, the user °
of''' '''these tutorials.'',r' ''' ACKNOWLEDGEMENTS'',r' °
''' In writing these tutorials, I am greatly indebted to Roy Sykes, wh °
ose''' °
'''excellent lectures increased my understanding of the language.''' °
'''Discussions with the late Harry Bertucelli clarified a number of''' °
'''concepts and caused me to change some improper terminology that was °
''' °
'''used in previous versions of these tutorials. Mr. Benjamin Archer'' °
' °
'''kindly checked out a nearly final version, bringing to my attention °
''' '''some ommisions, misspellings, and invalid terminology.'',r' °
X '''(PRESS ENTER to continue)''' °
*(1997 7 13 12 28 50 508) °
Fdo ÉFX 'do;T;E' 'Σ Expression driver' 'E╜''''' 'æ╜'' ''' 'T╜æ' °
'╕(^/'' ''=T)/0' °
'╕(('':''εT)doif ''B╜evaldd (+/^\'''' ''''=T)╟T'')/2' °
'''E╜ÉEM'' ÉEA T' '╕(0=µ,E)/2' °
'''This is not a valid APL2 expression''' 'æ╜''*''' '╕(''?''⌠╞1╟æ)/2' °
X 'E' '╕2' °
*(1997 7 13 12 28 50 508) °
Fdoif ÉFX 'U╢╜V╢ doif W╢;t╢' 'Σ Rule' '╕(^/~U╢╜V╢)/0' °
X '''U╢╜V╢ doif■ W╢'' ÉEA ''»V╢/W╢''' °
*(1997 9 9 12 50 14 444) °
Fendd ÉFX 'endd' 'Σ end of special feature' '20µ''²'' ╪ ╕(4<µÉLC)/0' °
X 'do' °
*(1997 8 15 11 54 26 524) °
Ferase ÉFX 'erase;t;EXIT;GO;HELP;DISPLAY;REVIEW;RULE;DISCLAIMER' °
'Σ Erase all global functions and variables' 't╜ÉNL 3' °
't╜(~t^.εlc,'' '')≡t' 't╜ÉEX(~t[;∞5]^.=''TEACH'')≡t' 't╜ÉNL 2' °
X 't╜ÉEX(~t^.εlc,'' '')≡t' °
*(1997 7 27 13 47 41 608) °
Fevaldd ÉFX 'u╜evaldd w;c;n' 'Σ Evaluate direct definition' 'u╜0' °
'n╜(w∞''Σ'')-1' 'c╜(((n╞w)⌠'':'')Γn╞w),Γ''ΣDD '',(n+1)╟w' °
'╕((1 label╞c)doif ''''''Invalid label'''''')/0' °
'╕((2=µc)doif ''u╜showdd 1╙c'')/0' °
'╕((3=ÉNC╞c)doif ''u╜⌡µÉ╜(╞c),'''' is already defined.'''''')/0' °
'╕((3=µc)doif ''u╜simdd c'')/0' 'c╜(Γ''α∙ aw'')replace■c' °
'u╜ε''u╜'',((''a''εεc[2 3 4])/''a ''),(╞c),'' w;t;b''' °
'u╜u(5πc)(''b╜(t╜'',(3πc),'')/'',addquote ''u╜'',4πc)' °
X 'u╜u,''╕(t doif b)/0''(''u╜'',2πc)' 'u╜╧ÉFX u' °
*(1997 7 25 13 27 52 564) °
Fexit ÉFX 'V exit W;T' 'Σ Exit if too many suspended functions' °
'╕(0⌠ÉNC ''V'')/L0 ╪ V╜10' 'L0:╕(V>µÉLC)/0' °
'''There are too many suspended functions''' '''Please enter '',W' °
X '╕' °
*(1997 7 26 12 33 39 536) °
Fget ÉFX 'U╜V get W;t;T;ÉPR' 'Σ Prompt for response from keyboard' °
'ÉPR╜T╜ÉAV[ÉIO+255] ╪ ╕(0⌠ÉNC ''V'')/L0 ╪ V╜1' 'L0:V╜V╧1' 'æ╜W ╪ t╜æ' °
'U╜(+/^\t=T)╟t' '╕(''╕''⌠╞U)/L1 ╪ ╕' 'L1:╕V/0' 't╜(U⌠'' '')ΓU' °
X 'U╜(µt),(ΓU),t' °
*(1997 7 28 13 33 8 424) °
Fglobals ÉFX 'globals' 'Σ Initialize useful global variables' °
'uc╜''ABCDEFGHIJKLMNOPQRSTUVWXYZ''' °
'lc╜''abcdefghijklmnopqrstuvwxyz''' 'dig╜''1234567890''' °
X 'r╜ÉAV[13+ÉIO]' 'q╜''''''''' °
*(1997 7 3 12 47 6 368) °
Finitialize ÉFX 'initialize;T' 'Σ Initialize workspace' °
'''AT ALL TIMES, TO CONTINUE, PRESS RETURN!'',r' °
'''To see disclaimers enter:'',r,'' disclaimer''' 'do' 'erase' °
'globals' °
'''Make sure the CAP LOCK light on your keyboard (upper right) is ON!' °
X'' 'endd' °
*(1997 7 27 13 14 33 444) °
Flabel ÉFX 'u╜v label w' °
'Σ Return 1 if label w does not begin with a cap' °
'╕(0⌠ÉNC ''v'')/L0 ╪ v╜0' 'L0:v╜v╧1 ╪ w╜εw ╪ ╕v/L1 ╪ ╕(u╜0⌠ÉNC w)/0' °
X 'L1:╕(u╜~^/wεlc,uc,dig)/0' 'u╜w[1]εlc,dig' °
XClc 1 26 abcdefghijklmnopqrstuvwxyz °
*(1997 7 13 12 28 55 528) °
Fnon ÉFX 'non;T;RC;ET;R' 'Σ Ignore keyboard entry' 'æ╜'' ''' 'T╜æ' °
'╕(0=µ(T⌠'' '')/T)/0' '(RC ET R)╜ÉEC T' '╕(0=RC)/2' °
X '╕((1=RC)doif ''R'')/2' '╕2' °
*(1997 7 13 12 28 55 528) °
Fnotb ÉFX 'u╜notb w' 'Σ Remove trailing blanks' °
'╕((1<╧w)doif ''u╜notb■ w'')/0' '╕((1<µµw)doif ''u╜πnotb Γ[2]w'')/0' °
X 'u╜(1-(,'' ''⌠Φw)∞1)╟w' °
*(1997 7 27 12 55 6 496) °
Fproblems ÉFX 'problems' 'Σ Problems' °
'''That is all for this lesson. Remember, if you want to practice,''' °
'''and plan to use direct definitions, be sure to first enter GO.''' °
'''Direct definitions will then be accepted. To exit GO, enter EXIT.'' °
,r' °
'''To erase a previously defined DIRECT DEFINITION FUNCTION, enter'',r °
' ''' )ERASE functionname'',r' °
X '''WARNING! do not use )ERASE on other labels.'',r' °
XCq 0 ' °
XCr 0 °
*(1997 7 13 12 28 56 532) °
Freplace ÉFX 'u╜v replace u;i;r;s' 'Σ Replace elements in v in u' °
'i╜Γ∞µu' 's╜2πv╜(v⌠'' '')Γv' 'i╜⌡r╜i⌡■Γ[1]u°.=╞v' °
X 'u[(εi)/εr]╜s[(εi)/εi⌡■∞µs]' °
*(1997 7 13 12 28 56 532) °
Fround ÉFX 'U╜V round W' 'Σ Half adjust to V th decimal' °
X 'U╜(╛0.5+W⌡10*V)÷10*V' °
*(1997 6 2 12 45 31 452) °
Frule ÉFX 'V rule W' 'Σ Additional remarks on rules' °
'╕(2=ÉNC ''V'')/L ╪ V╜0' 'L:╕(~(╞W)ε∞8)/LA ╪ V rulea╞W ╪ ╕L0' °
'LA:╕(~(╞W)ε9 10 11)/LB ╪ V ruleb╞W ╪ ╕L0' °
'LB:╕(~(╞W)ε11+∞8)/LC ╪ V rulec╞W ╪ ╕L0' °
'LC:╕((╞W)=19+∞10)/L20,L21,L22,L23,L24,L25,L26,L27,L28,L29' °
'''This rule number is undefined'' ╪ ╕' 'L20:╕(V>1)/L20X' °
''' RULE 20. The depth of an APL array is defined as the maximum''' °
''' depth to reach a simple scalar.'',2µr' '╕(0=V)/L0' °
'L20X:''The concept of depth provides the means of building complex da °
ta''' °
'''structures. This is the first of several rules dealing with depth.' °
'' '╕L0' 'L21:╕(V>1)/L21X' °
''' RULE 21. No APL2 expression can generate a depth 1 object contai °
ning''' °
''' ONLY a scalar. (Or, a scalar can not have depth 1.)'',2 °
µr' '╕(0=V)/L0' °
'L21X:''This rule can be treated as an axiom of APL2. In theory it is' °
'' °
'''possible to enclose a scalar, but that would lead to a significantl °
y''' °
'''different language. EXAMPLE: The reduction of a vector must return' °
'' °
'''a scalar. Doing repeated reduction could produce enclosed scalars'' °
' °
'''that would require removal of such depths before allowing compariso °
ns.''' '╕L0' 'L22:╕(V>1)/L22X' °
''' RULE 22. The depth of an array is given by the maximum length of °
''' °
''' the access vector associated with that array.'',2µr' °
'╕(0=V)/L0' °
'L22X:''When you use function DISPLAY, depth can be obtained by counti °
ng''' °
'''the number of boxes you must cross from outside to reach the innerm °
ost''' '''scalar.''' '╕L0' 'L23:╕(V>1)/L23X' °
''' RULE 23. Null elements of an access vector must be included to'' °
' ''' match corresponding rank zero arrays.'',2µr' °
'╕(0=V)/L0' °
'L23X:''The access vector works from left to right. The leftmost eleme °
nt''' °
'''removes the outermost box, and the rightmost element removes the''' °
'''innermost box.''' '╕L0' 'L24:╕(V>1)/L24X' °
''' RULE 24. The monadic disclose of a rank 0 array reveals the cont °
ents''' ''' of that array.'',2µr' '╕(0=V)/L0' °
'L24X:''This is a consequence of rule 21. A simple scalar is immune to °
''' '''to the process of enclosure or disclosure.''' '╕L0' °
'L25:╕(V>1)/L25X' °
''' RULE 25. The monadic disclose (without axis specification) reduc °
es''' °
''' depth by one, by adding a new last axis to the disclose °
d''' °
''' elements. FILL elements are used to complete the array. °
'',2µr' '╕(0=V)/L0' °
'L25X:''The fill element for numberic arrays is zero. The fill element °
for''' °
'''character arrays is a blank. The fill element for mixed arrays in'' °
' '''APL2 will be discussed in later sessions.''' '╕L0' °
'L26:╕(V>1)/L26X' °
''' RULE 26. Simple disclose requires that all components of a neste °
d''' °
''' array have the same rank (or be rank 0 arrays).'',2µr' °
'╕(0=V)/L0' °
'L26X:''We use the phrase ''''simple disclose'''' because, as we will °
learn''' °
'''later, you can define your own rules on how to disclose nested''' °
'''arrays.''' '╕L0' 'L27:╕(V>1)/L27X' °
''' RULE 27. Forms can be equivalent only if all rank 0 arrays conta °
in''' °
''' the same rank and shape (or rank 0 arrays)--recursively °
--'',2µr' '╕(0=V)/L0' °
'L27X:''Earlier we discussed functions that are dual. These are one to °
''' °
'''one transformations of data. Equivalent forms can be thought of as' °
'' '''a kind of dual representation of data structures.''' '╕L0' °
'L28:╕(V>1)/L28X' °
''' RULE 28. A zero in a partition vector will remove the associated °
''' ''' element.'',2µr' '╕(0=V)/L0' °
'L28X:''The components of a partition vector must be positive integers °
or''' °
'''zero. The presence of a zero is treated much the same as in boolean °
''' '''reduction.''' '╕L0' 'L29:╕(V>1)/L29X' °
''' RULE 29. Each place in the partition vector, where the value''' °
''' INCREASES marks a partition.'',2µr' '╕(0=V)/L0' °
'L29X:''A partition must ocurr BETWEEN two consecutive elements. These °
''' '''need not be simple scalars'',r' °
'show ''DISPLAY (1 1 2 2)Γ(1 2) ''''AB'''' (3 4) ''''C''''''' 'L0:do' °
X '╕(0=µW╜1╟W)/0' '╕L' °
*(1997 6 1 12 42 53 524) °
Frulea ÉFX 'V rulea W' 'Σ Additional remarks on rules' °
'╕(2=ÉNC ''V'')/L ╪ V╜0' 'L:╕(W=∞8)/L1,L2,L3,L4,L5,L6,L7,L8' °
'''For rules not described in this lesson, see workspace INDEX''' °
'╕0' 'L1:╕(V>1)/L1X' °
'''RULE 1. For arithmetic operations a vector must be matched with a'' °
' ''' scalar, or another vector of the same length.'',2µr' °
'╕(0=V)/0' °
'L1X:''This is the first of many rules dealing with the concept of''' °
'''CONFORMABILITY. This means that elements to be processed by APL2''' °
'''must in some ways match.''' '╕0' 'L2:╕(V>1)/L1X' °
'''RULE 2. The reduction operator places the function, (specified to'' °
' °
''' its left), between all pairs of the vector. It then evaluat °
es''' ''' the resulting expression.'',2µr' '╕(0=V)/0' °
'L2X:''There is more to this, but at this stage the rule is essentiall °
y''' '''correct.''' '╕0' 'L3:╕(V>1)/L1X' °
'''RULE 3. All APL2 expressions are evaluated from right to left'',2µr °
' '╕(0=V)/0' °
'L3X:''This rule is valid in APL, which is the earlier version of APL2 °
.''' °
'''For APL2, the rule has been restated in a totally different way.''' °
'''However until we introduce some concepts that are new to APL2, the' °
'' '''newer form reduces to RULE 3 as stated.''' '╕0' 'L4:╕(V>1)/L1X' °
'''RULE 4. Vectors in APL2 can have lengths of zero and one.'',2µr' °
'╕(0=V)/0' °
'L4X:''This is the first concept that begins to introduce the idea tha °
t no''' °
'''matter what the APL expression, if it is valid, it must produce a'' °
' °
'''valid APL2 object. (Shades of which came first, the chicken or the °
egg)''' '╕0' 'L5:╕(V>1)/L1X' °
'''RULE 5. The shape of a variable is a vector. The shape of a vector' °
'' ''' is a vector of length 1. The shape of a scalar is a''' °
''' vector of length zero.'',2µr' '╕(0=V)/0' °
'L5X:''The left argument of RESHAPE is by definition a vector. If APL2 °
is''' °
'''to be internally consistent, the inverse operation to RESHAPE (whic °
h''' '''is indeed SHAPE) MUST return the same type of object.''' '╕0' °
'L6:╕(V>1)/L1X' °
'''RULE 6. Reduction of a scalar returns that scalar REGARDLESS of''' °
''' the function to the left of the reduction operator.'',2µr' °
'╕(0=V)/0' °
'L6X:''Reduction BY DEFINITION reduces the RANK by one. The exception °
is''' °
'''for objects whose rank is zero. Since there is no such thing as''' °
'''negative rank, reduction is undefined for scalars, and therefore''' °
'''the result is to leave the APL2 object unchanged.''' '╕0' °
'L7:╕(V>1)/L1X' °
'''RULE 7. The reduction of a null vector produces the identity''' °
''' element of the function.'',2µr' '╕(0=V)/0' °
'L7X:''A null vector may be empty, but it still has rank equal to one. °
''' °
'''Therefore its reduction MUST be a scalar. Since there is no data''' °
'''in a null vector, the scalar must be such that it has no effect''' °
'''on the operation performed by the function: Zero added to anything' °
'' °
'''has no effect in addition; one multiplied by anything has no effect °
''' '''in multiplication; and so on.''' '╕0' 'L8:╕(V>1)/L1X' °
'''RULE 8. Parentheses can (and should) be used to modify the right''' °
''' to left rule to improve efficiency'',2µr' '╕(0=V)/0' °
'L8X:''Parentheses are used in APL2 for other purposes as well, but fo °
r''' °
'''now, we will use them just to modify the right to left rule (RULE 3 °
).''' °
'''If you place parentheses where they are not needed, APL2 will ignor °
Xe''' '''them.''' °
*(1997 6 1 12 49 37 488) °
Fruleb ÉFX 'V ruleb W' 'Σ Additional remarks on rules' °
'╕(2=ÉNC ''V'')/L ╪ V╜0' 'L:╕(9 10 11=╞W)/L9,L10,L11 ╪ ╕0' °
'L9:╕(V>1)/L9X' °
''' RULE 9: To produce a quote inside a character string, enter''' °
''' the quote twice.'',2µr' '╕(0=V)/0' °
'L9X:''This is used in most other programming languages.''' '╕0' °
'L10:╕(V>1)/L10X' °
''' RULE 10: In replication the left argument must contain only''' °
''' integers. The length of the left argument must be''' °
''' the same as the length of the right argument.'',2µr' °
'╕(0=V)/0' °
'L10X:''The left argument may also have negative integers. Only the nu °
mber''' °
'''of positive integers and zeros must add up to the length of the rig °
ht''' °
'''argument. Replicate with negative integers is not discussed here be °
cause''' °
'''the explanation requires concepts that have not yet been mentioned. °
'',r' 'show ''1 1 2 ²1 0 1 1 1 ²1 1 0 1 1/''''CALIFORNIAN''''''' '╕0' °
'L11:╕(V>1)/L11X' °
''' RULE 11: The expression inside square brackets must return''' °
''' positive integers in the range of the length of''' °
''' the indexed vector. If the expression is MISSING,''' °
''' the result is as if the brackets were missing.'',2µr' °
'╕(0=V)/0' °
'L11X:''The expression in brackets need not be a vector. It could be a °
n''' '''array as in the next example'',r' °
X 'show ''''''CALIFORNIA''''[3 3µ?9µ10]'' ''(∞4)[3 3µ∞4]''' °
*(1997 6 2 12 11 17 260) °
Frulec ÉFX 'V rulec W' 'Σ Additional remarks on rules' °
'╕(2=ÉNC ''V'')/L ╪ V╜0' °
'L:╕((11+∞8)=╞W)/L12,L13,L14,L15,L16,L17,L18,L19' 'L12:╕(V>1)/L12X' °
''' RULE 12. A scalar function is one that will produce a result on' °
'' °
''' every scalar element of a vector or array. EXAMPLES:''' °
''' + - ⌡ ÷ * are numeric scalar functions. , µ ∞ are NOT'' °
' ''' scalar functions.'',r' '╕(0=V)/0' °
'L12X:''This distinction will become clearer when we study more genera °
lized''' '''arrays.''' '╕0' 'L13:╕(V>1)/L13X' °
''' RULE 13. Scalars that work with vectors also work with arrays.'' °
,r' '╕(0=V)/0' °
'L13X:''No problem with simple scalars, but this rule may need modific °
ation''' °
'''when we deal with "rank zero arrays" that are not simple scalars.'' °
' '╕0' 'L14:╕(V>1)/L14X' °
''' RULE 14. Arrays with the same shape can be processed with scalar °
''' '''functions.'',r' '╕(0=V)/0' °
'L14X:''Arrays with distinct shapes can be processed as we shall see, °
but''' °
'''there will be restrictions, and we will use new operators.''' '╕0' °
'L15:╕(V>1)/L15X' °
''' RULE 15. The number of semicolons inside brackets must equal the °
''' ''' rank of the array MINUS 1.'',r' '╕(0=V)/0' °
'L15X:''There is no further generalization to this rule.''' '╕0' °
'L16:╕(V>1)/L16X' °
''' RULE 16. An axis specification can be a scalar, a vector or a''' °
''' null vector.'',r' '╕(0=V)/0' °
'L16X:''Recall that null array is the ONLY bracket specification that' °
'' °
'''makes sense for a scalar. We will use that property when dealing wi °
th''' '''rank 0 arrays.''' '╕0' 'L17:╕(V>1)/L17X' °
''' RULE 17. An axis specification can be any array containing''' °
''' valid integers.'',r' '╕(0=V)/0' °
'L17X:''With this rule, you can generate an APL2 object of arbitrary'' °
' '''rank.''' '╕0' 'L18:╕(V>1)/L18X' °
''' RULE 18. The shape of the result of axis specification is the''' °
''' catenation of the shapes of expressions inside brackets °
.''' °
''' If the expression for an axis is missing, the shape for °
''' ''' that axis is unchanged.'',r' '╕(0=V)/0' °
'L18X:''This is merely the rule for implementation of rule 17.''' °
'╕0' 'L19:╕(V>1)/L19X' °
''' RULE 19. Simple reduction of arrays removes its last dimension.' °
X',r' '╕(0=V)/0' 'L19X:''This is a generalization of rule 2.''' '╕0' °
*(1997 7 13 12 28 57 536) °
Fshow ÉFX '╢V show ╢W;╢T;╢B' 'Σ Display and execute ╢W' °
'╢T╜(0=ÉNC ''╢V'')doif ''╢V╜0''' °
'╕((0=╧╢W)doif ''show ╢W,'''' '''''')/0' °
'╕((1<╧╢W)doif ''╢V show ■╢W'')/0' ''' '',╢W' °
X '╕((╢V^'':''ε╢W)doif ''╢T╜evaldd ╢W'')/L0' '''ÉEM'' ÉEA ╢W' 'L0:do' °
*(1997 7 13 12 28 57 536) °
Fshowdd ÉFX 'u╜showdd w;a;b;c;r' °
'Σ Display a direct definition function' °
'╕((1=╧w)doif ''u╜showdd Γw'')/u╜0' °
'╕((3⌠ÉNC╞w)doif ''(ε╞w),'''' is not a function'''''')/0' °
'c╜Γ[2]ÉCR╞w' 'c╜notb(2╞c),(Γ''aw α∙'')replace■2╟c' °
'╕((~''ΣDD''╧3╞2πc)doif ''''''Not a direct definition function'''''')/ °
0' 'u╜1' 'b╜('' ''⌠╞c)Γ╞c' 'a╜'' ''' 'r╜2╟3πc' °
'╕((3=µc)doif ''a,(╞w),'''':'''',r,(3<µ2πc)/'''' Σ'''',3╟2πc'')/0' °
'a╜a,(╞w),'':'',(2╟5πc),'':''' 'b╜(+\r=''('')-+\r='')''' 'b╜b∞0' °
X 'a╜a,(²3╟(b-1)╞3╟r),'':'',2╟»(b+2)╟r' 'a,(3<µ2πc)/'' Σ'',3╟2πc' °
*(1997 7 13 12 28 57 536) °
Fshowfn ÉFX 'U╜V showfn W;F;N;T;ÉIO' 'Σ Simulate ╖W[É]' °
'T╜(0=ÉNC ''V'')doif ''V╜0''' 'ÉIO╜0' °
'U╜r,'' '',''╖'',W,''[É]'',(╞V)╞''╖''' 'N╜1╞µF╜ÉCR W' 'N╜«∞N' °
'N╜(N⌠'' '')ΓN' 'F╜(π''['',■N,■Γ''] ''),F' °
'T╜(1<µ,V)doif ''F╜F[1╟V;]'' ''U╜''''''''''' 'U╜²1╟U,r,,F,r' °
X 'U╜((-+/^\'' ''=ΦU)╟U),('' ╖'')[╞V],r' °
*(1997 7 13 12 28 58 540) °
Fsimdd ÉFX 'u╜simdd w;e' 'Σ Direct definition mode' 'u╜0' °
'╕((0⌠ÉNC╞w)doif ''''''Already defined'''''')/0' 'e╜''α''ε2πw' °
'w[2]╜Γ''u╜'',''α∙ aw'' replace 2πw' 'w╜w[1 3 2]' °
X 'w[1]╜Γε''u╜'',(e/''a ''),w[1],'' w''' 'u╜╧ÉFX w' °
*(1992 6 3 9 59 17 424) °
Ftab ÉFX 'U╜V tab W;T;A;B;C;D;E;F;G;M;ÉPW' 'Σ Tabulate list W' °
'T╜(0=ÉNC ''V'')doif ''V╜0''' 'M╜''Invalid data for tabulation''' °
'V╜4╞V' 'ÉPW╜130╛30⌐G╜V[2]+79⌡V[2]=0' °
'L1:╕((1<╧W)doif ''''''W╜∞0'''' ÉEA ''''W╜πW'''''')/L1' °
'╕(((0=µεW)δ2<µµW)doif ''U╜(~V╧4╞0)/M'')/0' °
'T╜(1≥µµU╜«W)doif ''U╜πW╜(U⌠'''' '''')ΓU''' °
'T╜(0<V[1])doif ''U╜(«(Φ1,╞µW)µ(V[3]µ'''' ''''),∞(╞µW)-V[3]),'''' '''' °
,U''' '╕(G<30)/0' 'T╜(F╜µεV[4])+C╜1╟B╜µA╜(V[3],0)╟U' °
'T╜⌐(1╞B)÷1⌐╛(ÉPW+F)÷T' 'U╜(E╜(V[3],C)╞U),[1](B╜T,1╟B)╞A' °
'''D╜εV[4]'' ÉEA ''D╜ÉAV[εV[4]+33⌡V[4]=0]''' 'L0:A╜(T,0)╟A' °
X '╕(0=1╞µA)/0' 'U╜U,(((T+V[3]),µD)µD),E,[1]B╞A' '╕L0' °
*(1997 7 13 12 28 59 544) °
Ftest ÉFX 'U╜V test W;P' °
'Σ Describe problem in W, (correct answer in V)' 'U╜2' 'L1:W' °
'É╜'' ''' 'P╜æ' '''╕L0'' ÉEA ''P╜»P''' '╕(V╧P)/0' °
X 'L0:╕(0=U╜U-1)/0' '''Incorrect. Try again''' '╕L1' °
XCuc 1 26 ABCDEFGHIJKLMNOPQRSTUVWXYZ °
*(1996 4 6 16 3 10 220) °
Fvec ÉFX 'U╜vec' 'Σ Draw 2d vector in plane' °
'U╜r,r,''2- +'',r '': °'',r,''1- °'',r' °
X 'U╜U,'' : °'',r,''0|....|....|'',r,'' 0 1 2'',r' °