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

  1. XNÉIO 0 1                                                                      °
  2. XNÉCT 0 1E²13                                                                  °
  3. XCÉFC 1 6 .,*0_²                                                               °
  4. XNÉRL 0 16807                                                                  °
  5. XCÉPR 1 1                                                                      °
  6. XCÉLX 1 5 TEACH                                                                °
  7.  AANTE╜(('ONE')('TWO'))(('NOT TWO')('FOUR'))(Γ'THREE')(('FIVE')('NOT SIX       °
  8. X'))(('ONE')('THREE'))(('NOT TWO')('FIVE'))(Γ'ONE')                            °
  9. *(1996 4 6 16 8 39 356)                                                        °
  10.  FBIND ÉFX 'BIND' 'Σ Binding rules of APL2'                                    °
  11.   '''  1. Brackets bind to the left'''                                         °
  12.   '''  2. Left arrow binds to the left'''                                      °
  13.   '''  3. Dyadic operator binds to the right'''                                °
  14.   '''  4. Strand notation binding'''                                           °
  15.   '''  5. Operator binds to its left'''                                        °
  16.   '''  6. Function binds to its left'''                                        °
  17.   '''  7. Function binds to its right'''                                       °
  18. X '''  8. Left arrow binds to its right'',r'                                   °
  19. XACONS╜('HERE')('THERE')('ONE')('FOUR')('SIX')('NOT SIX')('TWO')               °
  20. *(1997 9 14 12 30 44 504)                                                      °
  21. XFDISCLAIMER ÉFX 'DISCLAIMER' 'Σ Copyright statement' 'disclaimer'             °
  22. *(1996 4 6 16 8 39 356)                                                        °
  23.  FDISPLAY ÉFX 'D╜S DISPLAY A;ÉIO;R;C;HL;HC;HT;HB;VL;VB;V;W;N;B'                °
  24.   'Σ DISPLAY A GENERAL ARRAY IN PICTORIAL FORM'                                °
  25.   'Σ  NORMAL CALL IS MONADIC.  DYADIC CALL USED ONLY IN'                       °
  26.   'Σ    RECURSION TO SPECIFY DISPLAY RANK, SHAPE, AND DEPTH.' 'ÉIO╜0'          °
  27.   '»(0=ÉNC ''S'')/''S╜µA''' 'R╜╞µ,S                   Σ PSEUDO RANK.'          °
  28.   'C╜''┐┌└┘''                 Σ UR, UL, LL, AND LR CORNERS.'                   °
  29.   'HL╜''─''                   Σ HORIZONTAL LINE.'                              °
  30.   'HC╜HL,''Θ╕'',HL,''~+ε''      Σ HORIZONTAL BORDERS.'                         °
  31.   'HT╜HC[(0<R)⌡1+0<╞²1╞,S]' 'ΣW╜,0╧■╞0µΓ(1⌐µA)╞A'                              °
  32.   'HB╜HC[3+3╛(''2⌡~A╧«A'' ÉEA ''1+╞ε0⌡(1⌐⌡/µA)╞,A'')+3⌡1<µµS]'                 °
  33.   'VL╜''│''                   Σ VERTICAL LINE.'                                °
  34.   'VB╜VL,''Φ╟''               Σ VERTICAL BORDER.'                              °
  35.   'V╜VB[(1<R)⌡1+0<²1╞²1╟,S]'                                                   °
  36.   '»(0εµA)/''A╜(1⌐µA)µΓ╞A''   Σ SHOW PROTOTYPE OF EMPTIES.'                    °
  37.   '╕(1<╧A)/GEN' '╕(2<µµA)/D3'                                                  °
  38.   'D╜«A                     Σ SIMPLE ARRAYS.' 'W╜1╞µD╜(²2╞1 1,µD)µD'           °
  39.   'N╜²1+1╟µD' '╕(0=µµA)/SS'                                                    °
  40.   'D╜(C[1],V,((W-1)µVL),C[2]),((HT,NµHL),[0]D,[0]HB,NµHL),C[0],(WµVL),C[       °
  41.  3]' '╕0' 'SS:HB╜((0 '' '')=╞0µΓA)/'' -'''                                     °
  42.   'D╜'' '',('' '',[0]D,[0]HB,Nµ'' ''),'' ''' '╕0'                              °
  43.   'GEN:D╜«DISPLAY■A          Σ ENCLOSED ...' 'N╜Dδ.⌠'' '''                     °
  44.   'D╜(Nδ~1ΦN)≡D' 'D╜(δ≡~''  ''╤D)/D' 'D╜((1,µS)µS)DISPLAY D'                   °
  45.   '╕(2≥µ,S)╟D3E,0' 'D3:D╜0 ²1╟0 1╟«ΓA         Σ MULT-DIMENSIONAL ...'          °
  46.   'W╜1╞µD' 'N╜²1+1╟µD'                                                         °
  47.   'D╜(C[1],V,((W-1)µVL),C[2]),((HT,NµHL),[0]D,[0]HB,NµHL),C[0],(WµVL),C[       °
  48.  3]' 'D3E:N╜²2+µ,S'                                                            °
  49. X 'V╜C[Nµ1],[0]VB[1+0<²2╟,S],[0](((²3+╞µD),N)µVL),[0]C[Nµ2]' 'D╜V,D'           °
  50. *(1997 8 18 12 39 10 416)                                                      °
  51.  FEVALFRAME ÉFX 'U╜EVALFRAME W;F;N;R;T;P' 'Σ Evaluate frame W'                 °
  52.   'R╜1╞µF╜(FRAMEID∞ΓW)πFRAMES' '╕(1⌠µµF)/L0 ╪ U╜1╟F ╪ ╕0'                      °
  53.   'L0:N╜F[;1]∞''TEXT'' ''FUNC''' '╕(R<N[1])/L2 ╪ 1╟F[N[1];]'                   °
  54.   'L2:╕(R<N[2])/L3 ╪ »2πF[N[2];]' 'L3:╕(PεFRAMEID)/L4 ╪ U╜1 2╙F ╪ ╕0'          °
  55. X 'L4:EVALFRAME╞P'                                                             °
  56. *(1997 8 18 12 38 53 584)                                                      °
  57.  FEVALRULE ÉFX 'U╜EVALRULE W;N;T' 'Σ Fire rule W'                              °
  58.   'ACT[W]╜0 ╪ N╜WπCONS ╪ É╜FACTS╜FACTS,ΓN'                                     °
  59.   '╕(~T╜^/''NOT ''=4╞N)/L0 ╪ N╜4╟N' 'L0:╕T/L1 ╪ N╜''NOT '',N'                  °
  60. X 'L1:╕(U╜~(ΓN)εFACTS)/0 ╪ ''Contradiction'''                                  °
  61. *(1996 4 6 16 8 39 356)                                                        °
  62.  FEXIT ÉFX 'EXIT' 'Σ Exit from function' '''To log off type:   )OFF'''         °
  63. X '╕'                                                                          °
  64. XAFACTS╜('THREE')('NOT TWO')('ONE')('SIX')('TWO')                              °
  65. XAFRAMEID╜('ROOT')('FIC1')('REAL')                                             °
  66.  AFRAMES╜(4 4µ('NAME')('PERSON')('    ')('    ')('╞PTR')('ROOT')('FIC1')       °
  67.  ('REAL')('TEXT')('Is this person real or fictional?')('    ')('    ')('       °
  68.  FUNC')('P╜1 ''╞PTR'' GETVAL ''FICTIONAL'' ''REAL''')('    ')('    '))((       °
  69. X'NAME')('Huckleberry Finn'))(('NAME')('Abraham Lincoln'))                     °
  70. *(1997 8 18 12 39 13 428)                                                      °
  71.  FGETVAL ÉFX 'U╜V GETVAL W;X;P' 'Σ Extract contents of slot V given W'         °
  72.   'æ╜P╜ε''Enter one:'',W,■'' ''' 'X╜(µP)╟æ' 'P╜(1πV)Φ1╟,F[F[;1]∞Γ2πV;]'        °
  73. X 'U╜P[W∞ΓX]'                                                                  °
  74. *(1996 4 6 16 8 39 356)                                                        °
  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. XAGOALS╜('HERE')('THERE')                                                      °
  82. *(1997 8 18 12 36 5 384)                                                       °
  83.  FHELP ÉFX 'HELP;N;I;T' 'Σ Help to student' '''WHAT TO DO'',r'                 °
  84.   '''  ° To get out of the lesson''' '''       ENTER: EXIT'''                  °
  85.   '''  ° To log off APL2'''                                                    °
  86.   '''       FIRST, ENTER: EXIT  THEN ENTER: )OFF'''                            °
  87.   '''  ° To get help''' '''       ENTER: HELP'''                               °
  88.   '''  ° When you see the prompt on a blank line'''                            °
  89.   '''       ENTER AN APL2 EXPRESSION - OR JUST PRESS: ENTER''' 'do'            °
  90.   '''  ° If you get this line'',r'                                             °
  91.   '''This is not a valid APL2 expression'',r,''*'',r'                          °
  92.   '''        YOU CAN EITHER''' '''           A. PRESS: ENTER'''                °
  93.   '''           B. PRESS: ? and then ENTER to see what was incorrect'''        °
  94.   '''              in your expression causing that response'',r' 'do'          °
  95.   '''HINTS'',r'                                                                °
  96.   '''This lesson is made up of '',(«N╜6),'' components named TEACHx, whe       °
  97.  re''' '''the x stands for a digit:'',r' 'I╜0'                                 °
  98.   'L0:T╜''TEACH'',(«I╜I+1)' 'T,'' '',1╟notb(ÉCR T)[2;]' '╕(N>I)/L0'            °
  99.   'do'                                                                         °
  100.   '''You may review either of these components separately. To do that,''       °
  101.  '                                                                             °
  102.   '''first enter EXIT (and RETURN), then enter the name of the lesson.''       °
  103.  ' '''component (e.g. TEACH4).'',r'                                            °
  104.   '''To re-start the lesson, just enter TEACH'',r'                             °
  105.   '''When the screen fills up, it is a good idea to move the cursor to''       °
  106.  ' '''the start of a convenient paragraph, and press ENTER'',r'                °
  107.   '''You may also wish to press PAGE UP to review the prevous pages.'''        °
  108.   'do' '''RESOURCES'',r'                                                       °
  109.   '''You may also enter ONE of the following words at a time'',r'              °
  110. X '''REVIEW  Review of previous lesson''' 'endd'                               °
  111. *(1997 8 18 12 38 46 556)                                                      °
  112.  FINFEN ÉFX 'U╜INFEN;ACT;STACK;G;N;R;T' 'Σ Another inference engine'           °
  113.   'ACT╜(N╜µANTE)µ1 ╪ STACK╜Γ∞0' 'L0:R╜(^/■(ACT/ANTE)ε■ΓFACTS)/(ACT/∞N)'        °
  114.   'L2:╕(T╜1≥µR)/L3 ╪ PUSH(1╟R)ACT FACTS'                                       °
  115.   'L3:╕(0=µR)/L1 ╪ ╕(EVALRULE╞R)/L6 ╪ ╕0'                                      °
  116.   'L6:╕(δ/G╜FACTSεGOALS)/L4 ╪ ╕L0' 'L4:U╜G/FACTS ╪ ╕0'                         °
  117.   'L1:R╜,πPOP 1 ╪ ╕(0⌠╞R)/L5 ╪ ''Search failed'' ╪ ╕0'                         °
  118. X 'L5:(R ACT FACTS)╜R ╪ ╕L2'                                                   °
  119. *(1997 8 18 12 38 30 492)                                                      °
  120.  FPOP ÉFX 'U╜V POP W;T' 'Σ Remove W elements from STACK'                       °
  121.   '╕(0⌠ÉNC ''V'')/L0 ╪ U╜W╞πSTACK ╪ STACK╜ΓW╟πSTACK ╪ ╕0'                      °
  122. X 'L0:U╜W╞T╜VπSTACK ╪ STACK[V]╜ΓW╟T'                                           °
  123. *(1997 8 18 12 38 27 480)                                                      °
  124.  FPUSH ÉFX 'V PUSH W;T' 'Σ Push W on top of STACK'                             °
  125.   '╕(0⌠ÉNC ''V'')/L0 ╪ STACK╜Γ(ΓW),πSTACK ╪ ╕0'                                °
  126. X 'L0:STACK[V]╜Γ(ΓW),VπSTACK'                                                  °
  127. XASTACK╜(1µΓ'ONE')(1µΓ'THREE')                                                 °
  128. *(1997 9 2 12 30 56 504)                                                       °
  129.  FTEACH ÉFX 'TEACH' 'Σ Start lesson #15: APL2 by Zdenek V JIZBA'               °
  130.   'exit ''TEACH''' 'initialize'                                                °
  131.   'TEACH1 Σ The FIND primitive function; workspace 1 IDIOMS'                   °
  132.   'TEACH2 Σ The function MATCH'                                                °
  133.   'TEACH3 Σ The "without" primitive function'                                  °
  134.   'TEACH4 Σ Push down stack; functions PUSH and POP'                           °
  135.   'TEACH5 Σ A more general inference engine'                                   °
  136. X 'TEACH6 Σ hierarchical networks; Frames' 'problems'                          °
  137. *(1997 9 2 12 49 4 372)                                                        °
  138.  FTEACH1 ÉFX 'TEACH1;A;N;C' 'Σ FIND, using workspace IDIOMS'                   °
  139.   '''In lesson 14 we learned how to TRAP expressions without causing'''        °
  140.   '''interrupts. Testing whether an expression is executable does not'''       °
  141.   '''solve all problems when dealing with character data. In this lesson       °
  142.  '''                                                                           °
  143.   '''we will study more APL2 primitive functions that support extensive'       °
  144.  ''                                                                            °
  145.   '''manipulation of data. To illustrate the kind of problems where thes       °
  146.  e'''                                                                          °
  147.   '''functions are vital, we will describe a variety of structures that'       °
  148.  '' '''go under the label of KNOWLEDGE BASE.''' 'do'                           °
  149.   '''But first, let us introduce an APL2 primitive function called FIND.       °
  150.  '''                                                                           °
  151.   '''It is dyadic and uses the symbol ╤ (ÉAV[210]). The right argument i       °
  152.  s'''                                                                          °
  153.   '''an array to be searched for the ocurrence of the left argument. The       °
  154.  '''                                                                           °
  155.   '''function returns a boolean array of the same shape and rank as the        °
  156.  right'''                                                                      °
  157.   '''argument. A one in this array shows the start of the matching seque       °
  158.  nce.'',r' 'show ''''''SI''''╤''''MISSISSIPPI'''''' ''3 4╤∞6'''                °
  159.   '''Find can be applied to arrays of rank two or greater'',r'                 °
  160.   'show ''A╜4 4µ∞9'' ''A'' ''N╜2 2µ2 3 6 7'' ''N'' ''N╤A'''                    °
  161.   '''The matching pattern is identified by a 1 on the elements that have       °
  162.  ''' '''the smallest component values in the access vector'',r'                °
  163.   'show ''(1 2)(3 3)╙■ΓA'' ''(1 2)(3 3)╙■ΓN╤A'''                               °
  164.   '''The rank of the left argument can be less than or equal to the rank       °
  165.  ''' '''of the right argument:'',r'                                            °
  166.   'show ''C╜3 3µ''''ABCDE'''''' ''DISPLAY C'' ''''''DE''''╤C'' ''''''CD'       °
  167.  '''╤C'''                                                                      °
  168.   '''In the second example, the last C in row 1 cannot match, since the'       °
  169.  '' '''elements of the left argument (CD) must be contiguous.''' 'do'          °
  170.   '''Naturally, both the left and the right argument can be nested:'',r'       °
  171.   'show ''N╜2 4µ1 ''''ONE'''' 2 ''''TWO'''' 3 ''''THREE'''''' ''DISPLAY        °
  172.  N''' 'show ''DISPLAY (2 ''''TWO'''')╤N'''                                     °
  173.   '''If the right argument is a large array, then we might desire to als       °
  174.  o'''                                                                          °
  175.   '''determine the access vectors of all ones in this boolean array. Sup       °
  176.  pose''' '''we have the array'',r'                                             °
  177.   'show ''A╜5 7µ∞9'' ''A'' ''N╜(É╜2 2µ2Φ∞4)╤A'' ''N'''                         °
  178.   '''There are two positions where the left argument matches array A: 1        °
  179.  3'''                                                                          °
  180.   '''and 2 5. We need an algorithm to find these two access vectors.'''        °
  181.   'do' '''We begin by generating the row and column indices'',r'               °
  182.   'show ''DISPLAY ∞■µN'''                                                      °
  183.   '''Next we pair each of these row and column numbers using reduction.'       °
  184.  ''                                                                            °
  185.   '''since reduction produces a scalar, we extract the resulting array''       °
  186.  ' '''with First'',r' 'show ''DISPLAY ╞°.,/∞■µN'''                             °
  187.   '''Finally to extract only those elements of N that contain a 1'',r'         °
  188.   'show ''DISPLAY (,N)/,╞°.,/∞■µN'''                                           °
  189.   '''The idiom displayed in the last expression is very useful in many''       °
  190.  '                                                                             °
  191.   '''applications. It looks forbidding, but can be easily derived using'       °
  192.  ''                                                                            °
  193.   '''the three steps of our example. There may be times when you are in'       °
  194.  ''                                                                            °
  195.   '''a hurry to come up with a neat algorithm such as the one above, and       °
  196.  '''                                                                           °
  197.   '''do not wish to waste time developing it. There are publications'''        °
  198.   '''that list a great number of idioms to solve most of the commonly'''       °
  199.   '''ocurring problems. The IBM supplied library contains a special'''         °
  200.   '''workspace to help you in this respect.''' 'do'                            °
  201.   '''For example, to retrieve the idiom just described here, do the'''         °
  202.   '''following:'',r' '''  1. Exit this lesson'''                               °
  203.   '''  2. Enter )LOAD 1 IDIOMS''' '''  3. Enter IDIOMS'''                      °
  204.   '''  4. Specify BOOLEAN ARRAY as search argument'''                          °
  205.   '''  5. Look up Σ VECTOR OF POSITIONS OF ONE''''S IN BOOLEAN ARRAY'''        °
  206.   'do'                                                                         °
  207.   '''There are other alternate idioms to solve the same problem. Conside       °
  208.  r''' '''for example the following one'',r'                                    °
  209.   'show ''DISPLAY Γ[1](µN)ÿ(,N)/(2╙µN)+∞µ,N'''                                 °
  210.   '''As an exercise try to analyze this expression. If the efficiency of       °
  211.  '''                                                                           °
  212.   '''an algorithm is related to the number of functions invoked, could t       °
  213.  his''' '''algorithm be improved if it were defined as a function?'''          °
  214. X 'endd'                                                                       °
  215. *(1997 7 1 13 6 12 224)                                                        °
  216.  FTEACH2 ÉFX 'TEACH2;MATCH;FN;T;A;B;C' 'Σ Dyadic primitive MATCH'              °
  217.   '''In lesson 7 we studied the monadic primitive called DEPTH. It has''       °
  218.  '                                                                             °
  219.   '''the symbol ╧. There is also a dyadic version of ╧ called MATCH.'',r       °
  220.  '                                                                             °
  221.   '''In older versions of APL, testing whether two arrays are identical'       °
  222.  '' '''is complex. Consider comparing two arrays A and C.'',r'                 °
  223.   'show ''C╜A╜2 2µ∞4 ╪ B╜2 2µ∞3 ╪ (2 2╙A)╜ΓC ╪ (2 2╙C)╜ΓB ╪ DISPLAY A C'       °
  224.  ''                                                                            °
  225.   '''First the rank must match, then the shape, and finally the elements       °
  226.  .''' '''We could do it by defining function MATCH'',r'                        °
  227.   'show ''FN╜''''U╜V MATCH W;T'''' ''''Σ Return 1 only if V and W are id       °
  228.  entical'''''''                                                                °
  229.   'show ''FN╜FN,Γ''''╕(~U╜(╧V)=T╜╧W)/0 ╪ ╕(~U╜(µµV)=µµW)/0 ╪ ╕(T>0)/L0''       °
  230.  '''''                                                                         °
  231.   '''If the two arguments do not match in depth, return 0. Else if the''       °
  232.  '                                                                             °
  233.   '''two arguments do not match in rank, return 0. Else if the rank is''       °
  234.  ' '''not zero go to L0''' 'do' 'show ''FN╜FN,Γ''''U╜V=W ╪ ╕0'''''''           °
  235.   '''If the rank is zero, use the = compare and exit'',r'                      °
  236.   'show ''FN╜FN,Γ''''L0:╕(~U╜^/(µV)=µW)/0 ╪ U╜^/(,V) MATCH■ ,W'''''''          °
  237.   '''At L0, if the two arguments do not match in shape, return 0. Else a       °
  238.  pply''' '''MATCH to each element of the two arrays.''' 'do' 'T╜ÉFX FN'        °
  239.   '1 showfn ''MATCH''' 'do' 'show ''A MATCH C'''                               °
  240.   '''As function MATCH indicates, the process of matching two APL2 array       °
  241.  s'''                                                                          °
  242.   '''involves several steps. The dyadic version of ╧ handles it all.'',r       °
  243.  '                                                                             °
  244.   'show ''A╧C'' ''4╧''''4'''''' ''1 2 3╧∞3'' ''''''ABCD''''╧1Φ''''DABC''       °
  245.  '''' ''(2 2µ∞4)╧0 2°.+∞2'''                                                   °
  246.   '''The examples illustrate that match can be used to test whether APL2       °
  247.  '''                                                                           °
  248.   '''expressions generate a desired result. It is this aspect of functio       °
  249. Xn''' '''match that makes it so useful in some applications.''' 'endd'         °
  250. *(1997 7 3 13 20 43 412)                                                       °
  251.  FTEACH3 ÉFX 'TEACH3;N;C' 'Σ Primitive dyadic WITHOUT (~)'                     °
  252.   '''There is another primitive monadic function that has an interesting       °
  253.  '''                                                                           °
  254.   '''dyadic version. In lesson 4 we learned that monadic NOT (represente       °
  255.  d''' '''by ~) will reverse boolean values'',r' 'show ''~1 0'''                °
  256.   '''The dyadic version of ~ is called WITHOUT. Unlike its monadic versi       °
  257.  on'''                                                                         °
  258.   '''which is restricted to boolean data, Without will work with all'''        °
  259.   '''types of arrays. Without removes from the left rank 0 or 1 array'''       °
  260.   '''argument all ocurrences of elements in the right argument'',r'            °
  261.   'show ''(∞10)~2⌡∞10'' ''N╜∞6'' ''N~∞4'' ''N~0 1 0 1 0 1/N'''                 °
  262.   '''The shape of the right argument has no effect on this process'',r'        °
  263.   'show ''''''ABCDEFG''''~''''ACEG'''''' ''''''ABCDEFG''''~2 2µ''''ACEG'       °
  264.  ''''''                                                                        °
  265.   '''Without works on elements of an array, even if they are nested'',r'       °
  266.   'show ''''''ONE'''' ''''TWO'''' ''''THREE'''' ''''FOUR''''~''''ONE''''       °
  267.   ''''TWO'''' ''''SIX'''''''                                                   °
  268.   '''The left argument should be a vector or a rank 0 array, but the rig       °
  269.  ht''' '''argument is arbitrary.'',r'                                          °
  270.   'show ''DISPLAY (Γ2 2µ∞4)~2 2µ∞4'''                                          °
  271.   '''In the above example, the left argument is a rank 0 array, but the'       °
  272.  ''                                                                            °
  273.   '''right argument is treated as containing the scalars ∞4. Therefore t       °
  274.  he''' '''left argument is left unchanged''' 'do'                              °
  275.   'show ''DISPLAY (,2 2µ∞4)~Γ2 2µ∞4'''                                         °
  276.   '''In this example the left argument is equivalent to ∞4. The rank 0''       °
  277.  ' '''right argument is not present there''' 'do'                              °
  278.   '''When all elements of the left argument are removed, "without" retur       °
  279.  ns''' '''the prototype'',r'                                                   °
  280.   'show ''DISPLAY (Γ2 2µ∞4)~Γ2 2µ∞4'' ''DISPLAY (,2 2µ∞4)~2 2µ∞4'''            °
  281.   '''Now explain the following result:'',r'                                    °
  282. X 'show ''DISPLAY 1 2 (2 2µ∞4)~2 2µ∞4''' 'endd'                                °
  283. *(1997 7 3 14 7 28 304)                                                        °
  284.  FTEACH4 ÉFX 'TEACH4;FN;FN2;T'                                                 °
  285.   'Σ Using data structures; PUSH DOWN STACK'                                   °
  286.   '''USING DATA STRUCTURES'',r'                                                °
  287.   '''It is one thing to have powerful tools, but it is something else to       °
  288.  '''                                                                           °
  289.   '''be able to use them. In the remainder of this lesson we will sample       °
  290.  '''                                                                           °
  291.   '''some specific data structures, and define processes to use them.'''       °
  292.   'do'                                                                         °
  293.   '''We begin with the concept of a PUSH DOWN STACK. The concept is very       °
  294.  '''                                                                           °
  295.   '''similar to the physical device found in cafeterias. An empty plate'       °
  296.  ''                                                                            °
  297.   '''is handy to the customer in a device. As the top plate is removed,'       °
  298.  ''                                                                            °
  299.   '''a spring pushes the next empty plate into position for the next'''        °
  300.   '''customer. We will now define two APL2 functions, PUSH and POP to'''       °
  301.   '''simulate a generalized form of this activity. We will assume that''       °
  302.  ' '''there is a global variable called STACK. We initialize STACK'',r'        °
  303.   'show ''STACK╜Γ'''''''''''                                                   °
  304.   '''Function PUSH will enter data into this STACK. We will define PUSH'       °
  305.  '' '''as a dyadic function, but we will delay dealing with the left'''        °
  306.   '''argument for a while'',r'                                                 °
  307.   'FN╜''V PUSH W;T'' ''Σ Push W on top of STACK'''                             °
  308.   'FN╜FN,Γ''╕(0⌠ÉNC ''''V'''')/L0 ╪ STACK╜Γ(ΓW),πSTACK ╪ ╕0'''                 °
  309.   'T╜ÉFX FN,Γ''L0:ΣThis option to be developed later'''                        °
  310.   '1 showfn ''PUSH''' '''Let us see how this works'',r'                        °
  311.   'show ''DISPLAY STACK'' ''PUSH ''''ONE'''''' ''DISPLAY STACK'' ''PUSH        °
  312.  ''''TWO'''''''                                                                °
  313.   'show ''DISPLAY STACK'' ''PUSH ''''THREE'''''' ''DISPLAY STACK'''            °
  314.   '''Each time PUSH is invoked, the right argument to PUSH is placed'''        °
  315.   '''in front of the previous contents of STACK. To retrieve this stored       °
  316.  '''                                                                           °
  317.   '''information, we define function POP. This too will be dyadic, and''       °
  318.  ' '''again we will postpone dealing with the left argument'',r'               °
  319.   'FN2╜''U╜V POP W;T'' ''Σ Remove W elements from STACK'''                     °
  320.   'FN2╜FN2,Γ''╕(0⌠ÉNC ''''V'''')/L0 ╪ U╜W╞πSTACK ╪ STACK╜ΓW╟πSTACK ╪ ╕0'       °
  321.  '' 'T╜ÉFX FN2,Γ''L0:ΣThis option to be developed later'''                     °
  322.   '1 showfn ''POP'''                                                           °
  323.   '''POP returns W items from STACK. At the same time it also removes th       °
  324.  ese''' '''items from the stack'',r'                                           °
  325.   '''Let us now remove two items from stack'',r'                               °
  326.   'show ''DISPLAY POP 2'' ''DISPLAY STACK'''                                   °
  327.   '''Functions PUSH and POP as defined allow us to store temporary data'       °
  328.  ''                                                                            °
  329.   '''in an array called stack. Suppose now that we wish to store not'''        °
  330.   '''one, but several stacks. This can be done by defining a left argume       °
  331.  nt''' '''to PUSH and POP as an access vector'',r'                             °
  332.   'show ''STACK╜2µ'''''''' '''''''''' ''DISPLAY STACK'''                       °
  333.   '''We re-define push'',r' 'T╜ÉFX FN,Γ''L0:STACK[V]╜Γ(ΓW),VπSTACK'''          °
  334.   '1 showfn ''PUSH'''                                                          °
  335.   'show ''1 PUSH ''''ONE'''''' ''2 PUSH ''''TWO'''''' ''1 PUSH ''''UNO''       °
  336.  '''' ''2 PUSH ''''DOS''''''' 'show ''DISPLAY STACK'''                         °
  337.   '''To retrieve selectively from this compound stack, we redefine POP''       °
  338.  ,r' 'T╜ÉFX FN2,Γ''L0:U╜W╞T╜VπSTACK ╪ STACK[V]╜ΓW╟T'''                         °
  339.   '1 showfn ''POP''' 'do' '''And now we can extract from STACK'',r'            °
  340.   'show ''DISPLAY 2 POP 2'' ''DISPLAY STACK'' ''2 PUSH ''''THREE'''''''        °
  341. X 'show ''DISPLAY 1 POP 1'' ''DISPLAY STACK''' 'endd'                          °
  342. *(1997 7 7 12 41 20 416)                                                       °
  343.  FTEACH5 ÉFX 'TEACH5;FN;T' 'Σ Rule selection'                                  °
  344.   '''When we described the game of Blackjack, we generated two nested'''       °
  345.   '''arrays: ANTE and CONS. The simple inference engine of that game alw       °
  346.  ays'''                                                                        °
  347.   '''started with rule number 1. In more general Expert Systems, the rul       °
  348.  e'''                                                                          °
  349.   '''that is fired first is one that satisfies the conditions of ANTE. L       °
  350.  et'''                                                                         °
  351.   '''us assume that the elements of ANTE are CONJUNCTIONS. (To refresh y       °
  352.  our''' '''memory, a conjunction is an expression of the form'',r'             °
  353.   '''    cond1 AND cond2 AND ...'',r'                                          °
  354.   '''where expressions condx return a boolean value.)''' 'do'                  °
  355.   '''We will now develop a short application of such a general system. N       °
  356.  ormally'''                                                                    °
  357.   '''we would build a rule set consisting of phrases such as: "He has bl       °
  358.  ue eyes"'''                                                                   °
  359.   '''or "The person is heavy set". These phrases, called FACTS would be        °
  360.  searched'''                                                                   °
  361.   '''for in the antecedents of a rule set, and if found there, they woul       °
  362.  d be used'''                                                                  °
  363.   '''to generate new conclusions in the consequents of the rules. The co       °
  364.  nclusions'''                                                                  °
  365.   '''would then be incorporated into "new" FACTS. If a conclusion were o       °
  366.  f a'''                                                                        °
  367.   '''special type (such as "The person is George") called here GOALS, th       °
  368.  en this''' '''result would be printed, and the search would stop.'',r'        °
  369.   '''For simplicity, (and to make it easier to display an example) we wi       °
  370.  ll'''                                                                         °
  371.   '''replace phrases by short words (such as "ONE", "THERE" "NOT TWO"...       °
  372.  ). The''' '''concept, however should remain the same''' 'do'                  °
  373.   '''Here is an example of a ruleset'',r'                                      °
  374.   'ANTE╜(''ONE'' ''TWO'')(''NOT TWO'' ''FOUR'')(Γ''THREE'')(''FIVE'' ''N       °
  375.  OT SIX'')'                                                                    °
  376.   'ANTE╜ANTE,(''ONE'' ''THREE'')(''NOT TWO'' ''FIVE'')(Γ''ONE'')'              °
  377.   'CONS╜''HERE'' ''THERE'' ''ONE'' ''FOUR'' ''SIX'' ''NOT SIX'' ''TWO'''       °
  378.   'DISPLAY ''RULE#'' ''ANTE'' ''CONS'',[0.1](7 1µ,■∞7)(πANTE)(7 1µCONS)'       °
  379.   'do' '''We lso define a set of goals'',r'                                    °
  380.   'show ''GOALS╜''''HERE'''' ''''THERE'''''''                                  °
  381.   '''Suppose also that we begin the search with the following FACTS'',r'       °
  382.   'show ''FACTS╜''''TWO'''' ''''THREE'''''''                                   °
  383.   '''You can look at the rule set and find that by rule #3 fact ''''ONE'       °
  384.  ''' can'''                                                                    °
  385.   '''be added to FACTS. Then by rule #5 we get ''''SIX'''', by rule #7 w       °
  386.  e get'''                                                                      °
  387.   '''''''TWO'''', and by rule #1 ''''HERE'''', which is a GOAL.''' 'do'        °
  388.   '''In APL2, given the initial set of facts: ''''TWO'''' ''''THREE'''',       °
  389.   we want to'''                                                                °
  390.   '''determine which of the seven rules is to be triggered'',r'                °
  391.   'show ''(^/■ANTEε■ΓFACTS)/∞µANTE'''                                          °
  392.   '''The above expression tells us which rule to fire first. Let us now'       °
  393.  ''                                                                            °
  394.   '''write an inference engine that will operate on this kind of problem       °
  395.  .'',r' '''Since there are two steps involved'',r'                             °
  396.   '''  1. Find rules that can be fired''' '''  2. Fire the rule'',r'           °
  397.   '''We need two functions INFEN and EVALRULE.''' 'do'                         °
  398.   '''Now let us define function INFEN'',r'                                     °
  399.   'show ''FN╜''''U╜INFEN;ACT;STACK;G;N;R;T'''' ''''Σ Another inference e       °
  400.  ngine'''''''                                                                  °
  401.   '''We are making INFEN niladic, since ANTE, CONS, FACTS and GOALS are'       °
  402.  '' '''presumed to be global'',r'                                              °
  403.   'show ''FN╜FN,Γ''''ACT╜(N╜µANTE)µ1 ╪ STACK╜Γ∞0'''''''                        °
  404.   '''We initialize two local variables. ACT is a vector of currently act       °
  405.  ive'''                                                                        °
  406.   '''rules. STACK is to store the state of the search to allow for a pro       °
  407.  cess'''                                                                       °
  408.   '''called BACKTRACKING. Note that we initialize STACK to return a nume       °
  409.  ric''' '''null vector if empty'',r'                                           °
  410.   'show ''FN╜FN,Γ''''L0:R╜(^/■(ACT/ANTE)ε■ΓFACTS)/(ACT/∞N)'''''''              °
  411.   '''We apply the search algorithm, but we first reduce the ruleset to t       °
  412.  he''' '''currently active rules.'',r'                                         °
  413.   'show ''FN╜FN,Γ''''L2:╕(T╜1≥µR)/L3 ╪ PUSH (1╟R) ACT FACTS'''''''             °
  414.   '''If more than one rule fires, save current status of knowledge, so i       °
  415.  t'''                                                                          °
  416.   '''can be restored in case the first rule leads to a dead end. This is       °
  417.  ''' '''called BACKTRACKING.'',r'                                              °
  418.   'show ''FN╜FN,Γ''''L3:╕(0=µR)/L1 ╪ ╕(EVALRULE ╞R)/L6 ╪ ╕0'''''''             °
  419.   '''If no rules fire begin the process of backtracking. Else evaluate''       °
  420.  ' '''current rule. If it shows contradiction, do backtracking'',r'            °
  421.   'show ''FN╜FN,Γ''''L6:╕(δ/G╜FACTSεGOALS)/L4 ╪ ╕L0'''''''                     °
  422.   'show ''FN╜FN,Γ''''L4: U╜G/FACTS ╪ ╕0'''''''                                 °
  423.   '''If a goal shows up in the facts, return it and stop search. Else'''       °
  424.   '''continue the search'',r'                                                  °
  425.   'show ''FN╜FN,Γ''''L1:R╜,πPOP 1 ╪ ╕(0⌠╞R)/L5 ╪ ''''''''Search failed''       °
  426.  '''''' ╪ ╕0'''''''                                                            °
  427.   '''To backtrack, POP previous status of search, and if the stack is em       °
  428.  pty''' '''report failure'',r'                                                 °
  429.   'show ''FN╜FN,Γ''''L5:(R ACT FACTS)╜R ╪ ╕L2'''''''                           °
  430.   '''If stack is not empty, restore previously stored values of R, ACT''       °
  431.  ' '''and FACTS''' 'T╜ÉFX FN' 'do' '1 showfn ''INFEN''' 'do'                   °
  432.   '''We will write a very simple rule evaluation function''' 'do'              °
  433.   'show ''FN╜''''U╜EVALRULE W;N;T'''' ''''Σ Fire rule W'''''''                 °
  434.   'show ''FN╜FN,Γ''''ACT[W]╜0 ╪ N╜WπCONS ╪ É╜FACTS╜FACTS,ΓN'''''''             °
  435.   '''First, make this rule inactive, then extract the consequent, add it       °
  436.  '''                                                                           °
  437.   '''to the list of FACTS and display FACTS to show how the process work       °
  438.  s.''' 'do'                                                                    °
  439.   'show ''FN╜FN,Γ''''╕(~T╜^/''''''''NOT ''''''''=4╞N)/L0 ╪ N╜4╟N'''''''        °
  440.   'show ''FN╜FN,Γ''''L0:╕T/L1 ╪ N╜''''''''NOT '''''''',N'''''''                °
  441.   '''Then, if the consequent begins with NOT, drop "NOT" from N; if it d       °
  442.  oes'''                                                                        °
  443.   '''not, add "NOT" to N so that a test can be made for contradiction'''       °
  444.   'do'                                                                         °
  445.   'show ''FN╜FN,Γ''''L1:╕(U╜~(ΓN)εFACTS)/0 ╪ ''''''''Contradiction''''''       °
  446.  '''''''''                                                                     °
  447.   '''If the negation of consequent is in FACTS, enter "Contradiction"'''       °
  448.   '''and return 0 (failure).'',r' 'T╜ÉFX FN' '1 showfn ''EVALRULE'''           °
  449.   'do' '''Now let us see how it works'',r'                                     °
  450.   'show ''FACTS╜''''THREE'''' ''''TEN'''''' ''INFEN'' ''FACTS╜''''NOT TW       °
  451.  O'''' ''''FIVE'''''''                                                         °
  452.   'show ''INFEN'' ''FACTS╜''''THREE'''' ''''NOT TWO'''''' ''INFEN'''           °
  453. X 'endd'                                                                       °
  454. *(1997 7 7 13 28 42 456)                                                       °
  455.  FTEACH6 ÉFX 'TEACH6;T;FN' 'Σ Describe FRAMES'                                 °
  456.   '''Another data structure that can be useful is called FRAME. When use       °
  457.  d,'''                                                                         °
  458.   '''a frame is just one component of a hierarchical network. When we'''       °
  459.   '''define a frame structure, we must generate two nested vectors. (It        °
  460.  may'''                                                                        °
  461.   '''be possible to work with a single array, but things get a little mo       °
  462.  re'''                                                                         °
  463.   '''messy.) Let us call the two vectors FRAMES and FRAMEID. Vector FRAM       °
  464.  ES'''                                                                         °
  465.   '''contains the actual data structures, while vector FRAMEID is merely       °
  466.  '''                                                                           °
  467.   '''a list of unique POINTERS to each frame. Clearly the length of FRAM       °
  468.  ES''' '''must be the same as the length of FRAMEID.''' 'do'                   °
  469.   '''Since FRAMES represents a hierarchy, we can always designate one of       °
  470.  ''' '''the frames as the ROOT frame'',r'                                      °
  471.   'FRAMEID╜''ROOT'' ''FIC1'' ''REAL'''                                         °
  472.   'T╜(''NAME'' ''PERSON'')(''╞PTR'' ''ROOT'' ''FIC1'' ''REAL'')'               °
  473.   'T╜T,Γ''TEXT'' ''Is this person real or fictional?'''                        °
  474.   'T╜T,Γ''FUNC'' ''P╜1 ''''╞PTR'''' GETVAL ''''FICTIONAL'''' ''''REAL'''       °
  475.  ''''                                                                          °
  476.   'FRAMES╜(πT)(''NAME'' ''Huckleberry Finn'')(''NAME'' ''Abraham Lincoln       °
  477.  '')'                                                                          °
  478.   'show ''DISPLAY πFRAMEID'' ''DISPLAY (FRAMEID∞Γ''''ROOT'''')πFRAMES'''       °
  479.   '''The root frame is an array. The elements in the first column are'''       °
  480.   '''called SLOTS. For each slot, there is one or more VALUES. Values'''       °
  481.   '''in general can be arrays, valid APL2 expressions, or pointers to'''       °
  482.   '''other frames.''' 'do'                                                     °
  483.   '''In this particular illustration, we will adopt the following'''           °
  484.   '''conventions:'',r'                                                         °
  485.   ''' 1. Slots containing pointers are labels beginnimg with the symbol        °
  486.  ╞'''                                                                          °
  487.   ''' 2. If the values for a slot are pointers, then the first pointer''       °
  488.  '                                                                             °
  489.   '''    leads to the PREDECESOR frame. All subsequent pointers lead to'       °
  490.  '' '''    SUCCESSOR frames'''                                                 °
  491.   ''' 3. Frames that have no successors are called LEAVES.'''                  °
  492.   ''' 4. Frames have rank 2, but leaves may have rank 1'',r'                   °
  493.   'show ''DISPLAY 1╟FRAMES'''                                                  °
  494.   '''In this example the remaining frames are leaves''' 'do'                   °
  495.   '''Now let us write function EVALFRAME to evaluate a frame structure.'       °
  496.  ',r'                                                                          °
  497.   'show ''FN╜''''U╜EVALFRAME W;F;N;R;T;P'''' ''''Σ Evaluate frame W'''''       °
  498.  '' 'show ''FN╜FN,Γ''''R╜1╞µF╜(FRAMEID∞ΓW)πFRAMES'''''''                       °
  499.   'show ''FN╜FN,Γ''''╕(1⌠µµF)/L0 ╪ U╜1╟F ╪ ╕0'''''''                           °
  500.   '''Retrieve the contents of the frame into local variable F. If F is''       °
  501.  ' '''a vector, return the value''' 'do'                                       °
  502.   'show ''FN╜FN,Γ''''L0:N╜F[;1]∞''''''''TEXT'''''''' ''''''''FUNC'''''''       °
  503.  '''''''' 'show ''FN╜FN,Γ''''╕(R<N[1])/L2 ╪ 1╟F[N[1];]'''''''                  °
  504.   '''If the current frame has a slot labelled TEXT, display its value'''       °
  505.   'do' 'show ''FN╜FN,Γ''''L2:╕(R<N[2])/L3 ╪ »2πF[N[2];]'''''''                 °
  506.   '''If the current frame has a slot labelled FUNC, evaluate the APL2'''       °
  507.   '''expression (stored as value to slot FUNC). The result is assigned t       °
  508.  o P.''' 'do'                                                                  °
  509.   'show ''FN╜FN,Γ''''L3:╕(PεFRAMEID)/L4 ╪ U╜1 2╙F ╪ ╕0'''''''                  °
  510.   '''The local variable P contains the response to the inquiry made by G       °
  511.  ETVAL.'''                                                                     °
  512.   '''If P is not in FRAMEID, return row 1 col 2 of the FRAMES entry matc       °
  513.  hing''' '''the original inquiry''' 'do'                                       °
  514.   'show ''ÉFX FN,Γ''''L4:EVALFRAME ╞P'''''''                                   °
  515.   '''Else evaluate the current frame'',r' '1 showfn ''EVALFRAME'''             °
  516.   '''Function EVALFRAME is a bit simplistic, but it illustrates the type       °
  517.  '''                                                                           °
  518.   '''of processing that could be developed in frame based KNOWLEDGE.'''        °
  519.   'do'                                                                         °
  520.   '''Before we can test function EVALFRAME, we also have to define'''          °
  521.   '''function GETVAL, which is invoked in slot FUNC.'',r'                      °
  522.   'show ''FN╜''''U╜V GETVAL W;X;P'''' ''''Σ Extract contents of slot V g       °
  523.  iven W'''''''                                                                 °
  524.   '''This function is made up to suit this particular example'',r'             °
  525.   'show ''FN╜FN,''''æ╜P╜ε''''''''Enter one:'''''''',W,■'''''''' ''''''''       °
  526.  '''' ''''X╜(µP)╟æ'''''''                                                      °
  527.   'show ''ÉFX FN,''''P╜(1πV)Φ1╟,F[F[;1]∞Γ2πV;]'''' ''''U╜P[W∞ΓX]'''''''        °
  528.   '1 showfn ''GETVAL'''                                                        °
  529.   '''The last two expressions extract the contents associated with slot'       °
  530.  ''                                                                            °
  531.   '''given by V[2], and matched to the entries in W. If there is no matc       °
  532.  h,'''                                                                         °
  533.   '''the value returned is that of the first entry (the ROOT frame).'''        °
  534.   'do'                                                                         °
  535.   '''Let us see how this works. When asked to enter a choice, try first'       °
  536.  '' '''an invalid response'',r' 'show ''EVALFRAME ''''ROOT'''''''              °
  537.   '''As an exercise, consider defining function ADDFRAME. This function'       °
  538.  '' '''should prompt you to add new frames and to update appropriate'''        °
  539.   '''pointers in connecting frames. For example, use your ADDFRAME to'''       °
  540.   '''insert one that would ask you whether REAL person is still living.'       °
  541.  ''                                                                            °
  542.   '''(Prompt for ''''DEAD'''' or ''''LIVING'''') Then point to either Ab       °
  543. Xe Lincoln''' '''or a living person of your choice.''' 'endd'                  °
  544. *(1997 7 13 12 28 49 504)                                                      °
  545.  Faddquote ÉFX 'u╜addquote w'                                                  °
  546.   'Σ Put quotes around a string, and double existing quotes'                   °
  547. X 'u╜ÉAV[40],((1+w=ÉAV[40])/w),ÉAV[40]'                                        °
  548. *(1997 7 24 13 20 38 476)                                                      °
  549.  Fav ÉFX 'av;A;N;I;ÉIO' 'Σ Display characters in ÉAV' 'ÉIO╜0'                  °
  550.   'A╜22 78µ'' ''' 'N╜3 0«φ12 22µ1+∞356' 'A[;,(6⌡∞12)°.+2 3 4]╜N'               °
  551.   'A[;6+6⌡∞12]╜φ12 22µÉAV' 'ΣA[8 10 13;6]╜'' ''' 'A[13;6]╜'' '''               °
  552. X 'A[14+∞8;68 69 70 72]╜'' ''' 'A'                                             °
  553. *(1991 11 11 8 25 13 316)                                                      °
  554.  Fdate ÉFX 'u╜date w' 'Σ Format date and time of day' 'u╜«6╞w'                 °
  555. X 'u╜('' ''⌠u)Γu' 'u╜εu,■''-- .. '''                                           °
  556. XCdig 1 10 1234567890                                                          °
  557. *(1997 9 9 13 0 45 372)                                                        °
  558.  Fdisclaimer ÉFX 'disclaimer' 'Σ Copyright statement'                          °
  559.   '(10µ'' ''),''Copyright, Z. V. Jizba, 1995,1996,1997'',r'                    °
  560.   ''' This and subsequent workspaces labelled TEACHxx are made available       °
  561.  '''                                                                           °
  562.   '''at no cost to anyone who desires to learn how to use effectively'''       °
  563.   '''the IBM/OS2 version of APL2.'',r'                                         °
  564.   '''This software is provided "AS IS" with no WARRANTY of any kind, eit       °
  565.  her'''                                                                        °
  566.   '''express or implied. Any risk in its use resides with you, the user        °
  567.  of''' '''these tutorials.'',r' '''     ACKNOWLEDGEMENTS'',r'                  °
  568.   ''' In writing these tutorials, I am greatly indebted to Roy Sykes, wh       °
  569.  ose'''                                                                        °
  570.   '''excellent lectures increased my understanding of the language.'''         °
  571.   '''Discussions with the late Harry Bertucelli clarified a number of'''       °
  572.   '''concepts and caused me to change some improper terminology that was       °
  573.  '''                                                                           °
  574.   '''used in previous versions of these tutorials. Mr. Benjamin Archer''       °
  575.  '                                                                             °
  576.   '''kindly checked out a nearly final version, bringing to my attention       °
  577.  ''' '''some ommisions, misspellings, and invalid terminology.'',r'            °
  578. X '''(PRESS ENTER to continue)'''                                              °
  579. *(1997 7 13 12 28 50 508)                                                      °
  580.  Fdo ÉFX 'do;T;E' 'Σ Expression driver' 'E╜''''' 'æ╜''      ''' 'T╜æ'          °
  581.   '╕(^/'' ''=T)/0'                                                             °
  582.   '╕(('':''εT)doif ''B╜evaldd (+/^\'''' ''''=T)╟T'')/2'                        °
  583.   '''E╜ÉEM'' ÉEA T' '╕(0=µ,E)/2'                                               °
  584.   '''This is not a valid APL2 expression''' 'æ╜''*''' '╕(''?''⌠╞1╟æ)/2'        °
  585. X 'E' '╕2'                                                                     °
  586. *(1997 7 13 12 28 50 508)                                                      °
  587.  Fdoif ÉFX 'U╢╜V╢ doif W╢;t╢' 'Σ Rule' '╕(^/~U╢╜V╢)/0'                         °
  588. X '''U╢╜V╢ doif■ W╢'' ÉEA ''»V╢/W╢'''                                          °
  589. *(1997 9 9 12 50 14 444)                                                       °
  590.  Fendd ÉFX 'endd' 'Σ end of special feature' '20µ''²'' ╪ ╕(4<µÉLC)/0'          °
  591. X 'do'                                                                         °
  592. *(1997 8 18 12 34 4 372)                                                       °
  593.  Ferase ÉFX 'erase;t;EXIT;GO;HELP;DISPLAY;BIND;REVIEW;RULE;DISCLAIMER'         °
  594.   'Σ Erase all global functions and variables' 't╜ÉNL 3'                       °
  595.   't╜(~t^.εlc,'' '')≡t' 't╜ÉEX(~t[;∞5]^.=''TEACH'')≡t' 't╜ÉNL 2'               °
  596. X 't╜ÉEX(~t^.εlc,'' '')≡t' 't╜ÉNL 4' 't╜ÉEX(~t^.εlc,'' '')≡t'                  °
  597. *(1997 7 27 13 47 41 608)                                                      °
  598.  Fevaldd ÉFX 'u╜evaldd w;c;n' 'Σ Evaluate direct definition' 'u╜0'             °
  599.   'n╜(w∞''Σ'')-1' 'c╜(((n╞w)⌠'':'')Γn╞w),Γ''ΣDD '',(n+1)╟w'                    °
  600.   '╕((1 label╞c)doif ''''''Invalid label'''''')/0'                             °
  601.   '╕((2=µc)doif ''u╜showdd 1╙c'')/0'                                           °
  602.   '╕((3=ÉNC╞c)doif ''u╜⌡µÉ╜(╞c),'''' is already defined.'''''')/0'             °
  603.   '╕((3=µc)doif ''u╜simdd c'')/0' 'c╜(Γ''α∙ aw'')replace■c'                    °
  604.   'u╜ε''u╜'',((''a''εεc[2 3 4])/''a ''),(╞c),'' w;t;b'''                       °
  605.   'u╜u(5πc)(''b╜(t╜'',(3πc),'')/'',addquote ''u╜'',4πc)'                       °
  606. X 'u╜u,''╕(t doif b)/0''(''u╜'',2πc)' 'u╜╧ÉFX u'                               °
  607. *(1997 7 25 13 27 52 564)                                                      °
  608.  Fexit ÉFX 'V exit W;T' 'Σ Exit if too many suspended functions'               °
  609.   '╕(0⌠ÉNC ''V'')/L0 ╪ V╜10' 'L0:╕(V>µÉLC)/0'                                  °
  610.   '''There are too many suspended functions''' '''Please enter '',W'           °
  611. X '╕'                                                                          °
  612. *(1997 7 26 12 33 39 536)                                                      °
  613.  Fget ÉFX 'U╜V get W;t;T;ÉPR' 'Σ Prompt for response from keyboard'            °
  614.   'ÉPR╜T╜ÉAV[ÉIO+255] ╪ ╕(0⌠ÉNC ''V'')/L0 ╪ V╜1' 'L0:V╜V╧1' 'æ╜W ╪ t╜æ'        °
  615.   'U╜(+/^\t=T)╟t' '╕(''╕''⌠╞U)/L1 ╪ ╕' 'L1:╕V/0' 't╜(U⌠'' '')ΓU'               °
  616. X 'U╜(µt),(ΓU),t'                                                              °
  617. *(1997 7 28 13 33 8 424)                                                       °
  618.  Fglobals ÉFX 'globals' 'Σ Initialize useful global variables'                 °
  619.   'uc╜''ABCDEFGHIJKLMNOPQRSTUVWXYZ'''                                          °
  620.   'lc╜''abcdefghijklmnopqrstuvwxyz''' 'dig╜''1234567890'''                     °
  621. X 'r╜ÉAV[13+ÉIO]' 'q╜'''''''''                                                 °
  622. *(1997 7 3 12 47 6 368)                                                        °
  623.  Finitialize ÉFX 'initialize;T' 'Σ Initialize workspace'                       °
  624.   '''AT ALL TIMES, TO CONTINUE, PRESS RETURN!'',r'                             °
  625.   '''To see disclaimers enter:'',r,''    disclaimer''' 'do' 'erase'            °
  626.   'globals'                                                                    °
  627.   '''Make sure the CAP LOCK light on your keyboard (upper right) is ON!'       °
  628. X'' 'endd'                                                                     °
  629. *(1997 7 27 13 14 33 444)                                                      °
  630.  Flabel ÉFX 'u╜v label w'                                                      °
  631.   'Σ Return 1 if label w does not begin with a cap'                            °
  632.   '╕(0⌠ÉNC ''v'')/L0 ╪ v╜0' 'L0:v╜v╧1 ╪ w╜εw ╪ ╕v/L1 ╪ ╕(u╜0⌠ÉNC w)/0'         °
  633. X 'L1:╕(u╜~^/wεlc,uc,dig)/0' 'u╜w[1]εlc,dig'                                   °
  634. XClc 1 26 abcdefghijklmnopqrstuvwxyz                                           °
  635. *(1997 7 13 12 28 55 528)                                                      °
  636.  Fnon ÉFX 'non;T;RC;ET;R' 'Σ Ignore keyboard entry' 'æ╜''      ''' 'T╜æ'       °
  637.   '╕(0=µ(T⌠'' '')/T)/0' '(RC ET R)╜ÉEC T' '╕(0=RC)/2'                          °
  638. X '╕((1=RC)doif ''R'')/2' '╕2'                                                 °
  639. *(1997 7 13 12 28 55 528)                                                      °
  640.  Fnotb ÉFX 'u╜notb w' 'Σ Remove trailing blanks'                               °
  641.   '╕((1<╧w)doif ''u╜notb■ w'')/0' '╕((1<µµw)doif ''u╜πnotb Γ[2]w'')/0'         °
  642. X 'u╜(1-(,'' ''⌠Φw)∞1)╟w'                                                      °
  643. *(1997 7 27 12 55 6 496)                                                       °
  644.  Fproblems ÉFX 'problems' 'Σ Problems'                                         °
  645.   '''That is all for this lesson. Remember, if you want to practice,'''        °
  646.   '''and plan to use direct definitions, be sure to first enter GO.'''         °
  647.   '''Direct definitions will then be accepted. To exit GO, enter EXIT.''       °
  648.  ,r'                                                                           °
  649.   '''To erase a previously defined DIRECT DEFINITION FUNCTION, enter'',r       °
  650.  ' '''       )ERASE functionname'',r'                                          °
  651. X '''WARNING! do not use )ERASE on other labels.'',r'                          °
  652. XCq 0 '                                                                        °
  653. XCr 0                                                                         °
  654. *(1997 7 13 12 28 56 532)                                                      °
  655.  Freplace ÉFX 'u╜v replace u;i;r;s' 'Σ Replace elements in v in u'             °
  656.   'i╜Γ∞µu' 's╜2πv╜(v⌠'' '')Γv' 'i╜⌡r╜i⌡■Γ[1]u°.=╞v'                            °
  657. X 'u[(εi)/εr]╜s[(εi)/εi⌡■∞µs]'                                                 °
  658. *(1997 7 13 12 28 56 532)                                                      °
  659.  Fround ÉFX 'U╜V round W' 'Σ Half adjust to V th decimal'                      °
  660. X 'U╜(╛0.5+W⌡10*V)÷10*V'                                                       °
  661. *(1997 7 13 12 28 57 536)                                                      °
  662.  Fshow ÉFX '╢V show ╢W;╢T;╢B' 'Σ Display and execute ╢W'                       °
  663.   '╢T╜(0=ÉNC ''╢V'')doif ''╢V╜0'''                                             °
  664.   '╕((0=╧╢W)doif ''show ╢W,'''' '''''')/0'                                     °
  665.   '╕((1<╧╢W)doif ''╢V show ■╢W'')/0' '''      '',╢W'                           °
  666. X '╕((╢V^'':''ε╢W)doif ''╢T╜evaldd ╢W'')/L0' '''ÉEM'' ÉEA ╢W' 'L0:do'          °
  667. *(1997 7 13 12 28 57 536)                                                      °
  668.  Fshowdd ÉFX 'u╜showdd w;a;b;c;r'                                              °
  669.   'Σ Display a direct definition function'                                     °
  670.   '╕((1=╧w)doif ''u╜showdd Γw'')/u╜0'                                          °
  671.   '╕((3⌠ÉNC╞w)doif ''(ε╞w),'''' is not a function'''''')/0'                    °
  672.   'c╜Γ[2]ÉCR╞w' 'c╜notb(2╞c),(Γ''aw α∙'')replace■2╟c'                          °
  673.   '╕((~''ΣDD''╧3╞2πc)doif ''''''Not a direct definition function'''''')/       °
  674.  0' 'u╜1' 'b╜('' ''⌠╞c)Γ╞c' 'a╜''      ''' 'r╜2╟3πc'                           °
  675.   '╕((3=µc)doif ''a,(╞w),'''':'''',r,(3<µ2πc)/''''   Σ'''',3╟2πc'')/0'         °
  676.   'a╜a,(╞w),'':'',(2╟5πc),'':''' 'b╜(+\r=''('')-+\r='')''' 'b╜b∞0'             °
  677. X 'a╜a,(²3╟(b-1)╞3╟r),'':'',2╟»(b+2)╟r' 'a,(3<µ2πc)/''  Σ'',3╟2πc'             °
  678. *(1997 7 13 12 28 57 536)                                                      °
  679.  Fshowfn ÉFX 'U╜V showfn W;F;N;T;ÉIO' 'Σ Simulate ╖W[É]'                       °
  680.   'T╜(0=ÉNC ''V'')doif ''V╜0''' 'ÉIO╜0'                                        °
  681.   'U╜r,''      '',''╖'',W,''[É]'',(╞V)╞''╖''' 'N╜1╞µF╜ÉCR W' 'N╜«∞N'           °
  682.   'N╜(N⌠'' '')ΓN' 'F╜(π''['',■N,■Γ''] ''),F'                                   °
  683.   'T╜(1<µ,V)doif ''F╜F[1╟V;]'' ''U╜''''''''''' 'U╜²1╟U,r,,F,r'                 °
  684. X 'U╜((-+/^\'' ''=ΦU)╟U),('' ╖'')[╞V],r'                                       °
  685. *(1997 7 13 12 28 58 540)                                                      °
  686.  Fsimdd ÉFX 'u╜simdd w;e' 'Σ Direct definition mode' 'u╜0'                     °
  687.   '╕((0⌠ÉNC╞w)doif ''''''Already defined'''''')/0' 'e╜''α''ε2πw'               °
  688.   'w[2]╜Γ''u╜'',''α∙ aw'' replace 2πw' 'w╜w[1 3 2]'                            °
  689. X 'w[1]╜Γε''u╜'',(e/''a ''),w[1],'' w''' 'u╜╧ÉFX w'                            °
  690. *(1992 6 3 9 59 17 424)                                                        °
  691.  Ftab ÉFX 'U╜V tab W;T;A;B;C;D;E;F;G;M;ÉPW' 'Σ Tabulate list W'                °
  692.   'T╜(0=ÉNC ''V'')doif ''V╜0''' 'M╜''Invalid data for tabulation'''            °
  693.   'V╜4╞V' 'ÉPW╜130╛30⌐G╜V[2]+79⌡V[2]=0'                                        °
  694.   'L1:╕((1<╧W)doif ''''''W╜∞0'''' ÉEA ''''W╜πW'''''')/L1'                      °
  695.   '╕(((0=µεW)δ2<µµW)doif ''U╜(~V╧4╞0)/M'')/0'                                  °
  696.   'T╜(1≥µµU╜«W)doif ''U╜πW╜(U⌠'''' '''')ΓU'''                                  °
  697.   'T╜(0<V[1])doif ''U╜(«(Φ1,╞µW)µ(V[3]µ'''' ''''),∞(╞µW)-V[3]),'''' ''''       °
  698.  ,U''' '╕(G<30)/0' 'T╜(F╜µεV[4])+C╜1╟B╜µA╜(V[3],0)╟U'                          °
  699.   'T╜⌐(1╞B)÷1⌐╛(ÉPW+F)÷T' 'U╜(E╜(V[3],C)╞U),[1](B╜T,1╟B)╞A'                    °
  700.   '''D╜εV[4]'' ÉEA ''D╜ÉAV[εV[4]+33⌡V[4]=0]''' 'L0:A╜(T,0)╟A'                  °
  701. X '╕(0=1╞µA)/0' 'U╜U,(((T+V[3]),µD)µD),E,[1]B╞A' '╕L0'                         °
  702. *(1997 7 13 12 28 59 544)                                                      °
  703.  Ftest ÉFX 'U╜V test W;P'                                                      °
  704.   'Σ Describe problem in W, (correct answer in V)' 'U╜2' 'L1:W'                °
  705.   'É╜''      ''' 'P╜æ' '''╕L0'' ÉEA ''P╜»P''' '╕(V╧P)/0'                       °
  706. X 'L0:╕(0=U╜U-1)/0' '''Incorrect. Try again''' '╕L1'                           °
  707. XCuc 1 26 ABCDEFGHIJKLMNOPQRSTUVWXYZ                                           °
  708. *(1996 4 6 16 8 40 360)                                                        °
  709.  Fvec ÉFX 'U╜vec' 'Σ Draw 2d vector in plane'                                  °
  710.   'U╜r,r,''2-        +'',r '':      °'',r,''1-    °'',r'                       °
  711. X 'U╜U,'' :  °'',r,''0|....|....|'',r,'' 0    1    2'',r'                      °
  712.