home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
teach.zip
/
TEACH20A.ATF
< prev
next >
Wrap
Text File
|
1997-09-19
|
53KB
|
653 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 °
*(1996 4 6 16 11 2 220) °
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' °
*(1997 8 21 13 4 39 408) °
FCALCULUS ÉFX 'CALCULUS' 'Σ Review of differentiation and integration' °
'''Every polynomial, P(X), can be represented as a curve on a graph.'' °
' °
'''This has been known since the French mathematician Renee Descartes' °
'' °
'''published an appendix called "La Geometrie" in his famous book''' °
'''entitled "Discourse on Method". From this discovery in 1673,''' °
'''evolved many branches of mathematics, particularly one called''' °
'''Analytic Geometry.'',r' °
'''A CARTESIAN plot (named after Descartes) is a graph designed to''' °
'''display data. It is represented by two straight lines drawn at righ °
t''' '''angles on a graph paper.''' 'do' 'vec' °
'''The horizontal line is called the INDEPENDENT coordinate. It is als °
o''' °
'''called the ABSCISSA. The vertical line is the DEPENDENT variable,'' °
' °
'''also known as the ORDINATE. Points to be plotted on this graph are' °
'' °
'''pairs of numbers, such as the rows of the N⌡2 array A shown on the' °
'' '''graph'',r' 'show ''É╜A╜3 2µ.6 2 1 1 1.4 .5''' 'do' °
'''A polynomial P(X) can be drawn by plotting the number pairs (X,P(X) °
) on''' °
'''such a graph. The mathematicians of the 17th century discovered tha °
t''' °
'''the slope of the graph (X,P(X)) at X can be calculated using a simp °
le''' °
'''formula. The formula consists of changing terms of the polynomial i °
n''' '''the following way:'',r' °
''' 1. multiply the coefficient by the power of X''' °
''' 2. reduce the power of X by 1'',r' °
'''For example, the slope at any point X of the polynomial'',r' °
''' 2X + 3XX + 5XXX'',r' '''is given by'',r' °
''' 2 + 6X + 15XX''' 'do' °
'''Other mathematicians also discovered that the area under the polyno °
mial''' '''P(X) can be calculated with another simple formula:'',r' °
''' 1. Increase the power of each term by 1''' °
''' 2. Divide the coefficient by the new power'',r' °
'''Therefore the area under 2X + 3XX + 8XXX from 0 to X is given by'', °
r' ''' XX + XXX + 2XXXX''' 'do' °
'''It was the genius of Newton and Leibnitz to recognize these two''' °
'''operations as duals of each other. Today, the process of finding th °
e''' '''slope is called "taking the DERIVATIVE" and the process of''' °
'''finding the area under a curve is called "INTEGRATION".'',r' °
'''As we study primitive (and derived) APL2 functions, we may also''' °
'''learn about their derivatives and integrals. These are subjects tha °
t''' °
'''are studied in DIFFERENTIAL (derivatives) and INTEGRAL CALCULUS.''' °
'do' °
'''Although it is not our intention to teach calculus here, there is'' °
' '''one formula for finding derivatives that should be mentioned'',r' °
''' [1] d(Y)/d(X) = d(Y)/d(Z) ⌡ d(Z)/d(X)'',r' °
'''To illustrate the usage of this formula, consider finding the''' °
'''derivative of Y╜(1-X)*²1'',r' °
'''Calling the term (1-X) temporarily Z, we have Y╜Z*²1. Then applying °
''' '''[1] we have'',r' °
''' d(Y)/d(X) = (-Z*²2) ⌡ ²1 or'',r' °
X ''' = (1-X)*²2'',r' 'endd' °
*(1997 8 21 13 6 16 324) °
XFDEGREES ÉFX 'u╜DEGREES w' 'ΣDD' 'u╜180⌡w÷Ω1' °
*(1997 9 14 12 30 44 504) °
XFDISCLAIMER ÉFX 'DISCLAIMER' 'Σ Copyright statement' 'disclaimer' °
*(1996 4 6 16 11 2 220) °
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 11 2 220) °
FEXIT ÉFX 'EXIT' 'Σ Exit from function' '''To log off type: )OFF''' °
X '╕' °
*(1997 8 21 13 5 51 460) °
XFFOO ÉFX 'u╜FOO w' 'ΣDD' 'u╜+/w*0,∞20' °
*(1996 4 6 16 11 2 220) °
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 21 13 2 51 448) °
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╜5),'' 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 Listing of binding rules''' °
X '''CALCULUS Differentiation and integration''' 'endd' °
*(1997 8 21 13 5 48 448) °
XFPASCAL ÉFX 'u╜PASCAL w' 'ΣDD' 'u╜(0,∞w)!w' °
*(1997 8 21 13 6 17 328) °
XFRADIANS ÉFX 'u╜RADIANS w' 'ΣDD' 'u╜Ωw÷180' °
*(1997 9 5 12 8 6 228) °
FTEACH ÉFX 'TEACH' 'Σ Start lesson #20: APL2 by Zdenek V JIZBA' °
'exit ''TEACH''' 'initialize' °
'TEACH1 Σ Newton''s binomial expansion, analysis, infinite series' °
'TEACH2 Σ Convergence of infinite series' °
'TEACH3 Σ Measuring angles, degrees and radians' °
'TEACH4 Σ Theorems of Thales and Pythagoras; circular functions' °
X 'TEACH5 Σ Additional trigonometric functions' 'problems' °
*(1997 7 19 12 10 57 488) °
FTEACH1 ÉFX 'TEACH1;T' 'Σ Review power function and logarithm' °
'T╜ÉEX■''PASCAL'' ''FOO''' °
'''In the previous lesson we used the problem of interest rates to''' °
'''study the power function, the logarithm, and even the factorial and °
''' °
'''binomial functions. We learned that a number can be raised to power °
s''' '''that are not integers'',r' 'show ''5.67*3.21''' °
'''and we also learned that the factorial function works on numbers''' °
'''other than integers, (when it is called the Gamma function)'',r' °
'show ''!0.567''' °
'''We also defined a function to calculate the Pascal coefficients''' °
'''for a polynomial of degree N'',r' °
'1 show ''PASCAL:(0,∞∙)!∙'' ''PASCAL 6''' °
'''These coefficients can also be calculated starting with the exponen °
t''' '''of a polynomial such as (1 + X)*6'',r' °
'''1 + 6X + 15XX + 20XXX + 15XXXX + 6XXXXX + XXXXXX'',r' °
''' 1. We begin with the 1''' °
''' 2. We then multiply 1⌡(6-0)÷1 to get 6''' °
''' 3. Next we multiply 6⌡(6-1)÷2 to get 15''' °
''' 4. We continue with 15⌡(6-2)÷3 to get 20''' °
''' 5. And next 20⌡(6-3)÷4 to get 15''' °
''' 6. The next term is 15⌡(6-4)÷5 obtaining 6''' °
''' 7. And finally 6⌡(6-5)÷6 for the final 1''' 'do' °
'''On June 13th 1676, Isaac Newton wrote a letter to Henry Oldenburg'' °
' '''to be transmitted to Wilhelm Leibnitz. In this letter Newton''' °
'''described his discovery years earlier that the rules for expanding' °
'' °
'''binomial powers apply to ALL NUMBERS N. This discovery eventually'' °
' °
'''led to a new form of mathematics called ANALYSIS. It deals with''' °
'''expansions that have no endings. These formulas are now called''' °
'''INFINITE SERIES, and form an essential tool in modern mathematics.' °
',r' °
'''Just as an illustration, consider the expansion of (1-X)*N when N=² °
1'',r' ''' 1 (1⌡(²1-0)÷1) (²1⌡(²1-1)÷2) (1⌡(²1-2)÷3) ... or'',r' °
''' 1 ²1 1 ²1 ...''' °
'''but because the sign of X*K also alternates, we get 1÷1-X equals'', °
r' ''' 1 + X + XX + XXX + XXXX +...'',r' °
'''In APL2 we can form this expression as'',r' °
'1 show ''FOO:+/∙*0,∞20''' '''Here are some examples'',r' °
'show ''÷0.9'' ''FOO 0.1'' ''÷1.1'' ''FOO ²0.1''' °
'''At this point, if you have not been exposed to a math course called °
''' °
'''calculus, you may wish to enter CALCULUS for a short briefing.''' °
X 'endd' °
*(1997 7 19 12 15 13 332) °
FTEACH2 ÉFX 'TEACH2' °
'Σ Convergence, derivatives and integrals of infinite series' °
'''You might have noticed that as X gets larger, the comparison betwee °
n''' '''÷(1-X) and FOO X gets less accurate'',r' °
'show ''÷.6'' ''FOO .4'' ''÷.1'' ''FOO .9''' °
'''This is because FOO evaluates only the first 20 terms of the series °
'',r' '1 show ''FOO:'' ''+/1,.9*∞40'' ''+/1,.9*∞80'' ''+/1,.9*∞160''' °
'''The RATE OF CONVERGENCE slows down, and finally when X is 1 or''' °
'''greater, the summation no longer converges, but DIVERGES'',r' °
'show ''÷²1'' ''FOO 2'' ''÷5'' ''FOO ²4''' °
'''The problem of convergence and divergence of infinite series took'' °
' °
'''250 years before it was adequately understood by mathematicians.''' °
'''We mention it here, because it has bearing on APL2 algorithms.''' °
'do' °
'''Before we leave infinite series, consider the derivaive and the''' °
'''integral of Y╜(1-X)*²1. The derivative is DY╜(1-X)*²2 and the''' °
'''integral is IY╜╡(1-X). We can verify these relations by working''' °
'''with the series'',r' ''' Y╜ 1 + X + XX + XXX + ...'',r' °
'''For the derivative, we have'',r' °
''' DY╜ 1 + 2X + 3XX + 4XXX + ...'',r' °
'''and for the integral we have'',r' °
''' IY╜ X + (XX÷2) + (XXX÷3) + ...'',r' °
'''With APL2 these expressions can be readily evaluated'',r' °
'show ''÷(.5)*2'' ''+/(∞25)⌡1,.5*∞24''' °
'show ''╡.5'' ''-+/(÷∞35)⌡.5*∞35''' °
'''This last example shows that transcendental functions can be expres °
sed''' '''as infinite series. We will see more on that later on.''' °
X 'endd' °
*(1997 7 19 12 23 42 480) °
FTEACH3 ÉFX 'TEACH3;T' 'Σ Circle functions' °
'T╜ÉEX■''DEGREES'' ''RADIANS''' '''MEASURING ANGLES'',r' °
'''So far whenever we discussed a variable such as X, it was inplicitl °
y''' °
'''assumed to be a quantity that increases in a "straight line" way''' °
'''in the sense of a ruler measuring dimensions. The idea that a varia °
ble''' °
'''could also be thought of as measuring angles appears at first odd.' °
'' °
'''After all to measure angles we go "in circles" not in a straight''' °
'''line. Historically, this seeming inconsistency did not arise, becau °
se''' °
'''the earliest angular measurements were made by astronomers. To them °
''' °
'''the separation between stars were merely distances, and not angles. °
''' °
'''On the other hand, dating as far back as ancient Mesopotamia, the a °
ngles''' °
'''of a circle were divided into 360 units, called DEGREES. Some of th °
e''' °
'''earliest tables dealing with angles were those of Ptolemy who sough °
t''' '''to solve problems in SPHERICAL TRIGONOMETRY.''' 'do' °
'''One of the earliest problems tackled by Greek mathematicians was''' °
'''the SQUARING OF THE CIRCLE. There were some ingenious attempts, but °
''' °
'''none produced a useful result. However in the third century BC''' °
'''Archimedes succeeded in developing a method for approximating the a °
rc''' °
'''length of a circle. His method consisted of the measurement of the' °
'' °
'''perimeter of inscribed and circumscribed regular polygons. As the'' °
' °
'''number of sides of the polygons increase, the two perimeters approa °
ch''' '''that of the circular arc length.'',r' °
'''Another achievement along this line by Archimedes was a demonstrati °
on''' °
'''of the relation between the arc length of a circle, and the spiral' °
'' '''that bears his name.'',r' °
'''Historically, therefore, we have two distinct concepts for the''' °
'''measurement of angles. On the practical level (engineering, astrono °
my''' °
'''etc), we measure angles in degrees, minutes and seconds. In theoret °
ical''' °
'''studies (mathematics, physics), angles are measured in units of arc °
''' °
'''length called RADIANS. A radian is defined to be the length of a''' °
'''circular arc that has the same length as the radius of the circle.' °
'' 'do' °
'''Why do we mention all of this background? It is because most of us' °
'' °
'''learn to measure angles in degrees, minutes, and seconds, while''' °
'''the APL2 primitive CIRCLE function deals with arc length in radians °
.'',r' 'show ''Ω1'' ''Ω2''' °
'''The right argument to Ω is in units of half circle. In other words, °
''' °
'''the arc length of a circle spanning 180 degrees is the value given °
by''' °
'''Ω1. It also happens to be one of the most important constants of''' °
'''mathematics, called PI.''' 'do' °
'''We can define two functions: DEGREES and RADIANS, to convert from'' °
' '''one of these units to the other'',r' °
'1 show ''DEGREES:180⌡∙÷Ω1'' ''RADIANS:Ω∙÷180''' °
'''DEGREES returns radian argument in degrees and decimal fraction of' °
'' '''degrees'',r' 'show ''DEGREES Ω.5'' ''DEGREES Ω÷3''' °
'''RADIANS returns a degree right argument in radians'',r' °
'show ''6⌡RADIANS 30''' °
'''As an exercise, you might try defining an APL2 function that would' °
'' °
'''convert radian measures to degrees, minutes and seconds. This funct °
Xion''' '''should work for an arbitrary numeric array!''' 'endd' °
*(1997 7 19 12 33 16 416) °
FTEACH4 ÉFX 'TEACH4' 'Σ Triangle functions' '''TRIANGLE FUNCTIONS'',r' °
'''The earliest known proof of a mathematical theorem is one that''' °
'''deals with geometrical figures. The Greek merchant, astronomer''' °
'''and mathematician Thales of Miletus (640 - 546 BC) proved the''' °
'''theorem of similar triangles that bears his name'',r' 'tri2' °
'''In the two triangles, the inner angles are the same. By Thales''''' °
'' '''theorem, the ratios are equal'',r' °
''' (oa÷OA)=(ob÷OB)=(ab÷AB)'',r' 'do' °
'''Another important theorem of antiquity was that of Pythagoras''' °
'tri' °
'''The diagonal OB of a right angle triangle OAB is called the''' °
'''HYPOTHENUSE. By the theorem of Pythagoras, the following relation'' °
' '''holds:'',r,r,'' (OB*2)=(OA*2)+(AB*2)'',r' 'do' °
'''By convention, we can take the length OB=1, because by the theorem' °
'' °
'''of Thales we can always re-scale to an arbitrary sized triangle of' °
'' '''the same "shape". Therefore, if OB=1, then OA<1 and AB<1 for''' °
'''all right angle triangles. Given values [0≤X≤1] and [0≤Y≤1] for a'' °
' '''right angle triangle, we have the constraint'',r' °
''' 1=+/(X,Y)*2'',r' °
'''We can use this equation to find Y, given X'',r' °
'show ''X╜.3'' ''Y╜(1-X*2)*0.5'' ''Y''' °
'''There is a dyadic APL2 primitive to do this'',r' °
'show ''0ΩX'' ''0Ω0ΩX ''' °
'''From the last expression it is clear that 0ΩX is its own dual.''' °
'''It is also clear that the argument to 0Ω should be in the range''' °
'''0≤X≤1. For values outside this range the formula (1-X*2)*.5 will''' °
'''produce the square root of a negative number.''' °
'show ''X╜2'' ''(1-X*2)*.5'' ''0ΩX''' 'do' °
'''Let us look again at a right angle triangle'',r' 'tri' °
'''Since the length of the hypotenuse is 1, only one other quantity''' °
'''is sufficient to fully specify the right angle triangle. We have''' °
'''already seen that knowing AB we can determine OA using the dyadic'' °
' °
'''0Ω primitive. We can also determine the triangle knowing the arc''' °
'''length α. Given α we can obtain AB using another dyadic circular''' °
'''function, namely 1Ω'',r' 'show ''1Ω1''' °
'''The right argument in the above expression MUST BE in radians. The' °
'' °
'''value returned is the height of the side opposite to the angle α.'' °
' °
'''This function is called the SINE function. It is a PERIODIC one,''' °
'''because an angle measures the amount of rotation'',r' °
'show ''1ΩRADIANS 30'' ''1ΩRADIANS 390'' ''1ΩRADIANS 750''' °
'''Rotations greater than 360 are equivalent to rotations of the''' °
'''residue after dividing by 360'',r' 'show ''360|30 390 750''' °
'''By convention, positive rotation is counter clockwise starting from °
''' °
'''the direction of the positive X axis. Counter clockwise rotation''' °
'''is represented by negative numbers'',r' °
'show ''1ΩRADIANS ²330 ²690 ²1050''' '''since'',r' °
'show ''360|²330 ²690 ²1050''' °
'''(The word "sine" appears to have been used first around the 14th''' °
'''century as a mis-translation of an Arabic word to "sinus" meaning'' °
X' '''gulf.)''' 'endd' °
*(1997 7 21 14 20 3 328) °
FTEACH5 ÉFX 'TEACH5;X;Y;i' 'Σ More trig functions' °
'''Since only one measurement is needed to specify a right angle''' °
'''triangle with unit hypothenuse, then given α, the angle opposite''' °
'''to side AB is also determined. This angle is called the COMPLEMENTA °
RY''' °
'''angle (or CO-angle). For every primitive function defined on α, the °
re''' °
'''is a CO-function defined for the complementary angle. The side OA i °
s''' °
'''the sine of the CO-angle of α, and therefore it is also known as th °
e''' °
'''COSINE of α. The APL2 primitive dyadic circle function for the cosi °
ne''' '''is given by 2Ω'',r' °
'show ''2ΩRADIANS 30'' ''0Ω2ΩRADIANS 30''' °
'''It should be pointed out here that both the left and the right''' °
'''arguments of a circle function can be vectors or arrays'',r' °
'show ''1 2ΩRADIANS 30 90'' ''(2 2µ1 2 2 1)ΩRADIANS 30''' °
'show ''1ΩRADIANS É╜30+2 2µ0 90 ²90 0''' 'tri' °
'''So far we have developed functions to calculate OA from AB, AB from °
''' °
'''OA, AB from α and OA from α. To complete the pattern, we need a''' °
'''function to return α given AB or OA. Since such functions are duals °
''' °
'''of SINE and COSINE, their names are related, and in fact are ARC SI °
NE''' °
'''and ARC COSINE. The APL2 expression is also related, namely ²1Ω and °
''' '''²2Ω'',r' 'show ''DEGREES ²1 ²2Ω1 2ΩRADIANS 25 65''' °
'''When the angle is 0 or an integral multiple of 90 degrees, the''' °
'''triangle degenerates into a horizontal or vertical straight line.'' °
' '''Despite this, the circle functions still return values'',r' °
'show ''1Ω0'' ''²1Ω0''' °
'''The sine of 0 and arc-sine of zero represent the limiting value of' °
'' '''the line AB and the angle α as the triangle becomes a single''' °
'''horizontal line. The cosine and arc-cosine return respectively the' °
'' '''unit radius, and the arc'',r' 'show ''2Ω0'' ''²2Ω1''' °
'''When α approaches 90 degrees, the triangle degenerates into a verti °
cal''' '''line'',r' 'show ''1 2ΩΩ.5'' ''DEGREES ²1 ²2Ω1 0''' °
'''Consider now the following figure'',r' 'tan' °
'''The line OB is the same length as OC. Therefore, since the circle'' °
' '''passes through point C, the line CD is tangent to the circle.''' °
'do' °
'''We can find the length of CD by applying the theorem of Thales'',r' °
''' (AB÷OA)=CD÷OC'',r' '''Since OC=1, we therefore have'',r' °
''' CD=(tan α)=(sin α)÷cos α'',r' °
'''The TANGENT is another important circle function, and in APL2 it''' °
'''is defined by 3Ω. Not surprisingly ²3Ω is called ARC TANGENT'',r' °
'show ''3ΩRADIANS 45'' ''DEGREES ²3Ω1''' °
'''The COTANGENT of α naturally is given by (cos α)÷(sin α).''' 'do' °
'''Finally, on the same figure we could also define the length OD''' °
'''Again by the theorem of Thales we have'',r' °
''' (OB÷OA)=(OD÷OC)'',r' °
'''The quantity OC is called SECANT, and by replacing OB and OA, we''' °
'''have'',r' ''' (sec α)=1÷cos α'',r' °
'''Since this quantity is so readily obtained using 2Ω, it has not''' °
'''been defined by a primitive APL2 function. (The CO-angle function'' °
' '''of secant is natually called COSECANT.)''' 'do' °
''' OTHER CIRCULAR FUNCTIONS'',r' °
'''APL2 does not stop at 3Ω. There are additional circle functions,''' °
'''but here we will merely mention them. Circle functions 4 5 6 7,''' °
'''and ²4 ²5 ²6 ²7 are associated with properties of the HYPERBOLA.''' °
'''These are analogous to those of circular functions. To wit, 4Ω is'' °
' '''the hyperbolic equivalent of 0Ω and is given by'',r' °
'show ''X╜.6'' ''(1+X*2)*.5'' ''É╜Y╜4ΩX''' °
'''The formula for ²4Ω is'',r' 'show ''(²1+Y*2)*.5'' ''²4ΩY''' °
'''5Ω and ²5Ω are called HYPERBOLIC SINE and HYPERBOLIC ARC SINE''' °
'''6Ω and 7Ω follow the same pattern. 6Ω is the HYPERBOLIC COSINE''' °
'''and 7Ω is the HYPERBOLIC TANGENT. We will not pursue here these''' °
'''specialized functions.''' 'do' °
'''Circle functions 8 9 10 11 12, and ²8 ²9 ²10 ²11 ²12 deal with''' °
'''complex numbers. The result of 8ΩX will depend on whether X is''' °
'''greater than zero. If X less than 0, then 8ΩX will return the''' °
'''quantity (²1-X*2)*.5. If X is zero or greater, 8ΩX will return the' °
'' °
'''negative of this expression. The expression ²8ΩX returns the 8ΩX''' °
'''with signs on both the real and imaginary components reversed.'',r' °
'show ''8Ω5J1 .5J1'' ''²8Ω5J1 .5J1''' °
'''Here is a listing of the remaining cicular functions'',r' °
''' EXPRESSION RETURNS''' °
''' 9ΩX Real component of X''' ''' ²9ΩX X''' °
''' 10ΩX Absolute value of X''' °
''' ²10ΩX Complex conjugate of X''' °
''' 11ΩX Imaginary component of X''' °
''' ²11ΩX X multiplied by 0J1''' °
''' 12ΩX Phase of X''' °
''' ²12ΩX Exponential of X times 0J1'',r' °
'show ''X╜1J2'' ''(4 2µ9 ²9 10 ²10 11 ²11 12 ²12)ΩX''' °
'show ''(X⌡²10ΩX)*.5'' ''(X⌡+X)*.5'' ''10ΩX''' °
X 'show ''i╜0J1'' ''*i⌡X'' ''²12ΩX''' 'endd' °
*(1996 4 6 16 11 3 224) °
FTIME ÉFX 'U╜V TIME W;T' 'Σ Measure execution time of W' °
X 'U╜60 60 1000¥²3╞ÉTS' 'T╜»■VµΓW' 'U╜(,-U-60 60 1000¥²3╞ÉTS)÷V' °
XNX 0 2 °
XNY 0 0.9539392014169457 °
*(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]' °
*(1996 4 6 16 11 3 224) °
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 8 21 13 0 55 456) °
Ferase ÉFX °
'erase;t;EXIT;GO;HELP;DISPLAY;BIND;TIME;CALCULUS;tri2;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 °
*(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' °
*(1996 4 6 16 11 3 224) °
Fpause ÉFX 'V pause W;T' °
'Σ Pause, then print W V spaces right and return' °
X 'T╜(0=ÉNC ''V'')doif ''V╜6''' 'do' '(Vµ'' ''),W' 'do' °
*(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' °
*(1996 4 6 16 11 3 224) °
Ftan ÉFX 'U╜tan' 'Σ Draw 2d vector in plane' °
'U╜r,'' D'',r' 'U╜U,'' / |'',r' °
'U╜U,'' B / |'',r' °
'U╜U,'' /| |'',r '' / | |'',r,'' / | °
|'',r' °
'U╜U,'' / | |'',r,'' / α | |'',r,''O²²²²²²²²²²A²²² °
X²C'',r' °
*(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' °
*(1996 4 6 16 11 3 224) °
Ftri ÉFX 'U╜tri' 'Σ Draw 2d vector in plane' 'U╜r,'' B'',r' °
'U╜U,'' /|'',r '' / |'',r,'' / |'',r' °
X 'U╜U,'' / |'',r,'' / α |'',r,''O²²²²²²²²²²A'',r' °
*(1996 4 6 16 11 3 224) °
Ftri2 ÉFX 'U╜tri2' 'Σ Draw 2d vector in plane' °
'U╜r,'' B'',r '' /|'',r' °
'U╜U,'' / | b '',r' °
'U╜U,'' / | /|'',r' °
'U╜U,'' / | / |'',r' °
'U╜U,'' / | / |'',r' °
X 'U╜U,''O²²²²²²²²²²A o²²²²²²a'',r' °
XCuc 1 26 ABCDEFGHIJKLMNOPQRSTUVWXYZ °
*(1996 4 6 16 11 3 224) °
Fvec ÉFX 'U╜vec' 'Σ Draw 2d vector in plane' °
'U╜r,''2- ° '',r '': '',r,''1- °'',r' °
X 'U╜U,'' : °'',r,''0|....|....|'',r,'' 0 1 2'',r' °