RAPID.TXT 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. RIGAL RAPID PROGRAMMING GUIDE (W.E. 26.10.90)
  2. =============================
  3. Some considerations on fast Rigal execution and about
  4. some optimizations for recursive programs.
  5. Global algorithmic ideas :
  6. If your algorithm is tree-building - try use such ideas :
  7. 1.Every tree node accords to one call of Rigal rule
  8. 2.Next node is recursive call result (from previous rule),
  9. may be through some other rules.
  10. 3. Node is element of big array (list) and node refers to others
  11. by their "numbers of elements" in this array.
  12. 4. Tree (may be) not exist as data structure at execution
  13. time. Tree represented by tree-like history of execution
  14. of recursive rules."Good" nodes are accumulated in special list,
  15. or (more fast to search) in special another tree with well-chosen
  16. selectors. This way is good if tree building and tree traversing
  17. may be done in one pass.
  18. 5. Prepare all possible trees and tables in form of array or tree
  19. of arrays - before starting recursion. It helps to write
  20. cycles on lists , not on trees.
  21. 6. Use #CALL_PAS(60-66) - fast trees and lists.
  22. Local optimizations of programs.
  23. -------------------------------
  24. Don't use constructors in recursive called rule. It eats
  25. both time and memory.
  26. Operations in order of descending efficiency (from very slow to fast)
  27. as it is in compiled Rigal program.
  28. INEFFICIENT:
  29. ================
  30. SAVE; If SAVE is last statement in program -> it is implemented
  31. 1 1/2 times faster.
  32. LOAD
  33. #EXPLODE - very inefficient
  34. #IMPLODE
  35. FORALL $A IN $B - if $B is tree
  36. <* $A : $B *>
  37. $A !! $B - if $B is big list - elements copied one after one.
  38. $A ++ $B - if $B is big
  39. $A ++ $B - if $A is big
  40. $A:=<.D:E.> - every tree or list takes minimum 40 bytes
  41. $A:=(. D E .)
  42. #A ( $B $C ) - if call any rule with 2 or more parameters
  43. ( this will be optimized in nearest future )
  44. MIDDLE EFFICIENCY AND GOOD
  45. ==========================
  46. $A!.:=$K - if $A is small
  47. $A.$D:=$K
  48. $A++:=<. A:B, C:D, F:E.>
  49. $A!!(. A B C .)
  50. Arithmetical expressions
  51. $A.$B, $A[$B]
  52. $A.ABC $A[5]
  53. Patterns with constants.
  54. IMPLEMENTED VERY GOOD (in Pascal level):
  55. =======================================
  56. Clusters ( will be implemented in future )
  57. #CALL_PAS,#CHR, #ORD, predicates
  58. #LEN of tree or list
  59. #AA( $P1 $P2 $P3 $P4 ) - with one to four parameters
  60. FORALL $A IN $B - if $B is list
  61. $A+:=number
  62. $A !. $B
  63. IF/ELSE/FI, LOOP, BREAK , RETURN
  64. LAST #A $A
  65. $ $$
  66. $A:=$B;
  67. Single variable everywhere is of equal (or a
  68. little more) efficient as constant with the same value.
  69. ON PAGING CONTROL
  70. =================
  71. We recommend to use new #CALL_PAS(42) to know count
  72. of filled virtual memory pages in every N-th step
  73. of algorithm.
  74. Use #CALL_PAS(1) to require user to stop execution
  75. in every N-th step.
  76. If algorithm is iterative - use #CALL_PAS(45) to clean
  77. memory
  78. Every page is 8 KBytes.
  79. Totally is 256 pages ( 2 MBytes )
  80. In heap memory - no more than 50 pages,
  81. in 1300 Kb virtual disk - 170 pages
  82. in 300 Kb vitrual disk - 45 pages
  83. in hard disk - all remainder.
  84. One atom (or number) takes 8 bytes,
  85. One list of length N takes N*5 bytes, minimum 40
  86. One tree of length N takes N*10 bytes, minimum 40