Maple Programs for Logic Design

Alec Mihailovs

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],&not(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 [Maple Math] be a function given by a truth table

[Maple Math]

> TF(0010,[p,q]);

[Maple Math]

Notice that we enter the values of [Maple Math] from the truth table starting from the row of ones and ending on the row of zeroes. The variables [Maple Math] and [Maple Math] are entered inside square brackets, as a list. The next example explores function [Maple Math] 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 [Maple Math] from the bottom to the top. Variables [Maple Math] , [Maple Math] , and [Maple Math] are entered as a list, inside square brackets. The initial zero(es) in the binary representation of [Maple Math] can be safely ignored.

[Maple Math]

> TF(1000111,[a,b,c]);

[Maple Math]

Now an example of a truth table with "doesn't matter" values ( [Maple Math] 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);

[Maple Math]

> for n to 64 do if (gates[n]=2) then print(n) fi od;

[Maple Math]

[Maple Math]

[Maple Math]

> tf(1);

[Maple Math]

> tf(2);

[Maple Math]

> tf(18);

[Maple Math]

The last one is the simpliest.