home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
teach.zip
/
TEACH3A.ATF
< prev
next >
Wrap
Text File
|
1997-09-16
|
76KB
|
930 lines
XNÉIO 0 1 °
XNÉCT 0 1E²13 °
XCÉFC 1 6 .,*0_² °
XNÉRL 0 282475249 °
XCÉPR 1 1 °
XCÉLX 1 5 TEACH °
*(1997 4 27 12 39 30 516) °
FALGORITHM ÉFX 'ALGORITHM' 'Σ Origin of the word algorithm' °
'''The word ALGORITHM has an interesting history. The Arab mathematici °
an''' °
'''al-Khwarzimi adopted the hindu numerals as his notation when he''' °
'''wrote his popular textbook on mathematics. (The title was ''''''''A °
l-jabr''' °
'''wa''''l muqabalah'''''''', which incidentally is the origin of the °
word''' °
'''ALGEBRA.) The usage of hindu numerals was adopted in Europe, and th °
e''' °
'''symbolism was named after its (presumed) author: al-Khwarzimi. With °
''' °
'''time this became ''''algorism'''' and eventually ''''algorithm''''. °
As the''' °
'''word changed, so did its meaning. ALGORITHM today means a specific' °
'' '''process, or procedure, to be used in solving a problem.''' °
X 'endd' °
*(1997 5 18 12 35 31 472) °
FCOMPLEX ÉFX 'COMPLEX W;N;A;B;C;D;X' °
'Σ Power, floor and ceiling in the complex domain' '╕(W=1 2)/L1 L2' °
'L1:''If you try to take a root of a negative number, you may find str °
ange''' '''looking results.'',r' 'show ''²2*3'' ''²8*÷3''' °
'''Although ²2 is a valid cube root of ²8, the response is a complex n °
umber.''' °
'''Here is why! Recall from algebra that given an integer N, there exi °
st N''' °
'''distinct roots of a number. In selecting one of these N roots, APL2 °
''' °
'''ALWAYS returns the FIRST COUNTER-CLOCKWISE one in the complex plane °
.''' '╕L0' °
'L2:''Although floor and ceiling can be applied to numbers in the comp °
lex''' °
'''domain, the behavior of these two functions requires considerable'' °
' °
'''explanation. In general, one can say that FLOOR and CEILING of comp °
lex''' °
'''numbers generates complex numbers with integer values. What these'' °
' °
'''values are depends on the position of the number within the integer °
''' '''rectangle that bounds that number.'',r' °
'''Consider first a point exactly in the middle of that rectangle'',r' °
'show ''N╜.5J.5''' °
'''We will replicate this point in all four quadrants of the complex p °
lane'',r' 'show ''N╜N,+N'' ''N╜N,-N'' ''N''' °
'''Now, we will apply ceiling and floor'',r' 'show ''⌐N'' ''╛N''' °
'''Studying the result, one might come to the conclusion that ceiling °
will''' °
'''move to the upper left integer corner, while floor will place the'' °
' °
'''result in the lower right integer corner. Unfortunately, this is NO °
T''' °
'''the case in general. To see how these functions work, let us consid °
er''' °
'''how CEILING will work in the unit square. We have already seen that °
''' °
'''⌐.5J.5 returns 0J1. We will now generate a vector that spans the un °
it''' '''square in the range (0,1) and (0,i)'',r' °
'show ''X╜0 .2 .4 .5 .6 .8 1'' ''⌐X''' °
'''Along the real axis, the function produces 0 and 1 as expected. Now °
''' '''we will add a complex component to X'',r' °
'show ''X+0J.2'' ''⌐X+0J.2''' °
'''The first two entries (0J.2 and .2J.2) return 0J1, The last entry'' °
' °
'''(1J.2) returns 1J1. To see the pattern, we will increment X again'' °
,r' 'show ''X+0J.4'' ''⌐X+0J.4''' °
'''Now only two points (.5J.4 .6J.4) go to 1. The first three go to 0J °
1 and''' °
'''the last two go to 1J1. To complete the pattern, consider points wh °
ere''' '''the complex component is equal or greater than 0.5.'',r' °
'show ''X+0J.5'' ''⌐X+0J.5'' ''X+0J.8'' ''⌐X+0J.8''' °
'''The pattern can be summarized by the following diagram'',r' °
'square' °
'''Take the diagonal from 0 up to the point (0.5J0.5). All points belo °
w''' °
'''this diagonal go to 1. On the diagonal from (0.5J0.5) to 1, all poi °
nts''' °
'''ON or below (except of course 0.5J0.5) also go to 1. Points on the' °
'' °
'''diagonal from .5J.5 to 0J.5 as well as those to the left of this''' °
'''diagonal go to (0J1). All other points, namely those to the right o °
f''' '''the main diagonal (0J1 to 1J0) go to 1J1.''' 'do' °
'''You should try to use this procedure to find how CEILING and FLOOR' °
X'' '''behave for arbitrary points on the complex plane.''' 'L0:endd' °
*(1997 4 27 12 39 30 516) °
FDECIMAL ÉFX 'DECIMAL' 'Σ Story of decimal point' °
'''The usage of the decimal point is less than 400 years old. In the'' °
' °
'''sixteenth century, mathematicians still used fractions to indicate' °
'' °
'''the fractional part of a number. Viete, a french mathematician''' °
'''experimented with bold letters for the integral part, and light''' °
'''letters for the fractional part. He also tried a vertical bar to''' °
'''separate the integers from the fractions. Others, among them Stevin °
''' '''tried other approaches.'',r' °
'''The first usage of the decimal point (or comma) can be traced to''' °
'''Magini or Clavius, friends of Kepler. However, it was Napier who''' °
'''proposed a comma or period (in 1616) to indicate decimal fractions. °
'',r' °
'''Today the English speaking world uses the decimal point, but some'' °
' °
'''European countries have adopted the comma as the mark that separate °
s''' '''the integer part of a number from the fractional part.''' °
X 'endd' °
*(1997 8 24 13 14 34 440) °
FDIRECT ÉFX 'DIRECT' 'Σ Introduce DIRECT DEFINITION' °
''' WHY DIRECT DEFINITION'',r' °
'''APL as a programming language is not cast in concrete. There are''' °
'''always suggestions for its extension. Changes, however, are made on °
ly''' °
'''after extensive study to insure that the internal consistency of th °
e''' °
'''language remains, and only when such changes contribute to its util °
ity.''' °
'''Ken Iverson, the originator of the language, has in recent years''' °
'''developed a new "version" of APL called J, where he introduced seve °
ral''' '''new concepts such as TACIT PROGRAMMING.'',r' °
'''The concept of tacit programming is a significant departure from th °
e''' °
'''approach taken by APL2. It means that when a new function is define °
d,''' °
'''no specific reference is made of the arguments to that function. An °
''' °
'''example will illustrate this: Suppose that we desire to define a ne °
w''' °
'''function called RANK. A tacit program definition would equate the'' °
' °
'''APL2 symbols "µµ" with the "keyword" RANK. APL2 does not support su °
ch''' °
'''a concept (yet). Instead, the APL2 definition requires a combinatio °
n''' °
'''of the function PLUS its argument(s). Thus in APL2 we would define' °
'' '''this function as "µµx" where "x" represents the argument.''' °
'do' °
'''The idea for combining just the functions has evolved in Iverson''' °
's''' °
'''thinking over the years. When APL was first developed, users''' °
'''discovered that certain combinations of primitive functions were''' °
'''frequently used in the solution of many problems. Here is one examp °
le''' '''of such a combination'',r' ''' ∞µVECTOR'',r' °
'''The symbols "∞µ" when placed together generate a vector of ordinals °
''' °
'''that can be used in many ways. The word IDIOMS was introduced to''' °
'''define this concept. The new APL2 interpreters actually recognize'' °
' °
'''some of these idioms, and produce more efficient solutions. Another °
''' °
'''result was Iverson''''s introduction of a concept called DIRECT''' °
'''DEFINITION. This concept is not currently supported by APL2, but''' °
'''we will introduce and support it in this tutorial.''' 'do' °
'''Why do we go to extra lengths to describe a facility that is not''' °
'''even available in APL2? There are a number of reasons, but the''' °
'''primary one is pedagogical. The current method in APL2 for the''' °
'''creation of user defined functions has some aspects that mimic''' °
'''conventional programming techniques in other languages such as''' °
'''FORTRAN C or COBOL. A student who is familiar with programming in'' °
' °
'''one of these languages will have a tendency to develop algorithms'' °
' °
'''along the same lines. By making the student solve problems using''' °
'''initialy only DIRECT DEFINITION (DD), we force him to start thinkin °
g''' '''the way that APL2 was designed for.''' 'do' °
'''There are other reasons for using DD as well. The conventional mode °
for''' °
'''APL2 function definition cannot be readily adapted to an interactiv °
e''' °
'''tutorial such as this one (although, in later lessons we will use y °
et''' °
'''another way to define functions that do work interactively). Finall °
y,''' °
'''DD is often used in describing APL algorithms in the literature.'', °
r' °
'''We should also explain how this tutorial works. Each time there is °
a''' °
'''pause, and the cursor is placed on a blank line, you may enter''' °
'''any expression whatever to test your understanding of what you have °
''' °
'''just read. The text that you enter is not evaluated directly. It is °
''' °
'''captured as a character string and then evaluated in a controlled w °
ay''' °
'''to give you essentially the same effect as if you were in direct''' °
'''contact with APL2. By doing this, the tutorial method prevents even °
ts''' °
'''such as "INTERRUPTS" that normally would cause the tutorial to stop °
''' °
'''its continuity. A side advantage is the ability to recognize certai °
n''' '''types of grammar such as DD that are not supported by APL2.''' °
X 'endd' °
*(1997 9 14 12 30 44 504) °
XFDISCLAIMER ÉFX 'DISCLAIMER' 'Σ Copyright statement' 'disclaimer' °
*(1997 4 27 12 39 30 516) °
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' °
*(1997 4 27 12 39 30 516) °
FEXIT ÉFX 'EXIT' 'Σ Exit from function' '''To log off type: )OFF''' °
X '╕' °
*(1997 4 27 12 39 30 516) °
FEXPLAIN ÉFX 'EXPLAIN W' 'Σ Explain problems described in text' °
'L0:╕(1 2 3=1╞W╜,W)/L1,L2,L3' '╕0' 'L1:show ''µ/8 2 3''' °
'''Recall that in the reduction operator, the function to the left of' °
'' °
'''the slash is placed between the elements of the vector. So we have: °
'',r' ''' µ/8 2 3 is the same as 8µ2µ3'',r' °
'''Now evaluating from right to left, from 2µ3 we get 3 3'',r' °
'''and evaluating this result: 8µ3 3 we get 3 3 3 3 3 3 3 3.'',r' °
'''This is not the whole story. Recall that reduction removes one''' °
'''dimension from the right argument. This result seems to violate tha °
t''' '''rule; but does it?'',r' 'show ''µ(µ/8 2 3)'' ''µµ(µ/8 2 3)''' °
'''The parentheses in the above expression are used merely for clarity °
.''' °
'''The result is indeed a scalar; and yet it contains a vector of leng °
th''' °
'''eight. This seeming contradiction is your first introduction to''' °
'''non-simple scalars. These play a very important role in APL2, but w °
e''' °
'''will not study them until we become better acquainted with the simp °
ler''' '''aspects of APL2.''' 'do' '╕LX' 'L2:show ''µ/(2 3) (∞6)''' °
'''Inserting the function in the right argument vector, we get:'',r' °
''' (2 3)µ(∞6) which is the same as (2 3)µ1 2 3 4 5 6'',r' °
'''The left argument to RESHAPE (remember reshape?) calls for two''' °
'''rows and three columns using the right argument data.'',r' °
'''Here too as in the first example, we have'',r' °
'show ''µ(2 3) (∞6)'' ''µµ/(2 6) (∞6)''' °
'''The right argument to the reduction operator is a vector of a type' °
'' °
'''we have not yet studied. It is called a NESTED VECTOR. Since it is' °
'' °
'''a vector, its reduction is a SCALAR. For the time being, this is ju °
st''' °
'''a reminder that there is more to APL2, than the simple expressions' °
'' °
'''we have studied so far. We will of course study all aspects of APL2 °
''' '''in due time.''' 'do' '╕LX' 'L3:show ''µ/(2 3) ∞6''' °
'''Removing the blank in front of ∞ we get: µ/(2 3)∞6'',r' °
'''Now in (2 3)∞6 the parentheses are redundant so we have µ/2 3∞6.'', °
r' °
'''But the expression 2 3∞6 is a dyadic usage of ∞ called INDEX OF.'', °
r' °
'''You will recall that it looks for the presence of 6 in the left''' °
'''vector. Since 6 is not in vector 2 3, this expression returns''' °
'''one plus the length of vector 2 3, namely 3.'',r' °
'''Finally, the reduction of a scalar (or vector of length one) return °
s''' °
'''that value regardless of the function. Hence µ/(2 3) ∞6 returns 3.' °
X'' 'LX:╕(0<µW╜1╟W)/L0' °
*(1997 8 8 13 33 28 428) °
FGAME ÉFX 'GAME;N;GREATER;SMALLER;EQUAL;TO;THAN' °
'Σ Game to find number' °
'''We begin by defining three relational functions:'',r' °
'1 show ''GREATER:α>∙'' ''SMALLER:α<∙'' ''EQUAL:α=∙''' °
'''The symbols for < and > stand for "less than" and "greater than"'', °
r' 'show ''3 GREATER 5'' ''3 SMALLER 5'' ''3 EQUAL 5''' °
'''Next, we define ''''placeholder'''' functions:'',r' °
'1 show ''TO:∙'' ''THAN:∙''' °
'''These functions merely return the result of evaluating expression ∙ °
'',r' 'show ''TO 3⌡5'' ''THAN 6''' °
'''Finally, we use ROLL to generate a random integer between 1 and 100 °
'',r' 'show ''N╜?100''' '''Now we can play this game:''' °
'show ''IS N GREATER THAN 50'' ''IS N SMALLER THAN 43'' ''IS N EQUAL T °
O 5''' °
'''Now you try to find the value of N by asking questions. (NOTE: move °
''' °
'''the cursor to one of the lines above, change the numeric value, and °
X''' '''press Enter.)'',r' 'do' °
*(1996 4 6 15 59 48 592) °
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 25 13 26 57 584) °
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 press the DOWN arrow °
''' '''to scroll the screen up'',r' °
'''You may also wish to press PAGE UP to review previous pages.''' °
'do' '''RESOURCES'',r' °
'''You may also enter ONE of the following words at a time'',r' °
'''ALGORITHM The origin of this word''' °
'''DECIMAL History of development of decimal notation''' °
'''DIRECT Brief summary of recent APL developments''' °
'''GAME A game to find a number between 1 and 100''' °
'''POWER Monadic usage of the power function, complex numbers''' °
'''COMPLEX (1 or 2) Evaluation of complex number expressions''' °
X '''EXPLAIN (1 2 or 3) Explanation of three APL2 expressions''' 'endd' °
*(1997 9 16 12 21 25 400) °
FIS ÉFX 'u╜IS w;t;b' 'ΣDD' 'b╜(t╜w)/''u╜''''yes''''''' '╕(t doif b)/0' °
X 'u╜''no''' °
*(1997 5 4 12 39 40 468) °
FPOWER ÉFX 'POWER;e;N;i;PI' °
'Σ Exponential and power of complex numbers' °
'''When the * is used monadically, it is called EXPONENTIAL. The missi °
ng left''' '''argument is defaulted to the constant "e".''' 'e╜*1' °
'show ''e'' ''e*2'' ''*2''' °
'''Where does this constant come from? It is the limit of the expressi °
on''' ''' (1+÷N)*N as N approaches infinity'',r' °
'show ''N╜10*2 4 6 8'' ''N'' ''(1+÷N)*N''' °
''' POWER OF COMPLEX NUMBERS'',r' 'i╜0J1 ╪ PI╜Ω1' °
'''Since APL2 supports complex numbers, it is entirely valid to apply °
the''' '''power (exponential) to complex numbers'',r' °
'show ''i'' ''i*2'' ''2*i'' ''*i''' °
'''Consider, for example the famous Euler formula''' °
X 'show ''PI'' ''*i⌡PI''' 'endd' °
*(1997 5 30 13 54 49 672) °
FRULE ÉFX 'V RULE W' 'Σ Display rules' '╕(2=ÉNC ''V'')/L0' °
X '2 rule W ╪ ╕0' 'L0:V rule W' °
*(1997 8 26 12 5 8 304) °
FTEACH ÉFX 'TEACH' 'Σ Start third lesson in APL2 by Zdenek V JIZBA' °
'exit ''TEACH''' 'initialize' °
'TEACH1 Σ Parentheses, quote, high minus, workspace' °
'TEACH2 Σ The power function' °
'TEACH3 Σ Maximum, minimum, ceiling, floor, equal, not equal' °
'TEACH4 Σ Algorithm, user defined functions' °
'TEACH5 Σ Direct definition' 'TEACH6 Σ Conditional direct definition' °
X 'TEACH7 Σ Average, range and midrange' 'problems' °
*(1997 5 17 12 5 18 296) °
FTEACH1 ÉFX 'TEACH1' 'Σ Review lesson 2' 'exit ''TEACH1''' °
'''So far we have learned that in APL2, there are objects called DATA, °
''' °
'''FUNCTIONS and OPERATORS. We can ASSIGN data to VARIABLES. We can''' °
'''write EXPRESSIONS that are formulas for the solution of specific''' °
'''problems.''' 'do' °
'''We learned about several PRIMITIVE FUNCTIONS. These are invoked by' °
'' °
'''symbols that operate on data to generate a result. We pointed out'' °
' °
'''that you can find how to enter these symbols by selecting the OPTIO °
NS''' °
'''pull down menu and pressing the MODIFY KEYBOARD. We studied the''' °
'''following primitive functions: + - ⌡ ÷ = ⌠ ε µ ∞. Refresh your memo °
ry''' '''by entering a few expressions containing these symbols.''' °
'do' °
'''We learned that the slash / is a special symbol used to define an'' °
' °
'''OPERATOR called the REDUCTION OPERATOR. It connects a function left °
''' °
'''argument to data as the right argument.In particular,the combinatio °
n ''' °
'''+/ will add all the elements of a numeric vector. Go ahead,and try °
''' '''to use the reduction operator with different functions.''' 'do' °
'''We also learned that there are symbols that are part of the NOTATIO °
N''' °
'''of APL2. Some of these symbols have been incorporated from normal'' °
' °
'''usage that we have learned in school, such as the decimal point.''' °
'''(For a brief discussion of the history of decimal point type DECIMA °
L)''' °
'''Other APL2 notation is not as well known. The usage of the letter E °
''' '''to denote exponent in scientific notation is an example.''' °
'do' °
'''APL2 supports the usage of parentheses to change the DEFAULT''' °
'''sequence for evaluating expressions. The single quote '''' (not a'' °
' '''double quote ") is used to delimit caracter strings. APL2 also''' °
'''makes a distinction between a NEGATIVE SIGN (²) to indicate a''' °
'''property of a number (being less than zero), and a MINUS SIGN to''' °
'''indicate a multiplication by minus one. Finally, the left arrow ╜'' °
' '''is used to divert the result of evaluation to a VARIABLE.''' 'do' °
'''So you feel at ease with APL2 so far? Just for exercise, try to exp °
lain''' °
'''the following results: (You SHOULD have problems understanding them °
!''' °
'''For an explanation, enter EXPLAIN 1, EXPLAIN 2 and EXPLAIN 3)'',r' °
'show ''µ/8 2 3'' ''µ/(2 3) (∞6)'' ''µ/(2 3) ∞6''' °
'''In this lesson we are going to study a few more primitive functions °
.''' °
'''We will also learn about the DIRECT DEFINITION. Although APL2 does °
not''' °
'''support DIRECT DEFINITION, it is a useful tool for learning APL. Th °
is''' '''WORKSPACE contains software to evaluate it properly.''' 'do' °
'''Incidentally, a WORKSPACE is the name given to the amount of memory °
X''' '''allocated by APL2 to this, or any application.''' 'endd' °
*(1997 5 17 12 26 57 536) °
FTEACH2 ÉFX 'TEACH2' 'Σ Define power and exponential' 'exit ''TEACH2''' °
''' THE POWER FUNCTION'',r' °
'''We can use multiplication (⌡) to calculate the square of a number.' °
'' °
'''Using the reduction operator, we could even calculate arbitrary''' °
'''integer powers of a number. For example to raise two to the power'' °
' '''eight, we could enter'',r' 'show ''⌡/8µ2''' °
'''What we cannot do, however, is to use the times symbol to raise a'' °
' °
'''number to fractional powers, such as for example the square root.'' °
' °
'''In mathematical notation, the power of a number is displayed as a'' °
' °
'''superscript number to the right, and usually in a smaller font.''' °
'do' °
'''Since APL2 is limited to a simple linear text, it is not possible'' °
' '''to use the notation for powers that we learn in high school.''' °
'''There is a special symbol for power in APL2, and it is used''' °
'''as a DYADIC function. The number to be raised to a power is the''' °
'''left argument. The symbol for a power function is the asterisk, and °
''' '''the power is the right argument.'',r' °
'show ''10*3'' ''10*²3'' ''25*0.5'' ''25*÷2''' °
'''The last two examples show two ways of taking the square root. The' °
'' °
'''second approach has merit for taking roots of numbers that cannot'' °
' '''be expressed in decimal notation'',r' °
'show ''8*0.33333'' ''8*÷3''' 'do' °
'''Naturally, the power function works with vectors too'',r' °
'show ''2*0 1 2 3'' ''2 3 4 5*2'' ''2 3 4 5*5 4 3 2''' °
'''To see how APL2 deals with roots of negative numbers, enter COMPLEX °
1.''' 'do' °
'''Try out some powers, and include expressions that contain the''' °
'''monadic iota (∞). Then explain the results''' 'do' °
'''Enter POWER to see the monadic usage of the power function.''' °
'''The discussion will also touch on the power of COMPLEX NUMBERS.''' °
X 'do' 'endd' °
*(1997 5 17 12 27 23 404) °
FTEACH3 ÉFX 'TEACH3;NUMS;VECTOR' 'Σ Maximum minimum and residue' °
'exit ''TEACH3''' °
'''We normally think of addition, subtraction, multiplication, divisio °
n''' °
'''and exponentiation as the only elementary operations on numbers.''' °
'''There are some operations that are just as important, but tend to'' °
' °
'''be overlooked in teaching elementary math courses. Take the questio °
n''' °
'''as to which of the following numbers is the bigger one: 2 or 5.''' °
'do' °
'''Since we somehow recognize that 5 is bigger than 2, it may not seem °
''' °
'''too important to think of this process as one worth teaching at the °
''' °
'''elementary level. But then why should we bother with the obvious?'' °
,r' °
'''The reasons will become clearer when we study user defined function °
s.''' °
'''Right now, let us look at some of these elementary but useful primi °
tive''' '''APL2 functions.'',r' 'do' °
'''The symbol ⌐ is called MAXIMUM. When used dyadically, it compares'' °
' '''two numbers, and returns the larger one.'',r' °
'show ''2⌐5'' ''²2⌐²5''' °
'''The symbol ╛ is called MINIMUM. When used dyadically, it compares'' °
' '''two numbers, and returns the smaller one.'',r' °
'show ''2╛5'' ''²2╛²5''' °
'''Both of these functions can be used with the reduction operator.''' °
'''Can you predict what result will they produce?''' 'do' °
'''The reduction of a numeric vector using MAXIMUM will return a scala °
r.''' °
'''The value of that scalar will be the largest numeric value in the'' °
' °
'''vector. In a similar way MINIMUM will return the smallest value:'', °
r' 'show ''⌐/2 53 17 81 45'' ''╛/2 53 17 81 45''' °
'''Now you try it, assign to V a vector of numbers. Then write an APL2 °
''' °
'''expression to calculate the RANGE of that vector. (The word range h °
as''' °
'''many meanings, but here we use it to mean the difference between th °
e''' '''largest and smallest values.)''' 'do' °
'''There are also monadic versions of the symbols ⌐ and ╛. When used'' °
' '''monadically, ⌐ is called CEILING, and ╛ is called FLOOR'',r' °
'show ''⌐1.23 5 ²3.45'' ''╛1.23 5 ²3.45''' °
'''As you can see, ceiling and floor return integers (whole numbers)'' °
' '''that are nearest to the given value. Ceiling finds the larger''' °
'''integer, and floor finds the smaller integer. Monadic ⌐ and ╛''' °
'''have no effect on integers. Thus'',r' °
'show ''NUMS╜1.23 5 ²3.45'' ''NUMS=⌐NUMS'' ''NUMS=╛NUMS''' °
'''Floor and Ceiling can also be applied to complex numbers. Enter''' °
'''COMPLEX 2 to find out more about the peculiar behavior of these two °
''' '''monadic functions in the complex domain.''' 'do' °
'''There may be times when we are not interested in the VALUE of the'' °
' °
'''largest or smallest, but only in a relationship. We have already''' °
'''seen primitive functions = and ⌠'',r' °
'show ''2=3'' ''5=5'' ''3=∞6'' ''2 4 6 8⌠8 4 2 6''' °
'''These primitive functions were called RELATIONAL, and we used them' °
'' '''with character strings.'',r' °
'show ''''''HOUSE''''=''''MOUSE'''''' ''''''CAT''''⌠''''CUT''''''' °
'''For numeric variables there are several other relational functions. °
''' °
'''The symbol < is called LESS THAN. The symbol < is called GREATER TH °
AN.''' °
'''To complete the collection we have ≤ LESS THAN OR EQUAL and ≥ GREAT °
ER''' °
'''THAN OR EQUAL. You should practice with these symbols, but remember °
X,''' '''these work only with numeric data.''' 'endd' °
*(1997 5 16 13 43 27 484) °
FTEACH4 ÉFX 'TEACH4;NUMS;VECTOR;RATIO' °
'Σ Introduction to function definition' 'exit ''TEACH4''' °
'''Let us now describe an ALGORITHM, that uses the FLOOR (╛) function. °
''' '''(For the origin of the word "algorithm", enter ALGORITHM.)'',r' °
'''Given a vector of integers, count the number of its elements that a °
re''' '''divisible by 7. Let the vector be'',r' 'show ''VECTOR╜∞200''' °
'''The following expression will give us the result:'',r' °
'show ''+/(VECTOR÷7)=╛VECTOR÷7''' °
'''If we think of VECTOR as some arbitrary sequence of numbers, then'' °
' '''the above expression, becomes an equation of sorts. If such an''' °
'''expression is to be used frequently, it would be convenient to''' °
'''capture it in a more compact form. In other words, how do we progra °
m''' '''in APL2?'',r' 'do' °
'''The simple answer is that one can package one or more expressions'' °
' °
'''such as the one above. The result of this packaging is called a''' °
'''"USER DEFINED FUNCTION". The main difference between a User Defined °
''' °
'''Function, and a primitive function is in the representation. A''' °
'''primitive function is defined by a special symbol, while a User''' °
'''defined one is a text label.'',r' °
'''There are other differences. We have seen that primitive functions' °
'' °
'''always produce a result. This need not be true in User Defined ones °
.''' °
'''If an APL2 expression is not a valid one, an error message will be' °
'' °
'''produced. In a User Defined Function, errors can be "trapped".''' °
'''With the help of special features that are supported by the commerc °
ial''' °
'''version of APL2, it is also possible to access non-APL2 data, gener °
ate''' °
'''graphs on the screen and to "call" on non-APL2 software.'',r' °
'''User defined functions therefore are analogous to programs or''' °
'''subroutines of other programming laguages.'',r' 'do' °
'''The process of defining an APL2 user function can take several form °
s.''' °
'''Although a single expression such as the one above could be used as °
''' °
'''the definition of a function, it is more typical to catenate two or °
''' °
'''more such expressions together. The problem at hand provides an''' °
'''example of that.'',r' 'show ''+/(VECTOR÷7)=╛VECTOR÷7''' °
'''A careful inspection of the expression above, suggests that it may' °
'' °
'''not be very efficient, because the quantity "VECTOR÷7" is calculate °
d''' '''twice. A two step process seems to be more rational:'',r' °
'show ''RATIO╜VECTOR÷7'' ''+/RATIO=╛RATIO''' °
'''We will learn how to define multi-expression algorithms in a later' °
'' °
'''lesson. Right now, let us concentrate on those that can be written °
as''' °
'''single strings (the so called and sometimes maligned "one liners"). °
''' °
'''One of the guiding principles that led Iverson to develop APL was t °
he''' °
'''desire to simplify this process of designing new algorithms. The AP °
L2''' °
'''primitive functions have been selected with this purpose in mind.'' °
,r' °
'''Indeed, in his most recent work, Iverson has designed a new dialect °
''' °
'''of APL, called J, that strongly supports a concept called "tacit''' °
'''programming" that relies heavily on "one line definitions".''' °
X 'endd' °
*(1997 8 24 13 21 55 552) °
FTEACH5 ÉFX 'TEACH5;ORDINALS;T;PLUS' 'Σ Introduce DIRECT DEFINITION' °
'''We will introduce here a concept called DIRECT DEFINITION. This con °
cept''' °
'''is not supported by APL2, but because it is useful in teaching APL, °
this''' °
'''tutorial contains software that supports it, but only while you are °
within''' °
'''the lesson. To learn more about this subject, enter DIRECT''' 'do' °
''' DIRECT DEFINITION'',r' °
'''There are two forms of direct definition. The first form is illustr °
ated''' '''by function PLUS.'',r' 'T╜evaldd ''PLUS:α+∙''' °
''' PLUS:α+∙'',r' °
'''In this form there is a colon separating a label to the left from a °
n''' °
'''APL2 expression containing the greek letters α (alpha) and ∙ (omega °
).''' '''Let us see how this can be used:'',r' °
'show ''5 PLUS 3'' ''2 3 PLUS 5 6''' °
'''The label PLUS behaves exactly the same as if it were the symbol +' °
'' °
'''The greek letter α stands for the left argument, and the greek lett °
er''' °
'''∙ stands for the right argument. Suppose now that we desire to defi °
ne''' °
'''a new function for the expression ∞µVECTOR. Let us name this functi °
on''' '''ORDINALS:'',r' °
'1 show ''ORDINALS:∞µ∙'' ''ORDINALS ''''TEST''''''' °
'''Because function ORDINALS is monadic, the symbol α is missing in th °
Xe''' '''function definition.''' 'endd' °
*(1997 8 25 13 33 26 488) °
FTEACH6 ÉFX 'TEACH6;T' 'Σ Conditional direct definition' °
'exit ''TEACH6''' °
'''There is a second form of DIRECT DEFINITION. It is somewhat more''' °
'''complex, but it provides execution with condition. Function IS''' °
'''illustrates this conditional form:'',r' °
'T╜evaldd ''IS:''''no'''':∙:''''yes''''''' '1 show ''IS:''' °
'''There are now three colons. Let us see how function IS behaves:'',r °
' 'show ''IS 5>6'' ''IS 5<6''' °
'''In the first example, the expression ∙ is 5>6. It evaluates to zero °
''' °
'''since the inequality is clearly false. In the second example the''' °
'''expression ∙ is 5<6, which is clearly true. This expression therefo °
re''' °
'''evaluates to a one. Now, the direct definition IS contains three pa °
rts:''' °
'''The leftmost part is the APL expression ''''no''''. The middle part °
is ∙,''' '''and the rightmost part is ''''yes''''.''' 'do' °
'''So for the conditional direct definition, there are three rules for °
''' '''its evaluation:'',r' °
''' 1. Evaluate the middle expression. It MUST return a boolean valu °
e''' °
''' 2. If the result is true (1), evaluate the right expression.''' °
''' 3. If the result is false, evaluate the left expression.'',r' °
'''Before you experiment with direct definitions, you might first try' °
'' °
'''entering GAME. This game illustrates how you can use direct definit °
ion''' °
'''to build a simple but interesting application. Now you try defining °
''' °
'''some functions. Once defined exercise them. WARNING: The argument i °
n''' °
'''a direct definition HERE, MUST be either ∙ or (α and ∙). NEVER just °
X α!''' 'endd' °
*(1997 8 26 12 5 49 468) °
FTEACH7 ÉFX 'TEACH7;AVERAGE;RANGE;MIDRANGE' °
'Σ Sample direct definitions' 'exit ''TEACH7''' °
'''Let us see what can be done with direct definitions. We will now''' °
'''define a few sample user defined functions, but these will be erase °
d''' '''so that you can practice on your own.'',r' °
'''In the previous lesson, we found an expression for the average:'',r °
' '1 show ''AVERAGE:(+/∙)÷µ∙'' ''AVERAGE:'' ''AVERAGE ∞99''' °
'''In this lesson you were asked to define range.'',r' °
'1 show ''RANGE:(⌐/∙)-╛/∙'' ''RANGE ²10+33⌡∞10''' °
'''What about the following?'',r' °
'1 show ''MIDRANGE:0.5⌡(⌐/∙)+╛/∙'' ''MIDRANGE ²10+33⌡∞10''' °
'''Can you explain why we place ⌐/∙ in parentheses, but leave ╛/∙ alon °
e?'',r' 'do' °
'''As we proceed, we will use the direct definition to illustrate''' °
'''examples of APL2 usage. Eventually, we will also study the process' °
'' °
'''of defining user functions by switching from the "execution" mode'' °
X' '''to the "function definition" mode.''' '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 4 27 12 39 30 516) °
XFaq ÉFX 'U╜aq W' 'U╜Γaddquote W' °
*(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 9 16 12 25 17 384) °
Ferase ÉFX °
'erase;t;EXIT;HELP;DISPLAY;ALGORITHM;DECIMAL;EXPLAIN;GAME;POWER;COMPLE °
X;RULE;DISCLAIMER;DIRECT;GO' °
'Σ 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' 't╜ÉNL 4' 't╜ÉEX(~t^.εlc,'' '')≡t' °
*(1997 4 27 12 39 30 516) °
Ferrors ÉFX 'errors W;EC;RT;R' 'Σ Display error message' °
'╕((1<╧W)doif ''errors■ W'')/0' ''' '',W' '(EC RT R)╜ÉEC W' 'R' °
X 'do' °
*(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 5 31 11 30 1 380) °
Frule ÉFX 'V rule 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.''' '╕L0' '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.''' '╕L0' '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.''' '╕L0' '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)''' '╕L0' '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.''' '╕L0' °
'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.''' '╕L0' °
'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.''' '╕L0' '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.''' 'L0:do' '╕(0=µW╜1╟W)/0' '╕L' °
*(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 8 7 14 15 12 292) °
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+1)╟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' °
*(1997 5 18 12 10 24 344) °
Fsquare ÉFX 'square' 'Σ Unit square in the complex plane' °
'''i┌───────┐1+i''' ''' │ ° │''' ''' │ ° │''' °
X ''' │ ° ° │''' '''0└───────┘1''' °
*(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 °
*(1997 4 27 12 39 30 516) °
Fvec ÉFX 'U╜V vec W;T' 'Σ Draw 2d vector in plane' °
'T╜(0=ÉNC ''V'')doif ''V╜''''''''''' °
'U╜r,'' '',W[3],r,''2- +'',W[2],r '': °'',r,''1- °'',r' °
X 'U╜U,'' : °'',r,''0|....|....|.'',V,,'' '',W[1],r,'' 0 1 2'',r' °
*(1997 4 27 12 39 30 516) °
Fwords ÉFX 'U╜words W;ÉIO' 'Σ Convert phrase to words' 'ÉIO╜0' °
X 'U╜('' ''⌠W)ΓW' °