Skip to content

Notation of Boolean Formulae

Fredo Erxleben edited this page Apr 29, 2015 · 1 revision

In q2d it is possible to use different notation styles for specifying behaviour. Generally, a specification that contains multiple lines will be joined into one formula, by conjugating each line.

Operators

Most boolean operators can be written down in multiple ways:

Operation              | Mnemonic | Symbols
-----------------------+----------+--------
Negation               | not      | ! or ~
Conjunction            | and      | & or *
Disjunction            | or       | | or +
Exclusive Disjunction  | xor      | ^
Negated Conjunction    | nand     | (none)
Negated Disjunction    | nor      | (none)
Neg. Excl. Disjunction | xnor     | (none)

The negation is prefix, each other operator is infix. Operator precedence cam be expressed by the use of parenthesis.

Caution: If not specified otherwise, operator precedence is from left to right in order of appearance.

Boolean Terms

This simple notation form is composed of variables, operators and parenthesis to express precedence.

For example:

a and not (b xor c)
!r & (s ^ t) | r
a * ~b + c

Note: It is recommended to stick with one set of symbols / mnemonics and not mixing them. Bad example:

x and (!a ^ b) + q

Note: It is recommended to surround infix operators with spaces. Prefix operators should be preceded by a space and not be followed by one. Bad example:

x&(! a^b)|q 

Boolean Equations

It is also possible to use the form

var = term

where var is a boolean variable and term is a boolean term as described above. This is a short notation for

(!var | term) & (var | !term)

which is nothing more then the expansion of the equality operator into a boolean term.

CNF

(Wikipedia)

A clause is specified as a set of (negated) literals in square brackets. For example:

[ x,  y, !z]

Each clause occupies exactly one line, like so:

[ x,  y, !z]
[ x, !y,  z]

Note: Although not strictly required, it is encouraged to prefix positive literals with an extra space to align them their with negated versions. The order in which the literals appear should not be shuffled around.