home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
teach.zip
/
TEACH5A.ATF
< prev
next >
Wrap
Text File
|
1997-09-18
|
77KB
|
940 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 °
*(1997 5 15 14 39 13 412) °
FCOMPLEX ÉFX 'COMPLEX;N;A;B;C;D;X' °
'Σ Absolute value in the complex domain' °
''' ABSOLUTE VALUE OF COMPLEX NUMBERS'',r' °
'''For real numbers, absolute value is defined as the distance from 0 °
to''' °
'''the number. For complex numbers, we are not dealing with the real n °
umber''' °
'''axis, but rather with the complex plane. A simple euclidean approac °
h''' '''to calculate absolute value will not work.'',r' °
'show ''X╜1J1'' ''X*2'' ''(1J0+0J1)*2''' °
'''Squaring a complex number will generate another complex number.''' °
'do' 'show ''(1J0*2)+0J1*2''' °
'''Applying the theorem of Pythagoras also fails. In fact any point on °
a''' '''45 degree slope of the complex plane will return a zero.''' °
'do' °
'''To obtain the distance from origin of a complex number, it is requi °
red to''' °
'''multiply X by its "complex conjugate". This number is defined to ha °
ve''' °
'''the same values in the real and complex axes, but with an opposite' °
'' °
'''sign in the complex axis. The absolute value then becomes the posit °
ive''' '''square root of X times complex conjugate of X''' °
X 'show ''(X⌡+X)*.5'' ''|X''' 'endd' °
*(1997 5 3 14 0 20 236) °
FCONVENTION ÉFX 'CONVENTION' 'Σ Origin of algebraic notation' °
'''In modern algebra a function of one variable is described by the''' °
'''convention f(x). A function of two variables is written as f(x,y).' °
'' °
'''There are, however, some functions that are used so frequently, tha °
t''' '''special symbols have been assigned to them:'',r' °
''' + for plus(x,y)'',r,'' - for minus(x,y)''' °
''' ⌡ for times(x,y)'',r,'' ÷ for divide(x,y)'',r' °
'''and so on.''' 'do' °
'''There are special symbols to denote functions in one variable:'',r' °
''' |x| for absolute_value(x)'',r,'' x! for factorial(x)'', °
r' 'do' °
'''On the other hand for some functions we do not have special symbols °
:'',r' '''sin(x), cos(x), log(x) sinh(x) tanh(x)'',r' 'do' °
'''Many of these conventions date to the the beginnings of modern alge °
bra.''' °
'''In ancient Greece, mathematicians had no symbols other than letters °
of''' °
'''the alphabet. They relied on drawings of geometric figures, and on' °
'' °
'''a rhetorical argument in proving theorems. Starting in the third ce °
ntury''' °
'''A.D., a kind of shorthand was developed by Diophantus. The use of'' °
' °
'''abbreviations in the expression of mathematical relationship is kno °
wn''' '''as SYNCOPATED notation.'',r' 'do' °
'''In the 16th century, there was a period of experimentation with way °
s''' °
'''to use letters, digits and special symbols to describe mathematical °
''' °
'''relationships. For example, two German friends of Kepler used symbo °
ls''' °
'''+ and - in place of the letters p. and m.. Robert Recorde adopted t °
hese''' °
'''symbols, and added = to denote equality. Some notation used by Viet °
e,''' °
'''Chouquet, Burgi, Stevin and Bombelli did not survive. The adoption °
of''' °
'''our modern symbolism was not immediate. Viete, for example did not °
use''' °
'''the symbol ⌡, and for division used a horizontal bar. The ⌡ symbol' °
'' °
'''was first used by William Oughtred, and Thomas Harriot introduced < °
''' '''and >.'',r' 'do' °
'''In the 17th century, Descartes adopted the exponential superscript. °
''' °
'''This was the first of many notational conventions that cannot be''' °
'''represented in a linear form. With the advent of computers, we have °
''' °
'''limitations on the spatial arrangement of symbols. Most present day °
''' °
'''keyboards do not support subscripts and superscripts. Because of th °
is,''' °
'''mathematical notation had to be modified to comply with these''' °
'''limitations. Much as in the 16th century, there has been a variety °
of''' °
'''proposals for expressing symbols in a linear form. In some prograqm °
ming''' °
'''languages, there has been a regression to a syncopated approach.'', °
r' 'do' °
'''For example assignment to a variable may be given by :=; exponentia °
tion''' °
'''may be given by ** and so on. APL and APL2 has adopted an entirely' °
'' °
'''different strategy. All commonly used functions are assigned specia °
l''' °
'''symbols. For monadic functions, the symbol ALWAYS preceeds the argu °
ment.''' °
'''For dyadic functions, the symbol is ALWAYS placed between the two'' °
X' '''arguments.''' 'endd' °
*(1997 9 14 12 30 44 504) °
XFDISCLAIMER ÉFX 'DISCLAIMER' 'Σ Copyright statement' 'disclaimer' °
*(1996 4 6 16 1 57 400) °
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 5 3 14 5 42 344) °
FDUAL ÉFX 'DUAL' 'Σ Concept of duality explained' °
'''APL functions, can be compared to Mathematical functions. Although' °
'' °
'''the same word FUNCTION is used, the meaning and usage need not be t °
he''' °
'''same. In general, most if not all Mathematical functions can be rea °
dily''' °
'''defined as APL2 functions. Certain APL2 functions, however, would b °
e''' '''only marginally considered as mathematical.'',r' °
'''Catenation for example, where the expression A,B generates a vector °
C''' °
'''whose components are the elements of A and B would probably not be' °
'' °
'''considered a function in the strictest elementary algebraic sense.' °
'' 'do' °
'''In mathematics, a function of one variable x is denoted as f(x).''' °
'''In APL2 such a function is called MONADIC. A function of two variab °
les''' °
'''x and y would be written as F(x,y). In APL2 this would be a DYADIC' °
'' °
'''function. However, the APL2 expression f/VECTOR, where f stands for °
''' °
'''any valid primitive APL2 function can be considered as a function o °
f''' '''two variables, if VECTOR contains only two elements.''' 'do' °
'''Both algebraic and APL2 functions can be separated into two groups: °
'',r' °
''' 1. There are functions that produce an irreversible result.''' °
''' An example is multiplication. 4⌡5 produces 20, but having the' °
'' °
''' value of 20 we find that there is an infinity of number pairs' °
'' °
''' whose product is 20. Therefore this function is not what is''' °
''' called a ONE TO ONE relationship.'',r' °
''' 2. There are some functions for which there is a unique inverse. °
For''' °
''' example, if the product 4⌡5 returns 20 AND 4 (one of the facto °
rs)''' °
''' then the second factor can be always recovered (with 20÷4).'', °
r' °
'''In the second example the expressions 4⌡5 and 20÷4 are called DUALS °
''' '''(with respect to 5 -- the second factor).''' °
'''Some APL2 primitive functions are self duals. This means that a sec °
ond''' °
'''application of the same function will reproduce the original value. °
'',r' 'show ''-5'' ''--5'' ''÷7'' ''÷÷7''' °
'''Why is the concept of duals so important? As we will see later, man °
y''' °
'''problems can be solved readily in a form that involves transformati °
ons''' °
'''requiring dual conversion. Consider the following problem.'',r' °
'''PROBLEM: Adjust a fractional number to the nearest integer''' 'do' °
'''Let us say that we have two numbers 3.24 and 6.87. Clearly the near °
est''' °
'''integer to the first one is 3, and the nearest integer to the secon °
d''' °
'''one is 7. This problem is solved with a technique called HALF ADJUS °
T.''' '''We merely add one half and take the floor'',r' °
'show ''╛.5+3.24 6.87''' °
'''But now suppose we want to adjust 5.123 and 2.749 to the nearest on °
e''' °
'''hundreth. We solve this by applying ⌡100 and then its dual ÷100'',r °
' 'show ''(╛.5+100⌡5.123 2.749)÷100''' °
'''Encode and decode are dual, provided the left argument is preserved °
X.''' 'endd' °
*(1996 4 6 16 1 57 400) °
FEXIT ÉFX 'EXIT' 'Σ Exit from function' '''To log off type: )OFF''' °
X '╕' °
*(1996 4 6 16 1 57 400) °
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 12 12 29 51 516) °
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' °
'π''COMPLEX'' ''CONVENTION'' ''DUAL'' ''MODULO'' ''REVIEW'' ''RESIDUE' °
X'' 'endd' °
*(1997 5 3 14 6 3 192) °
FMODULO ÉFX 'MODULO;Y;X;Q5M13;Q13M5;Q13M17;Q17M13;Q3M5;Q5M3;Q3M7;Q7M3' °
'Σ Describe modulo arithmetic' °
'''Modulo arithmetic is a powerful tool in mathematics. Some of the''' °
'''most fundamental proofs of Algebra require familiarity with modulo' °
'' °
'''arithmetic. Two numbers A and B are said to be CONGRUENT MODULO C'' °
' °
'''if (C|A)=C|B. Modulo arithmetic can be derived from the following'' °
' '''properties:'',r' °
'show ''(17|5+7)=17|7+5 Σ Reflexive'' ''(17|27)=17|44''' °
'show ''(17|44)=17|27 Σ Symmetric'' ''(17|10)=17|27''' °
'show ''(17|27)=17|44'' ''(17|10)=17|44 Σ Transitive''' °
'''If the difference between two numbers A and B is divisible by C, th °
en''' '''A and B are CONGRUENT MODULO C.'',r' °
'show ''(17|44)-17|27 Σ 44 and 27 are CONGRUENT MODULO 17''' °
'''which is the same as'',r' 'show ''17|44-27''' °
'''One of the most famous results in modulo arithmetic is the law of'' °
' °
'''quadratic reciprocity. To show what this law means, let us first''' °
'''define a quadratic residue: For any X, the result of the expression °
''' °
'''P|Q-X*2 is called a quadratic residue if it returns a ZERO. P and Q °
''' '''are assumed to be primes.'',r' 'show ''X╜76'' ''17|²13+X*2''' °
'''Here (X*2) is a quadratic residue. There are actually many solution °
s''' °
'''to X. The theorem states that for the existence of X, the following °
''' '''situations may arise (For simplicity we set Y╜X*2):'',r' °
''' 1. if 4|P Q returns 3 3, then then Y exists only for one expressio °
n''' ''' of the form'',r' °
''' P|Q+Y or Q|P+Y'',r' °
''' 2. if 4|P Q returns 1 1 then ''' °
''' a. there is no Y╜X*2 or''' °
''' b. there is such Y, and there are also values of Y╜X*2 such tha °
t''' ''' both P|Q+Y and Q|P+Y are congruent'',r' °
''' 3. if 4|P Q returns 3 1 or 1 3, there is no such Y'',r' 'do' °
'''EXAMPLES''' '''Case 1'',r' °
''' We generate vectors Q3M7 and Q7M3, noting that 4|3 7 returns 3 3' °
',r' °
'show ''Q3M7╜(0=3|²7+(∞200)*2)/∞200'' ''Q7M3╜(0=7|²3+(∞200)*2)/∞200''' °
''' then'',r' 'show ''µQ3M7'' ''µQ7M3''' '''Case 2a''' °
''' First, we generate the following two vectors'',r' °
'show ''Q5M13╜(0=5|²13+(∞500)*2)/∞500'' ''Q13M5╜(0=13|²5+(∞500)*2)/∞50 °
0''' °
''' Since 4|5 13 returns 1 1 both or none has a solution. We have'',r °
' 'show ''µQ5M13'' ''µQ13M5''' ''' so 5 and 13 have no solution.'',r' °
'''Case 2b''' °
'show ''Q13M17╜(0=13|²17+(∞800)*2)/∞800'' ''Q17M13╜(0=17|²13+(∞800)*2) °
/∞800''' °
'show ''µQ13M17'' ''µQ17M13'' ''X╜(Q13M17εQ17M13)/Q13M17'' ''X''' °
''' where vector X gives solutions to the law of quadratic reciprocit °
y'',r' 'show ''13|²17+X*2'' ''17|²13+X*2''' '''Case 3''' °
''' We generate vectors Q3M5 and Q5M3, noting that 4|3 5 returns 3 1' °
',r' °
'show ''Q3M5╜(0=3|²5+(∞200)*2)/∞200'' ''Q5M3╜(0=5|²3+(∞200)*2)/∞200''' °
X ''' then'',r' 'show ''µQ3M5'' ''µQ5M3''' 'endd' °
*(1996 4 6 16 1 58 404) °
FMORE ÉFX 'MORE W' 'Σ More on aspects of new concepts' '╕(W=1 2)/L1,L2' °
'╕0' 'L1:''Both encode and decode accept negative numbers'',r' °
'show ''²10 ²10 ²10ÿ234'' ''²10|234'' ''²10|(234-²6)÷²10''' °
'show ''²10|(234-²6+²4⌡²10)÷²10⌡²10''' °
'''The reverse operation is not as clearcut, and is omitted. When the' °
'' '''right argument is negative,'',r' °
'show ''10 10 10ÿ²234'' ''10|²234'' ''10|(²234-6)÷10'' ''10|(²234-6+6⌡ °
10)÷10⌡10''' '''Finally, when both arguments are negative'',r' °
'show ''²10 ²10 ²10ÿ²234'' ''²10|²234'' ''²10|(²234-²4)÷²10''' °
'show ''²10|(²234-²4+²7⌡²10)÷²10⌡²10''' °
'''Now consider decode with negative numbers'',r' °
'show ''10¥2 3 4'' ''(100⌡2) + (10⌡3) + 1⌡4'' ''10¥-2 3 4''' °
'show ''(100⌡²2)+(10⌡²3)+1⌡²4'' ''²10¥2 3 4'' ''(²10⌡²10⌡2) + (²10⌡3) °
+ 1⌡4''' 'show ''²10¥-2 3 4'' ''(²10⌡²10⌡²2) + (²10⌡²3) + 1⌡²4''' °
'endd' '╕0' °
'L2:''Decode can be used to solve polynomials. Consider the following' °
'' °
'''polynomial in X (we use APL notation instead of superscripts)'',r' °
''' (2⌡X*3) + (3⌡X*2) + (7⌡X) - 20'',r' °
'''We can evaluate this polynomial for sample values of X'',r' °
''' X F(X)''' ''' 1 ²8''' ''' 2 22''' ''' ²1 ²26''' 'do' °
'show ''1¥2 3 7 ²20'' ''2¥2 3 7 ²20'' ''²1¥2 3 7 ²20''' °
'''Later we will learn how this process can be generalized to the''' °
X '''evaluation of F(X) where X is a vector''' 'endd' °
*(1997 5 4 13 38 24 404) °
FRESIDUE ÉFX 'RESIDUE;i;M;VECTOR' °
'Σ Residue applied to negative numbers' °
'''Residue is easy to explain when we deal with integers. For positive °
''' °
'''numbers that are not integers (these are also called "real" numbers °
)''' °
'''the concept of residue is still simple, but also benefits from some °
''' '''additional explanation. Consider the numbers 5.35 and 12.8'',r' °
'show ''5.35|12.8'' ''╛12.8÷5.35'' ''12.8-2⌡5.35''' °
'''Notice that we used the FLOOR of the ratio 12.8÷5.35 as the multipl °
ier''' °
'''in the last expression. In other words whatever the quantity in the °
''' °
'''left argument, it is multiplied an INTEGRAL number of times, such'' °
' °
'''that the residue is less than that argument. Of course residue work °
s''' '''with vector arguments'',r' °
'show ''5.2|∞10'' ''5.2|0.3+∞10'' ''(∞5)|1+∞5''' °
'''What happens when we use negative numbers?'',r' 'show ''²5|7''' °
'''This result requires more explanation. Let us assume that we are''' °
'''looking at the X axis. To calculate the value 5|7, we mark a point' °
'' °
'''7 units to the right of the origin. Then we take the compass, and'' °
' °
'''mark off the distance 5 as many times from the origin such that the °
''' °
'''compass point does not go past 7. We find that we fall short by 2'' °
,r' ''' ╕ x x+2''' °
''' |.....|.....|.....|.....|.....|.....|.....|''' °
''' 0 1 2 3 4 5 6 7'',r' 'show ''5|7''' °
'''Now let us look at ²5|7. The value of ╛7÷²5 is ²2. This time, since °
''' °
'''the 5 is a negative number, we begin at the 7, and move 2 times to' °
'' '''the left. This will give us the value of ²3.'',r' °
'''2x╜ x╜ ╜''' °
''' |.....|.....|.....|.....|.....|.....|.....|.....|.....|.....|''' °
'''²3 ²2 ²1 0 1 2 3 4 5 6 7'',r' °
'show ''²5|7''' °
'''When we evaluate 5|²7, we get 3. As before, we mark ²7 to the left' °
'' °
'''of the origin, and since 5 is positive, we start at the 7, and move °
''' '''two times (╛²7÷5) to the right. This will reach point 3.'',r' °
''' ╕ x 2x''' °
''' |.....|.....|.....|.....|.....|.....|.....|.....|.....|.....|''' °
'''²7 ²6 ²5 ²4 ²3 ²2 ²1 0 1 2 3'',r' °
'show ''5|²7''' °
'''Finally, when evaluating ²5|²7 note that ╛²7÷²5 is 1. Therefore we' °
'' °
'''move 5 units to the left, and note that we still are 2 units short' °
',r' ''' x ╜''' °
''' |.....|.....|.....|.....|.....|.....|.....|''' °
'''²7 ²6 ²5 ²4 ²3 ²2 ²1 0'',r' 'show ''²5|²7''' °
''' RESIDUE AND COMPLEX NUMBERS'',r' °
'''The same principle applies when the arguments to residue are comple °
x''' '''numbers'',r' 'show ''i╜0J1'' ''i|2''' °
'''The residue of dividing 2 by i is zero. Let us verify that'',r' °
'show ''╛2÷i'' ''2-i⌡0J²2''' °
'''The residue of two complex numbers works the same way'',r' °
'show ''M╜²9*÷3'' ''M'' ''i|M'' ''╛M÷i'' ''M-i⌡1J²1''' °
'''Here is another example'',r' °
'show ''M|20J10'' ''╛20J10÷M'' ''20J10-M⌡9J²6''' °
'''Selective specification can also use the residue'',r' °
'show ''VECTOR╜∞10'' ''((2=5|VECTOR)/VECTOR)╜''''X'''''' ''VECTOR''' °
X 'endd' °
*(1996 4 6 16 1 58 404) °
FREVIEW ÉFX 'REVIEW W;V' °
'Σ Review reduction, logical and indexing functions' °
'╕(W=∞3)/L1,L2,L3' '╕0' °
'L1:''COMPRESSION: boolean/vector'',r,''EXAMPLES'',r' °
'show ''0 1 1 0/∞4'' ''0 1 0 1 1 1 1 1 0 0 0/''''COMPRESSION''''''' °
'''REPLICATION: (integer vector)/vector'',r,''EXAMPLES''' °
'show ''(∞3)/∞3'' ''1 2 0 1 0 0 0 0 0 0 0/''''REPLICATION''''''' °
'''N-WISE REDUCTION: integer function/vector'',r,''EXAMPLES'',r' °
'show ''3⌡/∞10'' ''2⌠/''''MISSING''''''' '╕L0' °
'L2:''The logical functions are NOT OR AND NOR NAND, and their''' °
'''symbols are ~ δ ^ τ σ.'',r,''EXAMPLES '',r' °
'show ''~0 1'' ''0 1 0 1δ0 0 1 1'' ''0 1 0 1τ0 0 1 1'' ''0 1 0 1^0 0 1 °
1''' 'show ''0 1 0 1σ0 0 1 1''' '╕L0' °
'L3:''Squad indexing is a primitive function using the ╙ symbol.''' °
'''Bracket indexing is a notation to access elements of a vector''' °
'''and can be used to the left of the assignment arrow.'',r,''EXAMPLES °
'',r' °
'show ''3╙∞5'' ''(1 3 5 7)[1+∞2]'' ''V╜''''TEST'''''' ''V[3 2 4]''' °
X 'L0: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 32 9 320) °
FTEACH ÉFX 'TEACH' 'Σ Start fifth lesson in APL2 by Zdenek V JIZBA' °
'exit ''TEACH''' 'initialize' 'TEACH1 Σ More primitive functions' °
'TEACH2 Σ Lamp and direct definition of running average' °
'TEACH3 Σ Absolute value and residue' 'TEACH4 Σ Encode' °
'TEACH5 Σ Decode' 'TEACH6 Σ From arabic to roman, another way' °
X 'TEACH7 Σ The scan operator' 'problems' °
*(1997 5 3 11 48 5 356) °
FTEACH1 ÉFX 'TEACH1' 'Σ Review' 'exit ''TEACH1''' °
'''In lesson 4 we studied several forms of the reduction operator.''' °
'''To refresh your memory, write some expressions to do COMPRESSION''' °
'''REPLICATION, and N-WISE REDUCTION.''' 'do' °
'''Forgot what some of these are? Enter REVIEW 1 to see what these''' °
'''terms mean.'',r' 'do' °
'''We also learned about logical functions. Do you recall what these'' °
' '''are, and how they are used? If not, enter REVIEW 2.'',r' 'do' °
'''Finally, we studied two different methods of INDEXING of components °
''' °
'''of vectors. Try some expressions using indexing, or enter REVIEW 3. °
''' 'do' °
'''In this lesson we will study some more primitive functions. We will °
''' °
'''also produce a better solution to the problem of converting Arabic' °
'' '''numerals to Roman.''' 'do' °
'''We will also study another operator called SCAN, and a special symb °
ol''' '''called LAMP to allow comments in defined functions.'',r' °
''' WARNING! If you are not mathematically gifted, do NOT try out the °
''' °
''' suggested "detours" (i.e. upper case functions named in the text) °
,''' °
''' especially on a first reading of this lesson. Although some may g °
ive''' °
''' historic information, they tend to be technical, and will be best °
''' °
''' understood, only if you have some mathematical training. This add °
itional''' °
''' information is NOT essential for your mastery of APL2.''' 'do' °
'''Some of the functions described in this lesson are unconventional i °
n the''' °
'''sense that you are not likely to be familiar with them. As you read °
''' °
'''about these functions, you would do well to practice by entering yo °
ur''' °
'''own expressions whenever the prompt appears on a blank line.''' °
X 'endd' °
*(1997 5 3 11 50 19 420) °
FTEACH2 ÉFX 'TEACH2;RUNAV' 'Σ The lamp symbol' 'exit ''TEACH2''' °
''' COMMENTS'',r' °
'''There are occasions when it is desirable to write a line of comment °
s.''' °
'''Such a line is not to be considered to be part of an executable''' °
'''expression. There is a special APL2 symbol called LAMP Σ. Here are °
some''' '''examples of its usage:'',r' °
'''You may write a comment on your screen to be ignored by APL2:''' °
'show ''Σ This line is a comment line. it is not evaluated''' °
'''You may follow an expression to be evaluated by a comment:''' °
'show '' 5+/∞6 Σ Add the components of vector ∞6 5 elements at a t °
ime''' '''You may include a comment in a defined function algorithm''' °
'1 show ''RUNAV:(α+/∙)÷α Σ Running average of length α on vecto °
r ∙''' 'show ''5 RUNAV ∞7''' °
'''Incidentally, while IN THE LESSON, you can display a direct definit °
ion''' '''function by entering just the function name and a colon:''' °
'1 show ''RUNAV:''' °
'''The comment symbol is used most frequently as documentation of user °
X''' '''defined functions, as in the example of RUNAV.''' 'endd' °
*(1997 5 15 14 27 48 504) °
FTEACH3 ÉFX 'TEACH3' 'Σ Absolute value and residue' 'exit ''TEACH3''' °
''' ABSOLUTE VALUE''' °
'''Our modern mathematical notation is a collection of conventions''' °
'''that have been adopted by mathematicians over the past 500 years.'' °
' °
'''Even though these conventions have been very successful in providin °
g a''' °
'''vehicle for mathematical thought, they do have some inconsistencies °
.''' °
'''For a historic review of mathematical conventions, enter CONVENTION °
.'',r' 'do' °
'''One example of such an inconsistency is the commonly accepted notat °
ion''' °
'''to describe the absolute value of a number. Given a number A, its'' °
' °
'''absolute value is described as |A|. Clearly, |A| is a function, and °
''' °
'''as such it is entitled to a symbol, namely |. But for internal APL2 °
''' °
'''consistency, a single usage in front of the variable is called for. °
'',r' 'VECTOR╜²1 7 ²3 0 6 ²1 ²5 6 ²3 2' °
'show ''|²20'' ''VECTOR'' ''|VECTOR''' °
'''Absolute value is a monadic arithmetic function. It has no meaning °
for''' '''character data. Here are some examples of its usage:'',r' °
'''To find the largest and smallest absolute value:''' °
'show ''⌐/|VECTOR'' ''╛/|VECTOR''' '''To extract selected entries:''' °
'show ''(3<|VECTOR)/VECTOR'' ''(3>|VECTOR)/VECTOR''' °
'''Absolute value is also defined for complex numbers. Enter COMPLEX t °
o''' '''see a discussion of this subject''' 'do' °
''' RESIDUE'',r' °
'''The dyadic version of the | function is called RESIDUE. It returns' °
'' °
'''the residue after dividing the right argument by the left argument' °
',r' °
'show ''5|14'' ''╛14÷5'' ''14-2⌡5'' ''912|42875'' ''╛42875÷912'' ''428 °
75-47⌡912''' °
'''Residue can be applied to fractional, negative and complex numbers. °
''' '''To see about these aspects of residue, enter RESIDUE''' 'do' °
'''Since residue is a dyadic function, it can be used in reduction'',r °
' 'show ''|/5 12'' ''|/1,VECTOR''' °
'''Can you explain the result in the last expression?''' 'do' °
'''Here are some more examples showing how RESIDUE can be used to sele °
ct''' '''components of a vector.'',r' °
'show ''VECTOR╜|VECTOR'' ''VECTOR'' ''(2=5|VECTOR)/VECTOR'' ''(2⌠5|VEC °
TOR)/VECTOR''' °
'''In these last two examples all components of VECTOR with (=) and''' °
'''WITHOUT (⌠) residue equal to two after dividing by five are removed °
.'',r' °
'''If you have studied College Algebra, you might recognize residue''' °
'''as MODULO. It is the same thing. Enter MODULO to see an example of' °
'' °
'''the well known theorem by Gauss dealing with "quadratic residues".' °
X'' 'endd' °
*(1997 8 26 13 7 54 500) °
FTEACH4 ÉFX 'TEACH4' 'Σ Encode' 'exit ''TEACH4''' °
'''Most of the primitive arithmetic functions studied so far are eithe °
r''' °
'''well known or can be readily explained and understood by anyone who °
''' °
'''has minimal background in algebra. We will now introduce a primitiv °
e''' °
'''function that may be unfamiliar even to the most adept practitioner °
s''' '''of algebraic manipulations.'',r' 'do' °
'''The function is called ENCODE, and its symbol is(ÿ). Encode is a dy °
adic''' °
'''function, and it breaks down a number into residues after division' °
'' °
'''by cumulative products of the left argument. Here is an example'',r °
' 'show ''10 10 10ÿ234''' °
'''The process can be explained with the following sequence'',r' °
'show ''10|234'' ''10|(234-4)÷10'' ''10|(234-4+10⌡3)÷10⌡10''' °
'''The product of the elements of the left argument must equal or exce °
ed''' °
'''the value in the right argument. If this condition is satisfied, th °
en''' °
'''the result of this operation is a vector such that the following''' °
'''expression reproduces the right argument'',r' °
'show ''(2⌡100)+(3⌡10)+4⌡1''' °
'''To illustrate the generality of this concept, consider the followin °
g'',r' 'show ''(3µ11.1)ÿ234''' '''This is equivalent to'',r' °
'show ''11.1|234'' ''11.1|(234-.9)÷11.1'' ''11.1|(234-.9+9.9⌡11.1)÷11. °
1⌡11.1''' '''or'',r' 'show ''(1⌡11.1*2)+(9.9⌡11.1*1)+0.9⌡11.1*0''' °
'''The actual computation should proceed from the rightmost element of °
the''' °
'''left argument. Here is another example to illustrate this'',r' °
'show ''8 5 11ÿ234'' ''11|234'' ''5|(234-3)÷11'' ''8|(234-3+1⌡11)÷5⌡11 °
''' '''This can be represented as'',r' °
'show ''(4⌡5⌡11) + (1⌡11) + 3''' °
'''Encode requires that the product of the elements in the left argume °
nt''' °
'''MUST equal or exceed the largest value in the right argument.''' °
'''Notice that in this last example 234<8⌡5⌡11. If we had a vector as °
''' °
'''right argument, such that its product is less than 234, the encode' °
'' '''would return an invalid result'',r' °
'show ''⌡/3 5 11'' ''3 5 11|234'' ''(0⌡5⌡11) + (4⌡11) + 3''' °
'''One application of encode would be in the conversion of an angle in °
''' '''seconds to degrees, minutes and seconds'',r' °
X 'show ''360 60 60ÿ12345'' ''(3⌡60⌡60)+(25⌡60)+45''' 'endd' °
*(1997 5 3 13 57 35 520) °
FTEACH5 ÉFX 'TEACH5' 'Σ Decode' 'exit ''TEACH5''' °
'''Actually, the reverse problem is more likely to arise first. To''' °
'''convert an angle in degrees, minutes and seconds to just seconds''' °
'''minutes or degrees. Encode has an inverse operation (or DUAL), call °
ed''' '''DECODE. It is represented by the symbol (¥)'',r' °
'show ''10¥10 10 10ÿ243'' ''60¥24 60 60ÿ12345''' °
'''The concept of a DUAL is important in mathematics as well as in''' °
'''programming. If you want to find out more about it, enter DUAL.''' °
'do' °
'''The value in the left argument may be a single scalar if it is''' °
'''repeated. However, when the encode left argument is not repeated,'' °
' °
'''then the decode argument must contain a vector of the same lenth as °
''' '''that of the right argument'',r' °
'show ''5 6 7ÿ123'' ''0 6 7¥5 6 7ÿ123'' ''5 6 7¥5 6 7ÿ123''' °
'''We will return to encode and decode again, when we study arrays.''' °
'''Meanwhile, enter MORE 1 if you want to see more about these two''' °
'''primitive functions''' 'do' °
'''There is a relationship between decode and evaluation of polynomial °
Xs.''' '''If you have background in ALGEBRA, enter MORE 2''' 'endd' °
*(1997 5 3 13 57 20 460) °
FTEACH6 ÉFX 'TEACH6;T;ROMAN;RO;RX' °
'Σ Converting Arabic to Roman numerals; comments' 'exit ''TEACH6''' °
'''We can now rewrite the algorithm for the conversion of integers to' °
'' °
'''Roman numerals. This time we can do it for numbers up to 3999.''' °
'''Beyond that, the Romans used symbols not in the alphabet. For''' °
'''example 10000 was represented as Γ|π.'',r' °
'''We begin by defining function ROMAN'',r' °
'1 show ''ROMAN:RO 10 10 10 10ÿ∙:∙>3999:''''This number is too large'' °
''''' °
'''If the argument is less than 3999, the encode function converts the °
''' '''integer to a vector of digits'',r' 'show ''10 10 10 10ÿ2345''' °
'''This vector then becomes the right argument to defined function RO. °
''' '''We can write function RO as'',r' °
'T╜''RO:(∙[1]µ''''M''''),(''''CDM''''RX ∙[2]),(''''XLC''''RX ∙[3]),''' °
'IVX''''RX ∙[4]''' '1 show T' °
'''Function RO catenates four expressions. The first one merely displa °
ys''' °
'''as many symbols M, as there are thousands. The next three expressio °
ns''' '''each convert a digit into the apropriate Roman expression.''' °
'''Function RX is defined by'',r' °
'1 show ''RX:((∙>4)µα[2]),(5|∙)µα[1]:4=5|∙:α[1,2+∙=9]''' °
'''Since ∙ is a single digit value, RX tests if this value is 4 or 9.' °
'' °
'''This is done with the expression 4=5|∙. If this returns 1, then RX' °
'' °
'''returns the first symbol of the left argument, followed by the''' °
'''second or third, depending whether it is a 4 or 9'',r' °
'show ''W╜9'' ''''''IVX''''[1,2+W=9]'' ''W╜4'' ''''''CDM''''[1,2+W=9]' °
'' °
'''If the digit is not 4 or 9, then the left expression is evaluated.' °
'' '''In this case, if the value is greater than 4, then the second''' °
'''symbol of the left argument is catenated to the first symbol of the °
''' °
'''left argument repeated a number of times equal to the remainder whe °
n''' '''divided by 5'',r' °
'show ''W╜3'' ''''''XLC''''[((W>4)µ2),(5|W)µ1]'' ''W╜7'' ''''''IVX'''' °
[((W>4)µ2),(5|W)µ1]''' '''We can now test function ROMAN''' °
'show ''ROMAN 2345'' ''ROMAN 27'' ''ROMAN 1990''' °
'''This solution is not necesarily the shortest or even the best. As w °
e''' °
'''learn more about APL2, we may try to improve on this solution.'',r' °
X '''Now let us study a new operator''' 'endd' °
*(1997 5 4 13 59 44 568) °
FTEACH7 ÉFX 'TEACH7;V' 'Σ The scan operator' 'exit ''TEACH7''' °
''' THE SCAN OPERATOR'',r' °
'''The reduce operator inserts a function between every pair of elemen °
ts''' '''of a vector'',r' 'show ''+/(÷∞25)*3'' ''+/(÷∞50)*3''' °
'''What if we want to see all the intermediate values of this computat °
ion?''' °
'''There is an operator that will do that. It is called the SCAN opera °
tor.''' °
'''The symbol is \ and it can be obtained by pressing the upper case / °
.'',r' 'show ''+\∞5'' ''⌡\∞5'' ''÷\2 2 2 2 2 2 2 2''' °
'''The first example shows a sequence often called the triangular numb °
ers.''' '''It arises from adding points from a triangular shape'',r' °
''' Ω'',r '' Ω Ω'',r '' Ω Ω Ω'',r,'' : : :'',r' °
'''The second example is a special function, called the FACTORIAL. APL °
2''' °
'''has a special symbol for this function, but we will not study it no °
w.''' 'do' °
'''The third example illustrates the process of evaluation for scan.'' °
,r' 'show ''÷\6µ2'' ''÷/2'' ''÷/2 2'' ''÷/2 2 2'' ''÷/2 2 2 2''' °
'''and so on. Each element of the result is equivalent to the reductio °
n''' °
'''of the first N elements. You should recall that when a vector is''' °
'''reduced, the evaluation proceeds from RIGHT TO LEFT. So for the''' °
X '''third element we do not get (2÷2)÷2, but rather 2÷(2÷2)!''' 'endd' °
XCa 1 3 IVX °
*(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]' °
XCalpha 1 26 ABCDEFGHIJKLMNOPQRSTUVWXYZ °
*(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' °
XCb 1 0 °
Ac╜('R0')('(∙[1]µ''M''),(''CDM'' R1 ∙[2]),(''XLC'' R1 ∙[3]),''IVX'' R1 °
X∙[4]')('ΣDD ') °
XCd 0 ½ °
*(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 12 12 26 34 436) °
Ferase ÉFX °
'erase;T;EXIT;GO;HELP;DISPLAY;REVIEW;CONVENTION;MORE;DUAL;MODULO;RESID °
UE;COMPLEX;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' 'T╜ÉNL 4' '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 °
XNn 0 59 °
*(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' °
XCp 1 2 " °
*(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 12 3 40 432) °
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)=8+∞3)/L9,L10,L11' '''This rule number is undefined'' ╪ ╕' °
'L9:╕(V>1)/L9X' °
''' RULE 9: To produce a quote inside a character string, enter''' °
''' the quote twice.'',2µr' '╕(0=V)/L0' °
'L9X:''This is used in most other programming languages.''' '╕L0' °
'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)/L0' °
'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''''''' '╕L0' °
'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)/L0' °
'L11X:''The expression in brackets need not be a vector. It could be a °
n''' '''array as in the next example'',r' °
'show ''''''CALIFORNIA''''[3 3µ?9µ10]'' ''(∞4)[3 3µ∞4]''' °
'''For rules not described in this lesson, see workspace INDEX''' °
X 'L0:do' '╕(0=µW╜1╟W)/0' '╕L' °
*(1997 5 31 11 58 30 608) °
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.''' '╕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' °
XCs 1 2 " °
*(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' °
XNt 0 0 °
*(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' °
XCu 1 2 IV °
XCuc 1 26 ABCDEFGHIJKLMNOPQRSTUVWXYZ °
XNw 0 5 °
XCx 0 ! °