how to Simplify the the boolean function into POS and SOP forms? - boolean-expression

I'd like to simplify this boolean function: f(a,b,c,d)=∑(1,3,5,8,9,11,15) to its minimal SOP and POS forms.
My solution is:
SOP: A'·B'·C'·D + A'·B'·C·D + A'·B·C'·D + A·B'·C'·D' + A·B'·C'·D' + A·B'·C·D + A·B·C·D
POS: (A+B+C+D)·(A+B+C'+D')·(A+B'+C+D')·(A'+B+C+D)·(A'+B+C+D')·(A'+B+C'+D')·(A'+B+C'+D')
Is it right?
Is there more to do?

The minimal SOP (sum of products) and the minimal POS (product of sums) of the given boolean function are depicted in these two Karnaugh maps.
Each of the necessary terms corresponds by color with the graphic representation.
Using the Karnaugh map for only four variables is really quick, but I could also use the Quine–McCluskey algorithm or rules of Boolean algebra for the minterms and maxterms in the truth table:
index A B C D output minterms maxterms
-------+---------+--------+-------------+--------------------
0 0 0 0 0 0 ~ M0: (a+b+c+d)
1 0 0 0 1 1 ~ m1: a'·b'·c'·d
2 0 0 1 0 0 ~ M2: (a+b+c'+d)
3 0 0 1 1 1 ~ m3: a'·b'·c·d
4 0 1 0 0 0 ~ M4: (a+b'+c+d)
5 0 1 0 1 1 ~ m5: a'·b·c'·d
6 0 1 1 0 0 ~ M6: (a+b'+c'+d)
7 0 1 1 1 0 ~ M7: (a+b'+c'+d')
8 1 0 0 0 1 ~ m8: a·b'·c'·d'
9 1 0 0 1 1 ~ m9: a·b'·c'·d
10 1 0 1 0 0 ~ M10: (a'+b+c'+d)
11 1 0 1 1 1 ~ m11: a·b'·c·d
12 1 1 0 0 0 ~ M12: (a'+b'+c+d)
13 1 1 0 1 0 ~ M13: (a'+b'+c+d')
14 1 1 1 0 0 ~ M14: (a'+b'+c'+d)
15 1 1 1 1 1 ~ m15: a·b·c·d
You can also check the correctness of your future solutions by using wolfram alpha.

Related

permutation/combination with specific condition

Let us we have binary number to fill out 9 spots with specific condition: 0 always comes before 1. the possible conditions is 10:
1 1 1 1 1 1 1 1 1
0 1 1 1 1 1 1 1 1
0 0 1 1 1 1 1 1 1
0 0 0 1 1 1 1 1 1
0 0 0 0 1 1 1 1 1
0 0 0 0 0 1 1 1 1
0 0 0 0 0 0 1 1 1
0 0 0 0 0 0 0 1 1
0 0 0 0 0 0 0 0 1
0 0 0 0 0 0 0 0 0
Now lest us extent it to 0, 1, 2 with same rule. 0 should be always before 1 and/or 2. 1 should be before 1. Again, 9 spots are available to fill out.
I know that this yields to 55 combinations.
Question:
(1) what is the mathematical formulation to generalize this?
(2) How can I store all those 55 combinations? [any matlab code?]
Thanks
As the commenter said, the answer comes down to stars and bars. You can also think of this as counting the number of non-decreasing sequences i_1 <= i_2 <= ... <= i_k, where k is the number of symbols available and each i_j is a number between 0 and 9.
That said, here's a matlab script that generates all possibilities. Each row of the output matrix is one possible string of digits.
function M = bin_combs(L,k)
% L: length
% k: number of symbols
if k == 1
M = zeros(1,L);
else
M = zeros(0,L);
N = bin_combs(L,k-1);
for i = 1:size(N,1)
row = N(i,:);
for j=find(row==k-2)
new_row = row;
new_row(j:end) = new_row(j:end) + 1;
M = [M;new_row];
end
M = [M;row];
end
end
Some sample output:
>> size(bin_combs(9,3))
ans =
55 9
>> size(bin_combs(9,4))
ans =
220 9

solving binary linear equation in matlab

Consider a binary linear equation of form x*A = b. I want to solve for x, the efficiency way is by avoiding using x = b*inv(A) and instead using x= b/A.But with this command results are not in binary form. I tried the command x = mod(b/A ,2)but still result was not in binary. How to fix this?
example
`
x = 1 0 1 1 0 0 0 1 1 0`
and matrix A is
`0 1 0 1 0 0 1 1 1 1
0 1 1 1 1 1 1 1 0 1
0 0 1 0 1 1 0 1 1 1
1 0 0 1 1 1 1 1 1 1
1 1 0 0 1 1 0 0 0 0
0 1 1 1 0 1 1 0 1 0
0 0 1 1 0 0 0 1 0 0
1 1 1 1 0 1 0 1 1 1
1 0 1 0 1 1 1 0 1 1
1 1 1 0 0 0 1 1 0 0`
which is full rank.
then
>> b = mod (x*A,2)
b =
1 0 1 1 1 0 1 0 1 1
To find x, am getting
>> k = b / A
k =
Columns 1 through 6
1.3750 -0.5000 -0.7500 -0.7500 0.8750 -0.5000
Columns 7 through 10
1.8750 -0.5000 2.1250 -0.7500
or if am using modulus 2, the result is
>> k = mod (b / A,2)
k =
Columns 1 through 6
1.3750 1.5000 1.2500 1.2500 0.8750 1.5000
Columns 7 through 10
1.8750 1.5000 0.1250 1.2500
So ,how can I get x in the same binary form? and by the way matrices are all in class double not galois field
This example at Mathworks shows how to perform boolean matrix inversion with MATLAB and I believe answers your question.
I have not quite gotten it working perfectly, but I believe you need to use a combination of mod() and logical() for example:
A=logical(A);
b=(mod(x*A,2));
inverseA= ~A;
k=mod(b*inverseA,2)
this gives
k=[1 1 0 0 1 1 0 1 0 0]
which is not x, but i think if you play around with the logical function and logical operations in conjunction with mod() you should be able to get it to work
To solvexin binary form, matrix A should be in galois field.
consider the following example;
>> x = randi ([0 1],1,10)
x =
1 1 0 1 1 1 0 1 1 1
>> A = gf (randi([0 1],10,10))
A = GF(2) array.
Array elements =
Columns 1 through 6
1 1 1 0 0 1
1 0 1 0 1 0
1 0 1 1 0 1
0 0 0 0 0 1
1 1 1 0 1 1
0 1 0 1 0 1
0 0 0 1 1 1
0 1 0 0 1 0
0 0 1 0 1 0
0 0 1 0 0 1
Columns 7 through 10
1 1 0 0
1 0 1 1
1 1 0 0
0 0 1 0
1 1 1 1
0 1 1 1
1 0 1 0
1 1 1 0
1 0 0 0
1 1 1 0
then,
>> b = x*A
b = GF(2) array.
Array elements =
Columns 1 through 6
1 0 1 1 0 1
Columns 7 through 10
0 1 0 1
>> x_solved = b*inv (A)
x_solved = GF(2) array.
Array elements =
Columns 1 through 6
1 1 0 1 1 1
Columns 7 through 10
0 1 1 1
As you can see x_solved is the same as the original x. Therefore you should convert matrix A to galois field by just running a codeA = gf(A).

Matlab how to bitwise-AND of a vector and a matrix?

I want to find out the index of the matrix column in which the vector appears. My idea is to do AND of the vector over matrix and only the column that is the same will be 1 in the new vecotr. But I don't know how to do this. Below is example:
H =
0 0 0 0 1 1 1 1 1 1 1 1 0 0 0
0 1 1 1 0 0 0 1 1 1 1 0 1 0 0
1 0 1 1 0 1 1 0 0 1 1 0 0 1 0
1 1 0 1 1 0 1 0 1 0 1 0 0 0 1
S =
0 1 0 1
From that I want to get 2 as second column or even better vector
0 1 0 0 0 0 ... 0
Since there is error in second column.
How can I do this in Matlab or even better Octave?
Not really sure how you tried to approach the problem. But with repmat or bsxfun it is as simple as this:
all(bsxfun(#eq,H,S'))
How about
result = sum(H==repmat(S(:),[1 size(H,2)]))==4;
I found out the function
ismember(H', S, "rows")
works exactly as I want. Your answers are all good too, thanks.
That's pretty easy with broadcasting. The following will require Octave 3.6.0 or later but you can use bsxfun if you have a previous version:
octave-cli-3.8.1> h = logical ([
0 0 0 0 1 1 1 1 1 1 1 1 0 0 0
0 1 1 1 0 0 0 1 1 1 1 0 1 0 0
1 0 1 1 0 1 1 0 0 1 1 0 0 1 0
1 1 0 1 1 0 1 0 1 0 1 0 0 0 1]);
octave-cli-3.8.1> s = logical ([0 1 0 1]');
octave-cli-3.8.1> all (h == s)
ans =
0 1 0 0 0 0 0 0 0 0 0 0 0 0 0
From here, it's all a matter of using find to get the column numbers. It will even work if it matches more than 1 column:
octave-cli-3.8.1> find (all (h == s))
ans = 2

a combinational circuit that accepts a 4-bit number and generates a 3-bit binary number output that approximates the square root of the number

Design a combinational circuit that accepts a 4-bit number and generates a 3-bit binary number output that approximates the square root of the number. For example, if the square root is 3.5 or larger, give a result of 4. If the square root is < 3.5 and ≥ 2.5, give a result of 3.
Does my truth table on input goes this way? (I'm using A, B, C, D for my inputs)
INPUTS OUTPUTS Decimal - Square Root Value
__________ __________ ____________________________
A B C D W X Y Z
0 0 0 0 0 0 0 0 0 - 0
0 0 0 1 0 0 0 1 1 - 1
0 0 1 0 0 0 0 1 2 - 1.14
0 0 1 1 0 0 1 0 3 - 1.73
0 1 0 0 0 0 1 0 4 - 2
0 1 0 1 0 0 1 0 5 - 2.23
0 1 1 0 0 0 1 0 6 - 2.44
0 1 1 1 0 0 1 1 7 - 2.64
1 0 0 0 0 0 1 1 8 - 2.82
1 0 0 1 0 0 1 1 9 - 3
1 0 1 0 0 0 1 1 10 - 3.16
1 0 1 1 0 0 1 1 11 - 3.31
1 1 0 0 0 0 1 1 12 - 3.46
1 1 0 1 0 1 0 0 13 - 3.60
1 1 1 0 0 1 0 0 14 - 3.74
1 1 1 1 0 1 0 0 15 - 3.87
I'm having trouble generating the output table with "generates a 3-bit binary number output that approximates the square root of the number" Can someone help me with the outputs? Thank you.
Translate your input as decimal, get square root for each of them, and translate them in binary?
Exemple:
0000 => 0
Square root of 0 is 0
0 => 0000
So you have
A|B|C|D||W|X|Y|Z
0 0 0 0||0 0 0 0
And do the rest of your homework this way?

Calculating a partial cumulative sum for a square matrix

Let's say I have a square matrix M:
M = [0 0 0 0 0 1 9; 0 0 0 0 0 4 4; 0 0 1 1 6 1 1; 0 1 2 9 2 1 0; 2 1 8 3 2 0 0; 0 8 1 1 0 0 0; 14 2 0 1 0 0 0]
0 0 0 0 0 1 9
0 0 0 0 0 4 4
0 0 1 1 6 1 1
M = 0 1 2 9 2 1 0
2 1 8 3 2 0 0
0 8 1 1 0 0 0
14 2 0 1 0 0 0
Now I'd like to calculate two different cumulative sums: One that goes from the top of each column to the element of the column, that is a diagonal element of the matrix, and one that goes from the bottom of the column to the same diagonal element.
The resulting matrix M'should therefore be the following:
0 0 0 0 0 1 9
0 0 0 0 0 4 5
0 0 1 1 6 2 1
M' = 0 1 3 9 4 1 0
2 2 8 5 2 0 0
2 8 1 2 0 0 0
14 2 0 1 0 0 0
I hope the explanation of what I'm trying to achieve is comprehensible enough. Since my matrices are much larger than the one in this example, the calculation should be efficient as well...but so far I couldn't even figure out how to calculate it "inefficiently".
In one line using some flipping and the upper triangular function triu:
Mp = fliplr(triu(fliplr(cumsum(M)),1)) ...
+flipud(triu(cumsum(flipud(M)),1)) ...
+flipud(diag(diag(flipud(M))));
The following will do the job:
Mnew = fliplr(triu(cumsum(triu(fliplr(M)),1))) + flipud(triu(cumsum(triu(flipud(M)),1)));
Mnew = Mnew - fliplr(diag(diag(fliplr(Mnew)))) + fliplr(diag(diag(fliplr(M))));
But is it the fastest method?
I think logical indexing might get you there faster