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

  1. XNÉIO 0 1                                                                      °
  2. XNÉCT 0 1E²13                                                                  °
  3. XCÉFC 1 6 .,*0_²                                                               °
  4. XNÉRL 0 887972091                                                              °
  5. XCÉPR 1 1                                                                      °
  6. XCÉLX 1 5 TEACH                                                                °
  7. XAA╜1-ÉIO-∞20                                                                  °
  8. *(1997 8 18 12 54 27 544)                                                      °
  9.  FACC1 ÉFX 'Z╜KEYS ACC1 AMTS' 'Σ Accumulate AMTS by KEYS'                      °
  10. X 'Z╜((∞µKEYS)=KEYS∞KEYS)/KEYS' 'Z╜Z,[0.5]AMTS+.⌡KEYS°.=Z'                     °
  11. *(1997 8 18 12 54 32 564)                                                      °
  12.  FACC2 ÉFX 'Z╜KEYS ACC2 AMTS;P' 'Σ N⌡LOG N solution'                           °
  13.   'KEYS╜KEYS[Z╜√KEYS]' 'P╜²1╟1,KEYS⌠1ΦKEYS'                                    °
  14. X 'Z╜(P/KEYS),[0.5]+/■(+\P)ΓAMTS[Z]'                                           °
  15. *(1996 4 6 16 9 32 332)                                                        °
  16.  FALGORITHMS ÉFX 'ALGORITHMS' 'Σ Classification on basis of cost'              °
  17.   '''PROBLEM TYPE      SIZE FACTOR       EXAMPLE APL2 EXPRESSION'''            °
  18.   '''Constant              K             µA'''                                 °
  19.   '''Logarithmic          ╡N'''                                                °
  20.   '''Linear                N             -A'''                                 °
  21.   '''N(log N)           N⌡╡N             √A'''                                 °
  22.   '''Quadratic           N*2           A°.⌡A'''                                °
  23. X '''Cubic               N*3''' '''Exponential          *N'',r'                °
  24. XAB╜1-ÉIO-∞10                                                                  °
  25. *(1996 4 6 16 9 32 332)                                                        °
  26.  FBIND ÉFX 'BIND' 'Σ Binding rules of APL2'                                    °
  27.   '''  1. Brackets bind to the left'''                                         °
  28.   '''  2. Left arrow binds to the left'''                                      °
  29.   '''  3. Dyadic operator binds to the right'''                                °
  30.   '''  4. Strand notation binding'''                                           °
  31.   '''  5. Operator binds to its left'''                                        °
  32.   '''  6. Function binds to its left'''                                        °
  33.   '''  7. Function binds to its right'''                                       °
  34. X '''  8. Left arrow binds to its right'',r'                                   °
  35. XAC╜1 2 3 4 5                                                                  °
  36. XACOLS╜('PRODUCT')('AMOUNT')('PRICE')                                          °
  37. *(1997 9 14 12 30 44 504)                                                      °
  38. XFDISCLAIMER ÉFX 'DISCLAIMER' 'Σ Copyright statement' 'disclaimer'             °
  39. *(1996 4 6 16 9 32 332)                                                        °
  40.  FDISPLAY ÉFX 'D╜S DISPLAY A;ÉIO;R;C;HL;HC;HT;HB;VL;VB;V;W;N;B'                °
  41.   'Σ DISPLAY A GENERAL ARRAY IN PICTORIAL FORM'                                °
  42.   'Σ  NORMAL CALL IS MONADIC.  DYADIC CALL USED ONLY IN'                       °
  43.   'Σ    RECURSION TO SPECIFY DISPLAY RANK, SHAPE, AND DEPTH.' 'ÉIO╜0'          °
  44.   '»(0=ÉNC ''S'')/''S╜µA''' 'R╜╞µ,S                   Σ PSEUDO RANK.'          °
  45.   'C╜''┐┌└┘''                 Σ UR, UL, LL, AND LR CORNERS.'                   °
  46.   'HL╜''─''                   Σ HORIZONTAL LINE.'                              °
  47.   'HC╜HL,''Θ╕'',HL,''~+ε''      Σ HORIZONTAL BORDERS.'                         °
  48.   'HT╜HC[(0<R)⌡1+0<╞²1╞,S]' 'ΣW╜,0╧■╞0µΓ(1⌐µA)╞A'                              °
  49.   'HB╜HC[3+3╛(''2⌡~A╧«A'' ÉEA ''1+╞ε0⌡(1⌐⌡/µA)╞,A'')+3⌡1<µµS]'                 °
  50.   'VL╜''│''                   Σ VERTICAL LINE.'                                °
  51.   'VB╜VL,''Φ╟''               Σ VERTICAL BORDER.'                              °
  52.   'V╜VB[(1<R)⌡1+0<²1╞²1╟,S]'                                                   °
  53.   '»(0εµA)/''A╜(1⌐µA)µΓ╞A''   Σ SHOW PROTOTYPE OF EMPTIES.'                    °
  54.   '╕(1<╧A)/GEN' '╕(2<µµA)/D3'                                                  °
  55.   'D╜«A                     Σ SIMPLE ARRAYS.' 'W╜1╞µD╜(²2╞1 1,µD)µD'           °
  56.   'N╜²1+1╟µD' '╕(0=µµA)/SS'                                                    °
  57.   'D╜(C[1],V,((W-1)µVL),C[2]),((HT,NµHL),[0]D,[0]HB,NµHL),C[0],(WµVL),C[       °
  58.  3]' '╕0' 'SS:HB╜((0 '' '')=╞0µΓA)/'' -'''                                     °
  59.   'D╜'' '',('' '',[0]D,[0]HB,Nµ'' ''),'' ''' '╕0'                              °
  60.   'GEN:D╜«DISPLAY■A          Σ ENCLOSED ...' 'N╜Dδ.⌠'' '''                     °
  61.   'D╜(Nδ~1ΦN)≡D' 'D╜(δ≡~''  ''╤D)/D' 'D╜((1,µS)µS)DISPLAY D'                   °
  62.   '╕(2≥µ,S)╟D3E,0' 'D3:D╜0 ²1╟0 1╟«ΓA         Σ MULT-DIMENSIONAL ...'          °
  63.   'W╜1╞µD' 'N╜²1+1╟µD'                                                         °
  64.   'D╜(C[1],V,((W-1)µVL),C[2]),((HT,NµHL),[0]D,[0]HB,NµHL),C[0],(WµVL),C[       °
  65.  3]' 'D3E:N╜²2+µ,S'                                                            °
  66. X 'V╜C[Nµ1],[0]VB[1+0<²2╟,S],[0](((²3+╞µD),N)µVL),[0]C[Nµ2]' 'D╜V,D'           °
  67. *(1996 4 6 16 9 32 332)                                                        °
  68.  FEXIT ÉFX 'EXIT' 'Σ Exit from function' '''To log off type:   )OFF'''         °
  69. X '╕'                                                                          °
  70.  AFN╜('Z╜KEYS ACC2 AMTS;P')('Σ N⌡LOG N solution')('KEYS╜KEYS[Z╜√KEYS]')(       °
  71. X'P╜²1╟1,KEYS⌠1ΦKEYS')('Z╜(P/KEYS),[0.5]+/■(+\P)ΓAMTS[Z]')                     °
  72. *(1996 4 6 16 9 32 332)                                                        °
  73.  FGO ÉFX 'GO;T;E;B' 'Σ Expression driver' 'L0:B╜E╜''''' 'æ╜''      '''         °
  74.   'T╜æ' '╕(^/'' ''=T)/L0' '╕((^/'')OFF ''=5╞6╟T)doif ''EXIT'')/0'              °
  75.   '╕(('':''εT)doif ''B╜evaldd (+/^\'''' ''''=T)╟T'')/L0'                       °
  76.   '''E╜ÉEM'' ÉEA T' '╕(0=µ,E)/L0' '╕B/L0'                                      °
  77.   '''This is not a valid APL2 expression''' 'æ╜''*'''                          °
  78. X '╕(''?''⌠╞1╟æ)/L0' 'E' '╕L0'                                                 °
  79. *(1997 8 18 12 52 33 560)                                                      °
  80.  FHELP ÉFX 'HELP;N;I;T' 'Σ Help to student' '''WHAT TO DO'',r'                 °
  81.   '''  ° To get out of the lesson''' '''       ENTER: EXIT'''                  °
  82.   '''  ° To log off APL2'''                                                    °
  83.   '''       FIRST, ENTER: EXIT  THEN ENTER: )OFF'''                            °
  84.   '''  ° To get help''' '''       ENTER: HELP'''                               °
  85.   '''  ° When you see the prompt on a blank line'''                            °
  86.   '''       ENTER AN APL2 EXPRESSION - OR JUST PRESS: ENTER''' 'do'            °
  87.   '''  ° If you get this line'',r'                                             °
  88.   '''This is not a valid APL2 expression'',r,''*'',r'                          °
  89.   '''        YOU CAN EITHER''' '''           A. PRESS: ENTER'''                °
  90.   '''           B. PRESS: ? and then ENTER to see what was incorrect'''        °
  91.   '''              in your expression causing that response'',r' 'do'          °
  92.   '''HINTS'',r'                                                                °
  93.   '''This lesson is made up of '',(«N╜6),'' components named TEACHx, whe       °
  94.  re''' '''the x stands for a digit:'',r' 'I╜0'                                 °
  95.   'L0:T╜''TEACH'',(«I╜I+1)' 'T,'' '',1╟notb(ÉCR T)[2;]' '╕(N>I)/L0'            °
  96.   'do'                                                                         °
  97.   '''You may review either of these components separately. To do that,''       °
  98.  '                                                                             °
  99.   '''first enter EXIT (and RETURN), then enter the name of the lesson.''       °
  100.  ' '''component (e.g. TEACH4).'',r'                                            °
  101.   '''To re-start the lesson, just enter TEACH'',r'                             °
  102.   '''When the screen fills up, it is a good idea to move the cursor to''       °
  103.  ' '''the start of a convenient paragraph, and press ENTER'',r'                °
  104.   '''You may also wish to press PAGE UP to review the prevous pages.'''        °
  105.   'do' '''RESOURCES'',r'                                                       °
  106.   '''You may also enter ONE of the following words at a time'',r'              °
  107.   '''ALGORITHMS  Classification table of algorithms'''                         °
  108.   '''N TIME E    Evaluating expression E N times, and timing it'''             °
  109. X 'endd'                                                                       °
  110. *(1997 9 4 12 49 1 368)                                                        °
  111.  FTEACH ÉFX 'TEACH' 'Σ Start lesson #17: APL2 by Zdenek V JIZBA'               °
  112.   'exit ''TEACH''' 'initialize' 'TEACH1 Σ Solving problems with APL2'          °
  113.   'TEACH2 Σ Function TEST to time APL2 expressions'                            °
  114.   'TEACH3 Σ Classification of algorithms'                                      °
  115.   'TEACH4 Σ Strategies for efficient problem solving'                          °
  116.   'TEACH5 Σ Format by specification'                                           °
  117. X 'TEACH6 Σ Format by example; format control' 'problems'                      °
  118. *(1997 7 11 12 24 35 424)                                                      °
  119.  FTEACH1 ÉFX 'TEACH1;A;B'                                                      °
  120.   'Σ Discus how in APL there are many ways to solve a problem'                 °
  121.   '''In lesson 16 we investigated ways to use software that has been'''        °
  122.   '''developed in other workspaces. When designing a new application,'''       °
  123.   '''one not only should take advantage of previous work, but one should       °
  124.  '''                                                                           °
  125.   '''also try to define APL2 functions that are fast and efficient.'',r'       °
  126.   '''In this lesson we will explore the issue of optimal resource'''           °
  127.   '''utilization. A great deal of the material presented in this lesson'       °
  128.  '' '''is based on lectures and publications by Roy A. Sykes Jr.'',r'          °
  129.   'do' '''     SOLVING PROBLEMS WITH APL2'',r'                                 °
  130.   '''When experimenting with APL, one soon discovers that often there'''       °
  131.   '''are many ways to solve any one particular problem.  Consider the'''       °
  132.   '''following simple example: We have two numeric vectors, A and B'',r'       °
  133.   'show ''A╜?5µ10'' ''B╜?5µ10'''                                               °
  134.   '''Now, suppose we desire to find the sum of the product of A and B.''       °
  135.  ,r' 'show ''+/A⌡B'' ''A+.⌡B'''                                                °
  136.   '''Which of these two is preferable? Are there still other ways to'''        °
  137.   '''produce the same result?''' 'do'                                          °
  138.   '''The answer to these question lies partially in personal preference,       °
  139.  '''                                                                           °
  140.   '''but more importantly on the nature of the problem.  Suppose that'''       °
  141.   '''instead of vectors, A and B are arrays:'',r'                              °
  142.   'show ''A╜?3 3µ10'' ''B╜?3 3µ10'''                                           °
  143.   '''Will we still get the same results with the two expressions?'''           °
  144.   'do' 'show ''+/A⌡B'' ''A+.⌡B'''                                              °
  145.   '''Clearly at least one of these two expressions is incorrect.  When''       °
  146.  '                                                                             °
  147.   '''selecting an expression, it seems like a good idea to pick the one'       °
  148.  ''                                                                            °
  149.   '''that will produce valid results when generalized to higher order'''       °
  150.   '''arrays.''' 'do'                                                           °
  151.   '''Another criterion for selecting a particular expression is the amou       °
  152.  nt'''                                                                         °
  153.   '''of time it takes the computer to find an answer.  We have already s       °
  154.  een'''                                                                        °
  155.   '''one example of this in lesson 2.  The average can be obtained with:       °
  156.  '''                                                                           °
  157.   '''  (+/∙)÷µ∙   or with  +/∙÷µ∙.  The second expression is shorter, bu       °
  158.  t'''                                                                          °
  159.   '''it will clearly take more computer time, and be less accurate for l       °
  160.  ong''' '''vectors because of roundoff errors.''' 'do'                         °
  161.   'show ''A╜3 3µ∞9'' ''+/φA'' ''+≡A'' ''1¥A'''                                 °
  162.   '''The three expressions are different, yet they give the same answer.       °
  163.  ''' '''(Can you explain why the last one works?)'',r'                         °
  164.   '''To find out which of these three expressions is more efficient,we''       °
  165.  '                                                                             °
  166.   '''will use the System Function TIME STAMP (ÉTS), in function TIME.'',       °
  167.  r' '1 showfn ''TIME''' 'do'                                                   °
  168.   '''Function TIME evaluates the APL2 expression in the right argument.'       °
  169.  ''                                                                            °
  170.   '''It evaluates it the number of times specified in the left argument,       °
  171.  '''                                                                           °
  172.   '''and reports the average number of miliseconds for its execution.'''       °
  173.   '''(The overhead of the »■ is included in this estimate.)'',r'               °
  174.   'show ''100 TIME ''''+/φA'''''' ''100 TIME ''''+≡A'''''' ''100 TIME ''       °
  175.  ''1¥A'''''''                                                                  °
  176.   '''A reduction is certainly better than decode, but adding a transpose       °
  177.  '''                                                                           °
  178.   '''increases the number of primitive functions to two. In the second''       °
  179.  '                                                                             °
  180.   '''expression only one primitive function is applied, namely +, and'''       °
  181.   '''therefore this produces the best result.''' 'do'                          °
  182.   '''Testing of the efficiency of APL2 expressions is a good idea, but''       °
  183.  '                                                                             °
  184.   '''it may not lead to the best or most efficient code. If an algorithm       °
  185.  '''                                                                           °
  186.   '''is to be used heavily, then it may still be desirable to design an'       °
  187.  ''                                                                            °
  188.   '''object code by compilation of a FORTRAN or C source program. (These       °
  189.  '''                                                                           °
  190.   '''can be linked to APL2 using Name association and Processor 11.)'''        °
  191.   'do'                                                                         °
  192.   '''Certain commonly used idioms are recognized by the APL2 interpreter       °
  193.  '''                                                                           °
  194.   '''and their evaluation is optimized. Therefore applying function TIME       °
  195.  '''                                                                           °
  196.   '''when experimenting with alternate solutions is highly recommended,'       °
  197.  '' '''especially when developing applications for heavy usage.'',r'           °
  198.   '''One way to sharpen your APL skills is to try to find as many differ       °
  199.  ent'''                                                                        °
  200.   '''solutions to a problem as possible.  Roy Sykes has published many s       °
  201.  uch''' '''problems.  Here is one example:'',r'                                °
  202.   '''Write as many different expressions for turning a numeric vector V        °
  203.  into''' '''a one column matrix. One solution would be'',r'                    °
  204.   'show ''φ(1,µV)µV╜∞4'''                                                      °
  205.   '''Can you think of other expressions that will produce the same resul       °
  206.  t?''' 'do'                                                                    °
  207.   '''One rule of thumb used by Roy Sykes is to count the number of'''          °
  208.   '''primitive functions invoked in the expression. The fewer this numbe       °
  209.  r'''                                                                          °
  210.   '''the more efficient the evaluation. (This rule of thumb does not'''        °
  211. X '''always work as we have seen in the example above.)''' 'endd'              °
  212. *(1997 7 11 12 53 21 484)                                                      °
  213.  FTEACH2 ÉFX 'TEACH2;TEST;T' 'Σ Testing TIME'                                  °
  214.   '''Let us take another look at Time Stamp. It turns out that it is not       °
  215.  '''                                                                           °
  216.   '''a very reliable measurement of time. Although the results of the'''       °
  217.   '''experiment with function TIME seem reasonably valid, we must enter'       °
  218.  ''                                                                            °
  219.   '''a note of caution. Let us define function TEST to evaluate the inte       °
  220.  rnal''' '''consistency of ÉTS'',r'                                            °
  221.   'FN╜''U╜TEST W;T'' ''Σ Evaluate performance of ÉTS'''                        °
  222.   'FN╜FN,''U╜∞0'' ''L0:T╜60 60 1000¥²3╞ÉTS'''                                  °
  223.   'T╜ÉFX FN,Γ''U╜U,(60 60 1000¥²3╞ÉTS)-T ╪ ╕(0<W╜W-1)/L0'''                    °
  224.   '''Function TEST should measure the smallest time interval between'''        °
  225.   '''consecutive readings of ÉTS'',r' '1 showfn ''TEST'''                      °
  226.   '''The results will of course depend on your specific hardware, but'''       °
  227.   '''will also give you some idea of the accuracy of results with functi       °
  228.  on'''                                                                         °
  229.   '''TIME. Function TEST should produce a zero most of the time because'       °
  230.  '' '''it takes less than 10 miliseconds to evaluate ÉTS.'',r'                 °
  231.   'show ''TEST 10'''                                                           °
  232.   '''Next we will try TEST 1000 times (PRESS ENTER and NOTE the DELAY)''       °
  233.  ' 'do' 'show ''+/TEST 1000'''                                                 °
  234.   '''In general, you should use TIME on problems that take a significant       °
  235.  '''                                                                           °
  236.   '''interval of time to complete, and repeat the test more than once to       °
  237.  '''                                                                           °
  238.   '''get a feel for the probable error. The time values are not absolute       °
  239.  '''                                                                           °
  240.   '''because they include the overhead in function TIME. Furthermore, th       °
  241.  e'''                                                                          °
  242.   '''comparisons should be made using the same values in the left'''           °
  243.   '''argument of TIME. (Why?)''' 'do'                                          °
  244.   '''With these caveats, let us look at the question of the time it take       °
  245.  s'''                                                                          °
  246.   '''to solve problems on a computer. (Most of this section has been tak       °
  247.  en'''                                                                         °
  248.   '''from lecture notes of a free IBM seminar on APL2. The specific'''         °
  249.   '''lecture is that given by Roy A. Sykes on Optimized APL2.)''' 'do'         °
  250.   '''There are some computer problems that are inherently time consuming       °
  251.  .'''                                                                          °
  252.   '''Given a specific computer architecture, and a given problem, there        °
  253.  is'''                                                                         °
  254.   '''always a lower limit of time, it will take a computer to reach a'''       °
  255.   '''solution. For a given problem, this calculation time is in some way       °
  256.  '''                                                                           °
  257.   '''related to the amount of data to be processed. It makes sense to sa       °
  258.  y'''                                                                          °
  259.   '''that the expression +/∞1000 will take longer to evaluate than the''       °
  260.  ' '''expression +/∞10'',r'                                                    °
  261.   'show ''10 TIME ''''+/∞500'''''' ''10 TIME ''''+/∞5'''''''                   °
  262.   '''If we denote the size of the problem by N, then we can classify an'       °
  263.  ''                                                                            °
  264.   '''algorithm in terms of how N changes the solution time. The followin       °
  265.  g''' '''table summarizes these relations'',r' 'ALGORITHMS'                    °
  266. X '''Let us take a closer look at some of these algorithms''' 'endd'           °
  267. *(1997 7 11 13 6 34 352)                                                       °
  268.  FTEACH3 ÉFX 'TEACH3' 'Σ Examples of computation time'                         °
  269.   '''Before we show examples of these types of problems, there is a cave       °
  270.  at.'''                                                                        °
  271.   '''Some of the actual sample timings may not follow the predicted'''         °
  272.   '''duration because of optimizations by the APL2 interpreter.''' 'do'        °
  273.   '''Problems that can be solved in roughly the same amount of time'''         °
  274.   '''regardless of the data size fall under the category of CONSTANT.'''       °
  275.   '''A typical example of this type of problem is taking the shape of'''       °
  276.   '''an array (µA). Since in APL2 the dimensions of an array are stored'       °
  277.  ''                                                                            °
  278.   '''as part of the data structure, no processing is required other than       °
  279.  ''' '''the extraction of the information from a known location. The'''        °
  280.   '''algorithm first finds the rank, which then determines the location'       °
  281.  '' '''and size of the shape.''' 'do'                                          °
  282.   '''Problems dealing with a process called binary search are solved in'       °
  283.  ''                                                                            °
  284.   '''LOGARITHMIC time. This means that if the data size is doubled, the'       °
  285.  ''                                                                            °
  286.   '''time to solve the problem increases by a factor proportional to the       °
  287.  '''                                                                           °
  288.   '''logarithm of two. There are no simple examples of this type of'''         °
  289.   '''problem in APL2.''' 'do'                                                  °
  290.   '''In some problems, the time to reach a solution is directly related'       °
  291.  ''                                                                            °
  292.   '''to the size of the problem. This type of problem is called LINEAR''       °
  293.  ,r'                                                                           °
  294.   'show ''100 TIME ''''-∞10'''''' ''100 TIME ''''-∞50'''''' ''100 TIME '       °
  295.  '''-∞250'''''''                                                               °
  296.   '''(By extrapolating to a vector of length 0 you can estimate the'''         °
  297.   '''overhead for this particular algorithm.)''' 'do'                          °
  298.   '''In some problems the time to reach a solution increases faster than       °
  299.  '''                                                                           °
  300.   '''the data length, but less than the square of the length. These are'       °
  301.  '' '''called the N LOG N type problems'',r'                                   °
  302.   'show ''A╜?500µ10000'' ''100 TIME ''''√5╞A'''''' ''100 TIME ''''√50╞A'       °
  303.  '''''' 'show ''100 TIME ''''√500╞A'''''''                                     °
  304.   '''Problems that require four times the time when the data size is'''        °
  305.   '''doubled are called QUADRATIC. The outer product is one example of''       °
  306.  ' '''such problems'',r'                                                       °
  307.   'show ''C╜5╞B╜10╞A╜∞20'' ''100 TIME ''''C°.⌡C'''''' ''100 TIME ''''B°.       °
  308.  ⌡B''''''' 'show ''100 TIME ''''A°.⌡A'''''''                                   °
  309.   '''There is a simple APL2 example of a cubic type of problem, but we h       °
  310.  ave'''                                                                        °
  311.   '''not yet introduced the primitive function associated with it.'',r'        °
  312.   '''The most difficult problems to solve are those for which computatio       °
  313.  n'''                                                                          °
  314.   '''time increases exponentially. One example of such problems would be       °
  315.  '''                                                                           °
  316.   '''the game of chess, where the quality of game is related to the numb       °
  317.  er''' '''of moves ahead to be evaluated.''' 'do'                              °
  318.   '''What conclusion can we draw from this discussion?'',r'                    °
  319.   '''For one it is ALWAYS IMPORTANT to study alternate methods for solvi       °
  320.  ng'''                                                                         °
  321.   '''a given problem. If there are two algorithms, one being LINEAR, and       °
  322.  '''                                                                           °
  323.   '''another being QUADRATIC, the linear one is preferable. Consideratio       °
  324.  n'''                                                                          °
  325.   '''of the nature of the algorithm may be far more important than any''       °
  326. X' '''other factor in determining its utility.''' 'endd'                       °
  327. *(1997 7 11 13 17 36 404)                                                      °
  328.  FTEACH4 ÉFX 'TEACH4;PROD;KEYS;AMTS'                                           °
  329.   'Σ Strategies for efficient problem solving'                                 °
  330.   '''Earlier we mentioned that for every problem, there is a minimum tim       °
  331.  e'''                                                                          °
  332.   '''under optimal conditions. Assuming we have selected an optimal'''         °
  333.   '''algorithm, APL2 does not always solve problems in this minimal time       °
  334.  .'''                                                                          °
  335.   '''If we were to take the ratio of (minimal time)/(APL2 time), then we       °
  336.  '''                                                                           °
  337.   '''might find values anywhere between 0 and near 1.0. Let us call this       °
  338.  ''' '''ratio the APL2 EFFICIENCY.''' 'do'                                     °
  339.   '''What types of strategies should be used to improve the efficiency o       °
  340.  f'''                                                                          °
  341.   '''APL2 computation? On some problems it really does not matter much.'       °
  342.  ''                                                                            °
  343.   '''If we get a solution in 1/10 second with efficiency of 0.1, who car       °
  344.  es?'''                                                                        °
  345.   '''On the other hand, if it takes 60 minutes to solve a problem with''       °
  346.  '                                                                             °
  347.   '''a 0.9 efficiency, then any improvement in speed will be welcome. In       °
  348.  '''                                                                           °
  349.   '''such a case it is definitely recommended to investigate compiled co       °
  350.  de.''' 'do'                                                                   °
  351.   '''However even within APL2 it is the SELECTION of the best algorithm'       °
  352.  ''                                                                            °
  353.   '''that will determine the quality of performance. There is no substit       °
  354.  ute'''                                                                        °
  355.   '''to GOOD PROGRAMMING, no matter what computer language is used.'',r'       °
  356.   '''The following example is taken from Roy A. Sykes notes.''' 'do'           °
  357.   '''In business, products on sale are identified by numeric keys. Suppo       °
  358.  se''' '''that a store sells 4 products with the following keys:'',r'          °
  359.   'PROD╜201 346 537 664' 'show ''PROD'''                                       °
  360.   '''At the end of the day, when the sales from cash registers are'''          °
  361.   '''recorded, we may have the following results'',r' 'KEYS╜PROD[?5µ4]'        °
  362.   'AMTS╜?5µ9' 'show ''KEYS'' ''AMTS'''                                         °
  363.   '''We need an algorithm to add all AMTS associated with the same key.'       °
  364.  '' '''Here is one APL2 function to do that.'',r'                              °
  365.   'show ''FN╜''''Z╜KEYS ACC1 AMTS'''' ''''Σ Accumulate AMTS by KEYS'''''       °
  366.  '' 'show ''FN╜FN,Γ''''Z╜((∞µKEYS)=KEYS∞KEYS)/KEYS'''''''                      °
  367.   '''This expression is an idiom to identify the unique elements of KEYS       °
  368.  .'',r' 'show ''FN╜FN,Γ''''Z╜Z,[0.5]AMTS+.⌡KEYS°.=Z'''''''                     °
  369.   '''The outer product at right KEYS°.=Z generates a boolean array. The'       °
  370.  ''                                                                            °
  371.   '''inner product of this array with AMTS produces the desired sums.'''       °
  372.   '''these are then catenated to the unique elements of KEYS.''' 'do'          °
  373.   'show ''ÉFX FN''' '1 showfn ''ACC1''' 'show ''KEYS ACC1 AMTS'''              °
  374.   '''Function ACC1 is neat, but since it uses dot products, it is an'''        °
  375.   '''N SQUARE algorithm. As the number of KEYS doubles, the time to'''         °
  376.   '''solve the problem increases by four. We can do much better by'''          °
  377.   '''defining an N⌡LOG N algorithm.'',r'                                       °
  378.   'show ''FN╜''''Z╜KEYS ACC2 AMTS;P'''' ''''Σ N⌡LOG N solution'''''''          °
  379.   'show ''FN╜FN,''''KEYS╜KEYS[Z╜√KEYS]'''' ''''P╜²1╟1,KEYS⌠1ΦKEYS'''''''       °
  380.   '''First we sort KEYS in increasing order (N⌡LOG N). This collects'''        °
  381.   '''all like keys together. Then we generate boolean vector P giving'''       °
  382.   '''the boundaries of changes in keys.'',r'                                   °
  383.   'show ''FN╜FN,Γ''''Z╜(P/KEYS),[0.5]+/■(+\P)ΓAMTS[Z]'''''''                   °
  384.   '''Using the partition function we cluster AMTS for like keys and'''         °
  385.   '''add by groupings.''' 'do' 'show ''ÉFX FN''' '1 showfn ''ACC2'''           °
  386.   'show ''KEYS ACC2 AMTS'''                                                    °
  387.   '''We can see how these two functions behave'',r'                            °
  388.   'show ''10 TIME ''''KEYS ACC1 AMTS'''''' ''10 TIME ''''KEYS ACC2 AMTS'       °
  389.  '''''' '''As we increase the size of arrays'',r'                              °
  390.   'show ''KEYS╜PROD[?100µ4]'' ''AMTS╜?100µ10'' ''KEYS'' ''AMTS'''              °
  391.   '''We can see what effect this has on execution speed'',r'                   °
  392.   'show ''10 TIME ''''KEYS ACC1 AMTS'''''' ''10 TIME ''''KEYS ACC2 AMTS'       °
  393. X'''''' 'endd'                                                                 °
  394. *(1997 7 11 13 31 45 496)                                                      °
  395.  FTEACH5 ÉFX 'TEACH5;HDG;INVOICE' 'Σ Dyadic Format'                            °
  396.   '''     DYADIC FORMAT'',r'                                                   °
  397.   '''In many applications, particularly in business, it is not the'''          °
  398.   '''amount of computer time it takes to solve a problem, but the'''           °
  399.   '''ease of generating a report that matters.'',r'                            °
  400.   '''A computer user today expects to be able to see some sort of a'''         °
  401.   '''graphical display in color. Although APL2 is not designed to do'''        °
  402.   '''graphical processing, Auxilliary Processors (invoked by System'''         °
  403.   '''functions ÉSV*), or non-APL2 software (accessed by ÉNA), provide'''       °
  404.   '''the needed interface to support just about any demand.'',r'               °
  405.   '''The dyadic version of the format primitive supports some of the nee       °
  406.  ds''' '''in tabulation of data.''' 'do'                                       °
  407.   '''There are two distinct ways to use the dyadic format primitive:'''        °
  408.   '''In format by specification, the left argument is a simple integer''       °
  409.  ' '''vector. In format by example, the left argument is a simple'''           °
  410.   '''character vector.''' 'do' '''FORMAT BY SPECIFICATION'',r'                 °
  411.   '''Suppose we have a numeric array called INVOICE:'',r'                      °
  412.   'show ''INVOICE╜2 3µ10432 5 34.75 10446 10 55.95'' ''INVOICE'''              °
  413.   '''If the three columns are called PRODUCT, AMOUNT and PRICE'''              °
  414.   '''we can generate the following table'',r'                                  °
  415.   'show ''COLS╜''''PRODUCT'''' ''''AMOUNT'''' ''''PRICE'''''' ''COLS,[1]       °
  416.  INVOICE'''                                                                    °
  417.   '''Obviously, this would not be a very acceptable display. We can'''         °
  418.   '''control the spacing and number of decimal points of numeric'''            °
  419.   '''data with format by specification'',r'                                    °
  420.   'show ''8«INVOICE'' ''8 2«INVOICE'' ''12 0 9 0 10 2«INVOICE'''               °
  421.   '''In the first example we specified 8 decimal points for each'''            °
  422.   '''number in the array. In the second example we limited decimal'''          °
  423.   '''fraction to only two digits, but specified eight positions for'''         °
  424.   '''each number. In the third example we reserved twelve columns for'''       °
  425.   '''PRODUCT as an integer (12 0), nine columns for AMOUNT as an integer       °
  426.  '''                                                                           °
  427.   '''(9 0), and 10 columns for price with two decimal digits (10 2).'''        °
  428.   'do' '''But now, we no longer can catenate the headers as before'',r'        °
  429.   'show ''HDG╜ε12 9 10╞■''''PRODUCT'''' ''''AMOUNT'''' ''''PRICE'''''''        °
  430.   'show ''HDG,[1]12 0 9 0 10 2«INVOICE'''                                      °
  431.   '''This still does not look good. It is because the head labels are'''       °
  432.   '''left adjusted, while the numeric columns are right adjusted. We'''        °
  433.   '''can correct that with'',r'                                                °
  434.   'show ''HDG╜ε²12 ²9 ²10╞■''''PRODUCT'''' ''''AMOUNT'''' ''''PRICE'''''       °
  435.  '' 'show ''HDG,[1]12 0 9 0 10 2«INVOICE'''                                    °
  436.   '''This looks much better. In summary, in format by specification'''         °
  437.   '''the left argument can be a scalar integer, or an integer vector.'''       °
  438.   '''A single integer specifies the number of decimal points to be'''          °
  439.   '''displayed. A vector of length two specifies the number of columns''       °
  440.  ' '''(width of the field), and the number of decimal points for all'''        °
  441.   '''columns in the array. Finally a vector of length 2⌡²1╞µARRAY can'''       °
  442. X '''supply the width and number of decimals for each column.''' 'endd'        °
  443. *(1997 7 12 13 29 41 476)                                                      °
  444.  FTEACH6 ÉFX 'TEACH6;INVOICE;no;ds;at;PIC;ÉFC' 'Σ Format by example'           °
  445.   'ÉFC╜''.,*0_-''' '''FORMAT BY EXAMPLE'',r'                                   °
  446.   'INVOICE╜2 3µ10432 5 34.75 10446 10 55.95'                                   °
  447.   '''One problem with format by specification is its limitation to APL2'       °
  448.  ''                                                                            °
  449.   '''symbols. In format by example, the left argument is a character'''        °
  450.   '''vector describing the way each row of the table should look like.''       °
  451.  ,r'                                                                           °
  452.   ''' In business applications, it is common to see special symbols'''         °
  453.   '''(called decorations) associated with tabular data. Some of these'''       °
  454.   '''symbols cannot be readily obtained from the keyboard. They can be''       °
  455.  ' '''extracted from the atomic vector.'',r'                                   °
  456.   'show ''ÉAV[36 37 65]'' ''(no ds at)╜ÉAV[36 37 65]'''                        °
  457.   '''Variables "no" "ds" and "at", can then be used to design a characte       °
  458.  r'''                                                                          °
  459.   '''vector that can be used as a pattern for displaying tabular data.''       °
  460.  ,r'                                                                           °
  461.   'show ''PIC╜no,''''55555   55'''',at,''''   '''',ds,''''555.50 EA'''''       °
  462.  ' ''PIC'''                                                                    °
  463.   '''Vector PIC represents a picture of the desired format. It describes       °
  464.  ''' '''how the numeric information is to be formatted'',r'                    °
  465.   'show ''PIC«INVOICE''' '''   FORMAT CONTROL'',r'                             °
  466.   '''Before we describe the conventions used in format by example, we mu       °
  467.  st'''                                                                         °
  468.   '''introduce a System Variable called FORMAT CONTROL (ÉFC). This varia       °
  469.  ble'''                                                                        °
  470.   '''defines the symbols that are to be used in displaying numeric data        °
  471.  in''' '''conjunction with format by example.'',r' 'show ''ÉFC'''              °
  472.   '''ÉFC[1]     *Character to be used as decimal point'''                      °
  473.   '''ÉFC[2]      Character to mark thousands position'''                       °
  474.   '''ÉFC[3]      Fill for blanks (see below on usage of digit 8)'''            °
  475.   '''ÉFC[4]     *Fill for numeric overflow (avoiding DOMAIN ERROR)'''          °
  476.   '''ÉFC[5]      Character to be printed as blank'''                           °
  477.   '''ÉFC[6]     *Negative number indicator'',r'                                °
  478.   '''The elements marked with * are also used in format by specification       °
  479.  .'''                                                                          °
  480.   '''The first two elements of ÉFC are needed, because in some European'       °
  481.  ''                                                                            °
  482.   '''countries the decimal point and comma for thousands are interchange       °
  483.  d'''                                                                          °
  484.   '''We will first illustrate how ÉFC can be used to modify a tabulation       °
  485.  .'''                                                                          °
  486.   '''Then we will discuss the specifications of the left argument of'''        °
  487.   '''format by example.''' 'do'                                                °
  488.   '''When a number is greater than the allowed space, APL2 normally woul       °
  489.  d'''                                                                          °
  490.   '''cause an interrupt. However, when using Format by Example, this'''        °
  491.   '''interrupt need not ocurr; the space provided for that number can'''       °
  492.   '''be filled out by a special character in ÉFC[4]. When ÉFC[4] is 0,''       °
  493.  ' '''there will be an interrupt and an error message.'',r'                    °
  494.   'show ''ÉFC[4]'' ''TEST╜2 2µ²1 1234.56789 200 4'' ''''''55 555.50''''«       °
  495.  TEST'''                                                                       °
  496.   '''This interrup can be avoided if ÉFC[4] is assigned a "replacement"'       °
  497.  '' '''character'',r'                                                          °
  498.   'show ''ÉFC[4]╜''''?'''''' ''''''55 555.50''''«TEST'''                       °
  499.   '''In some European countries, the comma and period have their functio       °
  500.  n''' '''reversed'',r'                                                         °
  501.   'show ''ÉFC[1 2]╜ÉFC[2 1]'' ''''''555 5,555.50''''«TEST'''                   °
  502.   'ÉFC[1 2]╜ÉFC[2 1]' '''    ILLUSTRATIONS OF FORMAT BY EXAMPLE'',r'           °
  503.   '''Let us take another look at PIC'',r' 'show ''PIC'''                       °
  504.   '''This character string contains two types of symbols. Digits, and'''       °
  505.   '''elements of ÉFC[1 2] are called CONTROL CHARACTERS. These specify''       °
  506.  '                                                                             °
  507.   '''where and how numbers should be displayed. All other characters in'       °
  508.  ''                                                                            °
  509.   '''PIC will be displayed as they are but with location conditionally''       °
  510.  '                                                                             °
  511.   '''modified by the control characters. In the examples below, certain'       °
  512.  ''                                                                            °
  513.   '''control characters work only with numeric vectors. Let us see how''       °
  514.  ' '''use various digits'',r'                                                  °
  515.   '''5   Normal formatting rules of APL2'',r'                                  °
  516.   'show ''''''55 5555.55''''«TEST''' '''0   Pad with zeros'',r'                °
  517.   'show ''''''0555 0005.5000''''«TEST'''                                       °
  518.   '''1   Float the symbol or decorator only against negative number'',r'       °
  519.   'show ''(''''-551 5555.0'''')«TEST'''                                        °
  520.   '''2   Float the decorator only against positive number'',r'                 °
  521.   'show ''''''+552 5555.50''''«TEST'''                                         °
  522.   '''3   Float the decorator against all numbers'',r'                          °
  523.   'show ''(ds,''''5553.5 -513 '''')«ΦTEST'''                                   °
  524.   '''4   Counteract the effect of 1, 2 or 3'',r'                               °
  525.   'show ''''''-551.20CR''''«²1 10 ²100'' ''''''-551.40CR ''''«²1 10 ²100       °
  526.  ''' '''6   End of field. Display decorator to the right'',r'                  °
  527.   'show ''''''0006/06/06 06:06''''«5╞ÉTS'''                                    °
  528.   '''7   Use scientific notation'',r'                                          °
  529.   'show '''''' -1.70E-1''''«2.5 25.3'''                                        °
  530.   '''8   Fill empty portions of field with ÉFC[3]'',r'                         °
  531.   'show ''ÉFC[3]'' ''''''-1888 8555.50''''«TEST'''                             °
  532.   '''9   Pad with 0 the position of 9'',r'                                     °
  533. X 'show ''''''-9915 9995.50''''«TEST''' 'endd'                                 °
  534. XNTEST 2 2 2 ²1 1234.56789 200 4                                               °
  535. *(1997 7 11 12 13 12 288)                                                      °
  536.  FTIME ÉFX 'U╜V TIME W;T' 'Σ Measure execution time of W'                      °
  537. X 'U╜60 60 1000¥²3╞ÉTS' 'T╜»■VµΓW' 'U╜(,-U-60 60 1000¥²3╞ÉTS)÷V'               °
  538. XAV╜1 2 3 4                                                                    °
  539. *(1997 7 13 12 28 49 504)                                                      °
  540.  Faddquote ÉFX 'u╜addquote w'                                                  °
  541.   'Σ Put quotes around a string, and double existing quotes'                   °
  542. X 'u╜ÉAV[40],((1+w=ÉAV[40])/w),ÉAV[40]'                                        °
  543. *(1997 7 24 13 20 38 476)                                                      °
  544.  Fav ÉFX 'av;A;N;I;ÉIO' 'Σ Display characters in ÉAV' 'ÉIO╜0'                  °
  545.   'A╜22 78µ'' ''' 'N╜3 0«φ12 22µ1+∞356' 'A[;,(6⌡∞12)°.+2 3 4]╜N'               °
  546.   'A[;6+6⌡∞12]╜φ12 22µÉAV' 'ΣA[8 10 13;6]╜'' ''' 'A[13;6]╜'' '''               °
  547. X 'A[14+∞8;68 69 70 72]╜'' ''' 'A'                                             °
  548. *(1991 11 11 8 25 13 316)                                                      °
  549.  Fdate ÉFX 'u╜date w' 'Σ Format date and time of day' 'u╜«6╞w'                 °
  550. X 'u╜('' ''⌠u)Γu' 'u╜εu,■''-- .. '''                                           °
  551. XCdig 1 10 1234567890                                                          °
  552. *(1997 9 9 13 0 45 372)                                                        °
  553.  Fdisclaimer ÉFX 'disclaimer' 'Σ Copyright statement'                          °
  554.   '(10µ'' ''),''Copyright, Z. V. Jizba, 1995,1996,1997'',r'                    °
  555.   ''' This and subsequent workspaces labelled TEACHxx are made available       °
  556.  '''                                                                           °
  557.   '''at no cost to anyone who desires to learn how to use effectively'''       °
  558.   '''the IBM/OS2 version of APL2.'',r'                                         °
  559.   '''This software is provided "AS IS" with no WARRANTY of any kind, eit       °
  560.  her'''                                                                        °
  561.   '''express or implied. Any risk in its use resides with you, the user        °
  562.  of''' '''these tutorials.'',r' '''     ACKNOWLEDGEMENTS'',r'                  °
  563.   ''' In writing these tutorials, I am greatly indebted to Roy Sykes, wh       °
  564.  ose'''                                                                        °
  565.   '''excellent lectures increased my understanding of the language.'''         °
  566.   '''Discussions with the late Harry Bertucelli clarified a number of'''       °
  567.   '''concepts and caused me to change some improper terminology that was       °
  568.  '''                                                                           °
  569.   '''used in previous versions of these tutorials. Mr. Benjamin Archer''       °
  570.  '                                                                             °
  571.   '''kindly checked out a nearly final version, bringing to my attention       °
  572.  ''' '''some ommisions, misspellings, and invalid terminology.'',r'            °
  573. X '''(PRESS ENTER to continue)'''                                              °
  574. *(1997 7 13 12 28 50 508)                                                      °
  575.  Fdo ÉFX 'do;T;E' 'Σ Expression driver' 'E╜''''' 'æ╜''      ''' 'T╜æ'          °
  576.   '╕(^/'' ''=T)/0'                                                             °
  577.   '╕(('':''εT)doif ''B╜evaldd (+/^\'''' ''''=T)╟T'')/2'                        °
  578.   '''E╜ÉEM'' ÉEA T' '╕(0=µ,E)/2'                                               °
  579.   '''This is not a valid APL2 expression''' 'æ╜''*''' '╕(''?''⌠╞1╟æ)/2'        °
  580. X 'E' '╕2'                                                                     °
  581. *(1997 7 13 12 28 50 508)                                                      °
  582.  Fdoif ÉFX 'U╢╜V╢ doif W╢;t╢' 'Σ Rule' '╕(^/~U╢╜V╢)/0'                         °
  583. X '''U╢╜V╢ doif■ W╢'' ÉEA ''»V╢/W╢'''                                          °
  584. *(1997 9 9 12 50 14 444)                                                       °
  585.  Fendd ÉFX 'endd' 'Σ end of special feature' '20µ''²'' ╪ ╕(4<µÉLC)/0'          °
  586. X 'do'                                                                         °
  587. *(1997 8 18 12 50 27 528)                                                      °
  588.  Ferase ÉFX                                                                    °
  589.   'erase;t;EXIT;GO;HELP;DISPLAY;BIND;REVIEW;RULE;TIME;ALGORITHMS;DISCLAI       °
  590.  MER' 'Σ Erase all global functions and variables' 't╜ÉNL 3'                   °
  591.   't╜(~t^.εlc,'' '')≡t' 't╜ÉEX(~t[;∞5]^.=''TEACH'')≡t' 't╜ÉNL 2'               °
  592. X 't╜ÉEX(~t^.εlc,'' '')≡t' 't╜ÉNL 4' 't╜ÉEX(~t^.εlc,'' '')≡t'                  °
  593. *(1997 7 27 13 47 41 608)                                                      °
  594.  Fevaldd ÉFX 'u╜evaldd w;c;n' 'Σ Evaluate direct definition' 'u╜0'             °
  595.   'n╜(w∞''Σ'')-1' 'c╜(((n╞w)⌠'':'')Γn╞w),Γ''ΣDD '',(n+1)╟w'                    °
  596.   '╕((1 label╞c)doif ''''''Invalid label'''''')/0'                             °
  597.   '╕((2=µc)doif ''u╜showdd 1╙c'')/0'                                           °
  598.   '╕((3=ÉNC╞c)doif ''u╜⌡µÉ╜(╞c),'''' is already defined.'''''')/0'             °
  599.   '╕((3=µc)doif ''u╜simdd c'')/0' 'c╜(Γ''α∙ aw'')replace■c'                    °
  600.   'u╜ε''u╜'',((''a''εεc[2 3 4])/''a ''),(╞c),'' w;t;b'''                       °
  601.   'u╜u(5πc)(''b╜(t╜'',(3πc),'')/'',addquote ''u╜'',4πc)'                       °
  602. X 'u╜u,''╕(t doif b)/0''(''u╜'',2πc)' 'u╜╧ÉFX u'                               °
  603. *(1997 7 25 13 27 52 564)                                                      °
  604.  Fexit ÉFX 'V exit W;T' 'Σ Exit if too many suspended functions'               °
  605.   '╕(0⌠ÉNC ''V'')/L0 ╪ V╜10' 'L0:╕(V>µÉLC)/0'                                  °
  606.   '''There are too many suspended functions''' '''Please enter '',W'           °
  607. X '╕'                                                                          °
  608. *(1997 7 26 12 33 39 536)                                                      °
  609.  Fget ÉFX 'U╜V get W;t;T;ÉPR' 'Σ Prompt for response from keyboard'            °
  610.   'ÉPR╜T╜ÉAV[ÉIO+255] ╪ ╕(0⌠ÉNC ''V'')/L0 ╪ V╜1' 'L0:V╜V╧1' 'æ╜W ╪ t╜æ'        °
  611.   'U╜(+/^\t=T)╟t' '╕(''╕''⌠╞U)/L1 ╪ ╕' 'L1:╕V/0' 't╜(U⌠'' '')ΓU'               °
  612. X 'U╜(µt),(ΓU),t'                                                              °
  613. *(1997 7 28 13 33 8 424)                                                       °
  614.  Fglobals ÉFX 'globals' 'Σ Initialize useful global variables'                 °
  615.   'uc╜''ABCDEFGHIJKLMNOPQRSTUVWXYZ'''                                          °
  616.   'lc╜''abcdefghijklmnopqrstuvwxyz''' 'dig╜''1234567890'''                     °
  617. X 'r╜ÉAV[13+ÉIO]' 'q╜'''''''''                                                 °
  618. *(1997 7 3 12 47 6 368)                                                        °
  619.  Finitialize ÉFX 'initialize;T' 'Σ Initialize workspace'                       °
  620.   '''AT ALL TIMES, TO CONTINUE, PRESS RETURN!'',r'                             °
  621.   '''To see disclaimers enter:'',r,''    disclaimer''' 'do' 'erase'            °
  622.   'globals'                                                                    °
  623.   '''Make sure the CAP LOCK light on your keyboard (upper right) is ON!'       °
  624. X'' 'endd'                                                                     °
  625. *(1997 7 27 13 14 33 444)                                                      °
  626.  Flabel ÉFX 'u╜v label w'                                                      °
  627.   'Σ Return 1 if label w does not begin with a cap'                            °
  628.   '╕(0⌠ÉNC ''v'')/L0 ╪ v╜0' 'L0:v╜v╧1 ╪ w╜εw ╪ ╕v/L1 ╪ ╕(u╜0⌠ÉNC w)/0'         °
  629. X 'L1:╕(u╜~^/wεlc,uc,dig)/0' 'u╜w[1]εlc,dig'                                   °
  630. XClc 1 26 abcdefghijklmnopqrstuvwxyz                                           °
  631. *(1997 7 13 12 28 55 528)                                                      °
  632.  Fnon ÉFX 'non;T;RC;ET;R' 'Σ Ignore keyboard entry' 'æ╜''      ''' 'T╜æ'       °
  633.   '╕(0=µ(T⌠'' '')/T)/0' '(RC ET R)╜ÉEC T' '╕(0=RC)/2'                          °
  634. X '╕((1=RC)doif ''R'')/2' '╕2'                                                 °
  635. *(1997 7 13 12 28 55 528)                                                      °
  636.  Fnotb ÉFX 'u╜notb w' 'Σ Remove trailing blanks'                               °
  637.   '╕((1<╧w)doif ''u╜notb■ w'')/0' '╕((1<µµw)doif ''u╜πnotb Γ[2]w'')/0'         °
  638. X 'u╜(1-(,'' ''⌠Φw)∞1)╟w'                                                      °
  639. *(1997 7 27 12 55 6 496)                                                       °
  640.  Fproblems ÉFX 'problems' 'Σ Problems'                                         °
  641.   '''That is all for this lesson. Remember, if you want to practice,'''        °
  642.   '''and plan to use direct definitions, be sure to first enter GO.'''         °
  643.   '''Direct definitions will then be accepted. To exit GO, enter EXIT.''       °
  644.  ,r'                                                                           °
  645.   '''To erase a previously defined DIRECT DEFINITION FUNCTION, enter'',r       °
  646.  ' '''       )ERASE functionname'',r'                                          °
  647. X '''WARNING! do not use )ERASE on other labels.'',r'                          °
  648. XCq 0 '                                                                        °
  649. XCr 0                                                                         °
  650. *(1997 7 13 12 28 56 532)                                                      °
  651.  Freplace ÉFX 'u╜v replace u;i;r;s' 'Σ Replace elements in v in u'             °
  652.   'i╜Γ∞µu' 's╜2πv╜(v⌠'' '')Γv' 'i╜⌡r╜i⌡■Γ[1]u°.=╞v'                            °
  653. X 'u[(εi)/εr]╜s[(εi)/εi⌡■∞µs]'                                                 °
  654. *(1997 7 13 12 28 56 532)                                                      °
  655.  Fround ÉFX 'U╜V round W' 'Σ Half adjust to V th decimal'                      °
  656. X 'U╜(╛0.5+W⌡10*V)÷10*V'                                                       °
  657. *(1997 7 13 12 28 57 536)                                                      °
  658.  Fshow ÉFX '╢V show ╢W;╢T;╢B' 'Σ Display and execute ╢W'                       °
  659.   '╢T╜(0=ÉNC ''╢V'')doif ''╢V╜0'''                                             °
  660.   '╕((0=╧╢W)doif ''show ╢W,'''' '''''')/0'                                     °
  661.   '╕((1<╧╢W)doif ''╢V show ■╢W'')/0' '''      '',╢W'                           °
  662. X '╕((╢V^'':''ε╢W)doif ''╢T╜evaldd ╢W'')/L0' '''ÉEM'' ÉEA ╢W' 'L0:do'          °
  663. *(1997 7 13 12 28 57 536)                                                      °
  664.  Fshowdd ÉFX 'u╜showdd w;a;b;c;r'                                              °
  665.   'Σ Display a direct definition function'                                     °
  666.   '╕((1=╧w)doif ''u╜showdd Γw'')/u╜0'                                          °
  667.   '╕((3⌠ÉNC╞w)doif ''(ε╞w),'''' is not a function'''''')/0'                    °
  668.   'c╜Γ[2]ÉCR╞w' 'c╜notb(2╞c),(Γ''aw α∙'')replace■2╟c'                          °
  669.   '╕((~''ΣDD''╧3╞2πc)doif ''''''Not a direct definition function'''''')/       °
  670.  0' 'u╜1' 'b╜('' ''⌠╞c)Γ╞c' 'a╜''      ''' 'r╜2╟3πc'                           °
  671.   '╕((3=µc)doif ''a,(╞w),'''':'''',r,(3<µ2πc)/''''   Σ'''',3╟2πc'')/0'         °
  672.   'a╜a,(╞w),'':'',(2╟5πc),'':''' 'b╜(+\r=''('')-+\r='')''' 'b╜b∞0'             °
  673. X 'a╜a,(²3╟(b-1)╞3╟r),'':'',2╟»(b+2)╟r' 'a,(3<µ2πc)/''  Σ'',3╟2πc'             °
  674. *(1997 7 13 12 28 57 536)                                                      °
  675.  Fshowfn ÉFX 'U╜V showfn W;F;N;T;ÉIO' 'Σ Simulate ╖W[É]'                       °
  676.   'T╜(0=ÉNC ''V'')doif ''V╜0''' 'ÉIO╜0'                                        °
  677.   'U╜r,''      '',''╖'',W,''[É]'',(╞V)╞''╖''' 'N╜1╞µF╜ÉCR W' 'N╜«∞N'           °
  678.   'N╜(N⌠'' '')ΓN' 'F╜(π''['',■N,■Γ''] ''),F'                                   °
  679.   'T╜(1<µ,V)doif ''F╜F[1╟V;]'' ''U╜''''''''''' 'U╜²1╟U,r,,F,r'                 °
  680. X 'U╜((-+/^\'' ''=ΦU)╟U),('' ╖'')[╞V],r'                                       °
  681. *(1997 7 13 12 28 58 540)                                                      °
  682.  Fsimdd ÉFX 'u╜simdd w;e' 'Σ Direct definition mode' 'u╜0'                     °
  683.   '╕((0⌠ÉNC╞w)doif ''''''Already defined'''''')/0' 'e╜''α''ε2πw'               °
  684.   'w[2]╜Γ''u╜'',''α∙ aw'' replace 2πw' 'w╜w[1 3 2]'                            °
  685. X 'w[1]╜Γε''u╜'',(e/''a ''),w[1],'' w''' 'u╜╧ÉFX w'                            °
  686. *(1992 6 3 9 59 17 424)                                                        °
  687.  Ftab ÉFX 'U╜V tab W;T;A;B;C;D;E;F;G;M;ÉPW' 'Σ Tabulate list W'                °
  688.   'T╜(0=ÉNC ''V'')doif ''V╜0''' 'M╜''Invalid data for tabulation'''            °
  689.   'V╜4╞V' 'ÉPW╜130╛30⌐G╜V[2]+79⌡V[2]=0'                                        °
  690.   'L1:╕((1<╧W)doif ''''''W╜∞0'''' ÉEA ''''W╜πW'''''')/L1'                      °
  691.   '╕(((0=µεW)δ2<µµW)doif ''U╜(~V╧4╞0)/M'')/0'                                  °
  692.   'T╜(1≥µµU╜«W)doif ''U╜πW╜(U⌠'''' '''')ΓU'''                                  °
  693.   'T╜(0<V[1])doif ''U╜(«(Φ1,╞µW)µ(V[3]µ'''' ''''),∞(╞µW)-V[3]),'''' ''''       °
  694.  ,U''' '╕(G<30)/0' 'T╜(F╜µεV[4])+C╜1╟B╜µA╜(V[3],0)╟U'                          °
  695.   'T╜⌐(1╞B)÷1⌐╛(ÉPW+F)÷T' 'U╜(E╜(V[3],C)╞U),[1](B╜T,1╟B)╞A'                    °
  696.   '''D╜εV[4]'' ÉEA ''D╜ÉAV[εV[4]+33⌡V[4]=0]''' 'L0:A╜(T,0)╟A'                  °
  697. X '╕(0=1╞µA)/0' 'U╜U,(((T+V[3]),µD)µD),E,[1]B╞A' '╕L0'                         °
  698. *(1997 7 13 12 28 59 544)                                                      °
  699.  Ftest ÉFX 'U╜V test W;P'                                                      °
  700.   'Σ Describe problem in W, (correct answer in V)' 'U╜2' 'L1:W'                °
  701.   'É╜''      ''' 'P╜æ' '''╕L0'' ÉEA ''P╜»P''' '╕(V╧P)/0'                       °
  702. X 'L0:╕(0=U╜U-1)/0' '''Incorrect. Try again''' '╕L1'                           °
  703. XCuc 1 26 ABCDEFGHIJKLMNOPQRSTUVWXYZ                                           °
  704. *(1996 4 6 16 9 33 336)                                                        °
  705.  Fvec ÉFX 'U╜vec' 'Σ Draw 2d vector in plane'                                  °
  706.   'U╜r,r,''2-        +'',r '':      °'',r,''1-    °'',r'                       °
  707. X 'U╜U,'' :  °'',r,''0|....|....|'',r,'' 0    1    2'',r'                      °
  708.