home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / teach.zip / TEACH3A.ATF < prev    next >
Text File  |  1997-09-16  |  76KB  |  930 lines

  1. XNÉIO 0 1                                                                      °
  2. XNÉCT 0 1E²13                                                                  °
  3. XCÉFC 1 6 .,*0_²                                                               °
  4. XNÉRL 0 282475249                                                              °
  5. XCÉPR 1 1                                                                      °
  6. XCÉLX 1 5 TEACH                                                                °
  7. *(1997 4 27 12 39 30 516)                                                      °
  8.  FALGORITHM ÉFX 'ALGORITHM' 'Σ Origin of the word algorithm'                   °
  9.   '''The word ALGORITHM has an interesting history. The Arab mathematici       °
  10.  an'''                                                                         °
  11.   '''al-Khwarzimi adopted the hindu numerals as his notation when he'''        °
  12.   '''wrote his popular textbook on mathematics. (The title was ''''''''A       °
  13.  l-jabr'''                                                                     °
  14.   '''wa''''l muqabalah'''''''', which incidentally is the origin of the        °
  15.  word'''                                                                       °
  16.   '''ALGEBRA.) The usage of hindu numerals was adopted in Europe, and th       °
  17.  e'''                                                                          °
  18.   '''symbolism was named after its (presumed) author: al-Khwarzimi. With       °
  19.  '''                                                                           °
  20.   '''time this became ''''algorism'''' and eventually ''''algorithm''''.       °
  21.   As the'''                                                                    °
  22.   '''word changed, so did its meaning. ALGORITHM today means a specific'       °
  23.  '' '''process, or procedure, to be used in solving a problem.'''              °
  24. X 'endd'                                                                       °
  25. *(1997 5 18 12 35 31 472)                                                      °
  26.  FCOMPLEX ÉFX 'COMPLEX W;N;A;B;C;D;X'                                          °
  27.   'Σ Power, floor and ceiling in the complex domain' '╕(W=1 2)/L1 L2'          °
  28.   'L1:''If you try to take a root of a negative number, you may find str       °
  29.  ange''' '''looking results.'',r' 'show ''²2*3'' ''²8*÷3'''                    °
  30.   '''Although ²2 is a valid cube root of ²8, the response is a complex n       °
  31.  umber.'''                                                                     °
  32.   '''Here is why! Recall from algebra that given an integer N, there exi       °
  33.  st N'''                                                                       °
  34.   '''distinct roots of a number. In selecting one of these N roots, APL2       °
  35.  '''                                                                           °
  36.   '''ALWAYS returns the FIRST COUNTER-CLOCKWISE one in the complex plane       °
  37.  .''' '╕L0'                                                                    °
  38.   'L2:''Although floor and ceiling can be applied to numbers in the comp       °
  39.  lex'''                                                                        °
  40.   '''domain, the behavior of these two functions requires considerable''       °
  41.  '                                                                             °
  42.   '''explanation. In general, one can say that FLOOR and CEILING of comp       °
  43.  lex'''                                                                        °
  44.   '''numbers generates complex numbers with integer values. What these''       °
  45.  '                                                                             °
  46.   '''values are depends on the position of the number within the integer       °
  47.  ''' '''rectangle that bounds that number.'',r'                                °
  48.   '''Consider first a point exactly in the middle of that rectangle'',r'       °
  49.   'show ''N╜.5J.5'''                                                           °
  50.   '''We will replicate this point in all four quadrants of the complex p       °
  51.  lane'',r' 'show ''N╜N,+N'' ''N╜N,-N'' ''N'''                                  °
  52.   '''Now, we will apply ceiling and floor'',r' 'show ''⌐N'' ''╛N'''            °
  53.   '''Studying the result, one might come to the conclusion that ceiling        °
  54.  will'''                                                                       °
  55.   '''move to the upper left integer corner, while floor will place the''       °
  56.  '                                                                             °
  57.   '''result in the lower right integer corner. Unfortunately, this is NO       °
  58.  T'''                                                                          °
  59.   '''the case in general. To see how these functions work, let us consid       °
  60.  er'''                                                                         °
  61.   '''how CEILING will work in the unit square. We have already seen that       °
  62.  '''                                                                           °
  63.   '''⌐.5J.5 returns 0J1. We will now generate a vector that spans the un       °
  64.  it''' '''square in the range (0,1) and (0,i)'',r'                             °
  65.   'show ''X╜0 .2 .4 .5 .6 .8 1'' ''⌐X'''                                       °
  66.   '''Along the real axis, the function produces 0 and 1 as expected. Now       °
  67.  ''' '''we will add a complex component to X'',r'                              °
  68.   'show ''X+0J.2'' ''⌐X+0J.2'''                                                °
  69.   '''The first two entries (0J.2 and .2J.2) return 0J1, The last entry''       °
  70.  '                                                                             °
  71.   '''(1J.2) returns 1J1. To see the pattern, we will increment X again''       °
  72.  ,r' 'show ''X+0J.4'' ''⌐X+0J.4'''                                             °
  73.   '''Now only two points (.5J.4 .6J.4) go to 1. The first three go to 0J       °
  74.  1 and'''                                                                      °
  75.   '''the last two go to 1J1. To complete the pattern, consider points wh       °
  76.  ere''' '''the complex component is equal or greater than 0.5.'',r'            °
  77.   'show ''X+0J.5'' ''⌐X+0J.5'' ''X+0J.8'' ''⌐X+0J.8'''                         °
  78.   '''The pattern can be summarized by the following diagram'',r'               °
  79.   'square'                                                                     °
  80.   '''Take the diagonal from 0 up to the point (0.5J0.5). All points belo       °
  81.  w'''                                                                          °
  82.   '''this diagonal go to 1. On the diagonal from (0.5J0.5) to 1, all poi       °
  83.  nts'''                                                                        °
  84.   '''ON or below (except of course 0.5J0.5) also go to 1. Points on the'       °
  85.  ''                                                                            °
  86.   '''diagonal from .5J.5 to 0J.5 as well as those to the left of this'''       °
  87.   '''diagonal go to (0J1). All other points, namely those to the right o       °
  88.  f''' '''the main diagonal (0J1 to 1J0) go to 1J1.''' 'do'                     °
  89.   '''You should try to use this procedure to find how CEILING and FLOOR'       °
  90. X'' '''behave for arbitrary points on the complex plane.''' 'L0:endd'          °
  91. *(1997 4 27 12 39 30 516)                                                      °
  92.  FDECIMAL ÉFX 'DECIMAL' 'Σ Story of decimal point'                             °
  93.   '''The usage of the decimal point is less than 400 years old. In the''       °
  94.  '                                                                             °
  95.   '''sixteenth century, mathematicians still used fractions to indicate'       °
  96.  ''                                                                            °
  97.   '''the fractional part of a number. Viete, a french mathematician'''         °
  98.   '''experimented with bold letters for the integral part, and light'''        °
  99.   '''letters for the fractional part. He also tried a vertical bar to'''       °
  100.   '''separate the integers from the fractions. Others, among them Stevin       °
  101.  ''' '''tried other approaches.'',r'                                           °
  102.   '''The first usage of the decimal point (or comma) can be traced to'''       °
  103.   '''Magini or Clavius, friends of Kepler. However, it was Napier who'''       °
  104.   '''proposed a comma or period (in 1616) to indicate decimal fractions.       °
  105.  '',r'                                                                         °
  106.   '''Today the English speaking world uses the decimal point, but some''       °
  107.  '                                                                             °
  108.   '''European countries have adopted the comma as the mark that separate       °
  109.  s''' '''the integer part of a number from the fractional part.'''             °
  110. X 'endd'                                                                       °
  111. *(1997 8 24 13 14 34 440)                                                      °
  112.  FDIRECT ÉFX 'DIRECT' 'Σ Introduce DIRECT DEFINITION'                          °
  113.   '''     WHY DIRECT DEFINITION'',r'                                           °
  114.   '''APL as a programming language is not cast in concrete. There are'''       °
  115.   '''always suggestions for its extension. Changes, however, are made on       °
  116.  ly'''                                                                         °
  117.   '''after extensive study to insure that the internal consistency of th       °
  118.  e'''                                                                          °
  119.   '''language remains, and only when such changes contribute to its util       °
  120.  ity.'''                                                                       °
  121.   '''Ken Iverson, the originator of the language, has in recent years'''       °
  122.   '''developed a new "version" of APL called J, where he introduced seve       °
  123.  ral''' '''new concepts such as TACIT PROGRAMMING.'',r'                        °
  124.   '''The concept of tacit programming is a significant departure from th       °
  125.  e'''                                                                          °
  126.   '''approach taken by APL2. It means that when a new function is define       °
  127.  d,'''                                                                         °
  128.   '''no specific reference is made of the arguments to that function. An       °
  129.  '''                                                                           °
  130.   '''example will illustrate this: Suppose that we desire to define a ne       °
  131.  w'''                                                                          °
  132.   '''function called RANK. A tacit program definition would equate the''       °
  133.  '                                                                             °
  134.   '''APL2 symbols "µµ" with the "keyword" RANK. APL2 does not support su       °
  135.  ch'''                                                                         °
  136.   '''a concept (yet). Instead, the APL2 definition requires a combinatio       °
  137.  n'''                                                                          °
  138.   '''of the function PLUS its argument(s). Thus in APL2 we would define'       °
  139.  '' '''this function as "µµx" where "x" represents the argument.'''            °
  140.   'do'                                                                         °
  141.   '''The idea for combining just the functions has evolved in Iverson'''       °
  142.  's'''                                                                         °
  143.   '''thinking over the years. When APL was first developed, users'''           °
  144.   '''discovered that certain combinations of primitive functions were'''       °
  145.   '''frequently used in the solution of many problems. Here is one examp       °
  146.  le''' '''of such a combination'',r' '''        ∞µVECTOR'',r'                  °
  147.   '''The symbols "∞µ" when placed together generate a vector of ordinals       °
  148.  '''                                                                           °
  149.   '''that can be used in many ways. The word IDIOMS was introduced to'''       °
  150.   '''define this concept. The new APL2 interpreters actually recognize''       °
  151.  '                                                                             °
  152.   '''some of these idioms, and produce more efficient solutions. Another       °
  153.  '''                                                                           °
  154.   '''result was Iverson''''s introduction of a concept called DIRECT'''        °
  155.   '''DEFINITION. This concept is not currently supported by APL2, but'''       °
  156.   '''we will introduce and support it in this tutorial.''' 'do'                °
  157.   '''Why do we go to extra lengths to describe a facility that is not'''       °
  158.   '''even available in APL2? There are a number of reasons, but the'''         °
  159.   '''primary one is pedagogical. The current method in APL2 for the'''         °
  160.   '''creation of user defined functions has some aspects that mimic'''         °
  161.   '''conventional programming techniques in other languages such as'''         °
  162.   '''FORTRAN C or COBOL. A student who is familiar with programming in''       °
  163.  '                                                                             °
  164.   '''one of these languages will have a tendency to develop algorithms''       °
  165.  '                                                                             °
  166.   '''along the same lines. By making the student solve problems using'''       °
  167.   '''initialy only DIRECT DEFINITION (DD), we force him to start thinkin       °
  168.  g''' '''the way that APL2 was designed for.''' 'do'                           °
  169.   '''There are other reasons for using DD as well. The conventional mode       °
  170.   for'''                                                                       °
  171.   '''APL2 function definition cannot be readily adapted to an interactiv       °
  172.  e'''                                                                          °
  173.   '''tutorial such as this one (although, in later lessons we will use y       °
  174.  et'''                                                                         °
  175.   '''another way to define functions that do work interactively). Finall       °
  176.  y,'''                                                                         °
  177.   '''DD is often used in describing APL algorithms in the literature.'',       °
  178.  r'                                                                            °
  179.   '''We should also explain how this tutorial works. Each time there is        °
  180.  a'''                                                                          °
  181.   '''pause, and the cursor is placed on a blank line, you may enter'''         °
  182.   '''any expression whatever to test your understanding of what you have       °
  183.  '''                                                                           °
  184.   '''just read. The text that you enter is not evaluated directly. It is       °
  185.  '''                                                                           °
  186.   '''captured as a character string and then evaluated in a controlled w       °
  187.  ay'''                                                                         °
  188.   '''to give you essentially the same effect as if you were in direct'''       °
  189.   '''contact with APL2. By doing this, the tutorial method prevents even       °
  190.  ts'''                                                                         °
  191.   '''such as "INTERRUPTS" that normally would cause the tutorial to stop       °
  192.  '''                                                                           °
  193.   '''its continuity. A side advantage is the ability to recognize certai       °
  194.  n''' '''types of grammar such as DD that are not supported by APL2.'''        °
  195. X 'endd'                                                                       °
  196. *(1997 9 14 12 30 44 504)                                                      °
  197. XFDISCLAIMER ÉFX 'DISCLAIMER' 'Σ Copyright statement' 'disclaimer'             °
  198. *(1997 4 27 12 39 30 516)                                                      °
  199.  FDISPLAY ÉFX 'D╜S DISPLAY A;ÉIO;R;C;HL;HC;HT;HB;VL;VB;V;W;N;B'                °
  200.   'Σ DISPLAY A GENERAL ARRAY IN PICTORIAL FORM'                                °
  201.   'Σ  NORMAL CALL IS MONADIC.  DYADIC CALL USED ONLY IN'                       °
  202.   'Σ    RECURSION TO SPECIFY DISPLAY RANK, SHAPE, AND DEPTH.' 'ÉIO╜0'          °
  203.   '»(0=ÉNC ''S'')/''S╜µA''' 'R╜╞µ,S                   Σ PSEUDO RANK.'          °
  204.   'C╜''┐┌└┘''                 Σ UR, UL, LL, AND LR CORNERS.'                   °
  205.   'HL╜''─''                   Σ HORIZONTAL LINE.'                              °
  206.   'HC╜HL,''Θ╕'',HL,''~+ε''      Σ HORIZONTAL BORDERS.'                         °
  207.   'HT╜HC[(0<R)⌡1+0<╞²1╞,S]' 'ΣW╜,0╧■╞0µΓ(1⌐µA)╞A'                              °
  208.   'HB╜HC[3+3╛(''2⌡~A╧«A'' ÉEA ''1+╞ε0⌡(1⌐⌡/µA)╞,A'')+3⌡1<µµS]'                 °
  209.   'VL╜''│''                   Σ VERTICAL LINE.'                                °
  210.   'VB╜VL,''Φ╟''               Σ VERTICAL BORDER.'                              °
  211.   'V╜VB[(1<R)⌡1+0<²1╞²1╟,S]'                                                   °
  212.   '»(0εµA)/''A╜(1⌐µA)µΓ╞A''   Σ SHOW PROTOTYPE OF EMPTIES.'                    °
  213.   '╕(1<╧A)/GEN' '╕(2<µµA)/D3'                                                  °
  214.   'D╜«A                     Σ SIMPLE ARRAYS.' 'W╜1╞µD╜(²2╞1 1,µD)µD'           °
  215.   'N╜²1+1╟µD' '╕(0=µµA)/SS'                                                    °
  216.   'D╜(C[1],V,((W-1)µVL),C[2]),((HT,NµHL),[0]D,[0]HB,NµHL),C[0],(WµVL),C[       °
  217.  3]' '╕0' 'SS:HB╜((0 '' '')=╞0µΓA)/'' -'''                                     °
  218.   'D╜'' '',('' '',[0]D,[0]HB,Nµ'' ''),'' ''' '╕0'                              °
  219.   'GEN:D╜«DISPLAY■A          Σ ENCLOSED ...' 'N╜Dδ.⌠'' '''                     °
  220.   'D╜(Nδ~1ΦN)≡D' 'D╜(δ≡~''  ''╤D)/D' 'D╜((1,µS)µS)DISPLAY D'                   °
  221.   '╕(2≥µ,S)╟D3E,0' 'D3:D╜0 ²1╟0 1╟«ΓA         Σ MULT-DIMENSIONAL ...'          °
  222.   'W╜1╞µD' 'N╜²1+1╟µD'                                                         °
  223.   'D╜(C[1],V,((W-1)µVL),C[2]),((HT,NµHL),[0]D,[0]HB,NµHL),C[0],(WµVL),C[       °
  224.  3]' 'D3E:N╜²2+µ,S'                                                            °
  225. X 'V╜C[Nµ1],[0]VB[1+0<²2╟,S],[0](((²3+╞µD),N)µVL),[0]C[Nµ2]' 'D╜V,D'           °
  226. *(1997 4 27 12 39 30 516)                                                      °
  227.  FEXIT ÉFX 'EXIT' 'Σ Exit from function' '''To log off type:   )OFF'''         °
  228. X '╕'                                                                          °
  229. *(1997 4 27 12 39 30 516)                                                      °
  230.  FEXPLAIN ÉFX 'EXPLAIN W' 'Σ Explain problems described in text'               °
  231.   'L0:╕(1 2 3=1╞W╜,W)/L1,L2,L3' '╕0' 'L1:show ''µ/8 2 3'''                     °
  232.   '''Recall that in the reduction operator, the function to the left of'       °
  233.  ''                                                                            °
  234.   '''the slash is placed between the elements of the vector. So we have:       °
  235.  '',r' '''      µ/8 2 3    is the same as    8µ2µ3'',r'                        °
  236.   '''Now evaluating from right to left, from 2µ3 we get 3 3'',r'               °
  237.   '''and evaluating this result:  8µ3 3  we get   3 3 3 3 3 3 3 3.'',r'        °
  238.   '''This is not the whole story. Recall that reduction removes one'''         °
  239.   '''dimension from the right argument. This result seems to violate tha       °
  240.  t''' '''rule; but does it?'',r' 'show ''µ(µ/8 2 3)'' ''µµ(µ/8 2 3)'''         °
  241.   '''The parentheses in the above expression are used merely for clarity       °
  242.  .'''                                                                          °
  243.   '''The result is indeed a scalar; and yet it contains a vector of leng       °
  244.  th'''                                                                         °
  245.   '''eight. This seeming contradiction is your first introduction to'''        °
  246.   '''non-simple scalars. These play a very important role in APL2, but w       °
  247.  e'''                                                                          °
  248.   '''will not study them until we become better acquainted with the simp       °
  249.  ler''' '''aspects of APL2.''' 'do' '╕LX' 'L2:show ''µ/(2 3) (∞6)'''           °
  250.   '''Inserting the function in the right argument vector, we get:'',r'         °
  251.   '''      (2 3)µ(∞6)       which is the same as (2 3)µ1 2 3 4 5 6'',r'        °
  252.   '''The left argument to RESHAPE (remember reshape?) calls for two'''         °
  253.   '''rows and three columns using the right argument data.'',r'                °
  254.   '''Here too as in the first example, we have'',r'                            °
  255.   'show ''µ(2 3) (∞6)'' ''µµ/(2 6) (∞6)'''                                     °
  256.   '''The right argument to the reduction operator is a vector of a type'       °
  257.  ''                                                                            °
  258.   '''we have not yet studied. It is called a NESTED VECTOR. Since it is'       °
  259.  ''                                                                            °
  260.   '''a vector, its reduction is a SCALAR. For the time being, this is ju       °
  261.  st'''                                                                         °
  262.   '''a reminder that there is more to APL2, than the simple expressions'       °
  263.  ''                                                                            °
  264.   '''we have studied so far. We will of course study all aspects of APL2       °
  265.  ''' '''in due time.''' 'do' '╕LX' 'L3:show ''µ/(2 3) ∞6'''                    °
  266.   '''Removing the blank in front of ∞ we get:    µ/(2 3)∞6'',r'                °
  267.   '''Now in (2 3)∞6 the parentheses are redundant so we have µ/2 3∞6.'',       °
  268.  r'                                                                            °
  269.   '''But the expression 2 3∞6 is a dyadic usage of ∞ called INDEX OF.'',       °
  270.  r'                                                                            °
  271.   '''You will recall that it looks for the presence of 6 in the left'''        °
  272.   '''vector. Since 6 is not in vector 2 3, this expression returns'''          °
  273.   '''one plus the length of vector 2 3, namely 3.'',r'                         °
  274.   '''Finally, the reduction of a scalar (or vector of length one) return       °
  275.  s'''                                                                          °
  276.   '''that value regardless of the function. Hence µ/(2 3) ∞6 returns 3.'       °
  277. X'' 'LX:╕(0<µW╜1╟W)/L0'                                                        °
  278. *(1997 8 8 13 33 28 428)                                                       °
  279.  FGAME ÉFX 'GAME;N;GREATER;SMALLER;EQUAL;TO;THAN'                              °
  280.   'Σ Game to find number'                                                      °
  281.   '''We begin by defining three relational functions:'',r'                     °
  282.   '1 show ''GREATER:α>∙'' ''SMALLER:α<∙'' ''EQUAL:α=∙'''                       °
  283.   '''The symbols for < and > stand for "less than" and "greater than"'',       °
  284.  r' 'show ''3 GREATER 5'' ''3 SMALLER 5'' ''3 EQUAL 5'''                       °
  285.   '''Next, we define ''''placeholder'''' functions:'',r'                       °
  286.   '1 show ''TO:∙'' ''THAN:∙'''                                                 °
  287.   '''These functions merely return the result of evaluating expression ∙       °
  288.  '',r' 'show ''TO 3⌡5'' ''THAN 6'''                                            °
  289.   '''Finally, we use ROLL to generate a random integer between 1 and 100       °
  290.  '',r' 'show ''N╜?100''' '''Now we can play this game:'''                      °
  291.   'show ''IS N GREATER THAN 50'' ''IS N SMALLER THAN 43'' ''IS N EQUAL T       °
  292.  O 5'''                                                                        °
  293.   '''Now you try to find the value of N by asking questions. (NOTE: move       °
  294.  '''                                                                           °
  295.   '''the cursor to one of the lines above, change the numeric value, and       °
  296. X''' '''press Enter.)'',r' 'do'                                                °
  297. *(1996 4 6 15 59 48 592)                                                       °
  298.  FGO ÉFX 'GO;T;E;B' 'Σ Expression driver' 'L0:B╜E╜''''' 'æ╜''      '''         °
  299.   'T╜æ' '╕(^/'' ''=T)/L0' '╕((^/'')OFF ''=5╞6╟T)doif ''EXIT'')/0'              °
  300.   '╕(('':''εT)doif ''B╜evaldd (+/^\'''' ''''=T)╟T'')/L0'                       °
  301.   '''E╜ÉEM'' ÉEA T' '╕(0=µ,E)/L0' '╕B/L0'                                      °
  302.   '''This is not a valid APL2 expression''' 'æ╜''*'''                          °
  303. X '╕(''?''⌠╞1╟æ)/L0' 'E' '╕L0'                                                 °
  304. *(1997 8 25 13 26 57 584)                                                      °
  305.  FHELP ÉFX 'HELP;N;I;T' 'Σ Help to student' '''WHAT TO DO'',r'                 °
  306.   '''  ° To get out of the lesson''' '''       ENTER: EXIT'''                  °
  307.   '''  ° To log off APL2'''                                                    °
  308.   '''       FIRST, ENTER: EXIT  THEN ENTER: )OFF'''                            °
  309.   '''  ° To get help''' '''       ENTER: HELP'''                               °
  310.   '''  ° When you see the prompt on a blank line'''                            °
  311.   '''       ENTER AN APL2 EXPRESSION - OR JUST PRESS: ENTER''' 'do'            °
  312.   '''  ° If you get this line'',r'                                             °
  313.   '''This is not a valid APL2 expression'',r,''*'',r'                          °
  314.   '''        YOU CAN EITHER''' '''           A. PRESS: ENTER'''                °
  315.   '''           B. PRESS: ? and then ENTER to see what was incorrect'''        °
  316.   '''              in your expression causing that response'',r' 'do'          °
  317.   '''HINTS'',r'                                                                °
  318.   '''This lesson is made up of '',(«N╜7),'' components named TEACHx, whe       °
  319.  re''' '''the x stands for a digit:'',r' 'I╜0'                                 °
  320.   'L0:T╜''TEACH'',(«I╜I+1)' 'T,'' '',1╟notb(ÉCR T)[2;]' '╕(N>I)/L0'            °
  321.   'do'                                                                         °
  322.   '''You may review either of these components separately. To do that,''       °
  323.  '                                                                             °
  324.   '''first enter EXIT (and RETURN), then enter the name of the lesson.''       °
  325.  ' '''component (e.g. TEACH4).'',r'                                            °
  326.   '''To re-start the lesson, just enter TEACH'',r'                             °
  327.   '''When the screen fills up, it is a good idea to press the DOWN arrow       °
  328.  ''' '''to scroll the screen up'',r'                                           °
  329.   '''You may also wish to press PAGE UP to review previous pages.'''           °
  330.   'do' '''RESOURCES'',r'                                                       °
  331.   '''You may also enter ONE of the following words at a time'',r'              °
  332.   '''ALGORITHM   The origin of this word'''                                    °
  333.   '''DECIMAL     History of development of decimal notation'''                 °
  334.   '''DIRECT      Brief summary of recent APL developments'''                   °
  335.   '''GAME        A game to find a number between 1 and 100'''                  °
  336.   '''POWER       Monadic usage of the power function, complex numbers'''       °
  337.   '''COMPLEX (1 or 2)   Evaluation of complex number expressions'''            °
  338. X '''EXPLAIN (1 2 or 3) Explanation of three APL2 expressions''' 'endd'        °
  339. *(1997 9 16 12 21 25 400)                                                      °
  340.  FIS ÉFX 'u╜IS w;t;b' 'ΣDD' 'b╜(t╜w)/''u╜''''yes''''''' '╕(t doif b)/0'        °
  341. X 'u╜''no'''                                                                   °
  342. *(1997 5 4 12 39 40 468)                                                       °
  343.  FPOWER ÉFX 'POWER;e;N;i;PI'                                                   °
  344.   'Σ Exponential and power of complex numbers'                                 °
  345.   '''When the * is used monadically, it is called EXPONENTIAL. The missi       °
  346.  ng left''' '''argument is defaulted to the constant "e".''' 'e╜*1'            °
  347.   'show ''e'' ''e*2'' ''*2'''                                                  °
  348.   '''Where does this constant come from? It is the limit of the expressi       °
  349.  on''' '''  (1+÷N)*N     as N approaches infinity'',r'                         °
  350.   'show ''N╜10*2 4 6 8'' ''N'' ''(1+÷N)*N'''                                   °
  351.   '''      POWER OF COMPLEX NUMBERS'',r' 'i╜0J1 ╪ PI╜Ω1'                       °
  352.   '''Since APL2 supports complex numbers, it is entirely valid to apply        °
  353.  the''' '''power (exponential) to complex numbers'',r'                         °
  354.   'show ''i'' ''i*2'' ''2*i'' ''*i'''                                          °
  355.   '''Consider, for example the famous Euler formula'''                         °
  356. X 'show ''PI'' ''*i⌡PI''' 'endd'                                               °
  357. *(1997 5 30 13 54 49 672)                                                      °
  358.  FRULE ÉFX 'V RULE W' 'Σ Display rules' '╕(2=ÉNC ''V'')/L0'                    °
  359. X '2 rule W ╪ ╕0' 'L0:V rule W'                                                °
  360. *(1997 8 26 12 5 8 304)                                                        °
  361.  FTEACH ÉFX 'TEACH' 'Σ Start third lesson in APL2 by Zdenek V JIZBA'           °
  362.   'exit ''TEACH''' 'initialize'                                                °
  363.   'TEACH1 Σ Parentheses, quote, high minus, workspace'                         °
  364.   'TEACH2 Σ The power function'                                                °
  365.   'TEACH3 Σ Maximum, minimum, ceiling, floor, equal, not equal'                °
  366.   'TEACH4 Σ Algorithm, user defined functions'                                 °
  367.   'TEACH5 Σ Direct definition' 'TEACH6 Σ Conditional direct definition'        °
  368. X 'TEACH7 Σ Average, range and midrange' 'problems'                            °
  369. *(1997 5 17 12 5 18 296)                                                       °
  370.  FTEACH1 ÉFX 'TEACH1' 'Σ Review lesson 2' 'exit ''TEACH1'''                    °
  371.   '''So far we have learned that in APL2, there are objects called DATA,       °
  372.  '''                                                                           °
  373.   '''FUNCTIONS and OPERATORS. We can ASSIGN data to VARIABLES. We can'''       °
  374.   '''write EXPRESSIONS that are formulas for the solution of specific'''       °
  375.   '''problems.''' 'do'                                                         °
  376.   '''We learned about several PRIMITIVE FUNCTIONS. These are invoked by'       °
  377.  ''                                                                            °
  378.   '''symbols that operate on data to generate a result. We pointed out''       °
  379.  '                                                                             °
  380.   '''that you can find how to enter these symbols by selecting the OPTIO       °
  381.  NS'''                                                                         °
  382.   '''pull down menu and pressing the MODIFY KEYBOARD. We studied the'''        °
  383.   '''following primitive functions: + - ⌡ ÷ = ⌠ ε µ ∞. Refresh your memo       °
  384.  ry''' '''by entering a few expressions containing these symbols.'''           °
  385.   'do'                                                                         °
  386.   '''We learned that the slash / is a special symbol used to define an''       °
  387.  '                                                                             °
  388.   '''OPERATOR called the REDUCTION OPERATOR. It connects a function left       °
  389.  '''                                                                           °
  390.   '''argument to data as the right argument.In particular,the combinatio       °
  391.  n '''                                                                         °
  392.   '''+/ will add all the elements of a numeric vector. Go ahead,and try        °
  393.  ''' '''to use the reduction operator with different functions.''' 'do'        °
  394.   '''We also learned that there are symbols that are part of the NOTATIO       °
  395.  N'''                                                                          °
  396.   '''of APL2. Some of these symbols have been incorporated from normal''       °
  397.  '                                                                             °
  398.   '''usage that we have learned in school, such as the decimal point.'''       °
  399.   '''(For a brief discussion of the history of decimal point type DECIMA       °
  400.  L)'''                                                                         °
  401.   '''Other APL2 notation is not as well known. The usage of the letter E       °
  402.  ''' '''to denote exponent in scientific notation is an example.'''            °
  403.   'do'                                                                         °
  404.   '''APL2 supports the usage of parentheses to change the DEFAULT'''           °
  405.   '''sequence for evaluating expressions. The single quote '''' (not a''       °
  406.  ' '''double quote ") is used to delimit caracter strings. APL2 also'''        °
  407.   '''makes a distinction between a NEGATIVE SIGN (²) to indicate a'''          °
  408.   '''property of a number (being less than zero), and a MINUS SIGN to'''       °
  409.   '''indicate a multiplication by minus one. Finally, the left arrow ╜''       °
  410.  ' '''is used to divert the result of evaluation to a VARIABLE.''' 'do'        °
  411.   '''So you feel at ease with APL2 so far? Just for exercise, try to exp       °
  412.  lain'''                                                                       °
  413.   '''the following results: (You SHOULD have problems understanding them       °
  414.  !'''                                                                          °
  415.   '''For an explanation, enter EXPLAIN 1, EXPLAIN 2 and EXPLAIN 3)'',r'        °
  416.   'show ''µ/8 2 3'' ''µ/(2 3) (∞6)'' ''µ/(2 3) ∞6'''                           °
  417.   '''In this lesson we are going to study a few more primitive functions       °
  418.  .'''                                                                          °
  419.   '''We will also learn about the DIRECT DEFINITION. Although APL2 does        °
  420.  not'''                                                                        °
  421.   '''support DIRECT DEFINITION, it is a useful tool for learning APL. Th       °
  422.  is''' '''WORKSPACE contains software to evaluate it properly.''' 'do'         °
  423.   '''Incidentally, a WORKSPACE is the name given to the amount of memory       °
  424. X''' '''allocated by APL2 to this, or any application.''' 'endd'               °
  425. *(1997 5 17 12 26 57 536)                                                      °
  426.  FTEACH2 ÉFX 'TEACH2' 'Σ Define power and exponential' 'exit ''TEACH2'''       °
  427.   '''         THE POWER FUNCTION'',r'                                          °
  428.   '''We can use multiplication (⌡) to calculate the square of a number.'       °
  429.  ''                                                                            °
  430.   '''Using the reduction operator, we could even calculate arbitrary'''        °
  431.   '''integer powers of a number. For example to raise two to the power''       °
  432.  ' '''eight, we could enter'',r' 'show ''⌡/8µ2'''                              °
  433.   '''What we cannot do, however, is to use the times symbol to raise a''       °
  434.  '                                                                             °
  435.   '''number to fractional powers, such as for example the square root.''       °
  436.  '                                                                             °
  437.   '''In mathematical notation, the power of a number is displayed as a''       °
  438.  '                                                                             °
  439.   '''superscript number to the right, and usually in a smaller font.'''        °
  440.   'do'                                                                         °
  441.   '''Since APL2 is limited to a simple linear text, it is not possible''       °
  442.  ' '''to use the notation for powers that we learn in high school.'''          °
  443.   '''There is a special symbol for power in APL2, and it is used'''            °
  444.   '''as a DYADIC function. The number to be raised to a power is the'''        °
  445.   '''left argument. The symbol for a power function is the asterisk, and       °
  446.  ''' '''the power is the right argument.'',r'                                  °
  447.   'show ''10*3'' ''10*²3'' ''25*0.5'' ''25*÷2'''                               °
  448.   '''The last two examples show two ways of taking the square root. The'       °
  449.  ''                                                                            °
  450.   '''second approach has merit for taking roots of numbers that cannot''       °
  451.  ' '''be expressed in decimal notation'',r'                                    °
  452.   'show ''8*0.33333'' ''8*÷3''' 'do'                                           °
  453.   '''Naturally, the power function works with vectors too'',r'                 °
  454.   'show ''2*0 1 2 3'' ''2 3 4 5*2'' ''2 3 4 5*5 4 3 2'''                       °
  455.   '''To see how APL2 deals with roots of negative numbers, enter COMPLEX       °
  456.   1.''' 'do'                                                                   °
  457.   '''Try out some powers, and include expressions that contain the'''          °
  458.   '''monadic iota (∞). Then explain the results''' 'do'                        °
  459.   '''Enter POWER to see the monadic usage of the power function.'''            °
  460.   '''The discussion will also touch on the power of COMPLEX NUMBERS.'''        °
  461. X 'do' 'endd'                                                                  °
  462. *(1997 5 17 12 27 23 404)                                                      °
  463.  FTEACH3 ÉFX 'TEACH3;NUMS;VECTOR' 'Σ Maximum minimum and residue'              °
  464.   'exit ''TEACH3'''                                                            °
  465.   '''We normally think of addition, subtraction, multiplication, divisio       °
  466.  n'''                                                                          °
  467.   '''and exponentiation as the only elementary operations on numbers.'''       °
  468.   '''There are some operations that are just as important, but tend to''       °
  469.  '                                                                             °
  470.   '''be overlooked in teaching elementary math courses. Take the questio       °
  471.  n'''                                                                          °
  472.   '''as to which of the following numbers is the bigger one: 2 or 5.'''        °
  473.   'do'                                                                         °
  474.   '''Since we somehow recognize that 5 is bigger than 2, it may not seem       °
  475.  '''                                                                           °
  476.   '''too important to think of this process as one worth teaching at the       °
  477.  '''                                                                           °
  478.   '''elementary level. But then why should we bother with the obvious?''       °
  479.  ,r'                                                                           °
  480.   '''The reasons will become clearer when we study user defined function       °
  481.  s.'''                                                                         °
  482.   '''Right now, let us look at some of these elementary but useful primi       °
  483.  tive''' '''APL2 functions.'',r' 'do'                                          °
  484.   '''The symbol ⌐ is called MAXIMUM. When used dyadically, it compares''       °
  485.  ' '''two numbers, and returns the larger one.'',r'                            °
  486.   'show ''2⌐5'' ''²2⌐²5'''                                                     °
  487.   '''The symbol ╛ is called MINIMUM. When used dyadically, it compares''       °
  488.  ' '''two numbers, and returns the smaller one.'',r'                           °
  489.   'show ''2╛5'' ''²2╛²5'''                                                     °
  490.   '''Both of these functions can be used with the reduction operator.'''       °
  491.   '''Can you predict what result will they produce?''' 'do'                    °
  492.   '''The reduction of a numeric vector using MAXIMUM will return a scala       °
  493.  r.'''                                                                         °
  494.   '''The value of that scalar will be the largest numeric value in the''       °
  495.  '                                                                             °
  496.   '''vector. In a similar way MINIMUM will return the smallest value:'',       °
  497.  r' 'show ''⌐/2 53 17 81 45'' ''╛/2 53 17 81 45'''                             °
  498.   '''Now you try it, assign to V a vector of numbers. Then write an APL2       °
  499.  '''                                                                           °
  500.   '''expression to calculate the RANGE of that vector. (The word range h       °
  501.  as'''                                                                         °
  502.   '''many meanings, but here we use it to mean the difference between th       °
  503.  e''' '''largest and smallest values.)''' 'do'                                 °
  504.   '''There are also monadic versions of the symbols ⌐ and ╛. When used''       °
  505.  ' '''monadically, ⌐ is called CEILING, and ╛ is called FLOOR'',r'             °
  506.   'show ''⌐1.23 5 ²3.45'' ''╛1.23 5 ²3.45'''                                   °
  507.   '''As you can see, ceiling and floor return integers (whole numbers)''       °
  508.  ' '''that are nearest to the given value. Ceiling finds the larger'''         °
  509.   '''integer, and floor finds the smaller integer. Monadic ⌐ and ╛'''          °
  510.   '''have no effect on integers. Thus'',r'                                     °
  511.   'show ''NUMS╜1.23 5 ²3.45'' ''NUMS=⌐NUMS'' ''NUMS=╛NUMS'''                   °
  512.   '''Floor and Ceiling can also be applied to complex numbers. Enter'''        °
  513.   '''COMPLEX 2 to find out more about the peculiar behavior of these two       °
  514.  ''' '''monadic functions in the complex domain.''' 'do'                       °
  515.   '''There may be times when we are not interested in the VALUE of the''       °
  516.  '                                                                             °
  517.   '''largest or smallest, but only in a relationship. We have already'''       °
  518.   '''seen primitive functions = and ⌠'',r'                                     °
  519.   'show ''2=3'' ''5=5'' ''3=∞6'' ''2 4 6 8⌠8 4 2 6'''                          °
  520.   '''These primitive functions were called RELATIONAL, and we used them'       °
  521.  '' '''with character strings.'',r'                                            °
  522.   'show ''''''HOUSE''''=''''MOUSE'''''' ''''''CAT''''⌠''''CUT'''''''           °
  523.   '''For numeric variables there are several other relational functions.       °
  524.  '''                                                                           °
  525.   '''The symbol < is called LESS THAN. The symbol < is called GREATER TH       °
  526.  AN.'''                                                                        °
  527.   '''To complete the collection we have ≤ LESS THAN OR EQUAL and ≥ GREAT       °
  528.  ER'''                                                                         °
  529.   '''THAN OR EQUAL. You should practice with these symbols, but remember       °
  530. X,''' '''these work only with numeric data.''' 'endd'                          °
  531. *(1997 5 16 13 43 27 484)                                                      °
  532.  FTEACH4 ÉFX 'TEACH4;NUMS;VECTOR;RATIO'                                        °
  533.   'Σ Introduction to function definition' 'exit ''TEACH4'''                    °
  534.   '''Let us now describe an ALGORITHM, that uses the FLOOR (╛) function.       °
  535.  ''' '''(For the origin of the word "algorithm", enter ALGORITHM.)'',r'        °
  536.   '''Given a vector of integers, count the number of its elements that a       °
  537.  re''' '''divisible by 7. Let the vector be'',r' 'show ''VECTOR╜∞200'''        °
  538.   '''The following expression will give us the result:'',r'                    °
  539.   'show ''+/(VECTOR÷7)=╛VECTOR÷7'''                                            °
  540.   '''If we think of VECTOR as some arbitrary sequence of numbers, then''       °
  541.  ' '''the above expression, becomes an equation of sorts. If such an'''        °
  542.   '''expression is to be used frequently, it would be convenient to'''         °
  543.   '''capture it in a more compact form. In other words, how do we progra       °
  544.  m''' '''in APL2?'',r' 'do'                                                    °
  545.   '''The simple answer is that one can package one or more expressions''       °
  546.  '                                                                             °
  547.   '''such as the one above. The result of this packaging is called a'''        °
  548.   '''"USER DEFINED FUNCTION". The main difference between a User Defined       °
  549.  '''                                                                           °
  550.   '''Function, and a primitive function is in the representation. A'''         °
  551.   '''primitive function is defined by a special symbol, while a User'''        °
  552.   '''defined one is a text label.'',r'                                         °
  553.   '''There are other differences. We have seen that primitive functions'       °
  554.  ''                                                                            °
  555.   '''always produce a result. This need not be true in User Defined ones       °
  556.  .'''                                                                          °
  557.   '''If an APL2 expression is not a valid one, an error message will be'       °
  558.  ''                                                                            °
  559.   '''produced. In a User Defined Function, errors can be "trapped".'''         °
  560.   '''With the help of special features that are supported by the commerc       °
  561.  ial'''                                                                        °
  562.   '''version of APL2, it is also possible to access non-APL2 data, gener       °
  563.  ate'''                                                                        °
  564.   '''graphs on the screen and to "call" on non-APL2 software.'',r'             °
  565.   '''User defined functions therefore are analogous to programs or'''          °
  566.   '''subroutines of other programming laguages.'',r' 'do'                      °
  567.   '''The process of defining an APL2 user function can take several form       °
  568.  s.'''                                                                         °
  569.   '''Although a single expression such as the one above could be used as       °
  570.  '''                                                                           °
  571.   '''the definition of a function, it is more typical to catenate two or       °
  572.  '''                                                                           °
  573.   '''more such expressions together. The problem at hand provides an'''        °
  574.   '''example of that.'',r' 'show ''+/(VECTOR÷7)=╛VECTOR÷7'''                   °
  575.   '''A careful inspection of the expression above, suggests that it may'       °
  576.  ''                                                                            °
  577.   '''not be very efficient, because the quantity "VECTOR÷7" is calculate       °
  578.  d''' '''twice. A two step process seems to be more rational:'',r'             °
  579.   'show ''RATIO╜VECTOR÷7'' ''+/RATIO=╛RATIO'''                                 °
  580.   '''We will learn how to define multi-expression algorithms in a later'       °
  581.  ''                                                                            °
  582.   '''lesson. Right now, let us concentrate on those that can be written        °
  583.  as'''                                                                         °
  584.   '''single strings (the so called and sometimes maligned "one liners").       °
  585.  '''                                                                           °
  586.   '''One of the guiding principles that led Iverson to develop APL was t       °
  587.  he'''                                                                         °
  588.   '''desire to simplify this process of designing new algorithms. The AP       °
  589.  L2'''                                                                         °
  590.   '''primitive functions have been selected with this purpose in mind.''       °
  591.  ,r'                                                                           °
  592.   '''Indeed, in his most recent work, Iverson has designed a new dialect       °
  593.  '''                                                                           °
  594.   '''of APL, called J, that strongly supports a concept called "tacit'''       °
  595.   '''programming" that relies heavily on "one line definitions".'''            °
  596. X 'endd'                                                                       °
  597. *(1997 8 24 13 21 55 552)                                                      °
  598.  FTEACH5 ÉFX 'TEACH5;ORDINALS;T;PLUS' 'Σ Introduce DIRECT DEFINITION'          °
  599.   '''We will introduce here a concept called DIRECT DEFINITION. This con       °
  600.  cept'''                                                                       °
  601.   '''is not supported by APL2, but because it is useful in teaching APL,       °
  602.   this'''                                                                      °
  603.   '''tutorial contains software that supports it, but only while you are       °
  604.   within'''                                                                    °
  605.   '''the lesson. To learn more about this subject, enter DIRECT''' 'do'        °
  606.   '''                 DIRECT DEFINITION'',r'                                   °
  607.   '''There are two forms of direct definition. The first form is illustr       °
  608.  ated''' '''by function PLUS.'',r' 'T╜evaldd ''PLUS:α+∙'''                     °
  609.   '''       PLUS:α+∙'',r'                                                      °
  610.   '''In this form there is a colon separating a label to the left from a       °
  611.  n'''                                                                          °
  612.   '''APL2 expression containing the greek letters α (alpha) and ∙ (omega       °
  613.  ).''' '''Let us see how this can be used:'',r'                                °
  614.   'show ''5 PLUS 3'' ''2 3 PLUS 5 6'''                                         °
  615.   '''The label PLUS behaves exactly the same as if it were the symbol +'       °
  616.  ''                                                                            °
  617.   '''The greek letter α stands for the left argument, and the greek lett       °
  618.  er'''                                                                         °
  619.   '''∙ stands for the right argument. Suppose now that we desire to defi       °
  620.  ne'''                                                                         °
  621.   '''a new function for the expression ∞µVECTOR. Let us name this functi       °
  622.  on''' '''ORDINALS:'',r'                                                       °
  623.   '1 show ''ORDINALS:∞µ∙'' ''ORDINALS ''''TEST'''''''                          °
  624.   '''Because function ORDINALS is monadic, the symbol α is missing in th       °
  625. Xe''' '''function definition.''' 'endd'                                        °
  626. *(1997 8 25 13 33 26 488)                                                      °
  627.  FTEACH6 ÉFX 'TEACH6;T' 'Σ Conditional direct definition'                      °
  628.   'exit ''TEACH6'''                                                            °
  629.   '''There is a second form of DIRECT DEFINITION. It is somewhat more'''       °
  630.   '''complex, but it provides execution with condition. Function IS'''         °
  631.   '''illustrates this conditional form:'',r'                                   °
  632.   'T╜evaldd ''IS:''''no'''':∙:''''yes''''''' '1 show ''IS:'''                  °
  633.   '''There are now three colons. Let us see how function IS behaves:'',r       °
  634.  ' 'show ''IS 5>6'' ''IS 5<6'''                                                °
  635.   '''In the first example, the expression ∙ is 5>6. It evaluates to zero       °
  636.  '''                                                                           °
  637.   '''since the inequality is clearly false. In the second example the'''       °
  638.   '''expression ∙ is 5<6, which is clearly true. This expression therefo       °
  639.  re'''                                                                         °
  640.   '''evaluates to a one. Now, the direct definition IS contains three pa       °
  641.  rts:'''                                                                       °
  642.   '''The leftmost part is the APL expression ''''no''''. The middle part       °
  643.   is ∙,''' '''and the rightmost part is ''''yes''''.''' 'do'                   °
  644.   '''So for the conditional direct definition, there are three rules for       °
  645.  ''' '''its evaluation:'',r'                                                   °
  646.   '''   1. Evaluate the middle expression. It MUST return a boolean valu       °
  647.  e'''                                                                          °
  648.   '''   2. If the result is true (1), evaluate the right expression.'''        °
  649.   '''   3. If the result is false, evaluate the left expression.'',r'          °
  650.   '''Before you experiment with direct definitions, you might first try'       °
  651.  ''                                                                            °
  652.   '''entering GAME. This game illustrates how you can use direct definit       °
  653.  ion'''                                                                        °
  654.   '''to build a simple but interesting application. Now you try defining       °
  655.  '''                                                                           °
  656.   '''some functions. Once defined exercise them. WARNING: The argument i       °
  657.  n'''                                                                          °
  658.   '''a direct definition HERE, MUST be either ∙ or (α and ∙). NEVER just       °
  659. X α!''' 'endd'                                                                 °
  660. *(1997 8 26 12 5 49 468)                                                       °
  661.  FTEACH7 ÉFX 'TEACH7;AVERAGE;RANGE;MIDRANGE'                                   °
  662.   'Σ Sample direct definitions' 'exit ''TEACH7'''                              °
  663.   '''Let us see what can be done with direct definitions. We will now'''       °
  664.   '''define a few sample user defined functions, but these will be erase       °
  665.  d''' '''so that you can practice on your own.'',r'                            °
  666.   '''In the previous lesson, we found an expression for the average:'',r       °
  667.  ' '1 show ''AVERAGE:(+/∙)÷µ∙'' ''AVERAGE:'' ''AVERAGE ∞99'''                  °
  668.   '''In this lesson you were asked to define range.'',r'                       °
  669.   '1 show ''RANGE:(⌐/∙)-╛/∙'' ''RANGE ²10+33⌡∞10'''                            °
  670.   '''What about the following?'',r'                                            °
  671.   '1 show ''MIDRANGE:0.5⌡(⌐/∙)+╛/∙'' ''MIDRANGE ²10+33⌡∞10'''                  °
  672.   '''Can you explain why we place ⌐/∙ in parentheses, but leave ╛/∙ alon       °
  673.  e?'',r' 'do'                                                                  °
  674.   '''As we proceed, we will use the direct definition to illustrate'''         °
  675.   '''examples of APL2 usage. Eventually, we will also study the process'       °
  676.  ''                                                                            °
  677.   '''of defining user functions by switching from the "execution" mode''       °
  678. X' '''to the "function definition" mode.''' 'endd'                             °
  679. *(1997 7 13 12 28 49 504)                                                      °
  680.  Faddquote ÉFX 'u╜addquote w'                                                  °
  681.   'Σ Put quotes around a string, and double existing quotes'                   °
  682. X 'u╜ÉAV[40],((1+w=ÉAV[40])/w),ÉAV[40]'                                        °
  683. *(1997 4 27 12 39 30 516)                                                      °
  684. XFaq ÉFX 'U╜aq W' 'U╜Γaddquote W'                                              °
  685. *(1997 7 24 13 20 38 476)                                                      °
  686.  Fav ÉFX 'av;A;N;I;ÉIO' 'Σ Display characters in ÉAV' 'ÉIO╜0'                  °
  687.   'A╜22 78µ'' ''' 'N╜3 0«φ12 22µ1+∞356' 'A[;,(6⌡∞12)°.+2 3 4]╜N'               °
  688.   'A[;6+6⌡∞12]╜φ12 22µÉAV' 'ΣA[8 10 13;6]╜'' ''' 'A[13;6]╜'' '''               °
  689. X 'A[14+∞8;68 69 70 72]╜'' ''' 'A'                                             °
  690. *(1991 11 11 8 25 13 316)                                                      °
  691.  Fdate ÉFX 'u╜date w' 'Σ Format date and time of day' 'u╜«6╞w'                 °
  692. X 'u╜('' ''⌠u)Γu' 'u╜εu,■''-- .. '''                                           °
  693. XCdig 1 10 1234567890                                                          °
  694. *(1997 9 9 13 0 45 372)                                                        °
  695.  Fdisclaimer ÉFX 'disclaimer' 'Σ Copyright statement'                          °
  696.   '(10µ'' ''),''Copyright, Z. V. Jizba, 1995,1996,1997'',r'                    °
  697.   ''' This and subsequent workspaces labelled TEACHxx are made available       °
  698.  '''                                                                           °
  699.   '''at no cost to anyone who desires to learn how to use effectively'''       °
  700.   '''the IBM/OS2 version of APL2.'',r'                                         °
  701.   '''This software is provided "AS IS" with no WARRANTY of any kind, eit       °
  702.  her'''                                                                        °
  703.   '''express or implied. Any risk in its use resides with you, the user        °
  704.  of''' '''these tutorials.'',r' '''     ACKNOWLEDGEMENTS'',r'                  °
  705.   ''' In writing these tutorials, I am greatly indebted to Roy Sykes, wh       °
  706.  ose'''                                                                        °
  707.   '''excellent lectures increased my understanding of the language.'''         °
  708.   '''Discussions with the late Harry Bertucelli clarified a number of'''       °
  709.   '''concepts and caused me to change some improper terminology that was       °
  710.  '''                                                                           °
  711.   '''used in previous versions of these tutorials. Mr. Benjamin Archer''       °
  712.  '                                                                             °
  713.   '''kindly checked out a nearly final version, bringing to my attention       °
  714.  ''' '''some ommisions, misspellings, and invalid terminology.'',r'            °
  715. X '''(PRESS ENTER to continue)'''                                              °
  716. *(1997 7 13 12 28 50 508)                                                      °
  717.  Fdo ÉFX 'do;T;E' 'Σ Expression driver' 'E╜''''' 'æ╜''      ''' 'T╜æ'          °
  718.   '╕(^/'' ''=T)/0'                                                             °
  719.   '╕(('':''εT)doif ''B╜evaldd (+/^\'''' ''''=T)╟T'')/2'                        °
  720.   '''E╜ÉEM'' ÉEA T' '╕(0=µ,E)/2'                                               °
  721.   '''This is not a valid APL2 expression''' 'æ╜''*''' '╕(''?''⌠╞1╟æ)/2'        °
  722. X 'E' '╕2'                                                                     °
  723. *(1997 7 13 12 28 50 508)                                                      °
  724.  Fdoif ÉFX 'U╢╜V╢ doif W╢;t╢' 'Σ Rule' '╕(^/~U╢╜V╢)/0'                         °
  725. X '''U╢╜V╢ doif■ W╢'' ÉEA ''»V╢/W╢'''                                          °
  726. *(1997 9 9 12 50 14 444)                                                       °
  727.  Fendd ÉFX 'endd' 'Σ end of special feature' '20µ''²'' ╪ ╕(4<µÉLC)/0'          °
  728. X 'do'                                                                         °
  729. *(1997 9 16 12 25 17 384)                                                      °
  730.  Ferase ÉFX                                                                    °
  731.   'erase;t;EXIT;HELP;DISPLAY;ALGORITHM;DECIMAL;EXPLAIN;GAME;POWER;COMPLE       °
  732.  X;RULE;DISCLAIMER;DIRECT;GO'                                                  °
  733.   'Σ Erase all global functions and variables' 't╜ÉNL 3'                       °
  734.   't╜(~t^.εlc,'' '')≡t' 't╜ÉEX(~t[;∞5]^.=''TEACH'')≡t' 't╜ÉNL 2'               °
  735. X 't╜ÉEX(~t^.εlc,'' '')≡t' 't╜ÉNL 4' 't╜ÉEX(~t^.εlc,'' '')≡t'                  °
  736. *(1997 4 27 12 39 30 516)                                                      °
  737.  Ferrors ÉFX 'errors W;EC;RT;R' 'Σ Display error message'                      °
  738.   '╕((1<╧W)doif ''errors■ W'')/0' '''       '',W' '(EC RT R)╜ÉEC W' 'R'        °
  739. X 'do'                                                                         °
  740. *(1997 7 27 13 47 41 608)                                                      °
  741.  Fevaldd ÉFX 'u╜evaldd w;c;n' 'Σ Evaluate direct definition' 'u╜0'             °
  742.   'n╜(w∞''Σ'')-1' 'c╜(((n╞w)⌠'':'')Γn╞w),Γ''ΣDD '',(n+1)╟w'                    °
  743.   '╕((1 label╞c)doif ''''''Invalid label'''''')/0'                             °
  744.   '╕((2=µc)doif ''u╜showdd 1╙c'')/0'                                           °
  745.   '╕((3=ÉNC╞c)doif ''u╜⌡µÉ╜(╞c),'''' is already defined.'''''')/0'             °
  746.   '╕((3=µc)doif ''u╜simdd c'')/0' 'c╜(Γ''α∙ aw'')replace■c'                    °
  747.   'u╜ε''u╜'',((''a''εεc[2 3 4])/''a ''),(╞c),'' w;t;b'''                       °
  748.   'u╜u(5πc)(''b╜(t╜'',(3πc),'')/'',addquote ''u╜'',4πc)'                       °
  749. X 'u╜u,''╕(t doif b)/0''(''u╜'',2πc)' 'u╜╧ÉFX u'                               °
  750. *(1997 7 25 13 27 52 564)                                                      °
  751.  Fexit ÉFX 'V exit W;T' 'Σ Exit if too many suspended functions'               °
  752.   '╕(0⌠ÉNC ''V'')/L0 ╪ V╜10' 'L0:╕(V>µÉLC)/0'                                  °
  753.   '''There are too many suspended functions''' '''Please enter '',W'           °
  754. X '╕'                                                                          °
  755. *(1997 7 26 12 33 39 536)                                                      °
  756.  Fget ÉFX 'U╜V get W;t;T;ÉPR' 'Σ Prompt for response from keyboard'            °
  757.   'ÉPR╜T╜ÉAV[ÉIO+255] ╪ ╕(0⌠ÉNC ''V'')/L0 ╪ V╜1' 'L0:V╜V╧1' 'æ╜W ╪ t╜æ'        °
  758.   'U╜(+/^\t=T)╟t' '╕(''╕''⌠╞U)/L1 ╪ ╕' 'L1:╕V/0' 't╜(U⌠'' '')ΓU'               °
  759. X 'U╜(µt),(ΓU),t'                                                              °
  760. *(1997 7 28 13 33 8 424)                                                       °
  761.  Fglobals ÉFX 'globals' 'Σ Initialize useful global variables'                 °
  762.   'uc╜''ABCDEFGHIJKLMNOPQRSTUVWXYZ'''                                          °
  763.   'lc╜''abcdefghijklmnopqrstuvwxyz''' 'dig╜''1234567890'''                     °
  764. X 'r╜ÉAV[13+ÉIO]' 'q╜'''''''''                                                 °
  765. *(1997 7 3 12 47 6 368)                                                        °
  766.  Finitialize ÉFX 'initialize;T' 'Σ Initialize workspace'                       °
  767.   '''AT ALL TIMES, TO CONTINUE, PRESS RETURN!'',r'                             °
  768.   '''To see disclaimers enter:'',r,''    disclaimer''' 'do' 'erase'            °
  769.   'globals'                                                                    °
  770.   '''Make sure the CAP LOCK light on your keyboard (upper right) is ON!'       °
  771. X'' 'endd'                                                                     °
  772. *(1997 7 27 13 14 33 444)                                                      °
  773.  Flabel ÉFX 'u╜v label w'                                                      °
  774.   'Σ Return 1 if label w does not begin with a cap'                            °
  775.   '╕(0⌠ÉNC ''v'')/L0 ╪ v╜0' 'L0:v╜v╧1 ╪ w╜εw ╪ ╕v/L1 ╪ ╕(u╜0⌠ÉNC w)/0'         °
  776. X 'L1:╕(u╜~^/wεlc,uc,dig)/0' 'u╜w[1]εlc,dig'                                   °
  777. XClc 1 26 abcdefghijklmnopqrstuvwxyz                                           °
  778. *(1997 7 13 12 28 55 528)                                                      °
  779.  Fnon ÉFX 'non;T;RC;ET;R' 'Σ Ignore keyboard entry' 'æ╜''      ''' 'T╜æ'       °
  780.   '╕(0=µ(T⌠'' '')/T)/0' '(RC ET R)╜ÉEC T' '╕(0=RC)/2'                          °
  781. X '╕((1=RC)doif ''R'')/2' '╕2'                                                 °
  782. *(1997 7 13 12 28 55 528)                                                      °
  783.  Fnotb ÉFX 'u╜notb w' 'Σ Remove trailing blanks'                               °
  784.   '╕((1<╧w)doif ''u╜notb■ w'')/0' '╕((1<µµw)doif ''u╜πnotb Γ[2]w'')/0'         °
  785. X 'u╜(1-(,'' ''⌠Φw)∞1)╟w'                                                      °
  786. *(1997 7 27 12 55 6 496)                                                       °
  787.  Fproblems ÉFX 'problems' 'Σ Problems'                                         °
  788.   '''That is all for this lesson. Remember, if you want to practice,'''        °
  789.   '''and plan to use direct definitions, be sure to first enter GO.'''         °
  790.   '''Direct definitions will then be accepted. To exit GO, enter EXIT.''       °
  791.  ,r'                                                                           °
  792.   '''To erase a previously defined DIRECT DEFINITION FUNCTION, enter'',r       °
  793.  ' '''       )ERASE functionname'',r'                                          °
  794. X '''WARNING! do not use )ERASE on other labels.'',r'                          °
  795. XCq 0 '                                                                        °
  796. XCr 0                                                                         °
  797. *(1997 7 13 12 28 56 532)                                                      °
  798.  Freplace ÉFX 'u╜v replace u;i;r;s' 'Σ Replace elements in v in u'             °
  799.   'i╜Γ∞µu' 's╜2πv╜(v⌠'' '')Γv' 'i╜⌡r╜i⌡■Γ[1]u°.=╞v'                            °
  800. X 'u[(εi)/εr]╜s[(εi)/εi⌡■∞µs]'                                                 °
  801. *(1997 7 13 12 28 56 532)                                                      °
  802.  Fround ÉFX 'U╜V round W' 'Σ Half adjust to V th decimal'                      °
  803. X 'U╜(╛0.5+W⌡10*V)÷10*V'                                                       °
  804. *(1997 5 31 11 30 1 380)                                                       °
  805.  Frule ÉFX 'V rule W' 'Σ Additional remarks on rules'                          °
  806.   '╕(2=ÉNC ''V'')/L ╪ V╜0' 'L:╕((╞W)=∞8)/L1,L2,L3,L4,L5,L6,L7,L8'              °
  807.   '''For rules not described in this lesson, see workspace INDEX'''            °
  808.   '╕0' 'L1:╕(V>1)/L1X'                                                         °
  809.   '''RULE 1. For arithmetic operations a vector must be matched with a''       °
  810.  ' '''        scalar, or another vector of the same length.'',2µr'             °
  811.   '╕(0=V)/0'                                                                   °
  812.   'L1X:''This is the first of many rules dealing with the concept of'''        °
  813.   '''CONFORMABILITY. This means that elements to be processed by APL2'''       °
  814.   '''must in some ways match.''' '╕L0' 'L2:╕(V>1)/L1X'                         °
  815.   '''RULE 2. The reduction operator places the function, (specified to''       °
  816.  '                                                                             °
  817.   '''        its left), between all pairs of the vector. It then evaluat       °
  818.  es''' '''        the resulting expression.'',2µr' '╕(0=V)/0'                  °
  819.   'L2X:''There is more to this, but at this stage the rule is essentiall       °
  820.  y''' '''correct.''' '╕L0' 'L3:╕(V>1)/L1X'                                     °
  821.   '''RULE 3. All APL2 expressions are evaluated from right to left'',2µr       °
  822.  ' '╕(0=V)/0'                                                                  °
  823.   'L3X:''This rule is valid in APL, which is the earlier version of APL2       °
  824.  .'''                                                                          °
  825.   '''For APL2, the rule has been restated in a totally different way.'''       °
  826.   '''However until we introduce some concepts that are new to APL2, the'       °
  827.  '' '''newer form reduces to RULE 3 as stated.''' '╕L0' 'L4:╕(V>1)/L1X'        °
  828.   '''RULE 4. Vectors in APL2 can have lengths of zero and one.'',2µr'          °
  829.   '╕(0=V)/0'                                                                   °
  830.   'L4X:''This is the first concept that begins to introduce the idea tha       °
  831.  t no'''                                                                       °
  832.   '''matter what the APL expression, if it is valid, it must produce a''       °
  833.  '                                                                             °
  834.   '''valid APL2 object. (Shades of which came first, the chicken or the        °
  835.  egg)''' '╕L0' 'L5:╕(V>1)/L1X'                                                 °
  836.   '''RULE 5. The shape of a variable is a vector. The shape of a vector'       °
  837.  '' '''        is a vector of length 1. The shape of a scalar is a'''          °
  838.   '''        vector of length zero.'',2µr' '╕(0=V)/0'                          °
  839.   'L5X:''The left argument of RESHAPE is by definition a vector. If APL2       °
  840.   is'''                                                                        °
  841.   '''to be internally consistent, the inverse operation to RESHAPE (whic       °
  842.  h''' '''is indeed SHAPE) MUST return the same type of object.''' '╕L0'        °
  843.   'L6:╕(V>1)/L1X'                                                              °
  844.   '''RULE 6. Reduction of a scalar returns that scalar REGARDLESS of'''        °
  845.   '''        the function to the left of the reduction operator.'',2µr'        °
  846.   '╕(0=V)/0'                                                                   °
  847.   'L6X:''Reduction BY DEFINITION reduces the RANK by one. The exception        °
  848.  is'''                                                                         °
  849.   '''for objects whose rank is zero. Since there is no such thing as'''        °
  850.   '''negative rank, reduction is undefined for scalars, and therefore'''       °
  851.   '''the result is to leave the APL2 object unchanged.''' '╕L0'                °
  852.   'L7:╕(V>1)/L1X'                                                              °
  853.   '''RULE 7. The reduction of a null vector produces the identity'''           °
  854.   '''        element of the function.'',2µr' '╕(0=V)/0'                        °
  855.   'L7X:''A null vector may be empty, but it still has rank equal to one.       °
  856.  '''                                                                           °
  857.   '''Therefore its reduction MUST be a scalar. Since there is no data'''       °
  858.   '''in a null vector, the scalar must be such that it has no effect'''        °
  859.   '''on the operation performed by the function: Zero added to anything'       °
  860.  ''                                                                            °
  861.   '''has no effect in addition; one multiplied by anything has no effect       °
  862.  ''' '''in multiplication; and so on.''' '╕L0' 'L8:╕(V>1)/L1X'                 °
  863.   '''RULE 8. Parentheses can (and should) be used to modify the right'''       °
  864.   '''        to left rule to improve efficiency'',2µr' '╕(0=V)/0'              °
  865.   'L8X:''Parentheses are used in APL2 for other purposes as well, but fo       °
  866.  r'''                                                                          °
  867.   '''now, we will use them just to modify the right to left rule (RULE 3       °
  868.  ).'''                                                                         °
  869.   '''If you place parentheses where they are not needed, APL2 will ignor       °
  870. Xe''' '''them.''' 'L0:do' '╕(0=µW╜1╟W)/0' '╕L'                                 °
  871. *(1997 7 13 12 28 57 536)                                                      °
  872.  Fshow ÉFX '╢V show ╢W;╢T;╢B' 'Σ Display and execute ╢W'                       °
  873.   '╢T╜(0=ÉNC ''╢V'')doif ''╢V╜0'''                                             °
  874.   '╕((0=╧╢W)doif ''show ╢W,'''' '''''')/0'                                     °
  875.   '╕((1<╧╢W)doif ''╢V show ■╢W'')/0' '''      '',╢W'                           °
  876. X '╕((╢V^'':''ε╢W)doif ''╢T╜evaldd ╢W'')/L0' '''ÉEM'' ÉEA ╢W' 'L0:do'          °
  877. *(1997 8 7 14 15 12 292)                                                       °
  878.  Fshowdd ÉFX 'u╜showdd w;a;b;c;r'                                              °
  879.   'Σ Display a direct definition function'                                     °
  880.   '╕((1=╧w)doif ''u╜showdd Γw'')/u╜0'                                          °
  881.   '╕((3⌠ÉNC╞w)doif ''(ε╞w),'''' is not a function'''''')/0'                    °
  882.   'c╜Γ[2]ÉCR╞w' 'c╜notb(2╞c),(Γ''aw α∙'')replace■2╟c'                          °
  883.   '╕((~''ΣDD''╧3╞2πc)doif ''''''Not a direct definition function'''''')/       °
  884.  0' 'u╜1' 'b╜('' ''⌠╞c)Γ╞c' 'a╜''      ''' 'r╜2╟3πc'                           °
  885.   '╕((3=µc)doif ''a,(╞w),'''':'''',r,(3<µ2πc)/''''   Σ'''',3╟2πc'')/0'         °
  886.   'a╜a,(╞w),'':'',(2╟5πc),'':''' 'b╜(+\r=''('')-+\r='')''' 'b╜b∞0'             °
  887. X 'a╜a,(²3╟(b-1)╞3╟r),'':'',2╟»(b+1)╟r' 'a,(3<µ2πc)/''  Σ'',3╟2πc'             °
  888. *(1997 7 13 12 28 57 536)                                                      °
  889.  Fshowfn ÉFX 'U╜V showfn W;F;N;T;ÉIO' 'Σ Simulate ╖W[É]'                       °
  890.   'T╜(0=ÉNC ''V'')doif ''V╜0''' 'ÉIO╜0'                                        °
  891.   'U╜r,''      '',''╖'',W,''[É]'',(╞V)╞''╖''' 'N╜1╞µF╜ÉCR W' 'N╜«∞N'           °
  892.   'N╜(N⌠'' '')ΓN' 'F╜(π''['',■N,■Γ''] ''),F'                                   °
  893.   'T╜(1<µ,V)doif ''F╜F[1╟V;]'' ''U╜''''''''''' 'U╜²1╟U,r,,F,r'                 °
  894. X 'U╜((-+/^\'' ''=ΦU)╟U),('' ╖'')[╞V],r'                                       °
  895. *(1997 7 13 12 28 58 540)                                                      °
  896.  Fsimdd ÉFX 'u╜simdd w;e' 'Σ Direct definition mode' 'u╜0'                     °
  897.   '╕((0⌠ÉNC╞w)doif ''''''Already defined'''''')/0' 'e╜''α''ε2πw'               °
  898.   'w[2]╜Γ''u╜'',''α∙ aw'' replace 2πw' 'w╜w[1 3 2]'                            °
  899. X 'w[1]╜Γε''u╜'',(e/''a ''),w[1],'' w''' 'u╜╧ÉFX w'                            °
  900. *(1997 5 18 12 10 24 344)                                                      °
  901.  Fsquare ÉFX 'square' 'Σ Unit square in the complex plane'                     °
  902.   '''i┌───────┐1+i''' ''' │ °     │''' ''' │   °   │'''                        °
  903. X ''' │ °   ° │''' '''0└───────┘1'''                                           °
  904. *(1992 6 3 9 59 17 424)                                                        °
  905.  Ftab ÉFX 'U╜V tab W;T;A;B;C;D;E;F;G;M;ÉPW' 'Σ Tabulate list W'                °
  906.   'T╜(0=ÉNC ''V'')doif ''V╜0''' 'M╜''Invalid data for tabulation'''            °
  907.   'V╜4╞V' 'ÉPW╜130╛30⌐G╜V[2]+79⌡V[2]=0'                                        °
  908.   'L1:╕((1<╧W)doif ''''''W╜∞0'''' ÉEA ''''W╜πW'''''')/L1'                      °
  909.   '╕(((0=µεW)δ2<µµW)doif ''U╜(~V╧4╞0)/M'')/0'                                  °
  910.   'T╜(1≥µµU╜«W)doif ''U╜πW╜(U⌠'''' '''')ΓU'''                                  °
  911.   'T╜(0<V[1])doif ''U╜(«(Φ1,╞µW)µ(V[3]µ'''' ''''),∞(╞µW)-V[3]),'''' ''''       °
  912.  ,U''' '╕(G<30)/0' 'T╜(F╜µεV[4])+C╜1╟B╜µA╜(V[3],0)╟U'                          °
  913.   'T╜⌐(1╞B)÷1⌐╛(ÉPW+F)÷T' 'U╜(E╜(V[3],C)╞U),[1](B╜T,1╟B)╞A'                    °
  914.   '''D╜εV[4]'' ÉEA ''D╜ÉAV[εV[4]+33⌡V[4]=0]''' 'L0:A╜(T,0)╟A'                  °
  915. X '╕(0=1╞µA)/0' 'U╜U,(((T+V[3]),µD)µD),E,[1]B╞A' '╕L0'                         °
  916. *(1997 7 13 12 28 59 544)                                                      °
  917.  Ftest ÉFX 'U╜V test W;P'                                                      °
  918.   'Σ Describe problem in W, (correct answer in V)' 'U╜2' 'L1:W'                °
  919.   'É╜''      ''' 'P╜æ' '''╕L0'' ÉEA ''P╜»P''' '╕(V╧P)/0'                       °
  920. X 'L0:╕(0=U╜U-1)/0' '''Incorrect. Try again''' '╕L1'                           °
  921. XCuc 1 26 ABCDEFGHIJKLMNOPQRSTUVWXYZ                                           °
  922. *(1997 4 27 12 39 30 516)                                                      °
  923.  Fvec ÉFX 'U╜V vec W;T' 'Σ Draw 2d vector in plane'                            °
  924.   'T╜(0=ÉNC ''V'')doif ''V╜'''''''''''                                         °
  925.   'U╜r,'' '',W[3],r,''2-        +'',W[2],r '':      °'',r,''1-    °'',r'       °
  926. X 'U╜U,'' :  °'',r,''0|....|....|.'',V,,'' '',W[1],r,'' 0    1    2'',r'       °
  927. *(1997 4 27 12 39 30 516)                                                      °
  928.  Fwords ÉFX 'U╜words W;ÉIO' 'Σ Convert phrase to words' 'ÉIO╜0'                °
  929. X 'U╜('' ''⌠W)ΓW'                                                              °
  930.