home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
teach.zip
/
TEACH10A.ATF
< prev
next >
Wrap
Text File
|
1997-09-19
|
61KB
|
747 lines
XNÉIO 0 1 °
XNÉCT 0 1E²13 °
XCÉFC 1 6 .,*0_² °
XNÉRL 0 1954899097 °
XCÉPR 1 1 °
XCÉLX 1 5 TEACH °
XNA 2 2 3 0 1 0 1 0 1 °
XNB 2 6 3 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 °
*(1996 4 6 16 4 50 384) °
FBIND ÉFX 'BIND' 'Σ Binding rules of APL2' °
''' 1. Brackets bind to the left''' °
''' 2. Left arrow binds to the left''' °
''' 3. Dyadic operator binds to the right''' °
''' 4. Strand notation binding''' °
''' 5. Operator binds to its left''' °
''' 6. Function binds to its left''' °
''' 7. Function binds to its right''' °
X ''' 8. Left arrow binds to its right'',r' °
XNC 2 3 3 1 0 1 0 0 1 0 1 0 °
*(1997 9 14 12 30 44 504) °
XFDISCLAIMER ÉFX 'DISCLAIMER' 'Σ Copyright statement' 'disclaimer' °
*(1996 4 6 16 4 50 384) °
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 4 50 384) °
FEXIT ÉFX 'EXIT' 'Σ Exit from function' '''To log off type: )OFF''' °
X '╕' °
*(1996 4 6 16 4 50 384) °
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 16 12 5 16 296) °
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╜4),'' 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' °
'''BIND List of APL2 binding rules''' °
'''LINEAR Brief comments on history of Algebra, Complex numbers''' °
X '''MATRIX Geometric interpretation of Matrix Algebra''' 'endd' °
XNI 2 2 2 1 0 0 1 °
*(1997 6 12 13 35 36 476) °
FLINEAR ÉFX 'LINEAR' 'Σ Linear algebra' °
'''The ancient Greeks did not know Algebra, yet they were able to solv °
e''' °
'''simple algebraic problems using geometry. They were able to do this °
''' °
'''because they associated numbers with line segments. We will follow' °
'' °
'''this Greek tradition, and define what will be called the REAL AXIS. °
'',r' °
'''Consider a straight line that extends indefinitely in both directio °
ns.''' °
'''We mark one point on this line, and call it the ORIGIN. Next we mar °
k''' °
'''another point on the line in a direction we will call RIGHT, and ca °
ll''' °
'''this second point ONE. The half line from origin towards point one °
is''' °
'''called the positive axis. The half line in the opposite direction i °
s''' '''the negative axis.'',r' °
'''We can define addition, subtraction, multiplication and division''' °
'''on this line in such a way that it produces results that can be mat °
ched''' °
'''with addition, subtraction, multiplication and division with real'' °
' °
'''numbers. What we mean here is that for every result obtained with'' °
' °
'''numbers, we can associate a specific and unique point on the line.' °
'' 'do' °
'''When we use the term REAL NUMBER, we mean it in the Mathematical''' °
'''sense. However, if you are not familiar with that meaning, the usag °
e''' °
'''of the term is not central to this discussion. In modern terminolog °
y''' °
'''the association of numbers with points on a line is called MAPPING. °
''' °
'''To explain why all this trouble tying numbers with points on a line °
,''' °
'''we must briefly describe the evolution of algebraic thought.''' °
'do' ''' ALGEBRA'',r' °
'''The Renaissance in Western Europe brought renewed interest in the'' °
' °
'''study of Mathematics. Although much interest was devoted to the''' °
'''re-discovery of Greek Geometry, there was also much work done in''' °
'''the development of Algebra. There was a great deal of interest in'' °
' °
'''the solution of POLYNOMIAL equations. A polynomial is an algebraic' °
'' °
'''expression. It is a summation of distinct terms. We will mention he °
re''' °
'''only one type of polynomials, namely those containing one variable, °
''' '''which we will call ''''x''''.'',r' °
'''A term is either a constant, or the product of a constant and a''' °
'''positive and integral but finite power of x. In algebraic theory, t °
he''' °
'''constants are generally restricted to RATIONAL numbers. Specificall °
y''' °
'''excluded are the TRANSCENDENTAL numbers such as PI. A polynomial''' °
'''equation is formed when a polynomial is equated to zero. There is o °
nly a''' °
'''limited number of values of x that satisfy a polynomial equation.'' °
,r' °
'''The highest power of X in the polynomial determines its DEGREE. The °
''' °
'''fundamental theorem of algebra, first proved by Karl Friedrich Gaus °
s in''' °
'''1799 states that every polynomial has at least one root. A conseque °
nce''' °
'''of this theorem is that every polynomial of degree N can be factore °
d''' °
'''as a product of N first degree polynomials of the form Ax+B, where °
A and''' '''B are points on the COMPLEX PLANE.'',r' 'do' °
''' COMPLEX NUMBERS'',r' °
'''The mathematicians of the 16th century sought to find positive solu °
tions''' °
'''called ROOTS to polynomial equations. Gradually mathematicians bega °
n''' °
'''to also accept negative roots. There was a belief, that solutions s °
hould''' '''be limited to numeric values along the real axis.''' °
''' (We now know that the solution set is limited, since "most"''' °
''' points on the real axis, the transcendentals, cannot be roots °
''' ''' of polynomials with rational coefficients.)'',r' °
'''This belief was shattered, when it was discovered (and eventually'' °
' °
'''accepted, though with considerable resistance) that there exist''' °
'''COMPLEX roots. Complex numbers, can best be described as number pai °
rs.''' °
'''The second number of this pair is a number multiplied by the square °
''' °
'''root of negative one. Therefore, the NUMBER SYSTEM that defines the °
''' °
'''solution set of polynomial equations is a plane. This plane is defi °
ned''' °
'''by two axes. One is the real axis that we described above. The seco °
nd''' °
'''axis is (improperly) called the IMAGINARY axis. A point on this pla °
ne''' °
'''is described by two numbers, and the pair is also known as a VECTOR °
.''' °
'''Complex numbers (or vectors on the complex plane) can be added,''' °
'''subtracted, multiplied and divided just as real numbers can.''' °
'do' °
'''In the second half of the 19th century, mathematicians began to exp °
lore''' °
'''other number systems. William Hamilton, for example, tried to exten °
d''' °
'''complex numbers to three dimensions, and came up with QUATERNIONS.' °
'' °
'''Strangely enough, he discovered that this new number system no long °
er''' °
'''obeyed all the rules of arithmetic. In particular, if A and B are t °
wo''' °
'''numbers in his system, the product AB is not the same as BA. Techni °
cally''' '''this property is called non-commutative.'',r' °
'''At this point other mathematicians entered the investigations. For' °
'' °
'''example, it was asked why should the two axes be distinct. Why shou °
ld''' °
'''we not allow all axes to be real numbers. This approach led to the' °
'' °
'''development of VECTOR algebra. Cayley and Sylvester went even furth °
er.''' °
'''They studied vectors of vectors, by forming tables of numbers with' °
'' °
'''fixed numbers of rows and columns. This led to the development of'' °
' °
'''MATRIX algebra. Further extensions were also made, such as in TENSO °
R''' °
'''algebra. In the twentieth century, all of these developments have'' °
' °
'''been generalized. The study of number systems that support addition °
''' '''and multiplication is now called LINEAR ALGEBRA.''' 'do' °
'''APL2 has functions and operators that support the type of processes °
X''' '''that fall under the domain of linear algebra.''' 'endd' °
*(1996 4 6 16 4 50 384) °
FMATRIX ÉFX 'MATRIX;V' 'Σ Examples from matrix algebra' °
'''Let us look at vector V'',r' 'show ''V╜4 3''' °
'''We have already seen that the inner product of V with itself produc °
es''' °
'''the square of its individual components squared. If you were to plo °
t''' °
'''the point V on a graph, you should recognize that the three points' °
'' °
'''(0 0) (4 0) (4 3) form a right triangle. Therefore by the theorem'' °
' °
'''of Pythagoras, the distance from (0 0) to (4 3) should be 25, which °
''' °
'''is indeed the result of the inner product. In vector algebra, the i °
nner''' °
'''product of two vectors (of same length) is called the DOT PRODUCT'' °
,r' 'show ''1 2 3 4 5+.⌡5 4 3 2 1''' °
'''If the two vectors are the same, the square root of its dot product °
''' '''is called the NORM'',r' 'show ''(1 2 2+.⌡1 2 2)*.5''' °
'''Now let us form the following array'',r' °
'show ''R╜2 2µ.8 .6 ².6 .8'' ''R'' ''R+.⌡4 3''' °
'''The array R ROTATES the vector V so that it becomes aligned with''' °
'''the X axis. To see even better how this works, we will add a second °
''' '''vector'',r' 'show ''A╜2 2µ4 3 ²3 4'' ''A''' °
'''The array A can be thought of as a collection of two rows, each''' °
'''representing a vector in the plane. By construction, the two vector °
s''' °
'''are at right angles to each other. (You may wish to verify this by' °
'' °
'''plotting the two points (4 3) and (²3 4) on a graph, and by connect °
ing''' '''each point to the origin.)''' 'do' °
'''Now we can see what array R will do to array A'',r' °
'show ''R+.⌡φA''' °
'''Why did we have to transpose A? Because in matrix multiplication''' °
'''it is the COLUMNS of the right argument that are applied to the''' °
'''ROWS of the left argument!'',r' °
'''For that reason we can reverse the product'',r' 'show ''A+.⌡φR''' °
'''The equivalence of the last two expressions is not accidental.''' °
'''In general, for arbitrary arrays, we have φ(A+.⌡B) is the same''' °
'''as (φB)+.⌡φA'',r' °
'show ''B╜2 2µ3 4 ²4 3'' ''B'' ''φA+.⌡φB'' ''B+.⌡φA''' °
'''Now let us consider just R'',r' 'show ''R+.⌡φR''' °
'''When R is multiplied by itself, it generates I, the matrix that''' °
'''leaves an array unchanged by multiplication. In a sense I is the''' °
'''square of R, which leads to the interesting observation that in''' °
'''matrix algebra the square root of unity is not unity.''' 'do' °
'''In APL2 any numeric array can be multiplied by a scalar'',r' °
'show ''3⌡A'' ''3⌡UNIT 2'' ''A+.⌡3⌡UNIT 2''' °
'''The scalar is propagated on all elements of the array. In the secon °
d''' °
'''and third example we see that the I matrix times 2 acts the same as °
''' °
'''the scalar 2. A matrix that has non zero values only in the diagona °
l''' °
'''is called a DIAGONAL matrix. A diagonal matrix is also SYMMETRIC''' °
'''because φD is the same as D'',r' °
'show ''D╜2 2µ2 0 0 3'' ''D'' ''A+.⌡D'' ''D+.⌡A''' °
'''Notice that array D changes A by multiplying its first column by 2' °
'' °
'''and by multiplying its second column by 3. It is as if we changed'' °
' '''the scales on the X and Y axes.''' 'do' °
'''Applications of matrix algebra are countless. We will see some, as' °
'' °
'''we learn about other primitive APL2 functions. If you find this''' °
'''subject interesting, you might want to read any one of many textboo °
ks''' '''on the subject.'',r' °
X '''We will cover more of this same material in lesson 21.''' 'endd' °
XAN╜('JOHN')('MARY')('TED')('FRED')('EVE')('ANN') °
*(1997 7 4 12 5 54 396) °
FTEACH ÉFX 'TEACH' 'Σ Start lesson 10: APL2 by Zdenek V JIZBA' °
'exit ''TEACH''' 'initialize' 'TEACH1 Σ Inner product' °
'TEACH2 Σ Using the inner product on character and numeric arrays' °
'TEACH3 Σ Inner product and matrices' °
X 'TEACH4 Σ Matrix multiplication' 'problems' °
*(1997 8 30 11 5 26 388) °
FTEACH1 ÉFX 'TEACH1;NAMES;ATTEND;A' 'Σ APL2 inner product' °
'exit ''TEACH1''' °
'''In this lesson we will study one version of the DOT operator.''' °
'''This operator is distinguished from the ones we have studied before °
''' °
'''by its dyadic functionality. Whenever the dot operator is used,''' °
'''it must have both a left and a right function as an argument.''' °
'do' ''' INNER PRODUCT'',r' °
'''When the dot is preceeded by a function (and of course followed by' °
'' °
'''a function), it is called the ARRAY PRODUCT. This operator was desi °
gned''' °
'''initially to solve a specific type of mathematical problems. We wil °
l''' °
'''study these, but we will introduce the general principle of this''' °
'''operator in a more mundane way.''' 'do' °
'''Suppose that we have an vector of names called N'',r' °
'show ''N╜''''JOHN'''' ''''MARY'''' ''''TED'''' ''''FRED'''' ''''EVE'' °
'' ''''ANN''''''' °
'''We can convert this vector to an array, say NAMES'',r' °
'show ''NAMES╜πN'' ''DISPLAY NAMES''' °
'''The array NAMES has 6 rows and 4 columns. Now, suppose these names' °
'' °
'''represent members of a group. If the group meets, it may be useful' °
'' °
'''to generate an attendance record. Let us suppose that the following °
''' '''individuals attended a meeting'',r' °
'show ''A╜''''FRED'''' ''''MARY'''' ''''JIM''''''' °
'''We can also convert this vector to an array, say ATTEND'',r' °
'show ''ATTEND╜πA'' ''DISPLAY ATTEND''' °
'''The array ATTEND has 3 rows and 4 columns. What we would like to''' °
'''obtain is a 6 by 3 boolean array. The six rows to represent members °
''' °
'''of the group, and the three columns to represent the individuals''' °
'''attending the meeting'',r' °
'('' '',Γ[2]ATTEND),[1](Γ[2]NAMES),[2]B╜NAMES^.=φATTEND' 'do' °
'r,''The boolean array has a one only in those places where the row la °
bel''' '''matches the column label. Let us call that array B'',r' °
'show ''B''' °
'r,''We can identify all members who attended meeting'',r' °
'show ''(δ/B)/N''' '''and all who are not members'',r' °
'show ''(~δ≡B)/A''' °
'''Clearly the array B is very useful. It can be generated with the he °
lp''' '''of a special APL2 operator called ARRAY INNER PRODUCT'',r' °
'show ''NAMES^.=φATTEND''' °
'''Let us now disect this particular expression. We begin with the''' °
'''transpose of ATTEND'',r' °
'show ''φATTEND'' ''µNAMES'' ''µφATTEND''' °
'''Array φATTEND has 4 rows and 3 columns. Therefore the last dimensio °
n''' °
'''of NAMES matches the first dimension of φATTEND. This is a critical °
''' °
'''requirement, because the inner product removes this dimension from' °
'' °
'''the final result. Now let us see what the ^.= compound function doe °
s.''' 'do' °
'''It begins with the first row of NAMES (JOHN), and applies the right °
''' °
'''function argument (which is =) to the columns of φARRAY producing'' °
,r' '(4 1µ''JOHN'')(φATTEND)(4 3µ12╞0 0 1)' °
'r,''Having done this, the left argument of the operator (^) is used t °
o''' '''reduce the columns of this intermediate array'',r' °
''' ^≡''(4 3µ12╞0 0 1)' '3µ0' 'do' °
'r,''This result is then placed in the first row of B. Next, the secon °
d''' °
'''row of B (MARY) is applied with = to the right argument, producing' °
',r' '(4 1µ''MARY'')(φATTEND)(4 3µ0 1 0)' °
'r,''When this intermediate array is reduced by the left function (^), °
the''' '''result 0 1 0 is placed in the second row of B'',r' °
''' ^≡''(4 3µ0 1 0)' '2 3µ0 0 0 0 1' 'do' °
'''This process is then continued until the array B is complete.'',r' °
X 'B' 'endd' °
*(1997 6 13 12 27 58 532) °
FTEACH2 ÉFX 'TEACH2;N;A;NAMES;ATTEND;X;Y;V' °
'Σ inner product with vectors and arrays' 'exit ''TEACH2''' °
'''The application of inner product need not be used with arrays of th °
e''' '''same rank.'',r' °
'N╜''JOHN'' ''MARY'' ''TED'' ''FRED'' ''EVE'' ''ANN''' 'NAMES╜πN' °
'A╜''FRED'' ''MARY'' ''JIM''' 'ATTEND╜πA' °
'''Suppose our array of names is very long, and we wish to find out if °
''' '''JACK is on that list. Then the expressions'',r' °
'show ''NAMES^.=''''JACK'''''' ''NAMES^.=''''FRED''''''' °
'''return boolean vectors. Note that the right argument in the above'' °
' °
'''expressions is reduced with the second dimension in the left argume °
nt.''' 'do' '''As an extreme case both arguments could be vectors'',r' °
'show ''''''JACK''''^.=''''FRED'''''' ''''''JACK''''^.=''''JACK''''''' °
'''these two expressions are then equivalent to'',r' °
'show ''^/''''JACK''''=''''FRED'''''' ''^/''''JACK''''=''''JACK''''''' °
'''Going the other way, either one of the two arguments can have an''' °
'''arbitrary rank, as long as the last dimension of the left argument' °
'' '''is the same as the first dimension of the right argument'',r' °
'show ''µNAMES'' ''µNAMES^.=4 2 3µATTEND'' ''µ(2 2 6µATTEND)^.=NAMES'' °
' 'show ''µ(2 3 4µNAMES)^.=4 2 1 1 1µATTEND''' °
'''The inner product will work equally with numeric arguments'',r' °
'show ''X╜?2 6µ20'' ''X'' ''Y╜?6 3µ20'' ''Y'' ''X^.=Y''' °
'''In the following section we will deal with numeric arrays called''' °
'''MATRICES. For a background on these entities, enter LINEAR''' 'do' °
'''Although we could develop this subject in an abstract way, it may'' °
' °
'''be easier to understand if we associate matrices with geometric''' °
'''concepts. We realize that this is an artificial crutch, but is a''' °
'''necessary one if you do not have a great deal of mathematical''' °
'''background.''' 'do' °
'''We will start with numeric vectors. Consider'',r' °
'show ''V╜12 345''' °
'''The question that one has to ask is what do these numbers represent °
.''' °
'''If these values mean weight and cost of an object, then it is clear °
''' °
'''that only a restricted set of arithmetic operations have meaning.'' °
' °
'''Certainly the expression +/V is meaningless. On the other hand 2⌡V' °
'' °
'''has practical validity. We could plot the two components on a graph °
.''' °
'''Most likely weight has little or no relationship to cost, so a plot °
''' °
'''of weight (as the x coordinate) vs cost (as the y coordinate) for'' °
' °
'''many instances of V, is likely to have points scattered all over th °
e''' °
'''plane. Furthermore, for any value of x, there may be more than one' °
'' '''value of y. Mathematically, the pair (x,y) is not a function.''' °
'do' °
'''Suppose now that the two components of V represent time and distanc °
e.''' °
'''Then again +/V has no meaning, but we might be able to say that for °
''' °
'''every value of V[1], there is a corresponding value of V[2]. This'' °
' °
'''would make the components of V a FUNCTION. In modern terminology''' °
'''V[1], corresponds to the INDEPENDENT VARIABLE, and the set of''' °
'''admissible values of V[1] the DOMAIN. By convention, this is drawn' °
'' °
'''on graphs as the x axis. The y axis corresponds to V[2], the DEPEND °
ENT''' °
'''VARIABLE. The set of permissible values of V[2] is called the RANGE °
.'',r' °
'''The origin of the coordinate system (time,distance) can be shifted' °
'' °
'''arbitrarily, but the shifted axes must remain parallel to the origi °
nal''' '''ones if the graph is to remain meaningful.''' 'do' °
'''In APL2 the usage of the term VECTOR covers the above examples, but °
''' °
'''in Mathematics, the word VECTOR has a much more restricted meaning. °
''' °
'''It is unfortunate that APL2 has chosen a conflicting terminology.'' °
' 'do' °
'''When we come to arrays, the terminology is improved. In Mathematics °
''' °
'''a numeric APL2 array of rank 2 is called a MATRIX. We will now stud °
y''' °
'''the inner product operator as applied to VECTORS and MATRICES in th °
Xe''' '''mathematical sense.''' 'endd' °
*(1997 6 13 12 41 59 592) °
FTEACH3 ÉFX 'TEACH3;UNIT' 'Σ Vectors and matrices' 'exit ''TEACH3''' °
'''A vector in the mathematical sense is a point in a cartesian space' °
'' °
'''SPANNED by coordinate axes. The location and orientation of the axe °
s''' °
'''is quite arbitrary. The unit dimension along any axis can be assume °
d''' °
'''to be the same. The origin of coordinates can not only be shifted,' °
'' °
'''but it can also be rotated. We can even transform the nature of the °
''' °
'''coordinates. For example, instead of using cartesian coordinates,'' °
' '''we can use a polar coordinate system.''' 'do' °
'''Le us assume that we have'',r' 'show ''V╜4 3''' °
'''By the process of mapping, the vector V can be thought of as a poin °
t on''' °
'''the Euclidean plane. The straight line reaching this point from the °
''' '''origin is called a vector. We have'',r' °
'show ''V+.⌡V'' ''V+.⌡1 0'' ''V+.⌡0 1''' °
'''The first expression returns the square of the length of the vector °
.''' °
'''The second and third expressions return the x and y component.''' °
'do' '''We can combine the last two expressions'',r' °
'show ''I╜2 2µ1 0 0'' ''I'' ''V+.⌡I''' °
'''The matrix I when applied as an inner product to V returns V. Let'' °
' °
'''us see how this process works. The Vector V is first applied to the °
''' °
'''first column of I (1 0) with the right argument of the inner produc °
t''' °
'''(⌡), to produce (4 0). Then the left argument of the inner product' °
'' °
'''(+) reduces (4 0) to 4. Next V is applied to the second column of I °
''' °
'''to produce (0 3) and 3. The final result is the vector (4 3).''' °
'do' °
'''Clearly I is the matrix equivalent of 1 with respect to the inner'' °
' °
'''product (+.⌡). If I leaves a vector unchanged, let us see how it''' °
'''will transform an array'',r' °
'show ''A╜2 2µ∞4'' ''A'' ''A+.⌡I'' ''I+.⌡A''' °
'''So, I leaves an array unchanged whether it ''''multiplies'''' A on °
the''' °
'''right or on the left. Since I is such a useful array, we will defin °
e''' '''function UNIT to generate it'',r' °
'1 show ''UNIT:(∙,∙)µ1,∙µ0:∙=1:1'' ''DISPLAY UNIT 1'' ''UNIT 5''' °
'''Let us now apply the inner product to two distinct arrays A and B'' °
,r' 'show ''B╜2 2µΦ∞4'' ''B'' ''A+.⌡B'' ''B+.⌡A''' °
'''It does make a great deal of difference in what SEQUENCE we form''' °
'''the product. The property of having A⌡B return the same result as'' °
' °
'''B⌡A is called the COMMUTATIVE property. Clearly matrix inner produc °
t''' °
'''is non-commutative. Since this is not a textbook on linear algebra, °
''' °
'''we will not pursue the matrix inner product mathematically. We will °
,''' °
'''however, study how it can be applied as an APL2 compound function.' °
',r' °
'''(If you are iterested in geometric interpretation of the inner''' °
X '''product +.⌡, enter MATRIX.)''' 'endd' °
*(1997 6 13 12 41 30 476) °
FTEACH4 ÉFX 'TEACH4' 'Σ The inner product process' 'exit ''TEACH4''' °
'''We will now define arrays A and B in such a way that (µA) is the''' °
'''same as ΦµB'',r' °
'show ''A╜2 3µ0 1 0 1'' ''B╜3 2µ1 1 0 0 0'' ''A'' ''B'' ''A+.⌡B'' ''B+ °
.⌡A''' °
'''Because (µA)╜╕µφB, we were able to evaluate both inner products (A+ °
.⌡B)''' °
'''and (B+.⌡A). Not only are the results different, but the dimensions °
''' °
'''are not the same! You should try to verify these results by doing t °
he''' °
'''process of multiplication by hand. You may use the following scheme °
:''' 'do' °
'''Place your left index finger on the first element of the first row' °
'' °
'''of the left argument, and your right index finger on the first elem °
ent''' °
'''of the first column on the right argument. Then as you move your le °
ft''' °
'''finger to the right, you move your right finger down, proceed to''' °
'''cumulate the sum +/left⌡right. The sum is then placed in row 1,''' °
'''column 1 of the resulting array. Next you return your left finger'' °
' °
'''back to column 1 (of the same row), and place your right finger to' °
'' °
'''row 1 of column 2. Proceed as before, and place the sum in row 1''' °
'''column 2 of the result. Continue this process until all columns of' °
'' °
'''the right argument have been evaluated. Then move your left finger' °
'' °
'''to the second row of the left argument, and repeat the procedure''' °
'''to evaluate the second row of the result.''' 'do' °
'''If you have never done this, you should try it at least once. Get a °
''' °
'''piece of paper, and copy the values of A and B. Then use your index °
''' '''fingers to produce the result of A+.⌡B''' 'do' °
'''Once you have developed the technique, try to apply it to expressio °
ns''' °
'''with a different set of scalar functions. Since both A and B are''' °
'''boolean, you can evaluate'',r' 'show ''Aδ.^B'' ''Bδ.^A''' °
'''Indeed, you should try other scalar functions'',r' °
'show ''A⌐.╛B'' ''B╛.⌐A'' ''A+.-B'' ''A-.+B''' °
'''Now let us recall binding rules'',r' 'BIND' °
'''We are now in a position to see how binding rule 3 works'',r' °
'show ''+.⌡/A B''' °
'''By binding rule 3, the ⌡ is bound to the . operator. Then, by bindi °
ng''' °
'''rule 4, A and B are bound as a single vector. With binding rule 5 t °
he''' °
'''sub-expression +.⌡ becomes a compound function that is applied to'' °
' °
'''the elements of the vector to the right of the reduction operator.' °
'' '''To see that this usage is general consider'',r' °
'show ''C╜3 3µ1 0 1 0 0'' ''C'' ''+.⌡/C C'' ''+.⌡/C C C'' ''+.⌡/C C C °
XC''' 'endd' °
*(1996 4 6 16 4 50 384) °
FUNIT ÉFX 'u╜UNIT w;t;b' 'ΣDD' 'b╜(t╜w=1)/''u╜1''' '╕(t doif b)/0' °
X 'u╜(w,w)µ1,wµ0' °
XNV 1 2 4 3 °
*(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 16 11 56 54 648) °
Ferase ÉFX °
'erase;t;EXIT;GO;HELP;DISPLAY;REVIEW;RULE;BIND;LINEAR;MATRIX;UNIT;DISC °
LAIMER' 'Σ 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 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 4 50 384) °
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' °