boolean.tex 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. \documentstyle[11pt,reduce]{article}
  2. \title{BOOLEAN: Computing with boolean expressions}
  3. \date{}
  4. \author{
  5. H. Melenk\\[0.05in]
  6. Konrad--Zuse--Zentrum f\"ur Informationstechnik Berlin \\
  7. Takustra\"se 7 \\
  8. D--14195 Berlin -- Dahlem \\
  9. Federal Republic of Germany \\[0.05in]
  10. E--mail: melenk@zib.de \\[0.05in]
  11. }
  12. \begin{document}
  13. \maketitle
  14. \section{Introduction}
  15. The package {\bf Boolean} supports the computation with
  16. boolean expressions in the propositional calculus.
  17. The data objects are composed from algebraic expressions (``atomic parts'', ``leafs'')
  18. connected by the infix boolean operators {\bf and}, {\bf or},
  19. {\bf implies}, {\bf equiv}, and the unary prefix operator
  20. {\bf not}. {\bf Boolean} allows you to simplify expressions
  21. built from these operators, and to test properties like
  22. equivalence, subset property etc. Also the reduction of
  23. a boolean expression by a partial evaluation and combination
  24. of its atomic parts is supported.
  25. \section{Entering boolean expressions}
  26. In order to distinguish boolean data expressions from
  27. boolean expressions in the \REDUCE programming
  28. language (e.g. in an {\bf if} statement), each expression
  29. must be tagged explicitly by an operator {\bf boolean}.
  30. Otherwise the boolean operators are not accepted in the
  31. \REDUCE algebraic mode input.
  32. The first argument of {\bf boolean} can be any boolean expression,
  33. which may contain references to other boolean values.
  34. \begin{verbatim}
  35. boolean (a and b or c);
  36. q := boolean(a and b implies c);
  37. boolean(q or not c);
  38. \end{verbatim}
  39. Brackets are used to override the operator precedence as usual.
  40. The leafs or atoms of a boolean expression are those parts which
  41. do not contain a leading boolean operator. These are
  42. considered as constants during the boolean evaluation. There
  43. are two pre-defined values:
  44. \begin{itemize}
  45. \item {\bf true}, {\bf t} or {\bf 1}
  46. \item {\bf false}, {\bf nil} or {\bf 0}
  47. \end{itemize}
  48. These represent the boolean constants. In a result
  49. form they are used only as {\bf 1} and {\bf 0}.
  50. By default, a {\bf boolean} expression is converted to a
  51. disjunctive normal form, that is a form where terms are connected
  52. by {\bf or} on the top level and each term is set of leaf
  53. expressions, eventually preceded by {\bf not} and connected
  54. by {\bf and}. An operators {\bf or} or {\bf and} is omitted
  55. if it would have only one single operand. The result of
  56. the transformation is again an expression with leading
  57. operator {\bf boolean} such that the boolean expressions
  58. remain separated from other algebraic data. Only the boolean
  59. constants {\bf 0} and {\bf 1} are returned untagged.
  60. On output, the
  61. operators {\bf and} and {\bf or} are represented as
  62. \verb+/\+ and \verb+\/+, respectively.
  63. \begin{verbatim}
  64. boolean(true and false); -> 0
  65. boolean(a or not(b and c)); -> boolean(not(b) \/ not(c) \/ a)
  66. boolean(a equiv not c); -> boolean(not(a)/\c \/ a/\not(c))
  67. \end{verbatim}
  68. \section{Normal forms}
  69. The {\bf disjunctive} normal form is used by default. It
  70. represents the ``natural'' view and allows us to represent
  71. any form free or parentheses.
  72. Alternatively a {\bf conjunctive} normal form can be
  73. selected as simplification target, which is a form with
  74. leading operator {\bf and}. To produce that form add the keyword {\bf and}
  75. as an additional argument to a call of {\bf boolean}.
  76. \begin{verbatim}
  77. boolean (a or b implies c);
  78. ->
  79. boolean(not(a)/\not(b) \/ c)
  80. boolean (a or b implies c, and);
  81. ->
  82. boolean((not(a) \/ c)/\(not(b) \/ c))
  83. \end{verbatim}
  84. Usually the result is a fully reduced disjunctive or conjuntive normal
  85. form, where all redundant elements have been eliminated following the
  86. rules
  87. $ a \wedge b \vee \neg a \wedge b \longleftrightarrow b$
  88. $ a \vee b \wedge \neg a \vee b \longleftrightarrow b$
  89. Internally the full normal forms are computed
  90. as intermediate result; in these forms each term contains
  91. all leaf expressions, each one exactly once. This unreduced form is returned
  92. when you set the additional keyword {\bf full}:
  93. \begin{verbatim}
  94. boolean (a or b implies c, full);
  95. ->
  96. boolean(a/\b/\c \/ a/\not(b)/\c \/ not(a)/\b/\c \/ not(a)/\not(b)/\c
  97. \/ not(a)/\not(b)/\not(c))
  98. \end{verbatim}
  99. The keywords {\bf full} and {\bf and} may be combined.
  100. \section{Evaluation of a boolean expression}
  101. If the leafs of the boolean expression are algebraic expressions
  102. which may evaluate to logical values because the environment
  103. has changed (e.g. variables have been bound), you can re--investigate
  104. the expression using the operator {\tt testbool} with the boolean
  105. expression as argument. This operator tries to evaluate all
  106. leaf expressions in \REDUCE boolean style. As many
  107. terms as possible are replaced by their boolean values; the others
  108. remain unchanged. The resulting expression is contracted to a
  109. minimal form. The result {\bf 1} (= true) or {\bf 0} (=false)
  110. signals that the complete expression could be evaluated.
  111. In the following example the leafs are built as numeric greater test.
  112. For using ${\bf >}$ in the expressions the greater sign must
  113. be declared operator first. The error messages are meaningless.
  114. \begin{verbatim}
  115. operator >;
  116. fm:=boolean(x>v or not (u>v));
  117. ->
  118. fm := boolean(not(u>v) \/ x>v)
  119. v:=10$
  120. testbool fm;
  121. ***** u - 10 invalid as number
  122. ***** x - 10 invalid as number
  123. ->
  124. boolean(not(u>10) \/ x>10)
  125. x:=3$
  126. testbool fm;
  127. ***** u - 10 invalid as number
  128. ->
  129. boolean(not(u>10))
  130. x:=17$
  131. testbool fm;
  132. ***** u - 10 invalid as number
  133. ->
  134. 1
  135. \end{verbatim}
  136. \end{document}