Maple Programs for Logic Design
Converting truth tables to simlified formulas
This program gives the simplified expression of a function given by a truth table.
> TF:=proc(binnum,charlist) local d,f,i,j,k,m,n; with(logic); n:=nops(charlist); for i to 2^n do m[i]:=true; for j to n do m[i]:=m[i] &and `if`(convert(2^n+i-1,base,2)[j]=1,charlist[n-j+1],¬(charlist[n-j+1])) od od; d:=convert(2^(2^n)+convert(binnum,decimal,binary),base,2); f:=false;for k to 2^n do f:=f &or `if`(d[k]=1,m[k],false) od; f:=bsimp(f) end:
Here are a few examples using it. Let
be a function given by a truth table
> TF(0010,[p,q]);
Notice that we enter the values of
from the truth table starting from the row of ones and ending on the row of zeroes. The variables
and
are entered inside square brackets, as a list. The next example explores function
given by a truth table ordered from the row of zeroes to the row of ones. In that case we have to write the values of
from the bottom to the top. Variables
,
, and
are entered as a list, inside square brackets. The initial zero(es) in the binary representation of
can be safely ignored.
> TF(1000111,[a,b,c]);
Now an example of a truth table with "doesn't matter" values (
on p. 213).
> tf:=n->TF(101000101+sum(convert(n+63,base,2)[t]*10^(t+9),t=1..6),[A,B,C,D]):
> gates:=seq(nops(tf(n)),n=1..64): min(gates);
> for n to 64 do if (gates[n]=2) then print(n) fi od;
> tf(1);
> tf(2);
> tf(18);
The last one is the simpliest.