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

  1. XNÉIO 0 1                                                                      °
  2. XNÉCT 0 1E²13                                                                  °
  3. XCÉFC 1 6 .,*0_²                                                               °
  4. XNÉRL 0 1190959745                                                             °
  5. XCÉPR 1 1                                                                      °
  6. XCÉLX 1 5 TEACH                                                                °
  7. XAA╜1-ÉIO-∞6                                                                   °
  8. *(1996 4 6 15 59 48 592)                                                       °
  9.  FARABIC ÉFX 'ARABIC' 'Σ Origin of the arabic notation'                        °
  10.   '''The symbols representing numeric values (1234567890) can be traced'       °
  11.  ''                                                                            °
  12.   '''to a very old Hindu astronomical text called SINDHIND. In ancient''       °
  13.  '                                                                             °
  14.   '''times there were many competing forms for representing numbers. In'       °
  15.  ''                                                                            °
  16.   '''the period from the 7th to 13th century, the Greek, Roman and Hindu       °
  17.  '''                                                                           °
  18.   '''notations were used extensively by different groups. The Hindu nota       °
  19.  tion'''                                                                       °
  20.   '''eventually proved superior because it was based on only 10 symbols,       °
  21.  '''                                                                           °
  22.   '''including the zero, and could be used to represent arbitrarily larg       °
  23.  e''' '''numbers.'',r'                                                         °
  24.   '''Eventually the Hindu notation was adopted by Arabic scholars. When'       °
  25.  ''                                                                            °
  26.   '''the European translators of Arabic texts opened the doors to ancien       °
  27.  t'''                                                                          °
  28.   '''learning in the 13th and 14th centuries, the gradually evolving Hin       °
  29.  du'''                                                                         °
  30.   '''notation became known as Arabic. By the 16th century, the evolution       °
  31.  '''                                                                           °
  32.   '''was essentially complete as illustrated in the published works by''       °
  33.  ' '''Durer.'',r'                                                              °
  34.   '''Interestingly enough, the Arabs continued to evolve their own'''          °
  35.   '''notation, so that modern Arabic numerals are quite distinctive from       °
  36. X''' '''those used in the Western World.''' 'endd'                             °
  37. XCB 1 4 TEXT                                                                   °
  38. XNB1 1 4 0 1 0 1                                                               °
  39. XNB2 1 4 0 0 1 1                                                               °
  40. XAC╜3 3µ('A')('B')(1)(2)(3)('A')('B')(1)(2)                                    °
  41. *(1997 9 14 12 30 44 504)                                                      °
  42. XFDISCLAIMER ÉFX 'DISCLAIMER' 'Σ Copyright statement' 'disclaimer'             °
  43. *(1996 4 6 15 59 48 592)                                                       °
  44.  FDISPLAY ÉFX 'D╜S DISPLAY A;ÉIO;R;C;HL;HC;HT;HB;VL;VB;V;W;N;B'                °
  45.   'Σ DISPLAY A GENERAL ARRAY IN PICTORIAL FORM'                                °
  46.   'Σ  NORMAL CALL IS MONADIC.  DYADIC CALL USED ONLY IN'                       °
  47.   'Σ    RECURSION TO SPECIFY DISPLAY RANK, SHAPE, AND DEPTH.' 'ÉIO╜0'          °
  48.   '»(0=ÉNC ''S'')/''S╜µA''' 'R╜╞µ,S                   Σ PSEUDO RANK.'          °
  49.   'C╜''┐┌└┘''                 Σ UR, UL, LL, AND LR CORNERS.'                   °
  50.   'HL╜''─''                   Σ HORIZONTAL LINE.'                              °
  51.   'HC╜HL,''Θ╕'',HL,''~+ε''      Σ HORIZONTAL BORDERS.'                         °
  52.   'HT╜HC[(0<R)⌡1+0<╞²1╞,S]' 'ΣW╜,0╧■╞0µΓ(1⌐µA)╞A'                              °
  53.   'HB╜HC[3+3╛(''2⌡~A╧«A'' ÉEA ''1+╞ε0⌡(1⌐⌡/µA)╞,A'')+3⌡1<µµS]'                 °
  54.   'VL╜''│''                   Σ VERTICAL LINE.'                                °
  55.   'VB╜VL,''Φ╟''               Σ VERTICAL BORDER.'                              °
  56.   'V╜VB[(1<R)⌡1+0<²1╞²1╟,S]'                                                   °
  57.   '»(0εµA)/''A╜(1⌐µA)µΓ╞A''   Σ SHOW PROTOTYPE OF EMPTIES.'                    °
  58.   '╕(1<╧A)/GEN' '╕(2<µµA)/D3'                                                  °
  59.   'D╜«A                     Σ SIMPLE ARRAYS.' 'W╜1╞µD╜(²2╞1 1,µD)µD'           °
  60.   'N╜²1+1╟µD' '╕(0=µµA)/SS'                                                    °
  61.   'D╜(C[1],V,((W-1)µVL),C[2]),((HT,NµHL),[0]D,[0]HB,NµHL),C[0],(WµVL),C[       °
  62.  3]' '╕0' 'SS:HB╜((0 '' '')=╞0µΓA)/'' -'''                                     °
  63.   'D╜'' '',('' '',[0]D,[0]HB,Nµ'' ''),'' ''' '╕0'                              °
  64.   'GEN:D╜«DISPLAY■A          Σ ENCLOSED ...' 'N╜Dδ.⌠'' '''                     °
  65.   'D╜(Nδ~1ΦN)≡D' 'D╜(δ≡~''  ''╤D)/D' 'D╜((1,µS)µS)DISPLAY D'                   °
  66.   '╕(2≥µ,S)╟D3E,0' 'D3:D╜0 ²1╟0 1╟«ΓA         Σ MULT-DIMENSIONAL ...'          °
  67.   'W╜1╞µD' 'N╜²1+1╟µD'                                                         °
  68.   'D╜(C[1],V,((W-1)µVL),C[2]),((HT,NµHL),[0]D,[0]HB,NµHL),C[0],(WµVL),C[       °
  69.  3]' 'D3E:N╜²2+µ,S'                                                            °
  70. X 'V╜C[Nµ1],[0]VB[1+0<²2╟,S],[0](((²3+╞µD),N)µVL),[0]C[Nµ2]' 'D╜V,D'           °
  71. *(1996 4 6 15 59 48 592)                                                       °
  72.  FEXIT ÉFX 'EXIT' 'Σ Exit from function' '''To log off type:   )OFF'''         °
  73. X '╕'                                                                          °
  74. *(1996 4 6 15 59 48 592)                                                       °
  75.  FGO ÉFX 'GO;T;E;B' 'Σ Expression driver' 'L0:B╜E╜''''' 'æ╜''      '''         °
  76.   'T╜æ' '╕(^/'' ''=T)/L0' '╕((^/'')OFF ''=5╞6╟T)doif ''EXIT'')/0'              °
  77.   '╕(('':''εT)doif ''B╜evaldd (+/^\'''' ''''=T)╟T'')/L0'                       °
  78.   '''E╜ÉEM'' ÉEA T' '╕(0=µ,E)/L0' '╕B/L0'                                      °
  79.   '''This is not a valid APL2 expression''' 'æ╜''*'''                          °
  80. X '╕(''?''⌠╞1╟æ)/L0' 'E' '╕L0'                                                 °
  81. *(1997 8 22 12 47 29 540)                                                      °
  82.  FHELP ÉFX 'HELP;N;I;T' 'Σ Help to student' '''WHAT TO DO'',r'                 °
  83.   '''  ° To get out of the lesson''' '''       ENTER: EXIT'''                  °
  84.   '''  ° To log off APL2'''                                                    °
  85.   '''       FIRST, ENTER: EXIT  THEN ENTER: )OFF'''                            °
  86.   '''  ° To get help''' '''       ENTER: HELP'''                               °
  87.   '''  ° When you see a prompt on a blank line'''                              °
  88.   '''       ENTER AN APL2 EXPRESSION - OR JUST PRESS: ENTER''' 'do'            °
  89.   '''  ° If you get this line'',r'                                             °
  90.   '''This is not a valid APL2 expression'',r,''*'',r'                          °
  91.   '''        YOU CAN EITHER''' '''           A. PRESS: ENTER'''                °
  92.   '''           B. PRESS: ? and then ENTER to see what was incorrect'''        °
  93.   '''              in your expression causing that response'',r' 'do'          °
  94.   '''HINTS'',r'                                                                °
  95.   '''This lesson is made up of '',(«N╜8),'' components named TEACHx, whe       °
  96.  re''' '''the x stands for a digit:'',r' 'I╜0'                                 °
  97.   'L0:T╜''TEACH'',(«I╜I+1)' 'T,'' '',1╟notb(ÉCR T)[2;]' '╕(N>I)/L0'            °
  98.   'do'                                                                         °
  99.   '''You may review either of these components separately. To do that,''       °
  100.  '                                                                             °
  101.   '''first enter EXIT (and RETURN), then enter the name of the lesson.''       °
  102.  ' '''component (e.g. TEACH4).'',r'                                            °
  103.   '''To re-start the lesson, just enter TEACH'',r'                             °
  104.   '''When the screen fills up, it is a good idea to move the cursor to''       °
  105.  ' '''the start of a convenient paragraph, and press ENTER'',r'                °
  106.   '''You may also wish to press PAGE UP to review the prevous pages.'''        °
  107.   'do' '''RESOURCES'',r'                                                       °
  108.   '''You may also enter ONE of the following words at a time'',r'              °
  109. X '''ARABIC  Origin of the Arabic numerals''' 'endd'                           °
  110. *(1997 9 16 12 37 49 560)                                                      °
  111.  FRI ÉFX 'u╜RI w;t;b' 'ΣDD' 'b╜(t╜w=4)/''u╜''''IV''''''' '╕(t doif b)/0'       °
  112. X 'u╜wµ''I'''                                                                  °
  113. *(1997 9 16 12 37 31 488)                                                      °
  114.  FRIX ÉFX 'u╜RIX w;t;b' 'ΣDD' 'b╜(t╜9=w)/''u╜''''IX'''''''                     °
  115. X '╕(t doif b)/0' 'u╜RV w'                                                     °
  116. *(1997 9 16 12 36 49 556)                                                      °
  117.  FROMAN ÉFX 'u╜a ROMAN w;t;b' 'ΣDD'                                            °
  118.   'b╜(t╜39<w)/''u╜''''This number is too large''''''' '╕(t doif b)/0'          °
  119. X 'u╜RX w'                                                                     °
  120. *(1997 5 31 11 59 20 572)                                                      °
  121.  FRULE ÉFX 'V RULE W' 'Σ Display rules' '╕(2=ÉNC ''V'')/L0'                    °
  122. X '2 rule W ╪ ╕0' 'L0:V rule W'                                                °
  123. *(1997 9 16 12 37 44 540)                                                      °
  124.  FRV ÉFX 'u╜RV w;t;b' 'ΣDD' 'b╜(t╜4<w)/''u╜''''V'''',RV w-5'''                 °
  125. X '╕(t doif b)/0' 'u╜RI w'                                                     °
  126. *(1997 9 16 12 37 13 416)                                                      °
  127.  FRX ÉFX 'u╜RX w;t;b' 'ΣDD' 'b╜(t╜9<w)/''u╜''''X'''',RX w-10'''                °
  128. X '╕(t doif b)/0' 'u╜RIX w'                                                    °
  129. *(1997 8 11 12 43 22 452)                                                      °
  130.  FTEACH ÉFX 'TEACH' 'Σ Start fourth lesson in APL2 by Zdenek V JIZBA'          °
  131.   'exit ''TEACH''' 'initialize' 'TEACH1 Σ Catenation and ravel'                °
  132.   'TEACH2 Σ Compression' 'TEACH3 Σ Replication'                                °
  133.   'TEACH4 Σ N-wise reduction' 'TEACH5 Σ Logical primitive functions'           °
  134.   'TEACH6 Σ Indexing; indexing function and bracket indexing'                  °
  135.   'TEACH7 Σ Vector specification and selective specification'                  °
  136. X 'TEACH8 Σ From arabic to roman notation' 'problems'                          °
  137. *(1997 5 31 11 48 47 636)                                                      °
  138.  FTEACH1 ÉFX 'TEACH1' 'Σ Review previous lesson' 'exit ''TEACH1'''             °
  139.   '''In the previous lesson we learned about direct definition. Although       °
  140.  '''                                                                           °
  141.   '''this form of programming is not supported by APL2, it is a useful''       °
  142.  '                                                                             °
  143.   '''tool in studying the language. Direct definition is supported here'       °
  144.  ''                                                                            °
  145.   '''by built in software, and we will use it to study primitive functio       °
  146.  ns,''' '''operators, and other constructs of the language.'',r' 'do'          °
  147.   '''In this lesson we will learn about those features of APL2 that are'       °
  148.  ''                                                                            °
  149.   '''most useful in development of algorithms. We will find out what can       °
  150.  '''                                                                           °
  151.   '''be done with CATENATION, BOOLEAN VECTORS, LOGICAL FUNCTIONS and'''        °
  152.   '''INDEXING.'',r'                                                            °
  153.   '''Suppose we wanted to combine two words into one. Let us assume that       °
  154.  '''                                                                           °
  155.   '''the two words are IN and TENT. Let us try some experiments:'',r'          °
  156.   'show ''''''IN'''' ''''TENT'''''' ''''''IN''''''''TENT'''''''                °
  157.   '''If our goal was to generate the word INTENT, we have clearly failed       °
  158.  .''' 'do'                                                                     °
  159.   '''Let us see what these two expressions actually generate.'''               °
  160.   'show ''DISPLAY ''''IN'''' ''''TENT'''''' ''DISPLAY ''''IN''''''''TENT       °
  161.  '''''''                                                                       °
  162.   '''In the first example we merely created a two element vector contain       °
  163.  ing'''                                                                        °
  164.   '''the two words ''''IN'''' and ''''TENT''''. In the second example, t       °
  165.  he double'''                                                                  °
  166.   '''quote between IN and TENT was merely converted to a single quote.''       °
  167.  ' 'do' '''This provides us with a new rule:'',r' '0 RULE 9'                   °
  168.   '''The reason for this rule is to distinguish the end of a character''       °
  169.  ' '''string quote from a quote that is PART of the string.''' 'do'            °
  170.   '''But we still do not know how to combine strings into single strings       °
  171.  .''' '''The comma (,) serves that purpose'',r'                                °
  172.   'show ''''''IN'''',''''TENT'''''' ''DISPLAY ''''IN'''',''''TENT'''''''       °
  173.   '''The process of combining vectors with a comma is called CATENATION.       °
  174.  ''' '''It works with numbers as well'',r'                                     °
  175.   'show ''V1╜?3µ10'' ''V2╜?3µ10'' ''DISPLAY V1 V2'' ''DISPLAY V1,V2'''         °
  176.   'do'                                                                         °
  177.   '''Is there a monadic version of the comma? Yes, and it is called RAVE       °
  178.  L.'''                                                                         °
  179.   '''We will study it in lesson 6, but right now we can state two'''           °
  180.   '''properties of ravel:'',r'                                                 °
  181.   '''  1. The ravel of a scalar is a vector of length 1'',r'                   °
  182.   'show ''µ,5'''                                                               °
  183.   '''  2. The ravel of a vector leaves the vector unchanged'',r'               °
  184. X 'show ''µ3 4 5'' ''µ,3 4 5''' 'endd'                                         °
  185. *(1997 4 29 12 20 30 448)                                                      °
  186.  FTEACH2 ÉFX 'TEACH2;VECTOR;CONS' 'Σ Compression' 'exit ''TEACH2'''            °
  187.   '''In lesson 2 (TEACH2) we learned about reduction, and about the'''         °
  188.   '''special symbol called an OPERATOR. With the reduction operator'''         °
  189.   '''we are able to do with a single keystroke what in other programming       °
  190.  '''                                                                           °
  191.   '''languages requires special constructs usually called DO loops.'',r'       °
  192.   '''An operator certainly does not solve the problem any more efficient       °
  193.  ly'''                                                                         °
  194.   '''than a do loop. What it does, is to remove from you, the programmer       °
  195.  '''                                                                           °
  196.   '''the task of dealing with operational details that SHOULD be handled       °
  197.  ''' '''by the smart computer.''' 'do'                                         °
  198.   '''Since the reduction operator provides such a NOTATIONAL advantage,'       °
  199.  ''                                                                            °
  200.   '''it should be no surprise that its versatility has been extended.'',       °
  201.  r'                                                                            °
  202.   '''We have already seen that BOOLEAN vectors contain only values zero'       °
  203.  ''                                                                            °
  204.   '''and one. The zero values stand for denial (no, false) while the one       °
  205.  '''                                                                           °
  206.   '''values stand for affirmation (yes, true). It therefore makes sense'       °
  207.  '' '''to apply a boolean vector as a left argument to the reduction'''        °
  208.   '''operator'',r' 'show ''1 0 0 1 0 0 0 0 1/''''REDUCTION'''''''              °
  209.   '''The boolean vector has the same length as the character string. Onl       °
  210.  y'''                                                                          °
  211.   '''those letters are returned for which the corresponding boolean valu       °
  212.  e'''                                                                          °
  213.   '''is TRUE (1). This process of using boolean vectors as left argument       °
  214.  '''                                                                           °
  215.   '''to the reduction operator is called COMPRESSION. Unlike reduction,'       °
  216.  '' '''compression does not reduce the rank of the result'',r'                 °
  217.   'show ''µµ''''COMPRESSION'''''' ''µµ1 1 1 0 0 0 0 0 0 1 1/''''COMPRESS       °
  218.  ION''''''' '''It works just as well for numbers'',r'                          °
  219.   'show ''0 1 1/3 4 5'' ''(10µ1 0)/∞10'''                                      °
  220.   '''Note that in the second example the left argument is an APL2 expres       °
  221.  sion'''                                                                       °
  222.   '''that returns a boolean vector. To see the great power that this giv       °
  223.  es'''                                                                         °
  224.   '''us, recall that we can use any primitive functions that produce a''       °
  225.  ' '''boolean result.'',r'                                                     °
  226.   'show ''VECTOR╜?20µ10'' ''VECTOR'' ''(VECTOR<5)/VECTOR'''                    °
  227.   '''The last expression is an algorithm to extract only those elements'       °
  228.  ''                                                                            °
  229.   '''in the variable VECTOR, with a value less than 5. The next example'       °
  230.  '' '''shows how we can use this feature with character vectors'',r'           °
  231.   'show ''(''''MISSISSIPPI''''ε''''AEIOU'''')/''''MISSISSIPPI'''''''           °
  232.   '''To extract consonants, we could proceed in the following way:'',r'        °
  233.   'show ''CONS╜''''BCDFGHJKLMNPQRSTVWXZ'''''''                                 °
  234.   'show ''(''''MISSISSIPPI''''εCONS)/''''MISSISSIPPI'''''''                    °
  235.   '''Of course one could always use'',r'                                       °
  236.   'show ''(1-''''MISSISSIPPI''''ε''''AEIOU'''')/''''MISSISSIPPI'''''''         °
  237.   '''Later in this lesson we will see yet another way to remove wowels''       °
  238. X' '''without using CONS.''' 'endd'                                            °
  239. *(1997 5 31 11 50 39 612)                                                      °
  240.  FTEACH3 ÉFX 'TEACH3' 'Σ Replication' 'exit ''TEACH3'''                        °
  241.   '''The early versions of APL supported reduction, but it had been'''         °
  242.   '''pointed out that the process could be generalized. After all,'''          °
  243.   '''the boolean vector can be interpreted as saying: "Return the right'       °
  244.  ''                                                                            °
  245.   '''element the number of times indicated by the corresponding value'''       °
  246.   '''in the left argument."'',r'                                               °
  247.   '''Here we no longer think of the boolean vector as a YES NO switch,''       °
  248.  '                                                                             °
  249.   '''but rather as a kind of multiplier or replicator. APL2 indeed does'       °
  250.  '' '''support this more generalized notion of reduction, calling it'''        °
  251.   '''REPLICATION'',r'                                                          °
  252.   'show ''1 1 2 0 0 0 0 1 0 0 2 0 0 1 2 0 1 0 0 0 0/''''MISER FINDS TIP        °
  253.  IN IT''''''' '''Let us write the rule for replication:'',r'                   °
  254.   '0 RULE 10'                                                                  °
  255.   '''Naturally, replication will also work on numeric vectors, and even'       °
  256.  '' '''on mixed vectors'',r'                                                   °
  257.   'show ''+/(∞5)/∞5'' ''1 2 0 3/1 2,''''AB'''''''                              °
  258.   '''Why did we have to use a comma in the second example? Also explain        °
  259.  why''' '''the first example produces the same result as'',r'                  °
  260. X 'show ''+/(∞5)*2''' 'endd'                                                   °
  261. *(1997 9 16 12 42 1 388)                                                       °
  262.  FTEACH4 ÉFX 'TEACH4;VECTOR;PRICE;VOLATILITY' 'Σ N-wise reduction'             °
  263.   'exit ''TEACH4'''                                                            °
  264.   '''Since the reduction operator is so useful, can we improve on it?'''       °
  265.   '''APL as a language is not static. As new demands for problem solving       °
  266.  '''                                                                           °
  267.   '''arise, the APL community continues to seek ever more powerful ways'       °
  268.  '' '''to express complex processes with simple notation.'',r'                 °
  269.   '''In many fields of science as well as in economics and statistics'''       °
  270.   '''there is frequent need to calculate what is called "moving '''            °
  271.   '''averages". This is a process where given some integer, say N'''           °
  272.   '''we want to calculate the average for N consecutive values of a'''         °
  273.   '''vector. So for a vector of length M (naturally M≥N) we want to'''         °
  274.   '''produce a vector of (1+M-N) average values.''' 'do'                       °
  275.   '''   N-WISE REDUCTION'',r'                                                  °
  276.   '''In older versions of APL this calculation required a fairly simple'       °
  277.  ''                                                                            °
  278.   '''but still somewhat inconvenient expression. For one, the APL progra       °
  279.  mmer'''                                                                       °
  280.   '''had to remember the expression, derive it, or remember the name of'       °
  281.  ''                                                                            °
  282.   '''a user defined function that produced the desired result. Such a'''       °
  283.   '''mental effort distracts from the problem solving task at hand.'',r'       °
  284.   '''In APL2 there is a form of the reduction operator that solves this'       °
  285.  '' '''class of problems in a very simple way.'',r' 'show ''2+/∞10'''          °
  286.   '''This is equivalent to doing the following:'',r'                           °
  287.   '(∞9),''+'',(1+∞9),''='',[1.1]2+/∞10' 'do'                                   °
  288.   '''We could just as well have used other primitives. Consider ⌡ ⌐ and        °
  289.  ╛'',r'                                                                        °
  290.   'show ''3⌡/∞10'' ''VECTOR╜?20µ10'' ''VECTOR'' ''5⌐/VECTOR'' ''5╛/VECTO       °
  291.  R'''                                                                          °
  292.   '''One might ask if the idioms N⌐/VECTOR and N╛/VECTOR have any'''           °
  293.   '''practical applications. Consider the stock broker who is intersted'       °
  294.  ''                                                                            °
  295.   '''in the volatility of a stock over a period of say 5 weeks. Then if'       °
  296.  ''                                                                            °
  297.   '''VECTOR represents the closing price of a stock at the end of a'''         °
  298.   '''week for a period of 20 weeks, we can define volatility in the'''         °
  299.   '''following way:'',r'                                                       °
  300.   '1 show ''PRICE╜20+VECTOR'' ''VOLATILITY:(α⌐/∙)-α╛/∙'' ''5 VOLATILITY        °
  301.  PRICE'''                                                                      °
  302.   '''The point of any generalized APL2 primitive is that it has many'''        °
  303.   '''more application than those originally conceived. Consider the'''         °
  304.   '''following, which is an algorithm for finding double letter pairs'''       °
  305. X '''in text'',r' 'show ''2=/''''MISSISSIPPI''''''' 'endd'                     °
  306. *(1997 5 1 12 24 15 296)                                                       °
  307.  FTEACH5 ÉFX 'TEACH5' 'Σ Logical primitives' 'exit ''TEACH5'''                 °
  308.   '''As we have seen, boolean variables are useful in logical operations       °
  309.  .'''                                                                          °
  310.   '''If you have studied logic, you know of primitive logic functions'''       °
  311.   '''called NOT, AND and OR. Suppose that we have the following two bool       °
  312.  ean''' '''vectors'',r' 'show ''B1╜0 1 0 1'' ''B2╜0 0 1 1'''                   °
  313.   '''Now let us consider the primitive logical operations on these vecto       °
  314.  rs.'''                                                                        °
  315.   '''A logical NOT means negation so that what was true becomes false, a       °
  316.  nd'''                                                                         °
  317.   '''what was false becomes true. We certainly can do that with'',r'           °
  318.   'show ''1-B1'' ''1-B2'''                                                     °
  319.   '''There is, however, a simpler way with the logical primitive NOT (~)       °
  320.  '',r' 'show ''~B1'' ''~B2'''                                                  °
  321.   '''For simple expressions this may not seem as much of an advantage, b       °
  322.  ut'''                                                                         °
  323.   '''as logical expressions become more complex, the special symbol ~ is       °
  324.  '''                                                                           °
  325.   '''a big help. Furthermore, people working with logic are quite used t       °
  326.  o''' '''this notation. (For an even better reason, see below.)''' 'do'        °
  327.   '''In the same way we could use the primitives ⌐ and ╛ to simulate AND       °
  328.  ''' '''and OR'',r' 'show ''B1⌐B2'' ''B1╛B2'''                                 °
  329.   '''The first expression will return true if either the left or the rig       °
  330.  ht'''                                                                         °
  331.   '''argument returns true. The second expression will return true only        °
  332.  if'''                                                                         °
  333.   '''both arguments are true. Despite this, APL2 supports the two logica       °
  334.  l''' '''primitives AND ^, and OR δ'',r' 'show ''B1δB2'' ''B1^B2'''            °
  335.   '''There is a good reason for having these special primitives. If ⌐ or       °
  336.   ╛'''                                                                         °
  337.   '''are applied to arbitrary numeric vectors, APL2 will always produce        °
  338.  a'''                                                                          °
  339.   '''result. However ~, δ and ^ will work ONLY with boolean vectors. If        °
  340.  you'''                                                                        °
  341.   '''were to try an expression such as ^/∞5, you will get an ERROR MESSA       °
  342.  GE.''' 'do'                                                                   °
  343.   '''By using the logical primitives you allow APL2 to help you in the''       °
  344.  '                                                                             °
  345.   '''development of logical algorithms. It is amazing how frequently one       °
  346.  '''                                                                           °
  347.   '''produces a "logical" vector and be dismayed to find it not to be'''       °
  348.   '''boolean. (At least that is my experience.)''' 'do'                        °
  349.   '''Notice that ~ is monadic, while δ and ^ are dyadic. There are no'''       °
  350.   '''monadic δ and monadic ^. There is a dyadic ~, but it is not related       °
  351.  '''                                                                           °
  352.   '''to simple logical operations. We will study dyadic ~ in a later'''        °
  353.   '''session.'',r'                                                             °
  354.   '''We should, however mention two other logical primitives: NOR τ and'       °
  355.  '' '''NAND σ.''' 'show ''B1τB2'' ''B1σB2'''                                   °
  356.   '''You may have noticed that the four element vectors B1 and B2 show''       °
  357.  '                                                                             °
  358.   '''all possible combinations for pairs of true-false. Yet, there is'''       °
  359.   '''a total of 16 distinct patterns for a four character vector'''            °
  360.   '''containing 0 or 1. As an exercise, generate all 16 patterns using''       °
  361.  '                                                                             °
  362.   '''any primitive functions that you have studied so far, and the vecto       °
  363. Xrs''' '''B1 and B2. (Hint: start with 0^B1, B1^B2)''' 'endd'                  °
  364. *(1997 5 31 11 50 5 476)                                                       °
  365.  FTEACH6 ÉFX 'TEACH6' 'Σ Indexing;VECTOR' 'exit ''TEACH6'''                    °
  366.   '''            INDEXING'',r'                                                 °
  367.   '''We have been doing a lot with vectors as single entities. But suppo       °
  368.  se''' '''we wish to study individual components of a vector'',r'              °
  369.   'show ''VECTOR╜?10µ5'' ''VECTOR'''                                           °
  370.   '''How do we access the second element of VECTOR? There is an APL2 pri       °
  371.  mitive''' '''called the INDEXING FUNCTION. It uses the ╙ symbol.'',r'         °
  372.   'show ''2╙VECTOR'''                                                          °
  373.   '''The ╙ symbol is sometimes also called "squad". The indexing functio       °
  374.  n'''                                                                          °
  375.   '''is new to APL2. Although we introduce it here, a more detailed'''         °
  376.   '''discussion requires concepts not yet mentioned. The indexing functi       °
  377.  on'''                                                                         °
  378.   '''is meant to suplement an older notation called BRACKET INDEXING.'',       °
  379.  r'                                                                            °
  380.   '''Bracket indexing uses two symbols called square brackets. The left'       °
  381.  ''                                                                            °
  382.   '''square bracket [ and the right square bracket ]. To access the seco       °
  383.  nd'''                                                                         °
  384.   '''element of VECTOR, we would write the following expression'',r'           °
  385.   'show ''VECTOR[2]'''                                                         °
  386.   '''Notice that we do not refer to the bracket notation as a function.'       °
  387.  ',r' '''To access more than one element of VECTOR, we would write'',r'        °
  388.   'show ''VECTOR[1+∞4]'''                                                      °
  389.   '''The length of the result is equal to the length of the vector insid       °
  390.  e''' '''brackets'',r' 'show ''VECTOR[5µ2]'' ''µVECTOR[123µ1]'''               °
  391.   '''In lesson 2 we learned that vectors can have zero length. Let us'''       °
  392.   '''see what happens if we place such a null vector inside brackets'',r       °
  393.  ' 'show ''VECTOR[∞0]'' ''µVECTOR[∞0]'''                                       °
  394.   '''Now let us try to place NOTHING inside brackets.'',r'                     °
  395.   'show ''VECTOR[]'''                                                          °
  396.   '''Clearly NOTHING is not the same as NULL. Furthermore nothing behave       °
  397.  s''' '''as if the brackets were not there.''' 'do'                            °
  398.   '''Since the numbers inside brackets point to specific elements of'''        °
  399. X '''the vector, we have the following rule'',r' '0 RULE 11' 'endd'            °
  400. *(1997 5 4 13 8 23 280)                                                        °
  401.  FTEACH7 ÉFX 'TEACH7;VECTOR;A;B;C' 'Σ Specification' 'exit ''TEACH7'''         °
  402.   '''We have seen in lesson 1 that specification is the process of placi       °
  403.  ng'''                                                                         °
  404.   '''data into a VARIABLE by means of an assignment arrow. This process'       °
  405.  ''                                                                            °
  406.   '''has been extended in APL2. Many problems, that in the older version       °
  407.  s'''                                                                          °
  408.   '''of APL required complex expressions, can now be solved with a much'       °
  409.  '' '''simpler notation.''' 'do' '''     VECTOR SPECIFICATION'',r'             °
  410.   '''More than one variable can be assigned with a single specification'       °
  411.  ''                                                                            °
  412.   '''expression. The variables to the left of the assignment arrow shoul       °
  413.  d'''                                                                          °
  414.   '''be placed in parentheses. This is called VECTOR SPECIFICATION'',r'        °
  415.   'show ''(A B C)╜(∞6) ''''TEXT'''' (3 3µ''''AB'''',∞3)'' ''A'' ''B'' ''       °
  416.  C''' '''       SELECTIVE SPECIFICATION'',r'                                   °
  417.   '''In older versions of APL, only bracket indexing was allowed. In APL       °
  418.  2,'''                                                                         °
  419.   '''the expressions allowed to the left of the assignment arrow have be       °
  420.  en'''                                                                         °
  421.   '''extended. The expanded process is called SELECTIVE SPECIFICATION. T       °
  422.  he'''                                                                         °
  423.   '''expression including the variable into which the right argument is        °
  424.  to''' '''be placed must be in parentheses.'''                                 °
  425.   '''Here are some examples'',r'                                               °
  426.   'show ''VECTOR╜∞9'' ''(3╙VECTOR)╜0'' ''VECTOR'''                             °
  427.   'show ''(3╟VECTOR)╜∞6'' ''VECTOR'' ''((9µ1 0)/VECTOR)╜''''X'''''' ''VE       °
  428. XCTOR''' '''More examples will be shown in later lessons.''' 'endd'            °
  429. *(1997 8 11 13 12 58 476)                                                      °
  430.  FTEACH8 ÉFX 'TEACH8' 'Σ ROMAN exercise' 'exit ''TEACH7'''                     °
  431.   '''Earlier this lesson, we stated that the notation and primitive'''         °
  432.   '''functions described here, can be used in APL2 programming. As you''       °
  433.  '                                                                             °
  434.   '''learn about APL, try to think about specific problems of your own''       °
  435.  '                                                                             °
  436.   '''knowledge. Then try to develop APL solutions to these problems.'''        °
  437.   'do'                                                                         °
  438.   '''To give you some idea on how one may proceed, the following example       °
  439.  '''                                                                           °
  440.   '''illustrates a very important feature of APL, namely its recursive''       °
  441.  ' '''nature.'',r'                                                             °
  442.   '''The ancient Romans did not use what we now call the Arabic notation       °
  443.  '''                                                                           °
  444.   '''to describe numbers. The Roman notation consisted of the usage of''       °
  445.  '                                                                             °
  446.   '''the capital letters I V X L C D and M. These letters represented th       °
  447.  e'''                                                                          °
  448.   '''numbers 1 5 10 50 100 500 and 1000. To display a number, the letter       °
  449.  s'''                                                                          °
  450.   '''were placed with decreasing value from left to right, but with nota       °
  451.  ble'''                                                                        °
  452.   '''exceptions. For example 4 was represented as IV, and 6 was represen       °
  453.  ted'''                                                                        °
  454.   '''as VI. Let us now develop an algorithm for converting integers into       °
  455.  ''' '''the Roman notation.''' 'do'                                            °
  456.   '''To begin with, let us for simplicity go only as high as 39. (As we'       °
  457.  '' '''learn new primitives we will eventually do much better).'',r'           °
  458.   '1 show ''ROMAN:RX ∙:39<∙:''''This number is too large'''''''                °
  459.   '''Function ROMAN will return the message if we try to convert a'''          °
  460.   '''number greater than 39'',r' 'show ''ROMAN 40'''                           °
  461.   '''Next we define function RX'',r'                                           °
  462.   '1 show ''RX:RIX ∙:9<∙:''''X'''',RX ∙-10'''                                  °
  463.   '''Function RX calls on function RIX, so we have to define that one'',       °
  464.  r' '1 show ''RIX:RV ∙:9=∙:''''IX'''''''                                       °
  465.   '''Function RIX takes care of the special case when ∙ is 9'',r'              °
  466.   '1 show ''RV:RI ∙:4<∙:''''V'''',RV ∙-5'''                                    °
  467.   '''And finally we have to define RI'',r'                                     °
  468.   '1 show ''RI:∙µ''''I'''':∙=4:''''IV'''''''                                   °
  469.   '''Now we can test the ROMAN algorithm'',r'                                  °
  470.   'show ''ROMAN 39'' ''ROMAN 17'''                                             °
  471.   '''The method we have used to solve the conversion of Arabic numerals'       °
  472.  ''                                                                            °
  473.   '''to Roman is called a PRODUCTION SYSTEM. The algorithms in functions       °
  474.  '''                                                                           °
  475.   '''RX RV and RI are PRODUCTION RULES, and the set of possible branches       °
  476.  '''                                                                           °
  477.   '''is a TREE STRUCTURE called DISCRIMINATION NET. This terminology'''        °
  478.   '''is not related in any way to APL. It comes from a discipline'''           °
  479.   '''called Artificial Intelligence. This APL2 solution is an example of       °
  480.  '''                                                                           °
  481.   '''the RECURSIVE nature of the language, since both RX and RV may call       °
  482.  ''' '''on themselves with a reduced argument.''' 'do'                         °
  483.   '''As an exercise try to define functions in the same manner as ROMAN,       °
  484.  '''                                                                           °
  485.   '''to convert Roman notation to Arabic. (For the origin of Arabic nota       °
  486.  tion''' '''enter ARABIC.'',r'                                                 °
  487.   '''In a later chapter we will re-define ROMAN to evaluate numbers up''       °
  488.  '                                                                             °
  489.   '''to 3999. (Beyond that the Romans used a different notation with'''        °
  490. X '''special symbols Γ and π.)''' 'endd'                                       °
  491. XNV1 1 3 9 10 1                                                                °
  492. XNV2 1 3 10 6 6                                                                °
  493. XNVECTOR 1 10 1 1 3 5 1 3 3 5 4 3                                              °
  494. XCa 1 6                                                                        °
  495. *(1997 7 13 12 28 49 504)                                                      °
  496.  Faddquote ÉFX 'u╜addquote w'                                                  °
  497.   'Σ Put quotes around a string, and double existing quotes'                   °
  498. X 'u╜ÉAV[40],((1+w=ÉAV[40])/w),ÉAV[40]'                                        °
  499. XCalpha 1 26 ABCDEFGHIJKLMNOPQRSTUVWXYZ                                        °
  500. *(1997 7 24 13 20 38 476)                                                      °
  501.  Fav ÉFX 'av;A;N;I;ÉIO' 'Σ Display characters in ÉAV' 'ÉIO╜0'                  °
  502.   'A╜22 78µ'' ''' 'N╜3 0«φ12 22µ1+∞356' 'A[;,(6⌡∞12)°.+2 3 4]╜N'               °
  503.   'A[;6+6⌡∞12]╜φ12 22µÉAV' 'ΣA[8 10 13;6]╜'' ''' 'A[13;6]╜'' '''               °
  504. X 'A[14+∞8;68 69 70 72]╜'' ''' 'A'                                             °
  505. XCb 1 6 u╜'IV'                                                                 °
  506.  Ac╜('R0')('(∙[1]µ''M''),(''CDM'' R1 ∙[2]),(''XLC'' R1 ∙[3]),''IVX'' R1        °
  507. X∙[4]')('ΣDD ')                                                                °
  508. XCd 0 ½                                                                        °
  509. *(1991 11 11 8 25 13 316)                                                      °
  510.  Fdate ÉFX 'u╜date w' 'Σ Format date and time of day' 'u╜«6╞w'                 °
  511. X 'u╜('' ''⌠u)Γu' 'u╜εu,■''-- .. '''                                           °
  512. XCdig 1 10 1234567890                                                          °
  513. *(1997 9 9 13 0 45 372)                                                        °
  514.  Fdisclaimer ÉFX 'disclaimer' 'Σ Copyright statement'                          °
  515.   '(10µ'' ''),''Copyright, Z. V. Jizba, 1995,1996,1997'',r'                    °
  516.   ''' This and subsequent workspaces labelled TEACHxx are made available       °
  517.  '''                                                                           °
  518.   '''at no cost to anyone who desires to learn how to use effectively'''       °
  519.   '''the IBM/OS2 version of APL2.'',r'                                         °
  520.   '''This software is provided "AS IS" with no WARRANTY of any kind, eit       °
  521.  her'''                                                                        °
  522.   '''express or implied. Any risk in its use resides with you, the user        °
  523.  of''' '''these tutorials.'',r' '''     ACKNOWLEDGEMENTS'',r'                  °
  524.   ''' In writing these tutorials, I am greatly indebted to Roy Sykes, wh       °
  525.  ose'''                                                                        °
  526.   '''excellent lectures increased my understanding of the language.'''         °
  527.   '''Discussions with the late Harry Bertucelli clarified a number of'''       °
  528.   '''concepts and caused me to change some improper terminology that was       °
  529.  '''                                                                           °
  530.   '''used in previous versions of these tutorials. Mr. Benjamin Archer''       °
  531.  '                                                                             °
  532.   '''kindly checked out a nearly final version, bringing to my attention       °
  533.  ''' '''some ommisions, misspellings, and invalid terminology.'',r'            °
  534. X '''(PRESS ENTER to continue)'''                                              °
  535. *(1997 7 13 12 28 50 508)                                                      °
  536.  Fdo ÉFX 'do;T;E' 'Σ Expression driver' 'E╜''''' 'æ╜''      ''' 'T╜æ'          °
  537.   '╕(^/'' ''=T)/0'                                                             °
  538.   '╕(('':''εT)doif ''B╜evaldd (+/^\'''' ''''=T)╟T'')/2'                        °
  539.   '''E╜ÉEM'' ÉEA T' '╕(0=µ,E)/2'                                               °
  540.   '''This is not a valid APL2 expression''' 'æ╜''*''' '╕(''?''⌠╞1╟æ)/2'        °
  541. X 'E' '╕2'                                                                     °
  542. *(1997 7 13 12 28 50 508)                                                      °
  543.  Fdoif ÉFX 'U╢╜V╢ doif W╢;t╢' 'Σ Rule' '╕(^/~U╢╜V╢)/0'                         °
  544. X '''U╢╜V╢ doif■ W╢'' ÉEA ''»V╢/W╢'''                                          °
  545. *(1997 9 9 12 50 14 444)                                                       °
  546.  Fendd ÉFX 'endd' 'Σ end of special feature' '20µ''²'' ╪ ╕(4<µÉLC)/0'          °
  547. X 'do'                                                                         °
  548. *(1997 8 11 13 14 21 336)                                                      °
  549.  Ferase ÉFX 'erase;T;EXIT;GO;HELP;DISPLAY;ARABIC;RULE;DISCLAIMER'              °
  550.   'Σ Erase all global functions and variables' 'T╜ÉNL 3'                       °
  551.   'T╜(~T^.εlc,'' '')≡T' 'T╜ÉEX(~T[;∞5]^.=''TEACH'')≡T' 'T╜ÉNL 2'               °
  552. X 'T╜(~T^.εlc,'' '')≡T'                                                        °
  553. *(1997 7 27 13 47 41 608)                                                      °
  554.  Fevaldd ÉFX 'u╜evaldd w;c;n' 'Σ Evaluate direct definition' 'u╜0'             °
  555.   'n╜(w∞''Σ'')-1' 'c╜(((n╞w)⌠'':'')Γn╞w),Γ''ΣDD '',(n+1)╟w'                    °
  556.   '╕((1 label╞c)doif ''''''Invalid label'''''')/0'                             °
  557.   '╕((2=µc)doif ''u╜showdd 1╙c'')/0'                                           °
  558.   '╕((3=ÉNC╞c)doif ''u╜⌡µÉ╜(╞c),'''' is already defined.'''''')/0'             °
  559.   '╕((3=µc)doif ''u╜simdd c'')/0' 'c╜(Γ''α∙ aw'')replace■c'                    °
  560.   'u╜ε''u╜'',((''a''εεc[2 3 4])/''a ''),(╞c),'' w;t;b'''                       °
  561.   'u╜u(5πc)(''b╜(t╜'',(3πc),'')/'',addquote ''u╜'',4πc)'                       °
  562. X 'u╜u,''╕(t doif b)/0''(''u╜'',2πc)' 'u╜╧ÉFX u'                               °
  563. *(1997 7 25 13 27 52 564)                                                      °
  564.  Fexit ÉFX 'V exit W;T' 'Σ Exit if too many suspended functions'               °
  565.   '╕(0⌠ÉNC ''V'')/L0 ╪ V╜10' 'L0:╕(V>µÉLC)/0'                                  °
  566.   '''There are too many suspended functions''' '''Please enter '',W'           °
  567. X '╕'                                                                          °
  568. *(1997 7 26 12 33 39 536)                                                      °
  569.  Fget ÉFX 'U╜V get W;t;T;ÉPR' 'Σ Prompt for response from keyboard'            °
  570.   'ÉPR╜T╜ÉAV[ÉIO+255] ╪ ╕(0⌠ÉNC ''V'')/L0 ╪ V╜1' 'L0:V╜V╧1' 'æ╜W ╪ t╜æ'        °
  571.   'U╜(+/^\t=T)╟t' '╕(''╕''⌠╞U)/L1 ╪ ╕' 'L1:╕V/0' 't╜(U⌠'' '')ΓU'               °
  572. X 'U╜(µt),(ΓU),t'                                                              °
  573. *(1997 7 28 13 33 8 424)                                                       °
  574.  Fglobals ÉFX 'globals' 'Σ Initialize useful global variables'                 °
  575.   'uc╜''ABCDEFGHIJKLMNOPQRSTUVWXYZ'''                                          °
  576.   'lc╜''abcdefghijklmnopqrstuvwxyz''' 'dig╜''1234567890'''                     °
  577. X 'r╜ÉAV[13+ÉIO]' 'q╜'''''''''                                                 °
  578. *(1997 7 3 12 47 6 368)                                                        °
  579.  Finitialize ÉFX 'initialize;T' 'Σ Initialize workspace'                       °
  580.   '''AT ALL TIMES, TO CONTINUE, PRESS RETURN!'',r'                             °
  581.   '''To see disclaimers enter:'',r,''    disclaimer''' 'do' 'erase'            °
  582.   'globals'                                                                    °
  583.   '''Make sure the CAP LOCK light on your keyboard (upper right) is ON!'       °
  584. X'' 'endd'                                                                     °
  585. *(1997 7 27 13 14 33 444)                                                      °
  586.  Flabel ÉFX 'u╜v label w'                                                      °
  587.   'Σ Return 1 if label w does not begin with a cap'                            °
  588.   '╕(0⌠ÉNC ''v'')/L0 ╪ v╜0' 'L0:v╜v╧1 ╪ w╜εw ╪ ╕v/L1 ╪ ╕(u╜0⌠ÉNC w)/0'         °
  589. X 'L1:╕(u╜~^/wεlc,uc,dig)/0' 'u╜w[1]εlc,dig'                                   °
  590. XClc 1 26 abcdefghijklmnopqrstuvwxyz                                           °
  591. XNn 0 59                                                                       °
  592. *(1997 7 13 12 28 55 528)                                                      °
  593.  Fnon ÉFX 'non;T;RC;ET;R' 'Σ Ignore keyboard entry' 'æ╜''      ''' 'T╜æ'       °
  594.   '╕(0=µ(T⌠'' '')/T)/0' '(RC ET R)╜ÉEC T' '╕(0=RC)/2'                          °
  595. X '╕((1=RC)doif ''R'')/2' '╕2'                                                 °
  596. *(1997 7 13 12 28 55 528)                                                      °
  597.  Fnotb ÉFX 'u╜notb w' 'Σ Remove trailing blanks'                               °
  598.   '╕((1<╧w)doif ''u╜notb■ w'')/0' '╕((1<µµw)doif ''u╜πnotb Γ[2]w'')/0'         °
  599. X 'u╜(1-(,'' ''⌠Φw)∞1)╟w'                                                      °
  600. XCp 1 2  "                                                                     °
  601. *(1997 7 27 12 55 6 496)                                                       °
  602.  Fproblems ÉFX 'problems' 'Σ Problems'                                         °
  603.   '''That is all for this lesson. Remember, if you want to practice,'''        °
  604.   '''and plan to use direct definitions, be sure to first enter GO.'''         °
  605.   '''Direct definitions will then be accepted. To exit GO, enter EXIT.''       °
  606.  ,r'                                                                           °
  607.   '''To erase a previously defined DIRECT DEFINITION FUNCTION, enter'',r       °
  608.  ' '''       )ERASE functionname'',r'                                          °
  609. X '''WARNING! do not use )ERASE on other labels.'',r'                          °
  610. XCq 0 '                                                                        °
  611. XCr 0                                                                         °
  612. *(1997 7 13 12 28 56 532)                                                      °
  613.  Freplace ÉFX 'u╜v replace u;i;r;s' 'Σ Replace elements in v in u'             °
  614.   'i╜Γ∞µu' 's╜2πv╜(v⌠'' '')Γv' 'i╜⌡r╜i⌡■Γ[1]u°.=╞v'                            °
  615. X 'u[(εi)/εr]╜s[(εi)/εi⌡■∞µs]'                                                 °
  616. *(1997 7 13 12 28 56 532)                                                      °
  617.  Fround ÉFX 'U╜V round W' 'Σ Half adjust to V th decimal'                      °
  618. X 'U╜(╛0.5+W⌡10*V)÷10*V'                                                       °
  619. *(1997 5 31 12 3 40 432)                                                       °
  620.  Frule ÉFX 'V rule W' 'Σ Additional remarks on rules'                          °
  621.   '╕(2=ÉNC ''V'')/L ╪ V╜0' 'L:╕(~(╞W)ε∞8)/LA ╪ V rulea╞W ╪ ╕L0'                °
  622.   'LA:╕((╞W)=8+∞3)/L9,L10,L11' '''This rule number is undefined'' ╪ ╕'         °
  623.   'L9:╕(V>1)/L9X'                                                              °
  624.   '''   RULE 9: To produce a quote inside a character string, enter'''         °
  625.   '''           the quote twice.'',2µr' '╕(0=V)/L0'                            °
  626.   'L9X:''This is used in most other programming languages.''' '╕L0'            °
  627.   'L10:╕(V>1)/L10X'                                                            °
  628.   ''' RULE 10: In replication the left argument must contain only'''           °
  629.   '''          integers. The length of the left argument must be'''            °
  630.   '''          the same as the length of the right argument.'',2µr'            °
  631.   '╕(0=V)/L0'                                                                  °
  632.   'L10X:''The left argument may also have negative integers. Only the nu       °
  633.  mber'''                                                                       °
  634.   '''of positive integers and zeros must add up to the length of the rig       °
  635.  ht'''                                                                         °
  636.   '''argument. Replicate with negative integers is not discussed here be       °
  637.  cause'''                                                                      °
  638.   '''the explanation requires concepts that have not yet been mentioned.       °
  639.  '',r' 'show ''1 1 2 ²1 0 1 1 1 ²1 1 0 1 1/''''CALIFORNIAN''''''' '╕L0'        °
  640.   'L11:╕(V>1)/L11X'                                                            °
  641.   '''   RULE 11: The expression inside square brackets must return'''          °
  642.   '''            positive integers in the range of the length of'''            °
  643.   '''            the indexed vector. If the expression is MISSING,'''          °
  644.   '''            the result is as if the brackets were missing.'',2µr'         °
  645.   '╕(0=V)/L0'                                                                  °
  646.   'L11X:''The expression in brackets need not be a vector. It could be a       °
  647.  n''' '''array as in the next example'',r'                                     °
  648.   'show ''''''CALIFORNIA''''[3 3µ?9µ10]'' ''(∞4)[3 3µ∞4]'''                    °
  649.   '''For rules not described in this lesson, see workspace INDEX'''            °
  650. X 'L0:do' '╕(0=µW╜1╟W)/0' '╕L'                                                 °
  651. *(1997 5 31 11 58 30 608)                                                      °
  652.  Frulea ÉFX 'V rulea W' 'Σ Additional remarks on rules'                        °
  653.   '╕(2=ÉNC ''V'')/L ╪ V╜0' 'L:╕(W=∞8)/L1,L2,L3,L4,L5,L6,L7,L8'                 °
  654.   '''For rules not described in this lesson, see workspace INDEX'''            °
  655.   '╕0' 'L1:╕(V>1)/L1X'                                                         °
  656.   '''RULE 1. For arithmetic operations a vector must be matched with a''       °
  657.  ' '''        scalar, or another vector of the same length.'',2µr'             °
  658.   '╕(0=V)/0'                                                                   °
  659.   'L1X:''This is the first of many rules dealing with the concept of'''        °
  660.   '''CONFORMABILITY. This means that elements to be processed by APL2'''       °
  661.   '''must in some ways match.''' '╕L0' 'L2:╕(V>1)/L1X'                         °
  662.   '''RULE 2. The reduction operator places the function, (specified to''       °
  663.  '                                                                             °
  664.   '''        its left), between all pairs of the vector. It then evaluat       °
  665.  es''' '''        the resulting expression.'',2µr' '╕(0=V)/0'                  °
  666.   'L2X:''There is more to this, but at this stage the rule is essentiall       °
  667.  y''' '''correct.''' '╕L0' 'L3:╕(V>1)/L1X'                                     °
  668.   '''RULE 3. All APL2 expressions are evaluated from right to left'',2µr       °
  669.  ' '╕(0=V)/0'                                                                  °
  670.   'L3X:''This rule is valid in APL, which is the earlier version of APL2       °
  671.  .'''                                                                          °
  672.   '''For APL2, the rule has been restated in a totally different way.'''       °
  673.   '''However until we introduce some concepts that are new to APL2, the'       °
  674.  '' '''newer form reduces to RULE 3 as stated.''' '╕L0' 'L4:╕(V>1)/L1X'        °
  675.   '''RULE 4. Vectors in APL2 can have lengths of zero and one.'',2µr'          °
  676.   '╕(0=V)/0'                                                                   °
  677.   'L4X:''This is the first concept that begins to introduce the idea tha       °
  678.  t no'''                                                                       °
  679.   '''matter what the APL expression, if it is valid, it must produce a''       °
  680.  '                                                                             °
  681.   '''valid APL2 object. (Shades of which came first, the chicken or the        °
  682.  egg)''' '╕L0' 'L5:╕(V>1)/L1X'                                                 °
  683.   '''RULE 5. The shape of a variable is a vector. The shape of a vector'       °
  684.  '' '''        is a vector of length 1. The shape of a scalar is a'''          °
  685.   '''        vector of length zero.'',2µr' '╕(0=V)/0'                          °
  686.   'L5X:''The left argument of RESHAPE is by definition a vector. If APL2       °
  687.   is'''                                                                        °
  688.   '''to be internally consistent, the inverse operation to RESHAPE (whic       °
  689.  h''' '''is indeed SHAPE) MUST return the same type of object.''' '╕L0'        °
  690.   'L6:╕(V>1)/L1X'                                                              °
  691.   '''RULE 6. Reduction of a scalar returns that scalar REGARDLESS of'''        °
  692.   '''        the function to the left of the reduction operator.'',2µr'        °
  693.   '╕(0=V)/0'                                                                   °
  694.   'L6X:''Reduction BY DEFINITION reduces the RANK by one. The exception        °
  695.  is'''                                                                         °
  696.   '''for objects whose rank is zero. Since there is no such thing as'''        °
  697.   '''negative rank, reduction is undefined for scalars, and therefore'''       °
  698.   '''the result is to leave the APL2 object unchanged.''' '╕L0'                °
  699.   'L7:╕(V>1)/L1X'                                                              °
  700.   '''RULE 7. The reduction of a null vector produces the identity'''           °
  701.   '''        element of the function.'',2µr' '╕(0=V)/0'                        °
  702.   'L7X:''A null vector may be empty, but it still has rank equal to one.       °
  703.  '''                                                                           °
  704.   '''Therefore its reduction MUST be a scalar. Since there is no data'''       °
  705.   '''in a null vector, the scalar must be such that it has no effect'''        °
  706.   '''on the operation performed by the function: Zero added to anything'       °
  707.  ''                                                                            °
  708.   '''has no effect in addition; one multiplied by anything has no effect       °
  709.  ''' '''in multiplication; and so on.''' '╕L0' 'L8:╕(V>1)/L1X'                 °
  710.   '''RULE 8. Parentheses can (and should) be used to modify the right'''       °
  711.   '''        to left rule to improve efficiency'',2µr' '╕(0=V)/0'              °
  712.   'L8X:''Parentheses are used in APL2 for other purposes as well, but fo       °
  713.  r'''                                                                          °
  714.   '''now, we will use them just to modify the right to left rule (RULE 3       °
  715.  ).'''                                                                         °
  716.   '''If you place parentheses where they are not needed, APL2 will ignor       °
  717. Xe''' '''them.''' 'L0:do' '╕(0=µW╜1╟W)/0' '╕L'                                 °
  718. XCs 1 2 "                                                                      °
  719. *(1997 7 13 12 28 57 536)                                                      °
  720.  Fshow ÉFX '╢V show ╢W;╢T;╢B' 'Σ Display and execute ╢W'                       °
  721.   '╢T╜(0=ÉNC ''╢V'')doif ''╢V╜0'''                                             °
  722.   '╕((0=╧╢W)doif ''show ╢W,'''' '''''')/0'                                     °
  723.   '╕((1<╧╢W)doif ''╢V show ■╢W'')/0' '''      '',╢W'                           °
  724. X '╕((╢V^'':''ε╢W)doif ''╢T╜evaldd ╢W'')/L0' '''ÉEM'' ÉEA ╢W' 'L0:do'          °
  725. *(1997 7 13 12 28 57 536)                                                      °
  726.  Fshowdd ÉFX 'u╜showdd w;a;b;c;r'                                              °
  727.   'Σ Display a direct definition function'                                     °
  728.   '╕((1=╧w)doif ''u╜showdd Γw'')/u╜0'                                          °
  729.   '╕((3⌠ÉNC╞w)doif ''(ε╞w),'''' is not a function'''''')/0'                    °
  730.   'c╜Γ[2]ÉCR╞w' 'c╜notb(2╞c),(Γ''aw α∙'')replace■2╟c'                          °
  731.   '╕((~''ΣDD''╧3╞2πc)doif ''''''Not a direct definition function'''''')/       °
  732.  0' 'u╜1' 'b╜('' ''⌠╞c)Γ╞c' 'a╜''      ''' 'r╜2╟3πc'                           °
  733.   '╕((3=µc)doif ''a,(╞w),'''':'''',r,(3<µ2πc)/''''   Σ'''',3╟2πc'')/0'         °
  734.   'a╜a,(╞w),'':'',(2╟5πc),'':''' 'b╜(+\r=''('')-+\r='')''' 'b╜b∞0'             °
  735. X 'a╜a,(²3╟(b-1)╞3╟r),'':'',2╟»(b+2)╟r' 'a,(3<µ2πc)/''  Σ'',3╟2πc'             °
  736. *(1997 7 13 12 28 57 536)                                                      °
  737.  Fshowfn ÉFX 'U╜V showfn W;F;N;T;ÉIO' 'Σ Simulate ╖W[É]'                       °
  738.   'T╜(0=ÉNC ''V'')doif ''V╜0''' 'ÉIO╜0'                                        °
  739.   'U╜r,''      '',''╖'',W,''[É]'',(╞V)╞''╖''' 'N╜1╞µF╜ÉCR W' 'N╜«∞N'           °
  740.   'N╜(N⌠'' '')ΓN' 'F╜(π''['',■N,■Γ''] ''),F'                                   °
  741.   'T╜(1<µ,V)doif ''F╜F[1╟V;]'' ''U╜''''''''''' 'U╜²1╟U,r,,F,r'                 °
  742. X 'U╜((-+/^\'' ''=ΦU)╟U),('' ╖'')[╞V],r'                                       °
  743. *(1997 7 13 12 28 58 540)                                                      °
  744.  Fsimdd ÉFX 'u╜simdd w;e' 'Σ Direct definition mode' 'u╜0'                     °
  745.   '╕((0⌠ÉNC╞w)doif ''''''Already defined'''''')/0' 'e╜''α''ε2πw'               °
  746.   'w[2]╜Γ''u╜'',''α∙ aw'' replace 2πw' 'w╜w[1 3 2]'                            °
  747. X 'w[1]╜Γε''u╜'',(e/''a ''),w[1],'' w''' 'u╜╧ÉFX w'                            °
  748. XNt 0 1                                                                        °
  749. *(1992 6 3 9 59 17 424)                                                        °
  750.  Ftab ÉFX 'U╜V tab W;T;A;B;C;D;E;F;G;M;ÉPW' 'Σ Tabulate list W'                °
  751.   'T╜(0=ÉNC ''V'')doif ''V╜0''' 'M╜''Invalid data for tabulation'''            °
  752.   'V╜4╞V' 'ÉPW╜130╛30⌐G╜V[2]+79⌡V[2]=0'                                        °
  753.   'L1:╕((1<╧W)doif ''''''W╜∞0'''' ÉEA ''''W╜πW'''''')/L1'                      °
  754.   '╕(((0=µεW)δ2<µµW)doif ''U╜(~V╧4╞0)/M'')/0'                                  °
  755.   'T╜(1≥µµU╜«W)doif ''U╜πW╜(U⌠'''' '''')ΓU'''                                  °
  756.   'T╜(0<V[1])doif ''U╜(«(Φ1,╞µW)µ(V[3]µ'''' ''''),∞(╞µW)-V[3]),'''' ''''       °
  757.  ,U''' '╕(G<30)/0' 'T╜(F╜µεV[4])+C╜1╟B╜µA╜(V[3],0)╟U'                          °
  758.   'T╜⌐(1╞B)÷1⌐╛(ÉPW+F)÷T' 'U╜(E╜(V[3],C)╞U),[1](B╜T,1╟B)╞A'                    °
  759.   '''D╜εV[4]'' ÉEA ''D╜ÉAV[εV[4]+33⌡V[4]=0]''' 'L0:A╜(T,0)╟A'                  °
  760. X '╕(0=1╞µA)/0' 'U╜U,(((T+V[3]),µD)µD),E,[1]B╞A' '╕L0'                         °
  761. *(1997 7 13 12 28 59 544)                                                      °
  762.  Ftest ÉFX 'U╜V test W;P'                                                      °
  763.   'Σ Describe problem in W, (correct answer in V)' 'U╜2' 'L1:W'                °
  764.   'É╜''      ''' 'P╜æ' '''╕L0'' ÉEA ''P╜»P''' '╕(V╧P)/0'                       °
  765. X 'L0:╕(0=U╜U-1)/0' '''Incorrect. Try again''' '╕L1'                           °
  766. XCu 1 2 IV                                                                     °
  767. XCuc 1 26 ABCDEFGHIJKLMNOPQRSTUVWXYZ                                           °
  768. XNw 0 4                                                                        °
  769. XCx 0 !                                                                        °
  770.