sets.tex 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. \chapter{SETS: A basic set theory package}
  2. \label{SETS}
  3. \typeout{{SETS: A basic set theory package}}
  4. {\footnotesize
  5. \begin{center}
  6. Francis J. Wright \\
  7. School of Mathematical Sciences, Queen Mary and Westfield College \\
  8. University of London \\
  9. Mile End Road \\
  10. London E1 4NS, England \\[0.05in]
  11. e--mail: F.J.Wright@QMW.ac.uk
  12. \end{center}
  13. }
  14. \ttindex{SETS}
  15. The SETS package provides set theoretic operations on lists and represents
  16. the results as normal algebraic-mode lists, so that all other \REDUCE{}
  17. facilities that apply to lists can still be applied to lists that have
  18. been constructed by explicit set operations.
  19. \section{Infix operator precedence}
  20. The set operators are currently inserted into the standard \REDUCE{}
  21. precedence list (see section~\ref{sec-operators}) as follows:
  22. \begin{verbatim}
  23. or and not member memq = set_eq neq eq >= > <= < subset_eq
  24. subset freeof + - setdiff union intersection * / ^ .
  25. \end{verbatim}
  26. \section{Explicit set representation and MKSET}
  27. Explicit sets are represented by lists, and there is a need to convert
  28. standard \REDUCE\ lists into a set by removing duplicates. The
  29. package also orders the members of the set so the standard {\tt =}
  30. predicate will provide set equality.\ttindex{MKSET}
  31. \begin{verbatim}
  32. mkset {1,2,y,x*y,x+y};
  33. {x + y,x*y,y,1,2}
  34. \end{verbatim}
  35. The empty set is represented by the empty list \verb|{}|.
  36. \section{Union and intersection}
  37. The intersection operator has the name\ttindex{intersect} {\tt
  38. intersect}, and set union is denotes by\ttindex{union}{\tt union}.
  39. These operators will probably most commonly be used as binary infix
  40. operators applied to explicit sets,
  41. \begin{verbatim}
  42. {1,2,3} union {2,3,4};
  43. {1,2,3,4}
  44. {1,2,3} intersect {2,3,4};
  45. {2,3}
  46. \end{verbatim}
  47. \section{Symbolic set expressions}
  48. If one or more of the arguments evaluates to an unbound identifier
  49. then it is regarded as representing a symbolic implicit set, and the
  50. union or intersection will evaluate to an expression that still
  51. contains the union or intersection operator. These two operators are
  52. symmetric, and so if they remain symbolic their arguments will be
  53. sorted as for any symmetric operator. Such symbolic set expressions
  54. are simplified, but the simplification may not be complete in
  55. non-trivial cases. For example:
  56. \begin{verbatim}
  57. a union b union {} union b union {7,3};
  58. {3,7} union a union b
  59. a intersect {};
  60. {}
  61. \end{verbatim}
  62. Intersection distributes over union, which is not applied by default
  63. but is implemented as a rule list assigned to the variable {\tt
  64. set\_distribution\_rule}, {\em e.g.}
  65. \begin{verbatim}
  66. a intersect (b union c);
  67. (b union c) intersection a
  68. a intersect (b union c) where set_distribution_rule;
  69. a intersection b union a intersection c
  70. \end{verbatim}
  71. \section{Set difference}
  72. The set difference operator is represented by the symbol \verb|\| and
  73. is always output using this symbol, although it can also be input using
  74. \ttindex{setdiff} {\tt setdiff}. It is a binary operator.
  75. \begin{verbatim}
  76. {1,2,3} \ {2,4};
  77. {1,3}
  78. a \ {1,2};
  79. a\{1,2}
  80. a \ a;
  81. {}
  82. \end{verbatim}
  83. \section{Predicates on sets}
  84. Set membership, inclusion or equality are all binary infix operators.
  85. They can only be used within conditional statements or within the
  86. argument of the {\tt evalb}\ttindex{evalb} operator provided by this
  87. package, and they cannot remain symbolic -- a predicate that cannot be
  88. evaluated to a Boolean value causes a normal \REDUCE\ error.
  89. The {\tt evalb} operator provides a convenient shorthand for an {\tt
  90. if} statement designed purely to display the value of any Boolean
  91. expression (not only predicates defined in this package).
  92. \begin{verbatim}
  93. if a = a then true else false;
  94. true
  95. evalb(a = a);
  96. true
  97. if a = b then true else false;
  98. false
  99. \end{verbatim}
  100. \subsection{Set membership}
  101. Set membership is tested by the predicate \ttindex{member}{\tt member}.
  102. Its left operand is regarded as a potential set element and
  103. its right operand {\em must\/} evaluate to an explicit set. There is
  104. currently no sense in which the right operand could be an implicit set.
  105. \begin{verbatim}
  106. evalb(1 member {1,2,3});
  107. true
  108. evalb(2 member {1,2} intersect {2,3});
  109. true
  110. evalb(a member b);
  111. ***** b invalid as list
  112. \end{verbatim}
  113. \subsection{Set inclusion}
  114. Set inclusion is tested by the predicate {\tt subset\_eq}
  115. \ttindex{subset\_eq} where {\tt a subset\_eq b} is true if the set $a$
  116. is either a subset of or equal to the set $b$; strict inclusion is
  117. tested by the predicate {\tt subset}\ttindex{subset}
  118. where {\tt a subset b} is true if the set $a$ is {\em strictly\/} a
  119. subset of the set $b$ and is false is $a$ is equal to $b$. These
  120. predicates provide some support for symbolic set expressions, but is
  121. incomplete.
  122. \begin{verbatim}
  123. evalb({1,2} subset_eq {1,2,3});
  124. true
  125. evalb({1,2} subset_eq {1,2});
  126. true
  127. evalb({1,2} subset {1,2});
  128. false
  129. evalb(a subset a union b);
  130. true
  131. \end{verbatim}
  132. \newpage
  133. \begin{verbatim}
  134. evalb(a\b subset a);
  135. true
  136. \end{verbatim}
  137. An undecidable predicate causes a normal \REDUCE\ error, {\em e.g.\ }
  138. \begin{verbatim}
  139. evalb(a subset_eq {b});
  140. ***** Cannot evaluate a subset_eq {b} as Boolean-valued set
  141. expression
  142. \end{verbatim}
  143. \subsection{Set equality}
  144. As explained above, equality of two sets in canonical form can be
  145. reliably tested by the standard \REDUCE\ equality predicate ({\tt =}).