# Re: Truth Table Implementation

## tmk@netvision.net.il (Michael Tiomkin)1 Sep 2003 23:57:23 -0400

From comp.compilers

Related articles
Truth Table Implementation shibu_baby@yahoo.com (2003-08-23)
Re: Truth Table Implementation tmk@netvision.net.il (2003-09-01)
Re: Truth Table Implementation Mario.Trams@informatik.tu-chemnitz.de (Mario Trams) (2003-09-04)
| List of all articles for this month |

 From: tmk@netvision.net.il (Michael Tiomkin) Newsgroups: comp.compilers,sci.logic,comp.lang.vhdl Date: 1 Sep 2003 23:57:23 -0400 Organization: http://groups.google.com/ References: 03-08-081 Keywords: design Posted-Date: 01 Sep 2003 23:57:23 EDT

shibu_baby@yahoo.com (shibu) wrote in message news:03-08-081...
> Hi All,
> I have several truth tables like the following
>
> I/P1 I/P2 I/P3 I/P4 => O/P1, I/P1 I/P2 I/P3 => O/P1 O/P2, I/P1 I/P2
> I/P3 => O/P1 O/P2 O/P3 etc.
>
> I need to implement this as C code. What is the best way to implement
> this. I know SOP/POS will help me to simplify the truth tables.Is
> there any alternative way to solve this. Any generic/optimized way to
> solve this?
> Is there any lookup ideas to help me, so that I can say "N" Inputs and
> "Y" outputs...
>
> Regards
> Shibu

You have a set of dependences of your boolean function. In case that
there is only one function satisfying these dependences, they define
a truth table. The simplest way is to define a set of n k-dimensional
character arrays for a function from 2**k to 2**n (n boolean functions
with k arguments). In you case this might be
'unsigned char arr[4][2][2][2][2];' - n and k are equal to 4..

First, set all the elements of the arrays to some illegal boolean value,
e.g. 'memset(arr, 3, sizeof(arr))'. Then, for every rule, set the array
values to satisfy the rule - 'arr[0][1][1][1][1] = 0;' etc. For consistency
check, test if you ever change a value from 1 to 0 or vice versa -
in this case there is NO truth table satisfying your rules. When you
finished, test if there is an undefined value in the tables, a character
equal to 3 in our case. If this happens, your rules don't completely
define a set of boolean functions.

If you succeeded to build a lookup table, you can see the value
of the result Qi as 'arr[i][p1][p2]...'.

Good luck!

Michael

Post a followup to this message