home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 12 / CD_ASCQ_12_0294.iso / maj / 666 / h5.hlp < prev    next >
Text File  |  1992-12-05  |  4KB  |  101 lines

  1.  
  2.                                MAPS
  3.  
  4. { d1 -> r1, ..., dn -> rn }    map enumeration
  5. {}                             empty map
  6. { x -> e1 : x <- e2 }          map construction
  7. { x -> e1 : x <- e2 ; b }      map construction with boolean
  8. dom m                          domain of map m
  9. rng m                          range of map m
  10. m dr s                         domain restriction (s is a set)
  11. m ds s                         domain subtraction (s is a set)
  12. inverse m                      inverse of m
  13. m im s                         image of m (s is a set)
  14. m[x]                           application
  15. m[x,r]                         application with default error return
  16. m1 overwr m2                   overwrite
  17. m[d]= r                        map update
  18. first p                        first element of ordered pair
  19. second p                       second element of ordered pair
  20.  
  21. Maps are enumerated by delimiting their elements with curly brackets
  22. (because formally maps are sets of ordered pairs). The syntax is
  23. given by the following example.
  24.  
  25. m = {1->2,3->4,5->6};
  26.  
  27. where the first and second elements of each ordered pair is separated
  28. by the mapping symbol ->.
  29.  
  30. Maps can be constructed using map construction. In the following
  31. example, len returns the length of a string.
  32.  
  33. {x->len x:x <- {"abc","defg","hijkl"}};
  34.  
  35.          returns {"abc"->3,"defg"->4,"hijkl"->5}
  36.  
  37. The domain (range) of a map is obtained by forming a set composed
  38. of all the first (second) elements of the ordered pairs
  39.  
  40. dom m;               returns {1,3,5}
  41. rng m;               returns {2,4,6}
  42.  
  43. A single-valued map must have all its first elements unique. Notice
  44. that, in general, card (rng m) <= card (dom m). The cardinality of
  45. the range would be less, for example if
  46.  
  47. m = {1->2,3->2,5->6};
  48.  
  49. In this case, card(dom m) = 3, and card(rng m) = 2 (because of the
  50. duplicate elements in the range).
  51.  
  52. Given a domain element, we can obtain the corresponding range element
  53. using application (this is like a table lookup).
  54.  
  55. m[1];                returns 2
  56. m[5];                returns 6
  57.  
  58. If a domain element is given which does not exist in the map, a false
  59. value will be returned. However, it is possible to supply your own
  60. value to be returned in this situation. This is done by supplying an
  61. additional argument (called the default error return). For example,
  62.  
  63. m[7];                returns false
  64. m[7,"not found"];    returns "not found"
  65.  
  66. Given a set of domain elements as a second argument, the image operation
  67. (im) produces a set of the corresponding range elements (again assuming
  68. m={1->2,3->4,5->6})
  69.  
  70. m im {3,5};        returns {4,6}
  71.  
  72. Domain restriction (dr) and domain subtraction (ds) produce new maps
  73. from a given map by either allowing only certain domain elements in
  74. the given map to appear in the result map, or taking away certain
  75. domain elements from the given map. The domain elements are given
  76. in a set which is the second argument of these operations.
  77.  
  78. {1->2,3->2,5->6} dr {3,5};     returns  {3->2,5->6}
  79. {1->2,3->2,5->6} ds {3,5};     returns {1->2}
  80.  
  81. The inverse operation just interchanges the domain and range elements
  82. of a map.
  83.  
  84. inverse {1->2,3->2,5->6};      returns {2->1,2->3,6->5}
  85.  
  86. Note that the result of the above operation is a multi-valued map.
  87.  
  88. The overwrite operation m1 overwr m2 is defined as follows: Each
  89. mapping in m1 is included in the result, unless its domain element
  90. occurs in the domain of m2. In that case, it is replaced by the
  91. mapping from m2. Every mapping in m2 whose domain element does not
  92. occur in the domain of m1 is included in the result. Example:
  93.  
  94. {1->2,3->4} overwr {3->5,4->6};    returns {1->2,3->5,4->6}
  95.  
  96. The map update m[d]=r is an assignment and a special case of
  97. overwrite where the second operand (of overwrite) contains a
  98. single ordered pair. Assuming that m is equal to {1->2,3->4},
  99. m[3]=5; is equivalent to m overwr {3->5} and assigns to m the map
  100. {1->2,3->5}.
  101.