
Set Operations
Most operators can be applied to sets, with the operation performed on each
element of the set, sometimes individually and sometimes according to the rules
of Boolean algebra. "Set Operations," found later in this chapter, describes how
these operators are applied to sets.
Two-set Operations
For operations involving two or more sets, the sets must have the same number
of elements. The expression, "[a,b]+[c,d,e]," is not supported because the
sets have different numbers of elements.
For example, the Boolean equation
Chip_Sel = A15 & !A14 & A13;
represents an address decoder where A15, A14 and A13 are the three high-order
bits of a 16-bit address. The decoder can easily be implemented with set
operations. First, a constant set that holds the address lines is defined so that
the set can be referenced by name. This definition is done in the constant
declaration section of a module.
The declaration is
Addr = [A15,A14,A13];
which declares the constant set Addr. The equation
Chip_Sel = Addr == [1,0,1];
is functionally equivalent to
Chip_Sel = A15 & !A14 & A13;
If Addr is equal to [1,0,1], meaning that A15 = 1, A14 = 0 and A13 = 1, then
Chip_Sel is set to true. The set equation could also have been written as
Chip_Sel = Addr == 5;
because 101 binary equals 5 decimal.
In the example above, a special set with the high-order bits of the 16-bit
address was declared and used in the set operation. The full address could have
been used and the same function arrived at in other ways, as shown below.
Example 1
" declare some constants in declaration section
Addr = [a15..a0];
X = .X.; "simplify notation for don't care constant
Chip_Sel = Addr == [1,0,1,X,X,X,X,X,X,X,X,X,X,X,X];
Example 2
" declare some constants in declaration section
Addr = [a15..a0];
X =.X.;
Chip_Sel = (Addr >>= ^HA000) & (Addr <<= ^HBFFF);
Both solutions presented in these final two examples are functionally
equivalent to the original Boolean equation and to the first solution in which only the
high order bits are specified as elements of the set (Addr = [a15, a14, a13]).