Thanks,
Nimmi
That's quite an odd question, unanswerable as is. Didn't your professor
give you some more context ?
SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
> Kindly suggest the most elegant and efficient implementation of a
> multi-column truth table.
Perhaps a two-dimensional array?
--
"If a person keeps faithfully busy each hour of the working day, he
can count on waking up some morning to find himself one of the
competent ones of his generation."
--William James
Given a number of boolean inputs, the table lists all possible combinations
of inputs and for each row gives a boolean output.
For example...
A B OUTPUT
F F F
F T T
T F T
T T T
(Are we thinking of the same thing so far?)
The inputs of all truth tables are predictable. If the false becomes 0 and
true becomes 1, the input rows all progress from all zeros to all ones,
counting up in binary. Once we know how many inputs, we can discard them as
they can be trivially recreated.
The only thing left is the outputs. There will always be 2**n outputs.
Store them as a binary value or an array of booleans, whichever is more
convienient in your preferred language.
So now you've stored your output booleans, you need to index that array
given a set of input values. Turn the inputs into a set of bits and then
into a binary value as before, and there's your index.
Bill, twiddling.
> Nimmi wrote:
> ) Kindly suggest the most elegant and efficient implementation of a
> ) multi-column truth table.
>
> That's quite an odd question, unanswerable as is. Didn't your professor
> give you some more context ?
>
>
> SaSW, Willem
BDD are one way to efficiently store simple truth tables.
Are you going to have edges too ?
One way to code truth tables is to use a tabular approach. I will
describe the implementation of "non-boolean" truth tables (if there is
such a thing), since the traditional truth tables are degenerate cases
of the "non-boolean" truth tables
The simplest implementation is to use a multi-dimensional array.
Suppose the truth table has 4 input columns. In this case you could
use a four-dimensional array. Of course this assumes that in each
column the indices are zero-based and contiguous. If that is not the
case, you can still use a multi-dimensional array, but instead of
using the input column entries directly as indices, you can create a
mapping function that maps the input column values to a zero-based
contiguous range and use the mapped values instead. Kindly note that
there is no restriction on the output column of the truth table.
As an alternative, you could use a single dimension array and compute
the correct index to use "manually". Let us assume that the truth
table has four columns: A, B, C and D (arranged most significant to
least significant). Further, let us assume that the range of values
in these columns is as follows:
A 0..a-1 (i.e. number of values equals 'a')
B 0..b-1 (i.e. number of values equals 'b')
C 0..c-1 (i.e. number of values equals 'c')
D 0..d-1 (i.e. number of values equals 'd')
A multi-dimensional array index of the type Table[i][j][k][l] can be
translated into an index into a one-dimensional array using the
following formula:
b*c*d*i + c*d*j + d*k + l
This looks somewhat complicated, but once you get a hang of it, it is
really quite trivial.
Hope that helps
--ZF